From bc4a4a23ef569495fc16afd8fd45ece3ff5c3705 Mon Sep 17 00:00:00 2001 From: Yegappan Lakshmanan Date: Sun, 3 Jan 2021 20:44:46 -0800 Subject: [PATCH] Update help and readme --- README.md | 54 ++++++++++++++++++++++++++++++++++++++++++++++++ autoload/lsp.vim | 17 ++++++++++++++- doc/lsp.txt | 11 +++++++++- plugin/lsp.vim | 4 ++-- 4 files changed, 82 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index a19266f..66a00f4 100644 --- a/README.md +++ b/README.md @@ -2,3 +2,57 @@ Language Server Protocol (LSP) plugin for Vim9. +# Installation + +You can install this plugin directly from github using the following steps: + +``` + $ mkdir -p $HOME/.vim/pack/downloads/lsp + $ cd $HOME/.vim/packa/downloads/lsp + $ git clone https://github.com/yegappan/lsp +``` + +or you can use any one of the Vim plugin managers (dein.vim, pathogen, vam, +vim-plug, volt, Vundle, etc.) to install and manage this plugin. + +You will also need to install one or more language servers corresponding to the +programming languages that you are using. Refer to the https://langserver.org/ +page for the list of available language servers. + +# Configuration + +To register a LSP server, add the following lines to your .vimrc file: +``` + let lspServers = [ + \ { + \ 'filetype': ['c', 'cpp'], + \ 'path': '/usr/local/bin/clangd', + \ 'args': ['--background-index'] + \ }, + \ { + \ 'filetype': ['javascript', 'typescript'], + \ 'path': '/usr/local/bin/typescript-language-server', + \ 'args': ['--stdio'] + \ } + \ { + \ 'filetype': 'sh', + \ 'path': '/usr/local/bin/bash-language-server', + \ 'args': ['start'] + \ }, + \ ] + call lsp#addServer(lspServers) +``` + +The above lines add the LSP servers for C, C++, Javascript, Typescript and +Shell script file types. + +To add a LSP server, the following information is needed: + +Field|Description +-----|----------- +filetype|One or more file types supported by the LSP server. This can be a String or a List. To specify multiple multiple file types, use a List. +path|complete path to the LSP server executable (without any arguments). +args|a list of command-line arguments passed to the LSP server. Each argument is a separate List item. + +The LSP servers are added using the lsp#addServer() function. This function +accepts a list of LSP servers with the above information. diff --git a/autoload/lsp.vim b/autoload/lsp.vim index 2e799c8..ff0cc96 100644 --- a/autoload/lsp.vim +++ b/autoload/lsp.vim @@ -615,7 +615,9 @@ def lsp#updateOutlineWindow(fname: string, :setlocal modifiable :silent! :%d _ - setline(1, ['# File Outline', '# ' .. fname]) + setline(1, ['# LSP Outline View', + '# ' .. fnamemodify(fname, ':t') .. ' (' + .. fnamemodify(fname, ':h') .. ')']) # First two lines in the buffer display comment information var lnumMap: list> = [{}, {}] @@ -710,6 +712,8 @@ enddef def s:outlineCleanup() # Remove the outline autocommands :silent! autocmd! LSPOutline + + :silent! syntax clear LSPTitle enddef # open the symbol outline window @@ -739,6 +743,17 @@ def s:openOutlineWindow() :nnoremap :call outlineJumpToSymbol() :setlocal nomodifiable + # highlight all the symbol types + :syntax keyword LSPTitle File Module Namespace Package Class Method Property + :syntax keyword LSPTitle Field Constructor Enum Interface Function Variable + :syntax keyword LSPTitle Constant String Number Boolean Array Object Key Null + :syntax keyword LSPTitle EnumMember Struct Event Operator TypeParameter + + if str2nr(&t_Co) > 2 + highlight clear LSPTitle + highlight default link LSPTitle Title + endif + prop_type_add('LspOutlineHighlight', {bufnr: bufnr(), highlight: 'Search'}) augroup LSPOutline diff --git a/doc/lsp.txt b/doc/lsp.txt index 552fade..c802252 100644 --- a/doc/lsp.txt +++ b/doc/lsp.txt @@ -80,7 +80,7 @@ The following commands are provided: cursor in a new quickfix list. :LspHighlight Highlight all the matches for the keyword under cursor :LspHighlightClear Clear all the matches highlighted by :LspHighlight -:LspShowSymbols Show the list of symbols defined in the current file +:LspOutline Show the list of symbols defined in the current file in a separate window. :LspFormat Format the current file using the LSP server. :{range}LspFormat Format the specified range of files. @@ -91,6 +91,15 @@ The following commands are provided: :LspRename Rename the current symbol :LspCodeAction Apply the code action supplied by the LSP server to the diagnostic in the current line. +:LspSymbolSearch Perform a workspace wide search for a symbol +:LSPSelectionRange Visually select the current symbol range +:LSPFold Fold the current file +:LspWorkspaceAddFolder {folder} + Add a folder to the workspace +:LspWorkspaceRemoveFolder {folder} + Remove a folder from the workspace +:LspWorkspaceListFolders + Show the list of folders in the workspace ============================================================================== 4. Configuration *lsp-configuration* diff --git a/plugin/lsp.vim b/plugin/lsp.vim index 7f68c82..d60d781 100644 --- a/plugin/lsp.vim +++ b/plugin/lsp.vim @@ -36,8 +36,8 @@ command! -nargs=0 -bar LspCalling call lsp#outgoingCalls() command! -nargs=0 -bar LspRename call lsp#rename() command! -nargs=0 -bar LspCodeAction call lsp#codeAction() command! -nargs=? -bar LspSymbolSearch call lsp#symbolSearch() +command! -nargs=0 -bar LspSelectionRange call lsp#selectionRange() +command! -nargs=0 -bar LspFold call lsp#foldDocument() command! -nargs=0 -bar LspWorkspaceListFolders call lsp#listWorkspaceFolders() command! -nargs=1 -bar -complete=dir LspWorkspaceAddFolder call lsp#addWorkspaceFolder() command! -nargs=1 -bar -complete=dir LspWorkspaceRemoveFolder call lsp#removeWorkspaceFolder() -command! -nargs=0 -bar LspSelectionRange call lsp#selectionRange() -command! -nargs=0 -bar LspFold call lsp#foldDocument() -- 2.48.1