Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FZF support #211

Closed
wants to merge 21 commits into from
Closed

FZF support #211

wants to merge 21 commits into from

Conversation

ddcien
Copy link

@ddcien ddcien commented Dec 13, 2018

FZF support has been integrated into my commits. Now you can handle location, symbol, and code action selections with FZF if it is loaded.

1. Implement lsp#ui#vim#workspace_executecommand;
2. Use FZF for choosing action;
3. Fix parse_range;
4. Implement universal codeAction handler;
5. Implement cquery codeAction handler;
@mkwork
Copy link
Contributor

mkwork commented Dec 13, 2018

Sounds quite cool!

mattn and others added 10 commits December 18, 2018 09:42
* Add <plug> mappings
* Update doc
* Save/restore cursor position
* Cosmetic change
* selection should be inclusive
Because exclusive doesn't select fisrt character with 1GvG0
* Remove last extra \n
* Be graceful
* Use winsaveview/winrestoreview
let l:qfl = getqflist()
call map(l:qfl, {idx, item -> string(idx + 1) . '. ' . fnamemodify(expand(bufname(item['bufnr'])), ":~:.") . ':' . string(item['lnum']) . ':' . string(item['col']) . ':' . item['text']})
call fzf#run(fzf#wrap({'source': l:qfl, 'sink': function('s:jump_to_location'), 'options': '--reverse +m --prompt="Jump> "'}))
endif
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please reverse the condition. We may add yet-another selector in future.

if extensibie1
  call do_extend1()
  return
endif
if extensibie2
  call do_extend2()
  return
endif
call do_original()

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that makes sense. Fixed.

@prabirshrestha prabirshrestha changed the title FZF supoorted FZF support Dec 21, 2018
Copy link
Owner

@prabirshrestha prabirshrestha left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this great PR. Looking forward to it. Would it be possible to break the PR into multiple smaller PRs that can be merged separately?

As for FZF I'm a bit hesitant without full configuration and would like it to be in a different repo because lot of people have their own favorite fuzzy ui and would like to avoid maintaining all possible ui support in this repo. Might be something like lsp#ui#register_quickpick_ui('fzf', s:fuzzy_ui)that others can call and the user can set the default let g:lsp_default_fuzzy_ui = 'fzf'. This would allow anyone to build something like vim-lsp-ui-fzf.vim, vim-lsp-ui-ctrlp.vim, vim-lsp-ui-vim-fz.vim, vim-lsp-ui-denite.vim as external repos. I'm more than happy to officially endorse it in README.md. The primary reason I'm not fan of any fuzzy ui in vim is because they don't support 'on_change' callback when searching which is very useful when searching workspace symbols and other big searches.

@@ -135,7 +137,7 @@ function! s:register_events() abort
autocmd BufReadPost * call s:on_text_document_did_open()
autocmd BufWritePost * call s:on_text_document_did_save()
autocmd BufWinLeave * call s:on_text_document_did_close()
autocmd InsertLeave * call s:on_text_document_did_change()
autocmd InsertLeave,TextChanged * call s:on_text_document_did_change()
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would need to debounce TextChanged as it could slow down vim due to did change. When we implement incremental change it would be easier. But there is a PR currently for it at #188

return
endif

while l:index < len(l:codeActions)
call add(l:choices, string(l:index + 1) . ' - ' . l:codeActions[index]['title'])
if a:action['command'] ==# 'cquery._applyFixIt'
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:( we shouldn't add lang server specific things here. Why is this needed?

@@ -54,6 +55,14 @@ let s:symbol_kinds = {
\ '16': 'number',
\ '17': 'boolean',
\ '18': 'array',
\ '19': 'object',
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this can be in a different PR.

@prabirshrestha
Copy link
Owner

I'm getting closer to implementing a new fuzzy search plugin in vim with on_change support. The api will look something like this. (I haven't pushed the code yet)

function! s:on_change(id, value) abort
    " todo: properly debounce and cancel previous on-going search
    call s:search_npm(a:value, {items->quickpick#set_items(a:id, items)})
endfunction

function! s:on_accept(id, items) abort
    " use jobs for async install
    call quickpick#close(a:id)
    call job_start([&shell, &shellcmdflag, 'npm install ' . a:items[0]])
endfunction

let id = quickpick#create({
    \ 'on_change': function('s:on_change'),
    \ 'on_accept': function('s:on_accept'),
    \ 'auto_open': 0
    \ })
call quickpick#show(id)

Simple pickers one can directly using this api.

call quickpick#create({
    \ 'on_accept': function('s:on_accept'),
    \ 'items': ['item1', 'item2'],
    \ })

Then we can expose a extension point in vim-lsp that will look something like this.

call lsp#register_quickpick_ui('quickpick.vim', function('s:quickpick_vim'))
call lsp#register_quickpick_ui('ctrlp', function('s:ctrlp_quickpick'))
call lsp#register_quickpick_ui('fzf', function('s:fzf_quickpick'))
let g:lsp_default_quickpick_ui = 'fzf'

We need to figure out what the interface for register_quickpick_ui would like.

@prabirshrestha
Copy link
Owner

I have pushed the code for quickpick.vim. It is at a very early stage. In the meantime you can refer to prabirshrestha/quickpick.vim#1 for roadmap. I wouldn;'t support quickpick yet in vim-lsp because it is still very much work in progress and the api's may change.

@prabirshrestha
Copy link
Owner

Finally got a proof of concept for quickpick. Here is how it looks. This makes it lot more powerful than FZF/Ctrlp and would work well for document and specially workspace symbols where a project could have possible thousands of symbols and you would want the langserver to search instead of vim-lsp. quickpick.vim just acts as a dump ui.

NPM Picker

All the above is implemented in pure vimscript and follows the footstep of vim-lsp and asyncomplete.vim

Note: quickpick.vim is very much work in progress https://github.com/prabirshrestha/quickpick.vim

@mattn
Copy link
Collaborator

mattn commented Feb 15, 2019

Hi @ddcien

Thanks your contribution. Will you work about this PR ? If you don't, I'll continue to implement codeAction with your commits.

@edganiukov
Copy link

I would love to have FZF support.

@mattn
Copy link
Collaborator

mattn commented Mar 19, 2019

IMO, I do not like to lock-in to 1 selector command.

@prabirshrestha
Copy link
Owner

No plans to support FZF as first class support. There are lot of fuzzy search UI and I would like to avoid supporting N number of UIs. I personally use ctrlp and vim-fz with fzf executable which I find it lot better than fzf.vim.

if executable('fzf')
  nmap ,f <Plug>(fz)
  let g:fz_command = 'fzf'
  let g:fz_command_files = ''
  let g:fz_command_options_action = '--expect=%s'
  let g:ctrlp_map = ''
  nnoremap <C-p> :call fz#run({ 'type': 'cmd', 'cmd': 'git ls-files' })<CR>
else

Feel free to send a PR support for extending vim-lsp something like this.

call lsp#register_list_ui(myfzflistui#options())
let g:lsp_list_ui = ['fzf', 'quickfix', 'loclist']`

@mkwork
Copy link
Contributor

mkwork commented Jun 16, 2019

Fuzzy is not particular solution. That's algorithm.

@jiz4oh
Copy link
Contributor

jiz4oh commented Aug 16, 2023

Hi everyone, I have created a plugin vim-lspfuzzy that can show etc. documentsymbol and references in fzf window, any suggestion is appreciated and pr welcome

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants