From c07585b588071adc8e9670becadb89307153e4d1 Mon Sep 17 00:00:00 2001 From: Jonatha Gabriel <60396154+j0ng4b@users.noreply.github.com> Date: Tue, 11 Jun 2024 04:56:38 -0300 Subject: [PATCH] Added support to yeagappan lsp (#472) * Added support to yeagappan lsp * Update README and docs. --- README.md | 1 + autoload/vista/executive/yegappan_lsp.vim | 90 +++++++++++++++++++++++ doc/vista.txt | 3 + 3 files changed, 94 insertions(+) create mode 100644 autoload/vista/executive/yegappan_lsp.vim diff --git a/README.md b/README.md index 1b71144..ccce074 100644 --- a/README.md +++ b/README.md @@ -53,6 +53,7 @@ In addition to being a tags viewer, vista.vim can also be a symbol navigator sim - [x] [LanguageClient-neovim](https://github.com/autozimu/LanguageClient-neovim) - [x] [vim-lsc](https://github.com/natebosch/vim-lsc) - [x] [nvim-lspconfig](https://github.com/neovim/nvim-lspconfig) + - [x] [yegappan lsp](https://github.com/yegappan/lsp) - [x] Finder for tags and LSP symbols. - [x] [fzf](https://github.com/junegunn/fzf) - [x] [skim](https://github.com/lotabout/skim) diff --git a/autoload/vista/executive/yegappan_lsp.vim b/autoload/vista/executive/yegappan_lsp.vim new file mode 100644 index 0000000..16f0e90 --- /dev/null +++ b/autoload/vista/executive/yegappan_lsp.vim @@ -0,0 +1,90 @@ +" Copyright (c) 2019 Liu-Cheng Xu +" MIT License +" vim: ts=2 sw=2 sts=2 et + +let s:provider = fnamemodify(expand(''), ':t:r') + +let s:reload_only = v:false +let s:should_display = v:false + +let s:fetching = v:true + +function! s:HandleLSPResponse(server, results) abort + let s:fetching = v:false + if empty(a:results) + return [] + endif + + let s:data = vista#renderer#LSPPreprocess(a:results) + + if !empty(s:data) + let [s:reload_only, s:should_display] = vista#renderer#LSPProcess(s:data, s:reload_only, s:should_display) + + " Update cache when new data comes. + let s:cache = get(s:, 'cache', {}) + let s:cache[s:fpath] = s:data + let s:cache.ftime = getftime(s:fpath) + let s:cache.bufnr = bufnr('') + endif + + call vista#cursor#TryInitialRun() +endfunction + +function! s:AutoUpdate(fpath) abort + let s:reload_only = v:true + let s:fpath = a:fpath + call s:RunAsync() +endfunction + +function! s:Run() abort + call s:RunAsync() + while s:fetching + sleep 100m + endwhile + return get(s:, 'data', {}) +endfunction + +function! s:RunAsync() abort + call vista#SetProvider(s:provider) + + let bufnum = bufnr('%') + let params = #{textDocument: #{uri: lsp#util#LspFileToUri(bufname(bufnum))}} + let servers = lsp#buffer#BufLspServersGet(bufnum) + + for server in servers + if !server.isDocumentSymbolProvider + continue + endif + + silent call server.rpc_a('textDocument/documentSymbol', params, function('s:HandleLSPResponse')) + endfor +endfunction + +function! vista#executive#yegappan_lsp#Run(fpath) abort + let s:fpath = a:fpath + return s:Run() +endfunction + +function! vista#executive#yegappan_lsp#RunAsync() abort + call s:RunAsync() +endfunction + +function! vista#executive#yegappan_lsp#Execute(bang, should_display, ...) abort + call vista#source#Update(bufnr('%'), winnr(), expand('%'), expand('%:p')) + let s:fpath = expand('%:p') + + call vista#OnExecute(s:provider, function('s:AutoUpdate')) + + let g:vista.silent = v:false + let s:should_display = a:should_display + + if a:bang + return s:Run() + else + call s:RunAsync() + endif +endfunction + +function! vista#executive#yegappan_lsp#Cache() abort + return get(s:, 'cache', {}) +endfunction diff --git a/doc/vista.txt b/doc/vista.txt index 3b72a7e..e8cea6b 100644 --- a/doc/vista.txt +++ b/doc/vista.txt @@ -47,6 +47,7 @@ FEATURES *vista-feature [x] LanguageClient-neovim (https://github.com/autozimu/LanguageClient-neovim) [x] vim-lsc (https://github.com/natebosch/vim-lsc) [x] nvim-lsp (https://github.com/neovim/neovim) + [x] yegappan lsp (https://github.com/yegappan/lsp) [x] Finder for tags and LSP symbols. [x] fzf (https://github.com/junegunn/fzf) [x] Display decent detailed symbol info in cmdline. @@ -124,6 +125,8 @@ Vista *Vist `:Vista nvim_lsp` open vista window based on nvim-lsp. + `:Vista yegappan_lsp` open vista window based on yeagappan lsp. + *vista-finder* `:Vista finder` same with `:Vista finder fzf:ctags` .