]> Sergey Matveev's repositories - vim-lsp.git/commitdiff
Use sync RPC for text selection. Update the help text.
authorYegappan Lakshmanan <yegappan@yahoo.com>
Sat, 8 Oct 2022 15:25:31 +0000 (08:25 -0700)
committerYegappan Lakshmanan <yegappan@yahoo.com>
Sat, 8 Oct 2022 15:25:31 +0000 (08:25 -0700)
README.md
autoload/lsp/handlers.vim
autoload/lsp/lspserver.vim
doc/lsp.txt

index 7fa2bc886235a699063ce86e01fb75e5969afde1..8a9446862f5a861ed24f560f15ec654c63d5686b 100644 (file)
--- a/README.md
+++ b/README.md
@@ -1,6 +1,6 @@
 ![unit-tests](https://github.com/yegappan/mru/workflows/unit-tests/badge.svg?branch=master)
 
-Language Server Protocol (LSP) plugin for Vim9. You need Vim version 9.0 or above to use this plugin.
+Language Server Protocol (LSP) plugin for Vim. You need Vim version 9.0 or above to use this plugin.  This plugin is written using only the Vim9 script.
 
 ## Installation
 
@@ -23,8 +23,28 @@ You can also install and manage this plugin using any one of the Vim plugin mana
 
 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.
 
+## Features
+
+The following language server protocol (LSP) features are supported:
+
+* Code completion
+* Jump to definition, declaration, implementation, type definition
+* Display warning and error diagnostics
+* Find all symbol references
+* Workspace symbol search
+* Display code outline
+* Rename symbol
+* Display type and documentation on hover
+* Inlay hints
+* Code action
+* Formatting code
+* Folding code
+* Visually select symbol block/region
+
 ## Configuration
 
+To use the plugin features with a particular file type(s), you need to first register a LSP server for that file type(s).
+
 To register a LSP server, add the following lines to your .vimrc file (use only the LSP servers that you need from the below list):
 ```
    let lspServers = [
@@ -83,7 +103,7 @@ To register a LSP server, add the following lines to your .vimrc file (use only
    call LspAddServer(lspServers)
 ```
 
-The above lines add the LSP servers for C, C++, Javascript, Typescript, Shell script, Vim script, Go, Rust, Python and Fortran file types.
+The above lines add the LSP servers for C, C++, Javascript, Typescript, Shell script, Vim script, Go, Rust, Python and Fortran file types.  In addition to the above listed file types, this plugin also supports other file types.
 
 To add a LSP server, the following information is needed:
 
@@ -96,6 +116,9 @@ args|a list of command-line arguments passed to the LSP server. Each argument is
 The LSP servers are added using the LspAddServer() function. This function accepts a list of LSP servers with the above information.
 
 ## Supported Commands
+
+The following commands are provided to use the LSP features.
+
 Command|Description
 -------|-----------
 :LspShowServers|Display the list of registered LSP servers
index 85f41eec452b4cf279759d3518d1e65c2d286819..79efc0aeb4213eb8ef03aaa5c471ca98e173f943 100644 (file)
@@ -12,7 +12,6 @@ import './textedit.vim'
 import './symbol.vim'
 import './codeaction.vim'
 import './callhierarchy.vim' as callhier
-import './selection.vim'
 import './signature.vim'
 
 # process the 'initialize' method reply from the LSP server
@@ -474,16 +473,6 @@ def ProcessCodeActionReply(lspserver: dict<any>, req: dict<any>, reply: dict<any
   codeaction.ApplyCodeAction(lspserver, reply.result)
 enddef
 
-# Reply: 'textDocument/selectionRange'
-# Result: SelectionRange[] | null
-def ProcessSelectionRangeReply(lspserver: dict<any>, req: dict<any>, reply: dict<any>)
-  if reply.result->empty()
-    return
-  endif
-
-  selection.SelectionStart(lspserver, reply.result)
-enddef
-
 # Reply: 'textDocument/foldingRange'
 # Result: FoldingRange[] | null
 def ProcessFoldingRangeReply(lspserver: dict<any>, req: dict<any>, reply: dict<any>)
@@ -650,7 +639,6 @@ export def ProcessReply(lspserver: dict<any>, req: dict<any>, reply: dict<any>):
       'textDocument/rangeFormatting': ProcessFormatReply,
       'textDocument/rename': ProcessRenameReply,
       'textDocument/codeAction': ProcessCodeActionReply,
-      'textDocument/selectionRange': ProcessSelectionRangeReply,
       'textDocument/foldingRange': ProcessFoldingRangeReply,
       'workspace/executeCommand': ProcessWorkspaceExecuteReply,
       'workspace/symbol': ProcessWorkspaceSymbolReply,
index aa5545900c9ce2dc1e0121914290b15913f0633c..dfa48860e6a5c68bc1a1b2d83c0c1425764ee324 100644 (file)
@@ -920,13 +920,19 @@ def SelectionRange(lspserver: dict<any>, fname: string)
   # clear the previous selection reply
   lspserver.selection = {}
 
-  var req = lspserver.createRequest('textDocument/selectionRange')
   # interface SelectionRangeParams
   # interface TextDocumentIdentifier
-  req.params->extend({textDocument: {uri: util.LspFileToUri(fname)}, positions: [GetLspPosition()]})
-  lspserver.sendMessage(req)
+  var param = {}
+  param.textDocument = {}
+  param.textDocument.uri = util.LspFileToUri(fname)
+  param.positions = [GetLspPosition()]
+  var resp = lspserver.rpc('textDocument/selectionRange', param)
 
-  lspserver.waitForResponse(req)
+  if resp->empty() || resp.result->empty()
+    return
+  endif
+
+  selection.SelectionStart(lspserver, resp.result)
 enddef
 
 # Expand the previous selection or start a new one
index 99cb875941f6293215f184741fb60f149ac10228..3d07de71ce5261fcb33d84ba76f72d17f1c4cabf 100644 (file)
@@ -2,7 +2,7 @@
 
 Author: Yegappan Lakshmanan  (yegappan AT yahoo DOT com)
 For Vim version 9.0 and above
-Last change: Sep 29, 2022
+Last change: Oct 7, 2022
 
 ==============================================================================
                                                *lsp-license*
@@ -292,6 +292,10 @@ diagnostic messages, you can add the following line to your .vimrc file:
                        can be used to go back up the tag stack.  Also the
                        |``| mark is set to the position before the jump.
 
+                       You may want to map a key to invoke this command: >
+
+                           nnoremap <buffer> gd <Cmd>LspGotoDefinition<CR>
+<
                                                *:LspGotoDeclaration*
 :LspGotoDeclaration    Jumps to the declaration of the symbol under the
                        cursor. The behavior of this command is similar to the
@@ -303,12 +307,20 @@ diagnostic messages, you can add the following line to your .vimrc file:
                        |:LspGotoDefinition| command. Note that not all the LSP
                        servers support this feature.
 
+                       You may want to map a key to invoke this command: >
+
+                           nnoremap <buffer> gt <Cmd>LspGotoTypeDef<CR>
+<
                                                *:LspGotoImpl*
 :LspGotoImpl           Jumps to the implementation of the symbol under the
                        cursor. The behavior of this command is similar to the
                        |:LspGotoDefinition| command. Note that not all the LSP
                        servers support this feature.
 
+                       You may want to map a key to invoke this command: >
+
+                           nnoremap <buffer> gi <Cmd>LspGotoImpl<CR>
+<
                                                *:LspPeekDefinition*
 :LspPeekDefinition     Displays the line where the symbol under the cursor is
                        defined in the |preview-window|. The symbol is
@@ -502,24 +514,33 @@ diagnostic messages, you can add the following line to your .vimrc file:
                        Default is false
 
                                                *:LspSelectionExpand*
-:LspSelectionExpand    Expand the current symbol range visual selection. It
-                       is useful to create a visual map to use this command.
-                       Example: >
+:LspSelectionExpand    Visually select the region of the symbol under the
+                       cursor.  In visual mode, expands the current symbol
+                       visual region selection to include the next level.
+
+                       For example, if the cursor is on a "for" statement,
+                       this command selects the "for" statement and the body
+                       of the "for" statement.
+
+                       It is useful to create a visual map to use this
+                       command.  Example: >
 
-                           xnoremap <silent> le <Cmd>LspSelectionExpand<CR>
+                        xnoremap <silent> <Leader>e <Cmd>LspSelectionExpand<CR>
 <
-                       With the above map, you can press "le" in visual mode
-                       successively to expand the current visual region.
+                       With the above map, you can press "\e" in visual mode
+                       successively to expand the current symbol visual
+                       region.
 
                                                *:LspSelectionShrink*
 :LspSelectionShrink    Shrink the current symbol range visual selection. It
                        is useful to create a visual map to use this command.
                        Example: >
 
-                           xnoremap <silent> ls <Cmd>LspSelectionShrink<CR>
+                        xnoremap <silent> <Leader>s <Cmd>LspSelectionShrink<CR>
 <
-                       With the above map, you can press "ls" in visual mode
-                       successively to shrink the current visual region.
+                       With the above map, you can press "\s" in visual mode
+                       successively to shrink the current symbol visual
+                       region.
 
                                                *:LspFold*
 :LspFold               Fold the current file.