
-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
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 = [
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:
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
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
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>)
'textDocument/rangeFormatting': ProcessFormatReply,
'textDocument/rename': ProcessRenameReply,
'textDocument/codeAction': ProcessCodeActionReply,
- 'textDocument/selectionRange': ProcessSelectionRangeReply,
'textDocument/foldingRange': ProcessFoldingRangeReply,
'workspace/executeCommand': ProcessWorkspaceExecuteReply,
'workspace/symbol': ProcessWorkspaceSymbolReply,
# 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
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*
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
|: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
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.