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). If you used [vim-plug](https://github.com/junegunn/vim-plug) to install the LSP plugin, the steps are described later in this section.
```viml
-vim9script
-
-# Clangd language server
-LspAddServer([{
- name: 'clangd',
- filetype: ['c', 'cpp'],
- path: '/usr/local/bin/clangd',
- args: ['--background-index']
- }])
-
-# Javascript/Typescript language server
-LspAddServer([{
- name: 'typescriptlang',
- filetype: ['javascript', 'typescript'],
- path: '/usr/local/bin/typescript-language-server',
- args: ['--stdio'],
- }])
-
-# Go language server
-LspAddServer([{
- name: 'golang',
- filetype: ['go', 'gomod'],
- path: '/usr/local/bin/gopls',
- args: ['serve'],
- syncInit: v:true
- }])
-
-# Rust language server
-LspAddServer([{
- name: 'rustlang',
- filetype: ['rust'],
- path: '/usr/local/bin/rust-analyzer',
- args: [],
- syncInit: v:true
- }])
+
+" Clangd language server
+call LspAddServer([#{
+ \ name: 'clangd',
+ \ filetype: ['c', 'cpp'],
+ \ path: '/usr/local/bin/clangd',
+ \ args: ['--background-index']
+ \ }])
+
+" Javascript/Typescript language server
+call LspAddServer([#{
+ \ name: 'typescriptlang',
+ \ filetype: ['javascript', 'typescript'],
+ \ path: '/usr/local/bin/typescript-language-server',
+ \ args: ['--stdio'],
+ \ }])
+
+" Go language server
+call LspAddServer([#{
+ \ name: 'golang',
+ \ filetype: ['go', 'gomod'],
+ \ path: '/usr/local/bin/gopls',
+ \ args: ['serve'],
+ \ syncInit: v:true
+ \ }])
+
+" Rust language server
+call LspAddServer([#{
+ \ name: 'rustlang',
+ \ filetype: ['rust'],
+ \ path: '/usr/local/bin/rust-analyzer',
+ \ args: [],
+ \ syncInit: v:true
+ \ }])
```
The above lines register the language servers for C/C++, Javascript/Typescript, Go and Rust file types. Refer to the [Wiki](https://github.com/yegappan/lsp/wiki) page for various language server specific configuration.
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.
-initializationOptions|User provided initialization options. May be of any type. For example the *intelephense* PHP language server accept several options here with the License Key among others.
+initializationOptions|User provided initialization options. May be of any type. For example the *intelephense* PHP language server accept several options here with the License Key among others.
customNotificationHandlers|A dictionary of notifications and functions that can be specified to add support for custom language server notifications.
features|A dictionary of booleans that can be specified to toggle what things a given LSP is providing (folding, goto definition, etc) This is useful when running multiple servers in one buffer.
If you used [vim-plug](https://github.com/junegunn/vim-plug) to install the LSP plugin, then you need to use the VimEnter autocmd to initialize the LSP server and to set the LSP server options. For example:
```viml
-vim9script
-var lspServers = [
- {
- name: 'clang',
- filetype: ['c', 'cpp'],
- path: '/usr/local/bin/clangd',
- args: ['--background-index']
- }
- ]
-autocmd VimEnter * LspAddServer(lspServers)
-
-var lspOpts = {'autoHighlightDiags': v:true}
-autocmd VimEnter * LspOptionsSet(lspOpts)
+let lspServers = [
+ \ #{
+ \ name: 'clang',
+ \ filetype: ['c', 'cpp'],
+ \ path: '/usr/local/bin/clangd',
+ \ args: ['--background-index']
+ \ }
+ \ ]
+autocmd VimEnter * call LspAddServer(lspServers)
+
+let lspOpts = {'autoHighlightDiags': v:true}
+autocmd VimEnter * call LspOptionsSet(lspOpts)
```
## Supported Commands
*lsp.txt* Language Server Protocol (LSP) Plugin for Vim9
- ___ _______ _______ ~
- | | | || |~
- | | | _____|| _ |~
- | | | |_____ | |_| |~
- | |___ |_____ || ___|~
- | | _____| || | ~
- |_______||_______||___| ~
-
-
Author: Yegappan Lakshmanan (yegappan AT yahoo DOT com)
For Vim version 9.0 and above
Last change: April 11, 2023
+==============================================================================
+ *lsp-license*
+License: MIT License
+Copyright (c) 2020-2023 Yegappan Lakshmanan
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to
+deal in the Software without restriction, including without limitation the
+rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+sell copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+IN THE SOFTWARE.
+
==============================================================================
CONTENTS *lsp-contents*
15. Custom LSP Completion Kinds .............. |lsp-custom-kinds|
16. Multiple Language Servers for a buffer ... |lsp-multiple-servers|
17. Language Servers Features ................ |lsp-features|
- 18. License .................................. |lsp-license|
==============================================================================
1. Overview *lsp-overview*
filetype: ['go', 'gomod', 'gohtmltmpl', 'gotexttmpl'],
path: '/path/to/.go/bin/gopls',
args: [],
- syncInit: v:true,
+ syncInit: true,
},
{
name: 'rustls',
filetype: ['rust'],
path: '/path/to/.cargo/bin/rust-analyzer',
args: [],
- syncInit: v:true,
+ syncInit: true,
},
{
name: 'bashls',
filetype: ['php'],
path': '/usr/local/bin/intelephense',
args: ['--stdio'],
- syncInit: v:true,
+ syncInit: true,
initializationOptions: {
licenceKey: 'xxxxxxxxxxxxxxx'
}
*lsp-cfg-omnicompl*
omnicompl (Optional) a boolean value that enables (true)
or disables (false) omni-completion for this file
- types. By default this is set to "v:true".
+ types. By default this is set to "true".
*lsp-cfg-syncInit*
syncInit (Optional) for language servers (e.g. rust analyzer,
gopls, etc.) that take time to initialize and reply to
a "initialize" request message this should be set to
- "v:true". If this is set to true, then a synchronous
+ "true". If this is set to true, then a synchronous
call is used to initialize the language server,
otherwise the server is initialized asynchronously.
- By default this is set to "v:false".
+ By default this is set to "false".
*lsp-cfg-debug*
debug (Optional) log the messages printed by this language
server in stdout and stderr to a file. Useful for
]
autocmd VimEnter * LspAddServer(lspServers)
- var lspOpts = {'autoHighlightDiags': v:true}
+ var lspOpts = {'autoHighlightDiags': true}
autocmd VimEnter * LspOptionsSet(lspOpts)
<
*lsp-options* *LspOptionsSet*
For example, to disable the automatic placement of signs for the LSP
diagnostic messages, you can add the following line to your .vimrc file: >
- LspOptionsSet({'autoHighlightDiags': v:false})
+ LspOptionsSet({'autoHighlightDiags': false})
<
The LspOptionsGet() function returns a |Dict| of all the LSP plugin options,
To get a particular option value you can use the following: >
*:LspDiagCurrent*
:LspDiagCurrent Displays the diagnostic message (if any) for the
current line. If the option 'showDiagInPopup' is set
- to v:true (default), then the message is displayed in
+ to true (default), then the message is displayed in
a popup window. Otherwise the message is displayed in
the status message area.
documentation in the preview window instead of in a
popup set >
- LspOptionsSet({'hoverInPreview': v:true})
+ LspOptionsSet({'hoverInPreview': true})
<
Default is false.
references in a quickfix list instead of in a location
list set >
- LspOptionsSet({'useQuickfixForLocations': v:true})
+ LspOptionsSet({'useQuickfixForLocations': true})
<
*:LspShowSignature*
:LspShowSignature Displays the signature of the symbol (e.g. a function
this, you can set the showSignature option to false in
your .vimrc file: >
- LspOptionsSet({'showSignature': v:false})
+ LspOptionsSet({'showSignature': false})
<
Default is true.
You can get the function signature echoed in cmdline
rather than displayed in popup if you use >
- LspOptionsSet({'echoSignature': v:true})
+ LspOptionsSet({'echoSignature': true})
<
Default is false.
use the keys described in |popupmenu-keys| with this menu.
To disable the auto-completion for all the files, you can set the
-'autoComplete' option to v:false in your .vimrc file: >
+'autoComplete' option to false in your .vimrc file: >
- LspOptionsSet({'autoComplete': v:false})
+ LspOptionsSet({'autoComplete': false})
<
If this variable is set, then the LSP plugin will not automatically start
completion in insert mode and instead supports omni-completion (|compl-omni|).
var lspServers = [
{
filetype: 'python',
- omnicompl: v:false,
+ omnicompl: false,
path: '/usr/local/bin/pyls',
args: ['--check-parent-process', '-v']
}
|:LspDiagHighlightEnable| command.
To disable the automatic placement of signs on the lines with a diagnostic
-message, you can set the 'autoHighlightDiags' option to v:false: >
+message, you can set the 'autoHighlightDiags' option to false: >
- LspOptionsSet({'autoHighlightDiags': v:false})
+ LspOptionsSet({'autoHighlightDiags': false})
<
-By default the 'autoHighlightDiags' option is set to v:true.
+By default the 'autoHighlightDiags' option is set to true.
The function lsp#lsp#ErrorCount() function can be used to get the count of the
diagnostic messages in the current buffer by type. This function returns a
The |:LspDiagShow| command creates a new location list with the current list
of diagnostics for the current buffer. To automatically add the diagnostics
messages to the location list, you can set the 'autoPopulateDiags' option to
-v:true. By default this option is set to v:false.
+true. By default this option is set to false.
When using GUI Vim or in a terminal Vim with 'ballooneval' option set, when
the mouse is moved over the diagnostic sign displayed in the sign column, then
the diagnostic message is displayed in a popup. By default, the diagnostic
message popup is not displayed when the mouse is moved over the text in the
line. To display the diagnostic message when hovering the mouse over the text
-of the line, you can set the 'noDiagHoverOnLine' option to v:false. By
-default, this option is set to v:true.
+of the line, you can set the 'noDiagHoverOnLine' option to false. By
+default, this option is set to true.
To display the diagnostic message for the current line in the status area, you
-can set the 'showDiagOnStatusLine' option to v:true. By default, this option
-is set to v:false.
+can set the 'showDiagOnStatusLine' option to true. By default, this option
+is set to false.
By default, the |:LspDiagCurrent| command displays the diagnostic message for
the current line in a popup window. To display the message in the status
:LspServer debug off
<
By default, the messages are not logged. Another method to enable the debug
-is to set the "debug" field to v:true when adding a language server
+is to set the "debug" field to true when adding a language server
using |LspAddServer()|.
The messages printed by the language server in the stdout are logged to the
1. change the order of language servers, and specify that a given language
server should be used for a given method.
-2. set the unwanted features to |v:false| in the features |Dictionary| >
+2. set the unwanted features to |false| in the features |Dictionary| >
- features: { 'codeAction': v:false }
+ features: { 'codeAction': false }
<
For example, if you want to use the efm-langserver for formatting, but the
typescript-language-server for everything else: >
diagnostics Used to disable diagnostics for a single
language server, by default diagnostics are
combined from all running servers, by setting
- this to |v:false| you can ignore diagnostics
+ this to |false| you can ignore diagnostics
from a specific server.
*lsp-features-documentFormatting*
documentFormatting Used by |:LspFormat|, and 'formatexpr'
*lsp-features-typeDefinition*
typeDefinition Used by |:LspGotoTypeDef|, and |:LspPeekTypeDef|
-==============================================================================
- *lsp-license*
-License: MIT License
-Copyright (c) 2020-2023 Yegappan Lakshmanan
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to
-deal in the Software without restriction, including without limitation the
-rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
-sell copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
-IN THE SOFTWARE.
vim:tw=78:ts=8:noet:ft=help:norl: