1 *lsp.txt* Language Server Protocol (LSP) Plugin for Vim9
4 Author: Yegappan Lakshmanan (yegappan AT yahoo DOT com)
5 For Vim version 9.0 and above
6 Last change: June 25, 2023
8 ==============================================================================
9 CONTENTS *lsp-contents*
11 1. Overview ................................. |lsp-overview|
12 2. Requirements ............................. |lsp-installation|
13 3. Usage .................................... |lsp-usage|
14 4. Configuration............................. |lsp-configuration|
15 5. Commands ................................. |lsp-commands|
16 6. Insert Mode Completion ................... |lsp-ins-mode-completion|
17 7. Diagnostics .............................. |lsp-diagnostics|
18 8. Tag Function ............................. |lsp-tagfunc|
19 9. LSP Formatting ........................... |lsp-format|
20 10. Call Hierarchy ........................... |lsp-call-hierarchy|
21 11. Autocommands ............................. |lsp-autocmds|
22 12. Highlight Groups ......................... |lsp-highlight-groups|
23 13. Debugging ................................ |lsp-debug|
24 14. Custom Command Handlers .................. |lsp-custom-commands|
25 15. Custom LSP Completion Kinds .............. |lsp-custom-kinds|
26 16. Multiple Language Servers for a buffer ... |lsp-multiple-servers|
27 17. Language Servers Features ................ |lsp-features|
28 18. License .................................. |lsp-license|
30 ==============================================================================
31 1. Overview *lsp-overview*
33 The Language Server Protocol (LSP) plugin implements a LSP client for Vim9.
34 Refer to the following pages for more information about LSP:
36 https://microsoft.github.io/language-server-protocol/
37 https://langserver.org/
39 This plugin needs Vim version 9.0 and after. You will need a programming
40 language specific server in your system to use this plugin. Refer to the above
41 pages for a list of available language servers for the various programming
44 The Github repository for this plugin is available at:
46 http://github.com/yegappan/lsp
48 ==============================================================================
49 2. Installation *lsp-installation*
51 You can install this plugin directly from github using the following steps:
53 $ mkdir -p $HOME/.vim/pack/downloads/opt
54 $ cd $HOME/.vim/pack/downloads/opt
55 $ git clone https://github.com/yegappan/lsp
57 or you can use any one of the Vim plugin managers (dein.vim, pathogen, vam,
58 vim-plug, volt, Vundle, etc.) to install and manage this plugin.
60 To uninstall the LSP plugin, either use the uninstall command provided by the
61 plugin manager or manually remove the $HOME/.vim/pack/downloads/lsp directory.
63 To use this plugin, add the following line to your .vimrc file:
67 ==============================================================================
70 The following commands are provided:
72 :LspCodeAction Apply the code action supplied by the language server
73 to the diagnostic in the current line.
74 :LspCodeLens Display all the code lens commands available for the
75 current file and apply the selected command.
76 :LspDiag current Display the diagnostic message for the current line.
77 :LspDiag first Jump to the first diagnostic message for the current
79 :LspDiag here Jump to the next diagnostic message in the current
81 :LspDiag highlight disable
82 Disable highlighting lines with a diagnostic message
83 for the current Vim session.
84 :LspDiag highlight enable
85 Enable highlighting lines with a diagnostic message
86 for the current Vim session.
87 :LspDiag last Jump to the last diagnostic message for the current
89 :LspDiag next Jump to the next diagnostic message for the current
90 buffer after the current cursor position.
91 :LspDiag prev Jump to the previous diagnostic message for the
92 current buffer before the current current position.
93 :LspDiag show Display the diagnostics messages from the language
94 server for the current buffer in a location list.
95 :LspDocumentSymbol Display the symbols in the current file in a popup
96 menu and jump to the location of a selected symbol.
97 :LspFold Fold the current file
98 :LspFormat Format a range of lines in the current file using the
99 language server. The default range is the entire
100 file. See |lsp-format| for more information.
101 :LspGotoDeclaration Go to the declaration of the symbol under cursor
102 :LspGotoDefinition Go to the definition of the symbol under cursor
103 :LspGotoImpl Go to the implementation of the symbol under cursor
104 :LspGotoTypeDef Go to the type definition of the symbol under cursor
105 :LspHighlight Highlight all the matches for the keyword under cursor
106 :LspHighlightClear Clear all the matches highlighted by :LspHighlight
107 :LspHover Show the documentation for the symbol under the cursor
109 :LspIncomingCalls Display the list of symbols calling the current symbol
111 :LspInlayHints Enable or disable inlay hints.
112 :LspOutgoingCalls Display the list of symbols called by the current
114 :LspOutline Show the list of symbols defined in the current file
115 in a separate window.
116 :LspPeekDeclaration Open the declaration of the symbol under cursor in a
118 :LspPeekDefinition Open the definition of the symbol under cursor in a
120 :LspPeekImpl Open the implementation of the symbol under cursor in
122 :LspPeekReferences Display the list of references to the symbol under
123 cursor in a popup window.
124 :LspPeekTypeDef Open the type definition of the symbol under cursor in
126 :LspRename Rename the current symbol
127 :LspSelectionExpand Expand the current symbol range visual selection
128 :LspSelectionShrink Shrink the current symbol range visual selection
129 :LspServer Command to display the status and messages from a
130 language server and to restart the language server.
131 :LspShowAllServers Display the status of all the registered language
133 :LspShowReferences Display the list of references to the keyword under
134 cursor in a new location list.
135 :LspShowSignature Display the signature of the symbol under cursor.
136 :LspSubTypeHierarchy Display the sub type hierarchy in a popup window.
137 :LspSuperTypeHierarchy Display the super type hierarchy in a popup window.
138 :LspSwitchSourceHeader Switch between a source and a header file.
139 :LspSymbolSearch Perform a workspace wide search for a symbol
140 :LspWorkspaceAddFolder {folder}
141 Add a folder to the workspace
142 :LspWorkspaceListFolders
143 Show the list of folders in the workspace
144 :LspWorkspaceRemoveFolder {folder}
145 Remove a folder from the workspace
147 ==============================================================================
148 4. Configuration *lsp-configuration*
149 *LspAddServer()* *g:LspAddServer()*
151 To use the plugin features with a particular file type(s), you need to first
152 register a language server for that file type(s).
154 To register one or more language servers, use the LspAddServer() function with
155 a list of lanaguge server details in the .vimrc file.
157 To register a language server, add the following lines to your .vimrc file
158 (use only the language servers that you need from the below list).
159 If you used [vim-plug](https://github.com/junegunn/vim-plug) to install the
160 LSP plugin, the steps are described later in this section: >
165 name: 'typescriptls',
166 filetype: ['javascript', 'typescript'],
167 path: '/usr/local/bin/typescript-language-server',
173 path: '/usr/local/bin/pyls',
174 args: ['--check-parent-process', '-v']
177 LspAddServer(lspServers)
179 Depending on the location of the typescript and python pyls language servers
180 installed in your system, update the "path" in the above snippet
183 Another example, for adding the language servers for the C, C++, Golang, Rust,
184 Shell script, Vim script and PHP file types: >
190 filetype: ['c', 'cpp'],
191 path: '/usr/local/bin/clangd',
192 args: ['--background-index']
196 filetype: ['go', 'gomod', 'gohtmltmpl', 'gotexttmpl'],
197 path: '/path/to/.go/bin/gopls',
204 path: '/path/to/.cargo/bin/rust-analyzer',
211 path: '/usr/local/bin/bash-language-server',
217 path: '/usr/local/bin/vim-language-server',
223 path': '/usr/local/bin/intelephense',
226 initializationOptions: {
227 licenceKey: 'xxxxxxxxxxxxxxx'
231 LspAddServer(lspServers)
233 To add a language server, the following information is needed:
236 name (Optional) name of the language server. Can by any
237 string. Used in LSP messages and log files.
239 path complete path to the language server executable
240 (without any arguments).
242 args a |List| of command-line arguments passed to the
243 language server. Each space separated language server
244 command-line argument is a separate List item.
246 filetype One or more file types supported by the language
247 server. This can be a |String| or a |List|. To
248 specify multiple file types, use a List.
249 *lsp-cfg-initializationOptions*
250 initializationOptions
251 (Optional) for lsp servers (e.g. intelephense) some
252 additional initialization options may be required
253 or useful for initialization. Those can be provided in
254 this dictionary and if present will be transmitted to
256 *lsp-cfg-workspaceConfig*
257 workspaceConfig (Optional) a json encodable value that will be sent to
258 the language server after initialization as the
259 "settings" in a "workspace/didChangeConfiguration"
260 notification. Refer to the language server
261 documentation for the values that will be accepted in
262 this notification. This configuration is also used to
263 respond to the "workspace/configuration" request
264 message from the language server.
266 rootSearch (Optional) a List of file and directory names used to
267 locate the root path or uri of the workspace. The
268 directory names in "rootSearch" must end in "/" or
269 "\". Each file and directory name in "rootSearch" is
270 searched upwards in all the parent directories. If
271 multiple directories are found, then the directory
272 closest to the directory of the current buffer is used
273 as the workspace root.
275 If this parameter is not specified or the files are
276 not found, then the current working directory is used
277 as the workspace root for decendent files, for any
278 other files the parent directory of the file is used.
280 *lsp-cfg-runIfSearch*
281 runIfSearch (Optional) a List of file and directory names used to
282 determinate if a server should run or not. The
283 directory names in "runIfSearch" must end in "/" or
284 "\". Each file and directory name in "runIfSearch" is
285 searched upwards in all the parent directories.
286 Exactly like |lsp-cfg-rootSearch|.
288 If a file or directory is found then the server will
289 be started, otherwise it will not.
291 If this parameter is not specified or is an empty
292 list, then the server will be started unless
293 |lsp-cfg-runUnlessSearch| prevents it.
295 *lsp-cfg-runUnlessSearch*
296 runUnlessSearch (Optional) Opposite of |lsp-cfg-runIfSearch|.
298 Additionally the following configurations can be made:
300 *lsp-cfg-customNotificationHandlers*
301 customNotificationHandlers
302 (Optional) some lsp servers (e.g.
303 typescript-language-server) will send additional
304 notifications which you might want to silence or
305 handle. The provided notification handlers will be
306 called with a reference to the "lspserver" and the
311 filetype: ['javascript', 'typescript'],
312 path: '/usr/local/bin/typescript-language-server',
314 customNotificationHandlers: {
315 '$/typescriptVersion': (lspserver, reply) => {
316 echom printf("TypeScript Version = %s",
317 reply.params.version)
322 *lsp-cfg-customRequestHandlers*
323 customRequestHandlers
324 (Optional) some lsp servers will send additional
325 request replies which you might want to silence or
326 handle. The provided request handlers will be called
327 with a reference to the "lspserver" and the "request".
329 features *lsp-cfg-features*
330 (Optional) toggle which features should be enabled for
331 a given language server. See |lsp-multiple-servers|
332 and |lsp-features| for more information.
334 forceOffsetEncoding *lsp-cfg-forceOffsetEncoding*
335 (Optional) a |String| value that forces the use of a
336 specific offset encoding in LSP messages. If this
337 option is not specified, then the UTF offset encoding
338 is negotiated with the server during initialization.
339 Supported values are 'utf-8' or 'utf-16' or 'utf-32'.
340 The Vim native offset encoding is 'utf-32'. For the
341 'utf-8' and 'utf-16' encodings, the offsets need to be
342 encoded and decoded in every LSP message and will
346 omnicompl (Optional) a boolean value that enables (true)
347 or disables (false) omni-completion for these file
348 types. By default this is set to "v:true". This value
349 is applicable only if auto completion is disabled
350 (|lsp-opt-autoComplete|).
352 *lsp-cfg-processDiagHandler*
354 (Optional) A |Funcref| or |lambda| that takes a list
355 of language server diagnostics and returns a new list
356 of filtered, or otherwise changed diagnostics. Can be
357 used to remove unwanted diagnostics, prefix the
358 diagnostics text, etc. The following example will
359 remove all but errors and warnings: >
363 filetype: ['javascript', 'typescript'],
364 path: '/usr/local/bin/typescript-language-server',
366 processDiagHandler: (diags: list<dict<any>>) => {
367 # Only include errors and warnings
368 return diags->filter((diag, ix) => {
369 return diag.severity <= 2
374 And this example will prefix the diagnostic message
375 with the string "TypeScript: ": >
379 filetype: ['javascript', 'typescript'],
380 path: '/usr/local/bin/typescript-language-server',
382 processDiagHandler: (diags: list<dict<any>>) => {
383 return diags->map((diag, ix) => {
384 diag.message = $'TypeScript: {diag.message}'
391 syncInit (Optional) for language servers (e.g. rust analyzer,
392 gopls, etc.) that take time to initialize and reply to
393 a "initialize" request message this should be set to
394 "true". If this is set to true, then a synchronous
395 call is used to initialize the language server,
396 otherwise the server is initialized asynchronously.
397 By default this is set to "false".
400 debug (Optional) log the messages printed by this language
401 server in stdout and stderr to a file. Useful for
402 debugging a language server. By default the
403 messages are not logged. See |lsp-debug| for more
407 traceLevel (Optional) set the debug trace level for this language
408 server. Â Supported values are: "off", "debug" and
409 "verbose". By default this is seto "off".
411 The language servers are added using the LspAddServer() function. This
412 function accepts a list of language servers with the above information.
414 If you used [vim-plug](https://github.com/junegunn/vim-plug) to install the
415 LSP plugin, then you need to use the VimEnter autocmd to initialize the
416 language server and to set the language server options. For example: >
422 filetype: ['c', 'cpp'],
423 path: '/usr/local/bin/clangd',
424 args: ['--background-index']
427 autocmd VimEnter * LspAddServer(lspServers)
429 var lspOpts = {'autoHighlightDiags': true}
430 autocmd VimEnter * LspOptionsSet(lspOpts)
432 *lsp-options* *LspOptionsSet*
435 Some of the LSP plugin features can be enabled or disabled by using the
436 LspOptionsSet() function. This function accepts a dictionary argument with the
437 following optional items:
440 aleSupport |Boolean| option. If true, diagnostics will be sent to
441 Ale, instead of being displayed by this plugin.
442 This is useful to combine all LSP and linter
443 diagnostics. By default this is set to false.
445 *lsp-opt-autoComplete*
446 autoComplete |Boolean| option. In insert mode, automatically
447 complete the current symbol. Otherwise use
448 omni-completion. By default this is set to true.
450 *lsp-opt-autoHighlight*
451 autoHighlight |Boolean| option. In normal mode, automatically
452 highlight all the occurrences of the symbol under the
453 cursor. By default this is set to false.
455 *lsp-opt-autoHighlightDiags*
456 autoHighlightDiags |Boolean| option. Automatically place signs on the
457 lines with a diagnostic message from the language
458 server. By default this is set to true.
460 *lsp-opt-autoPopulateDiags*
461 autoPopulateDiags |Boolean| option. Automatically populate the location
462 list with diagnostics from the language server.
463 By default this is set to false.
465 *lsp-opt-completionMatcher*
466 completionMatcher |String| option. Enable fuzzy or case insensitive
467 completion for language servers that replies with a
468 full list of completion items. Some language servers
469 does completion filtering in the server, while other
470 relies on the client to do the filtering.
472 This option only works for language servers that
473 expect the client to filter the completion items.
475 This option accepts one of the following values:
476 case - case sensitive matching (default).
477 fuzzy - fuzzy match completion items.
478 icase - ignore case when matching items.
480 *lsp-opt-completionTextEdit*
481 completionTextEdit |Boolean| option. If true, apply the LSP server
482 supplied text edits after a completion. If a snippet
483 plugin is going to apply the text edits, then set
484 this to false to avoid applying the text edits twice.
485 By default this is set to true.
487 *lsp-opt-completionKinds*
488 completionKinds |Dictionary| option. See |lsp-custom-kinds| for all
489 completion kind names.
491 *lsp-opt-customCompletionKinds*
492 customCompletionKinds |Boolean| option. If you set this to true, you can
493 set custom completion kinds using the option
496 *lsp-opt-diagSignErrorText*
497 diagSignErrorText |String| option. Change diag sign text for errors
500 *lsp-opt-diagSignHintText*
501 diagSignHintText |String| option. Change diag sign text for hints
504 *lsp-opt-diagSignInfoText*
505 diagSignInfoText |String| option. Change diag sign text for info
508 *lsp-opt-diagSignWarningText*
509 diagSignWarningText |String| option. Change diag sign text for warnings
512 *lsp-opt-diagVirtualTextAlign*
513 diagVirtualTextAlign |String| option. Alignment of diagnostics messages
514 if |lsp-opt-showDiagWithVirtualText| is set to true.
515 Allowed values are 'above', 'below' or 'after'
516 By default this is set to 'above',
518 *lsp-opt-echoSignature*
519 echoSignature |Boolean| option. In insert mode, echo the current
520 symbol signature instead of showing it in a popup.
521 By default this is set to false.
523 *lsp-opt-hideDisabledCodeActions*
524 hideDisabledCodeActions |Boolean| option. Hide all the disabled code actions.
525 By default this is set to false.
527 *lsp-opt-highlightDiagInline*
528 highlightDiagInline |Boolean| option. Highlight the diagnostics inline.
529 By default this is set to false.
531 *lsp-opt-hoverInPreview*
532 hoverInPreview |Boolean| option. Show |:LspHover| in a preview window
534 By default this is set to false.
536 *lsp-opt-ignoreMissingServer*
537 ignoreMissingServer |Boolean| option. Do not print a missing language
538 server executable. By default this is set to false.
540 *lsp-opt-keepFocusInDiags*
541 keepFocusInDiags |Boolean| option. Focus on the location list window
542 after ":LspDiag show".
543 By default this is set to true.
545 *lsp-opt-keepFocusInReferences*
546 keepFocusInReferences |Boolean| option. Focus on the location list window
547 after LspShowReferences.
548 By default this is set to true.
550 *lsp-opt-noDiagHoverOnLine*
551 noDiagHoverOnLine |Boolean| option. Suppress diagnostic hover from
552 appearing when the mouse is over the line instead of
554 By default this is set to true.
556 *lsp-opt-noNewlineInCompletion*
557 noNewlineInCompletion |Boolean| option. Suppress adding a new line on
558 completion selection with <CR>.
559 By default this is set to false.
561 *lsp-opt-outlineOnRight*
562 outlineOnRight |Boolean| option. Open the outline window on the
563 right side, by default this is false.
565 *lsp-opt-outlineWinSize*
566 outlineWinSize |Number| option. The size of the symbol Outline
567 window. By default this is set to 20.
569 *lsp-opt-showDiagInPopup*
570 showDiagInPopup |Boolean| option. When using the ":LspDiag current"
571 command to display the diagnostic message for the
572 current line, use a popup window to display the
573 message instead of echoing in the status area.
574 By default this is set to true.
576 *lsp-opt-showDiagOnStatusLine*
577 showDiagOnStatusLine |Boolean| option. Show a diagnostic message on a
578 status line. By default this is set to false.
580 *lsp-opt-showDiagWithSign*
581 showDiagWithSign |Boolean| option. Place a sign on lines with
582 diagnostics. By default this is set to true. The
583 "autoHighlightDiags" option should be set to true.
585 *lsp-opt-showDiagWithVirtualText*
586 showDiagWithVirtualText |Boolean| option. Show diagnostic message text from
587 the language server with virtual text. By default
588 this is set to false. The "autoHighlightDiags" option
589 should be set to true.
590 Needs Vim version 9.0.1157 or later.
592 *lsp-opt-showInlayHints*
593 showInlayHints |Boolean| option. Show inlay hints from the language
594 server. By default this is set to false. The inlay
595 hint text is displayed as a virtual text. Needs Vim
596 version 9.0.0178 or later.
598 *lsp-opt-showSignature*
599 showSignature |Boolean| option. In insert mode, automatically show
600 the current symbol signature in a popup.
601 By default this is set to true.
603 *lsp-opt-snippetSupport*
604 snippetSupport |Boolean| option. Enable snippet completion support.
605 Need a snippet completion plugin like vim-vsnip.
606 By default this is set to false.
608 *lsp-opt-ultisnipsSupport*
609 ultisnipsSupport |Boolean| option. Enable SirVer/ultisnips support.
610 Need a snippet completion plugin SirVer/ultisnips.
611 By default this is set to false.
613 *lsp-opt-vssnipSupport*
614 vsnipSupport |Boolean| option. Enable hrsh7th/vim-vsnip support.
615 Need snippet completion plugins hrsh7th/vim-vsnip
616 and hrsh7th/vim-vsnip-integ. Make sure
617 ultisnipsSupport is set to false before enabling this.
618 By default this option is set to false.
620 *lsp-opt-usePopupInCodeAction*
621 usePopupInCodeAction |Boolean| option. When using the |:LspCodeAction|
622 command to display the code action for the current
623 line, use a popup menu instead of echoing.
624 By default this is set to false.
626 *lsp-opt-useQuickfixForLocations*
627 useQuickfixForLocations |Boolean| option. Show |:LspShowReferences| in a
628 quickfix list instead of a location list.
629 By default this is set to false.
631 *lsp-opt-useBufferCompletion*
632 useBufferCompletion |Boolean| option. If enabled, the words from the
633 current buffer are added to the auto completion list.
634 By default this is set to false.
636 *lsp-opt-bufferCompletionTimeout*
637 bufferCompletionTimeout |Number| option. Specifies how long (in milliseconds)
638 to wait while processing current buffer for
639 autocompletion words. If set too high Vim performance
640 may degrade as the current buffer contents are
641 processed every time the completion menu is displayed.
642 If set to 0 the entire buffer is processed without
644 By default this is set to 100 ms.
646 For example, to disable the automatic placement of signs for the LSP
647 diagnostic messages, you can add the following line to your .vimrc file: >
649 LspOptionsSet({'autoHighlightDiags': false})
651 The LspOptionsGet() function returns a |Dict| of all the LSP plugin options,
652 To get a particular option value you can use the following: >
654 echo LspOptionsGet()['autoHighlightDiags']
656 ==============================================================================
657 5. Commands *lsp-commands*
659 A description of the various commands provided by this plugin is below. You
660 can map these commands to keys and make it easier to invoke them.
663 :LspCodeAction [query] Apply the code action supplied by the language server
664 to the diagnostic in the current line. This works only
665 if there is a diagnostic message for the current line.
666 You can use the ":LspDiag current" command to display
667 the diagnostic for the current line.
669 When [query] is given the code action starting with
670 [query] will be applied. [query] can be a regexp
671 pattern, or a digit corresponding to the index of the
672 code actions in the created prompt.
674 When [query] is not given you will be prompted to
675 select one of the actions supplied by the language
679 :LspCodeLens Display a list of code lens commands available for the
680 current buffer and apply the selected code lens
684 :LspDiag current Displays the diagnostic message (if any) for the
685 current line. If the option 'showDiagInPopup' is set
686 to true (default), then the message is displayed in
687 a popup window. Otherwise the message is displayed in
688 the status message area.
690 :LspDiag! current Only display a diagnostic message if it's directly
691 under the cursor. Otherwise works exactly like
694 To show the current diagnotic under the cursor while
695 moving around the following autocmd can be used: >
699 au CursorMoved * silent! LspDiag! current
703 :LspDiag first Jumps to the location of the first diagnostic message
704 for the current file.
707 :LspDiag here Jumps to the location of the diagnostic message in
708 the current line (start from current column).
710 :LspDiag highlight disable *:LspDiag-highlight-disable*
711 Disable highlighting lines with a diagnostic message
712 for the current Vim session.
713 To always disable the highlighting, set the
714 autoHighlightDiags option to false.
716 :LspDiag highlight enable *:LspDiag-highlight-enable*
717 Enable highlighting lines with a diagnostic message
718 for the current Vim session. Note that highlighting
719 lines with a diagnostic message is enabled by default.
722 :LspDiag last Jumps to the location of the first diagnostic message
723 for the current file.
726 :[count]LspDiag next Go to the [count] diagnostic message after the current
727 cursor position. If [count] is omitted, then 1 is
728 used. If [count] exceeds the number of diagnostics
729 after the current position, then the last diagnostic
733 :[count]LspDiag prev Go to the [count] diagnostic message before the
734 current cursor position. If [count] is omitted, then
735 1 is used. If [count] exceeds the number of
736 diagnostics before the current position, then first
737 last diagnostic is selected.
740 :LspDiag show Creates a new location list with the diagnostics
741 messages (if any) from the language server for the
742 current file and opens the location list window. You
743 can use the Vim location list commands to browse the
747 :LspDocumentSymbol Display the symbols in the current file in a popup
748 menu. When a symbol is selected in the popup menu by
749 pressing <Enter> or <Space>, jump to the location of
752 The <Up>, <Down>, <C-F>, <C-B>, <PageUp>, <PageDown>,
753 <C-Home>, <C-End>, <C-N>, <C-P> keys can be used to
754 scroll the popup menu. The <Esc> or <Ctrl-C> keys can
755 be used to cancel the popup menu.
757 If one or more keyword characters are typed, then only
758 the symbols containing the keyword characters are
759 displayed in the popup menu. Fuzzy searching is used
760 to get the list of matching symbols. The <BS> key can
761 be used to erase the last typed character. The <C-U>
762 key can be used to erase all the characters.
764 When scrolling through the symbols in the popup menu,
765 the corresponding range of lines is highlighted.
768 :LspFold Create folds for the current buffer.
771 :LspFormat Format the current file using the language server. The
772 'shiftwidth' and 'expandtab' values set for the
773 current buffer are used when format is applied.
775 :{range}LspFormat Format the specified range of lines in the current
776 file using the language server.
778 *:LspGotoDeclaration*
779 :[count]LspGotoDeclaration
780 Jumps to the declaration of the symbol under the
781 cursor. The behavior of this command is similar to the
782 |:LspGotoDefinition| command.
785 :[count]LspGotoDefinition
786 Jumps to the [count] definition of the symbol under
787 the cursor. If there are multiple matches and [count]
788 isn't specified, then a location list will be created
789 with the list of locations.
791 If there is only one location, or [count] is provided
792 then the following will apply:
794 If the file is already present in a window, then jumps
795 to that window. Otherwise, opens the file in a new
796 window. If the current buffer is modified and
797 'hidden' is not set or if the current buffer is a
798 special buffer, then a new window is opened. If the
799 jump is successful, then the current cursor location
800 is pushed onto the tag stack. The |CTRL-T| command
801 can be used to go back up the tag stack. Also the
802 |``| mark is set to the position before the jump.
804 This command supports |:command-modifiers|. You can
805 use the modifiers to specify whether a new window or
806 a new tab page is used and where the window is opened.
809 # Open a horizontally split window
810 :topleft LspGotoDefinition
811 # Open a vertically split window
812 :vert LspGotoDefinition
813 # Open a new tab page
814 :tab LspGotoDefinition
816 You may want to map a key to invoke this command: >
818 nnoremap <buffer> gd <Cmd>LspGotoDefinition<CR>
819 nnoremap <buffer> <C-W>gd <Cmd>topleft LspGotoDefinition<CR>
821 Or if you want to support [count]gd >
823 nnoremap <buffer> gd <Cmd>execute v:count .. 'LspGotoDefinition'<CR>
824 nnoremap <buffer> <C-W>gd <Cmd>execute 'topleft ' .. v:count .. 'LspGotoDefinition'<CR>
827 :[count]LspGotoImpl Jumps to the implementation of the symbol under the
828 cursor. The behavior of this command is similar to the
829 |:LspGotoDefinition| command. Note that not all the
830 language servers support this feature.
832 You may want to map a key to invoke this command: >
834 nnoremap <buffer> gi <Cmd>LspGotoImpl<CR>
837 :[count]LspGotoTypeDef Jumps to the type definition of the symbol under the
838 cursor. The behavior of this command is similar to the
839 |:LspGotoDefinition| command. Note that not all the
840 language servers support this feature.
842 You may want to map a key to invoke this command: >
844 nnoremap <buffer> gt <Cmd>LspGotoTypeDef<CR>
847 :LspHighlight Highlights all the matches for the symbol under
848 cursor. The text, read and write references to the
849 symbol are highlighted using Search, DiffChange and
850 DiffDelete highlight groups respectively.
853 :LspHighlightClear Clears all the symbol matches highlighted by the
854 |:LspHighlight| command.
857 :LspHover Show the documentation for the symbol under the cursor
858 in a popup window. If you want to show the symbol
859 documentation in the preview window instead of in a
862 LspOptionsSet({'hoverInPreview': true})
864 You can use the |K| key in normal mode to display the
865 documentation for the keyword under the cursor by
866 setting the 'keywordprg' Vim option: >
868 :set keywordprg=:LspHover
871 :LspIncomingCalls Display a hierarchy of symbols calling the symbol
872 under the cursor in a window. See
873 |lsp-call-hierarchy| for more information. Note that
874 not all the language servers support this feature.
877 :LspInlayHints Enable or disable inlay hints. Supports the "enable"
878 and "disable" arguments. When "enable" is specified,
879 enables the inlay hints for all the buffers with a
880 language server that supports inlay hints. When
881 "disable" is specified, disables the inlay hints.
884 :LspOutoingCalls Display a hierarchy of symbols called by the symbol
885 under the cursor in a window. See
886 |lsp-call-hierarchy| for more information. Note that
887 not all the language servers support this feature.
890 :[count]LspOutline Opens a vertically split window with the list of
891 symbols defined in the current file. The current
892 symbol is highlighted. The symbols are grouped by
893 their type. You can select a symbol and press <Enter>
894 to jump to the position of the symbol. As you move the
895 cursor in a file, the current symbol is automatically
896 highlighted in the outline window. If you open a new
897 file, the outline window is automatically updated with
898 the symbols in the new file. Folds are created in the
899 outline window for the various group of symbols.
901 You can use |lsp-opt-outlineOnRight| and
902 |lsp-opt-outlineWinSize| to customize the placement
903 and size of the window.
905 This command also supports |:command-modifiers|. You
906 can use the modifiers specify the position of the
907 window. Note that the default is ":vert :topleft" or
908 ":vert :botright" depending on
909 |lsp-opt-outlineOnRight|
911 This command also supports providing a [count] to
912 specify the size of the window. Note that this
913 overrides the values defined in
914 |lsp-opt-outlineWinSize|.
917 # Open the outline window just above the current
919 :aboveleft LspOutline
921 # Open the outline window just next to the current
922 # window, this is different from the default, when
923 # you have multiple splits already
924 :vert aboveleft LspOutline
926 # Same as above, but with a width of 50
927 :vert aboveleft 50LspOutline
929 *:LspPeekDeclaration*
930 :[count]LspPeekDeclaration
931 Displays the line where the symbol under the
932 cursor is declared in a popup window. The
933 behavior of this command is similar to the
934 |:LspPeekDefinition| command.
937 :[count]LspPeekDefinition
938 Displays the line where the symbol under the cursor is
939 defined in a popup window. The symbol is highlighted
940 in the popup window. Moving the cursor or pressing
941 <Esc> will close the popup window.
942 When more than one symbol is found all of them will be
943 shown. The corresponding file for the symbol is
944 displayed in another popup window. As the selection
945 in the symbol popup menu changes, the file in the
947 When [count] is provided only the [count] symbol will
951 :[count]LspPeekImpl Displays the implementation of the symbol under the
952 cursor in a popup window. The behavior of this
953 command is similar to the |:LspPeekDefinition|
954 command. Note that not all the language servers
955 support this feature.
958 :LspPeekReferences Displays the list of references to the symbol under
959 cursor in a popup menu. The corresponding file for
960 the reference is displayed in another popup window.
961 As the selection in the reference popup menu changes,
962 the file in the popup is updated.
965 :[count]LspPeekTypeDef Displays the line where the type of the symbol under
966 the cursor is defined in a popup window. The
967 behavior of this command is similar to the
968 |:LspPeekDefinition| command. Note that not all the
969 language servers support this feature.
972 :LspRename [newName] Rename the current symbol.
974 When [newName] is not given, then you will be prompted
975 to enter the new name for the symbol. You can press
976 <Esc> or enter an empty string in the prompt to cancel
979 *:LspSelectionExpand*
980 :LspSelectionExpand Visually select the region of the symbol under the
981 cursor. In visual mode, expands the current symbol
982 visual region selection to include the next level.
984 For example, if the cursor is on a "for" statement,
985 this command selects the "for" statement and the body
986 of the "for" statement.
988 It is useful to create a visual map to use this
991 xnoremap <silent> <Leader>e <Cmd>LspSelectionExpand<CR>
993 With the above map, you can press "\e" in visual mode
994 successively to expand the current symbol visual
997 *:LspSelectionShrink*
998 :LspSelectionShrink Shrink the current symbol range visual selection. It
999 is useful to create a visual map to use this command.
1002 xnoremap <silent> <Leader>s <Cmd>LspSelectionShrink<CR>
1004 With the above map, you can press "\s" in visual mode
1005 successively to shrink the current symbol visual
1009 :LspServer { debug | restart | show | trace }
1010 Command to display and control the language server for
1011 the current buffer. Each argument has additional
1012 sub-commands which are described below.
1014 debug { on | off | messages | errors }
1015 Command to enable or disable the language server
1016 debug messages and to display the debug messages
1017 and error messages received from the language
1018 server. The following sub-commands are supported:
1019 errors Open the log file containing the
1020 language server error messages.
1022 Open the log file containing the
1023 language server debug messages.
1024 off Disable the logging of the language
1026 on Enable the logging of the messages
1027 emitted by the language server in the
1028 standard output and standard error.
1029 By default, the language server messages are not
1030 logged. On a Unix-like system, when enabled,
1031 these messages are logged to the
1032 /tmp/lsp-<server-name>.log and
1033 /tmp/lsp-<server-name>.err file respectively. On
1034 MS-Windows, the %TEMP%/lsp-<server-name>.log and
1035 %TEMP%/lsp-<server-name>.err% files are used. See
1036 |lsp-debug| for more information.
1039 Restart (stop and then start) the language server
1040 for the current buffer. All the loaded buffers
1041 with the same filetype as the current buffer are
1042 added back to the server.
1044 show {capabilities | initializeRequest | messages
1046 The following sub-commands are supported:
1048 Display the list of language server
1049 capabilities for the current buffer.
1050 The server capabilities are described
1051 in the LSP protocol specification
1052 under the "ServerCapabilities"
1055 Display the contents of the language
1056 server initialization request message
1059 Display the log messages received from
1060 the language server. This includes
1061 the messages received using the
1062 "window/logMessage" and "$/logTrace"
1065 Display the language server status for
1066 the current buffer. The output shows
1067 the path to the language server
1068 executable and the server status.
1070 trace { off | messages | verbose }
1071 Set the language server debug trace value using
1072 the "$/setTrace" command.
1074 *:LspShowAllServers*
1075 :LspShowAllServers Displays the list of registered language servers and
1076 their status. The language servers are registered
1077 using the LspAddServer() function. The output is
1078 displayed in a scratch buffer. The output shows the
1079 Vim file type, the corresponding language server
1080 status and the path to the language server executable.
1081 The language server information for each buffer is
1084 *:LspShowReferences*
1085 :LspShowReferences Creates a new location list with the list of locations
1086 where the symbol under the cursor is referenced and
1087 opens the location window. If you want to show the
1088 references in a quickfix list instead of in a location
1091 LspOptionsSet({'useQuickfixForLocations': true})
1094 :LspShowSignature Displays the signature of the symbol (e.g. a function
1095 or method) before the cursor in a popup.
1097 The popup is also automatically displayed in insert
1098 mode after entering a symbol name followed by a
1099 separator (e.g. a opening parenthesis). To disable
1100 this, you can set the showSignature option to false in
1103 LspOptionsSet({'showSignature': false})
1107 You can get the function signature echoed in cmdline
1108 rather than displayed in popup if you use >
1110 LspOptionsSet({'echoSignature': true})
1114 *:LspSubTypeHierarchy*
1115 :LspSubTypeHierarchy Show the sub type hierarchy for the symbol under the
1116 cursor in a popup window. The file containing the
1117 type is shown in another popup window. You can jump
1118 to the location where a type is defined by browsing
1119 the popup menu and selecting an entry.
1121 *:LspSuperTypeHierarchy*
1122 :LspSuperTypeHierarchy Show the super type hierarchy for the symbol under the
1123 cursor in a popup window. The file containing the
1124 type is shown in another popup window. As the current
1125 entry in the type hierarchy popup menu changes, the
1126 file popup window is updated to show the location
1127 where the type is defined. You can jump to the
1128 location where a type is defined by selecting the
1129 entry in the popup menu.
1131 Note that the type hierarchy support is based on the
1132 protocol supported by clangd. This is different from
1133 the one specified in the 3.17 of the LSP standard.
1135 *:LspSwitchSourceHeader*
1136 :LspSwitchSourceHeader Switch between source and header files. This is a
1137 Clangd specific extension and only works with C/C++
1141 :LspSymbolSearch <sym> Perform a workspace wide search for the symbol <sym>.
1142 If <sym> is not supplied, then you will be prompted to
1143 enter the symbol name (the keyword under the cursor is
1144 used as the default). If there is only one matching
1145 symbol, then the cursor will be positioned at the
1146 symbol location. Otherwise a popup window is opened
1147 with the list of matching symbols. You can enter a
1148 few characters to narrow down the list of matches. The
1149 displayed symbol name can be erased by pressing
1150 <Backspace> or <C-U> and a new symbol search pattern
1151 can be entered. You can close the popup menu by
1152 pressing the escape key or by pressing CTRL-C.
1154 In the popup menu, the following keys can be used:
1156 CTRL-F - Scroll one page forward
1158 CTRL-B - Scroll one page backward
1160 CTRL-Home - Jump to the first entry
1161 CTRL-End - Jump to the last entry
1162 <Up> - Go up one entry
1164 <Down> - Go down one entry
1166 <Enter> - Open the selected file
1167 <Esc> - Close the popup menu
1169 <BS> - Erase one character from the
1172 <C-U> - Erase the filter text
1174 Any other alphanumeric key will be used to narrow down
1175 the list of names displayed in the popup menu. When
1176 you type a filter string, then only the symbols fuzzy
1177 matching the string are displayed in the popup menu.
1178 You can enter a new search pattern to do a workspace
1181 This command accepts |:command-modifiers| which can be
1182 used to jump to a symbol in a horizontally or
1183 vertically split window or a new tab page: >
1185 :topleft LspSymbolSearch foo
1186 :vert LspSymbolSearch bar
1187 :tab LspSymbolSearch baz
1189 *:LspWorkspaceAddFolder*
1190 :LspWorkspaceAddFolder {folder}
1191 Add a folder to the workspace
1193 :LspWorkspaceListFolders *:LspWorkspaceListFolders*
1194 Show the list of folders in the workspace.
1196 *:LspWorkspaceRemoveFolder*
1197 :LspWorkspaceRemoveFolder {folder}
1198 Remove a folder from the workspace
1200 ==============================================================================
1201 6. Insert mode completion *lsp-ins-mode-completion*
1203 By default, in insert mode, the LSP plugin automatically displays the matches
1204 for the symbol under the cursor in an insert-completion popup menu. You can
1205 use the keys described in |popupmenu-keys| with this menu.
1207 To disable the auto-completion for all the files, you can set the
1208 'autoComplete' option to false in your .vimrc file: >
1210 LspOptionsSet({'autoComplete': false})
1212 If this variable is set, then the LSP plugin will not automatically start
1213 completion in insert mode and instead supports omni-completion (|compl-omni|).
1214 It sets the 'omnifunc' option for the buffers which have a registered language
1215 server. To complete a symbol in insert mode manually, you can press CTRL-X
1216 CTRL-O to invoke completion using the items suggested by the language server.
1218 You can also enable or disable omni-completion for a specific language
1219 server by setting the 'omnicompl' item to 'false' when registering a lsp
1220 server for the filetype. If this item is not specified, then omni-completion
1221 is enabled by default. The following example disables omni-completion for
1229 path: '/usr/local/bin/pyls',
1230 args: ['--check-parent-process', '-v']
1234 If you want to use omni completion, in addition to the automatic completion,
1235 then you can set the 'omnifunc' option to the "g:LspOmniFunc" function: >
1237 set omnifunc=g:LspOmniFunc
1239 To use omni completion, press CTRL-X CTRL-O in insert mode. Refer to
1240 |compl-omni| for more information.
1242 When doing insert-mode completion, the plugin sends a request message to the
1243 language server to return a list of possible completion matches for the
1244 current cursor position. The plugin retrieves the keyword before the cursor
1245 (see 'iskeyword') and then filters the returned list of completion items
1246 against this keyword and displays the completion menu. Some language servers
1247 does completion filtering in the server, while other relies on the client to
1248 do the filtering. By default, case sensitive comparison is used to filter the
1249 returned items. You can modify the 'completionMatcher' option to use either
1250 case insensitive or fuzzy comparison.
1252 ==============================================================================
1253 7. Diagnostics *lsp-diagnostics*
1255 When a source file has syntax errors or warnings or static analysis warnings,
1256 the LSP plugin highlights them by placing |signs| in the |sign-column|. You
1257 can use the ":LspDiag show" command to display all the diagnostic messages for
1258 the current file in a |location-list-window|. You can use the
1259 ":LspDiag first" command to jump to the line with the first diagnostic
1260 message, the ":LspDiag next" command to jump to the next nearest line with the
1261 diagnostic message, the ":LspDiag prev" command to jump to the previous
1262 nearest line with the diagnostic message, the ":LspDiag here" command to jump
1263 to the diagnostic message in the current line. You can use the ":LspDiag
1264 current" command to display the entire diagnostic message from the language
1265 server for the current line.
1267 By default, the lines with a diagnostic message have a sign placed on them and
1268 are highlighted. You can disable the automatic sign placement by setting the
1269 "showDiagWithSign" option to v:false. By default, this option is set to
1270 v:true. The line with the diagnostics is highlighted using the "LspDiagLine"
1273 You can also display the diagnostic message as a virtual text near the
1274 location of the diagnostics by setting the "showDiagWithVirtualText" option to
1275 v:true. This needs Vim version 9.0.1157 or later. By default this option is
1276 set to v:false. The position of the virtual text is controlled by the
1277 "diagVirtualTextAlign" option. By default, this is set to 'above'. The other
1278 supported values are 'below' and 'after'.
1280 The range of text for a diagnostic message can be automatically highlighted by
1281 setting the "highlightDiagInline" option to v:true. By default, this option
1282 is set to v:false. The text is highlighted using the "LspDiagInlineError" or
1283 "LspDiagInlineHint" or "LspDiagInlineInfo" or "LspDiagInlineWarning" highlight
1286 You can temporarily disable the automatic diagnostic highlighting for the
1287 current Vim session using the ":LspDiag highlight disable" command and
1288 re-enable them using the ":LspDiag highlight enable" command.
1290 To disable the automatic highlighting of the diagnostics, you can set the
1291 'autoHighlightDiags' option to v:false: >
1293 LspOptionsSet({'autoHighlightDiags': false})
1295 By default the 'autoHighlightDiags' option is set to v:true.
1297 The function lsp#lsp#ErrorCount() function can be used to get the count of the
1298 diagnostic messages in the current buffer by type. This function returns a
1299 Dictionary with the following keys: Info, Hint, Warn and Error. The value for
1300 these keys is the number of diagnostic messages of the corresponding type.
1301 This function can be used to display the number of diagnostics in the current
1302 buffer in a 'statusline'.
1304 For some diagnostic errors/warnings, the language server may provide an
1305 automatic fix. To apply this fix, you can use the |:LspCodeAction| command.
1306 This command applies the action provided by the language server (if any) for
1309 The ":LspDiag show" command creates a new location list with the current list
1310 of diagnostics for the current buffer. To automatically add the diagnostics
1311 messages to the location list, you can set the 'autoPopulateDiags' option to
1312 true. Â By default this option is set to false. Â When new diagnostics are
1313 received for a buffer, if a location list with the diagnostics is already
1314 present, then it is refreshed with the new diagnostics.
1316 When using GUI Vim or in a terminal Vim with 'ballooneval' option set, when
1317 the mouse is moved over the diagnostic sign displayed in the sign column, then
1318 the diagnostic message is displayed in a popup. By default, the diagnostic
1319 message popup is not displayed when the mouse is moved over the text in the
1320 line. To display the diagnostic message when hovering the mouse over the text
1321 of the line, you can set the 'noDiagHoverOnLine' option to false. By
1322 default, this option is set to true.
1324 To display the diagnostic message for the current line in the status area, you
1325 can set the 'showDiagOnStatusLine' option to true. By default, this option
1328 By default, the ":LspDiag current" command displays the diagnostic message
1329 for the current line in a popup window. To display the message in the status
1330 message area instead, you can set the 'showDiagInPopup' option to false. By
1331 default this is set to true.
1333 The lsp#diag#GetDiagsForBuf() function can be used to get all the LSP
1334 diagnostics in a buffer. Â This function optionally accepts a buffer number.
1335 If the buffer number argument is not specified, then the current buffer is
1336 used. Â This function returns a |List| of diagnostics sorted by their line and
1337 column number. Â Each diagnostic is a |Dict| returned by the language server.
1339 ==============================================================================
1340 8. Tag Function *lsp-tagfunc*
1342 The |:LspGotoDefinition| command can be used jump to the location where a
1343 symbol is defined. To jump to the symbol definition using the Vim
1344 |tag-commands|, you can set the 'tagfunc' option to the 'lsp#lsp#TagFunc'
1347 setlocal tagfunc=lsp#lsp#TagFunc
1349 After setting the above option, you can use |Ctrl-]| and other tag related
1350 commands to jump to the symbol definition.
1352 Note that most of the language servers return only one symbol location even if
1353 the symbol is defined in multiple places in the code.
1355 ==============================================================================
1356 9. Code Formatting *lsp-format*
1358 The |:LspFormat| command can be used to format either the entire file or a
1359 selected range of lines using the language server. The 'shiftwidth' and
1360 'expandtab' values set for the current buffer are used when format is applied.
1362 To format code using the 'gq' command, you can set the 'formatexpr' option: >
1364 setlocal formatexpr=lsp#lsp#FormatExpr()
1366 ==============================================================================
1367 10. Call Hierarchy *lsp-call-hierarchy*
1369 The |:LspIncomingCalls| and the |:LspOutoingCalls| commands can be used to
1370 display the call hierarchy of a symbol. For example, the functions calling a
1371 function or the functions called by a function. These two commands open a
1372 window containing the call hierarchy tree. You can use the Vim motion
1373 commands to browse the call hierarchy.
1375 In the call hierarchy tree window, the following keys are supported:
1377 <Enter> Jump to the location of the symbol under the
1379 - Expand and show the symbols calling or called
1380 by the symbol under the cursor.
1381 + Close the call hierarchy for the symbol under
1384 You can display either the incoming call hierarchy or the outgoing call
1385 hierarchy in this window. You cannot display both at the same time.
1387 In the call hierarchy tree window, the following commands are supported:
1389 *:LspCallHierarchyRefresh*
1390 :LspCallHierarchyRefresh Query the language server again for the top
1391 level symbol and refresh the call hierarchy
1393 *:LspCallHierarchyIncoming*
1394 :LspCallHierarchyIncoming Display the incoming call hierarchy for the
1395 top level symbol. If the window is currently
1396 displaying the outgoing calls, then it is
1397 refreshed to display the incoming calls.
1398 *:LspCallHierarchyOutgoing*
1399 :LspCallHierarchyOutgoing Display the outgoing call hierarchy for the
1400 top level symbol. If the window is currently
1401 displaying the incoming calls, then it is
1402 refreshed to display the outgoing calls.
1404 ==============================================================================
1405 11. Autocommands *lsp-autocmds*
1408 LspAttached A |User| autocommand fired when the LSP client
1409 attaches to a buffer. Can be used to configure
1410 buffer-local mappings or options.
1413 LspDiagsUpdated A |User| autocommand invoked when new
1414 diagnostics are received from the language
1415 server. This is invoked after the LSP client
1416 has processed the diagnostics. Â The function
1417 lsp#diag#GetDiagsForBuf() can be used to get
1418 all the diagnostics for a buffer.
1420 ==============================================================================
1421 12. Highlight Groups *lsp-highlight-groups*
1423 The following highlight groups are used by the LSP plugin. You can define
1424 these highlight groups in your .vimrc file before sourcing this plugin to
1427 *LspDiagInlineError* Used to highlight inline error diagnostics.
1428 By default, linked to the "SpellBad" highlight
1430 *LspDiagInlineHint* Used to highlight inline hint diagnostics.
1431 By default, linked to the "SpellLocal"
1433 *LspDiagInlineInfo* Used to highlight inline info diagnostics.
1434 By default, linked to the "SpellRare"
1436 *LspDiagInlineWarning* Used to highlight inline warning diagnostics.
1437 By default, linked to the "SpellCap" highlight
1439 *LspDiagLine* Used to highlight a line with one or more
1440 diagnostics. By default linked to the
1441 "DiffAdd" highlight group. Use "NONE" to
1443 *LspDiagSignErrorText* Used to highlight the sign text for error
1444 diags. By default linked to 'ErrorMsg'.
1445 *LspDiagSignHintText* Used to highlight the sign text for hint
1446 diags. By default linked to 'Question'.
1447 *LspDiagSignInfoText* Used to highlight the sign text for info
1448 diags. By default linked to 'Pmenu'.
1449 *LspDiagSignWarningText* Used to highlight the sign text for warning
1450 diags. By default linked to 'Search'.
1451 *LspDiagVirtualText* Used to highlight diagnostic virtual text.
1452 By default, linked to the "LineNr" highlight
1454 *LspDiagVirtualTextError* Used to highlight virtual text for error diags.
1455 By default, linked to the "SpellBad" highlight
1457 *LspDiagVirtualTextHint* Used to highlight virtual text for hint
1458 diags. By default, linked to the "SpellLocal"
1460 *LspDiagVirtualTextInfo* Used to highlight virtual text for info
1461 diags. By default, linked to the "SpellRare"
1463 *LspDiagVirtualTextWarning* Used to highlight virtual text for warning
1464 diags. By default, linked to the "SpellCap"
1466 *LspInlayHintsParam* Used to highlight inlay hints of kind
1467 "parameter". By default, linked to the
1468 "Label" highlight group.
1469 *LspInlayHintsType* Used to highlight inlay hints of kind "type".
1470 By default, linked to the "Conceal" highlight
1472 *LspSigActiveParameter* Used to highlight the active signature
1473 parameter. By default, linked to the "LineNr"
1475 *LspSymbolName* Used to highlight the symbol name when using
1476 the |:LspDocumentSymbol| command. By default,
1477 linked to the "Search" highlight group.
1478 *LspSymbolRange* Used to highlight the range of lines
1479 containing a symbol when using the
1480 |:LspDocumentSymbol| command. By default,
1481 linked to the "Visual" highlight group.
1483 For example, to override the highlight used for diagnostics virtual text, you
1484 can use the following: >
1486 highlight LspDiagVirtualText ctermfg=Cyan guifg=Blue
1490 highlight link LspDiagLine NONE
1491 highlight link LspDiagVirtualText WarningMsg
1493 ==============================================================================
1494 13. Debugging *lsp-debug*
1496 To debug this plugin, you can log the language server protocol messages sent
1497 and received by the plugin from the language server. The following command
1498 enables the logging of the messages from the language server for the current
1503 This command also clears the log files. The following command disables the
1504 logging of the messages from the language server for the current buffer: >
1506 :LspServer debug off
1508 By default, the messages are not logged. Another method to enable the debug
1509 is to set the "debug" field to true when adding a language server
1510 using |LspAddServer()|.
1512 The messages printed by the language server in the stdout are logged to the
1513 lsp-<server-name>.log file and the messages printed in the stderr are logged
1514 to the lsp-<server-name>.err file. On a Unix-like system, these files are
1515 created in the /tmp directory. On MS-Windows, these files are created in the
1518 The following command opens the file containing the messages printed by the
1519 language server in the stdout: >
1521 :LspServer debug messages
1523 The following command opens the file containing the messages printed by the
1524 language server in the stderr: >
1526 :LspServer debug errors
1528 To debug language server initialization problems, after enabling the above
1529 server debug, you can restart the server for the file type in the current
1530 buffer using the following command: >
1534 The language servers typically support command line options to enable debug
1535 messages and to increase the verbosity of the messages. You can refer to the
1536 language server documentation for information about this. You can include
1537 these options when registering the language server with this plugin.
1539 If a language server supports the "$/logTrace" LSP notification, then you can
1540 use the :LspServerTrace command to set the server trace value: >
1542 :LspServer trace { off | messages | verbose }
1544 ==============================================================================
1545 14. Custom Command Handlers *lsp-custom-commands*
1547 When applying a code action, the language server may issue a non-standard
1548 command. For example, the Java language server uses non-standard commands
1549 (e.g. java.apply.workspaceEdit). To handle these commands, you can register a
1550 callback function for each command using the LspRegisterCmdHandler() function.
1554 import autoload "lsp/textedit.vim"
1556 def WorkspaceEdit(cmd: dict<any>)
1557 for editAct in cmd.arguments
1558 textedit.ApplyWorkspaceEdit(editAct)
1561 g:LspRegisterCmdHandler('java.apply.workspaceEdit', WorkspaceEdit)
1563 Place the above code in a file named lsp_java/plugin/lsp_java.vim and load
1566 The callback function should accept a Dict argument. The Dict argument
1567 contains the LSP Command interface fields. Refer to the LSP specification for
1568 more information about the "Command" interface.
1570 ==============================================================================
1571 15. Custom LSP Completion Kinds *lsp-custom-kinds*
1573 When a completion popup is triggered, the LSP client will use a default kind
1574 list to show in the completion "kind" section, to customize it, you need to
1575 use the option |lsp-opt-customCompletionKinds| and set all custom kinds in the
1576 option |lsp-opt-completionKinds| . There is a table with all default LSP
1580 ------------------------|--------------------
1608 For example, if you want to change the "Method" kind to the kind "method()": >
1613 customCompletionKinds: true,
1615 "Method": "method()"
1619 In the completion popup, will show something like this: >
1621 var file = new File()
1625 | createIfNotExists method() |
1628 ==============================================================================
1629 16. Multiple Language Servers for a buffer *lsp-multiple-servers*
1631 It's possible to run multiple language servers for a given buffer.
1633 By default the language server defined first will be used for as much as it
1634 supports, then the next and so on. With the exception that diagnostics from
1635 all running language servers will be combined.
1637 This means that you can define a language server that only supports a subset
1638 of features at first and then define the general purpose language server after
1644 # This language server reports that it only supports
1645 # textDocument/documentFormatting, so it will be used
1646 # for :LspFormat but nothing else.
1649 path: 'html-pretty-lsp',
1652 # This language server also supports
1653 # textDocument/documentFormatting, but since it's been
1654 # defined later, the one above will be used instead.
1655 # However this server also supports
1656 # textDocument/definition, textDocument/declaration,
1657 # etc, so it will be used for :LspGotoDefinition,
1658 # :LspGotoDeclaration, etc
1661 path: 'html-language-server',
1666 As shown in the example above the order of when the language servers are being
1667 defined is taken into account for a given method. However sometimes the
1668 language server that you want to use for formatting also reports that it
1669 supports other features. In such a case you can do one of two things:
1671 1. change the order of language servers, and specify that a given language
1672 server should be used for a given method.
1674 2. set the unwanted features to |false| in the features |Dictionary| >
1676 features: { 'codeAction': false }
1678 For example, if you want to use the efm-langserver for formatting, but the
1679 typescript-language-server for everything else: >
1684 # this language server will be used by default, as it's defined
1685 # as the first LSP for 'javascript' and 'typescript'
1687 filetype: ['javascript', 'typescript'],
1688 path: '/usr/local/bin/typescript-language-server',
1691 # this language server will be used for documentFormatting
1693 filetype: ['efm-langserver'],
1694 path: '/usr/local/bin/efm-langserver',
1697 documentFormatting: true
1702 Another way is to disable the unwanted features: for example if you don't want
1703 diagnostics from the typescript-language-server, but want to use it for
1710 filetype: ['javascript', 'typescript'],
1711 path: '/usr/local/bin/typescript-language-server',
1719 ==============================================================================
1720 17. Language Server Features *lsp-features*
1722 When using multiple language servers for a given file type, by providing the
1723 configuration |lsp-cfg-features| it is possible to specify which language
1724 server should be used for a given method/functionality. The following feature
1725 flags are supported: See |lsp-multiple-servers| for examples.
1727 *lsp-features-callHierarchy*
1728 callHierarchy Used by the|:LspIncomingCalls| and the
1729 |:LspOutgoingCalls| commands.
1730 *lsp-features-codeAction*
1731 codeAction Used by the |:LspCodeAction| command.
1732 *lsp-features-codeLens*
1733 codeLens Used by the |:LspCodeLens| command.
1734 *lsp-features-completion*
1735 completion Used by 24/7 Completion and 'omnifunc'
1736 *lsp-features-declaration*
1737 declaration Used by the |:LspGotoDeclaration|, and
1738 the |:LspPeekDeclaration| commands.
1739 *lsp-features-definition*
1740 definition Used by the|:LspGotoDefinition|, and
1741 the |:LspPeekDefinition| commands.
1742 *lsp-features-diagnostics*
1743 diagnostics Used to disable diagnostics for a single
1744 language server, by default diagnostics are
1745 combined from all running servers, by setting
1746 this to |false| you can ignore diagnostics
1747 from a specific server.
1748 *lsp-features-documentFormatting*
1749 documentFormatting Used by the |:LspFormat| command, and
1751 *lsp-features-documentHighlight*
1752 documentHighlight Used by the |:LspHighlight| and the
1753 |:LspHighlightClear| commands.
1754 *lsp-features-documentSymbol*
1755 documentSymbol Used by the |:LspDocumentSymbol| and the
1756 |:LspOutline| commands.
1757 *lsp-features-foldingRange*
1758 foldingRange Used by the|:LspFold| command.
1759 *lsp-features-hover*
1760 hover Used by the |:LspHover| command.
1761 *lsp-features-implementation*
1762 implementation Used by the |:LspGotoImpl| and the
1763 |:LspPeekImpl| commands.
1764 *lsp-features-inlayHint*
1765 inlayHint Used to show the inlay hints for
1766 function/method arguments.
1767 *lsp-features-references*
1768 references Used by the |:LspShowReferences| command.
1769 *lsp-features-rename*
1770 rename Used by the |:LspRename| command.
1771 *lsp-features-selectionRange*
1772 selectionRange Used by the |:LspSelectionExpand| and the
1773 |:LspSelectionShrink| commands.
1774 *lsp-features-signatureHelp*
1775 signatureHelp Used by the |:LspShowSignature| command.
1776 *lsp-features-typeDefinition*
1777 typeDefinition Used by the |:LspGotoTypeDef| and the
1778 |:LspPeekTypeDef| commands.
1779 typeHierarchy Used by the |:LspSubTypeHierarchy| and the
1780 |:LspSuperTypeHiearchy| commands.
1781 workspaceSymbol Used by the |:LspSymbolSearch| command.
1783 ==============================================================================
1785 License: MIT License
1786 Copyright (c) 2020-2023 Yegappan Lakshmanan
1788 Permission is hereby granted, free of charge, to any person obtaining a copy
1789 of this software and associated documentation files (the "Software"), to
1790 deal in the Software without restriction, including without limitation the
1791 rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
1792 sell copies of the Software, and to permit persons to whom the Software is
1793 furnished to do so, subject to the following conditions:
1795 The above copyright notice and this permission notice shall be included in
1796 all copies or substantial portions of the Software.
1798 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1799 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1800 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1801 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1802 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
1803 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
1806 ==============================================================================
1808 vim:tw=78:ts=8:noet:ft=help:norl: