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 true.
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-noNewlineInCompletion*
551 noNewlineInCompletion |Boolean| option. Suppress adding a new line on
552 completion selection with <CR>.
553 By default this is set to false.
555 *lsp-opt-outlineOnRight*
556 outlineOnRight |Boolean| option. Open the outline window on the
557 right side, by default this is false.
559 *lsp-opt-outlineWinSize*
560 outlineWinSize |Number| option. The size of the symbol Outline
561 window. By default this is set to 20.
563 *lsp-opt-showDiagInBalloon*
564 showDiagInBalloon |Boolean| option. When the mouse is over a range of
565 text referenced by a diagnostic, display the
566 diagnostic text in a balloon. By default this is set
567 to true. In a GUI Vim, this needs the |+balloon_eval|
568 feature. In a terminal Vim, this needs the
569 |+balloon_eval_term| feature. In a terminal Vim,
570 'mouse' option should be set to enable mouse.
571 If this option is set to true, then the 'ballooneval'
572 and 'balloonevalterm' options are set.
574 *lsp-opt-showDiagInPopup*
575 showDiagInPopup |Boolean| option. When using the ":LspDiag current"
576 command to display the diagnostic message for the
577 current line, use a popup window to display the
578 message instead of echoing in the status area.
579 By default this is set to true.
581 *lsp-opt-showDiagOnStatusLine*
582 showDiagOnStatusLine |Boolean| option. Show a diagnostic message on a
583 status line. By default this is set to false.
585 *lsp-opt-showDiagWithSign*
586 showDiagWithSign |Boolean| option. Place a sign on lines with
587 diagnostics. By default this is set to true. The
588 "autoHighlightDiags" option should be set to true.
590 *lsp-opt-showDiagWithVirtualText*
591 showDiagWithVirtualText |Boolean| option. Show diagnostic message text from
592 the language server with virtual text. By default
593 this is set to false. The "autoHighlightDiags" option
594 should be set to true.
595 Needs Vim version 9.0.1157 or later.
597 *lsp-opt-showInlayHints*
598 showInlayHints |Boolean| option. Show inlay hints from the language
599 server. By default this is set to false. The inlay
600 hint text is displayed as a virtual text. Needs Vim
601 version 9.0.0178 or later.
603 *lsp-opt-showSignature*
604 showSignature |Boolean| option. In insert mode, automatically show
605 the current symbol signature in a popup.
606 By default this is set to true.
608 *lsp-opt-snippetSupport*
609 snippetSupport |Boolean| option. Enable snippet completion support.
610 Need a snippet completion plugin like vim-vsnip.
611 By default this is set to false.
613 *lsp-opt-ultisnipsSupport*
614 ultisnipsSupport |Boolean| option. Enable SirVer/ultisnips support.
615 Need a snippet completion plugin SirVer/ultisnips.
616 By default this is set to false.
618 *lsp-opt-vssnipSupport*
619 vsnipSupport |Boolean| option. Enable hrsh7th/vim-vsnip support.
620 Need snippet completion plugins hrsh7th/vim-vsnip
621 and hrsh7th/vim-vsnip-integ. Make sure
622 ultisnipsSupport is set to false before enabling this.
623 By default this option is set to false.
625 *lsp-opt-usePopupInCodeAction*
626 usePopupInCodeAction |Boolean| option. When using the |:LspCodeAction|
627 command to display the code action for the current
628 line, use a popup menu instead of echoing.
629 By default this is set to false.
631 *lsp-opt-useQuickfixForLocations*
632 useQuickfixForLocations |Boolean| option. Show |:LspShowReferences| in a
633 quickfix list instead of a location list.
634 By default this is set to false.
636 *lsp-opt-useBufferCompletion*
637 useBufferCompletion |Boolean| option. If enabled, the words from the
638 current buffer are added to the auto completion list.
639 By default this is set to false.
641 *lsp-opt-bufferCompletionTimeout*
642 bufferCompletionTimeout |Number| option. Specifies how long (in milliseconds)
643 to wait while processing current buffer for
644 autocompletion words. If set too high Vim performance
645 may degrade as the current buffer contents are
646 processed every time the completion menu is displayed.
647 If set to 0 the entire buffer is processed without
649 By default this is set to 100 ms.
651 For example, to disable the automatic placement of signs for the LSP
652 diagnostic messages, you can add the following line to your .vimrc file: >
654 LspOptionsSet({'autoHighlightDiags': false})
656 The LspOptionsGet() function returns a |Dict| of all the LSP plugin options,
657 To get a particular option value you can use the following: >
659 echo LspOptionsGet()['autoHighlightDiags']
661 ==============================================================================
662 5. Commands *lsp-commands*
664 A description of the various commands provided by this plugin is below. You
665 can map these commands to keys and make it easier to invoke them.
668 :LspCodeAction [query] Apply the code action supplied by the language server
669 to the diagnostic in the current line. This works only
670 if there is a diagnostic message for the current line.
671 You can use the ":LspDiag current" command to display
672 the diagnostic for the current line.
674 When [query] is given the code action starting with
675 [query] will be applied. [query] can be a regexp
676 pattern, or a digit corresponding to the index of the
677 code actions in the created prompt.
679 When [query] is not given you will be prompted to
680 select one of the actions supplied by the language
684 :LspCodeLens Display a list of code lens commands available for the
685 current buffer and apply the selected code lens
689 :LspDiag current Displays the diagnostic message (if any) for the
690 current line. If the option 'showDiagInPopup' is set
691 to true (default), then the message is displayed in
692 a popup window. Otherwise the message is displayed in
693 the status message area.
695 :LspDiag! current Only display a diagnostic message if it's directly
696 under the cursor. Otherwise works exactly like
699 To show the current diagnotic under the cursor while
700 moving around the following autocmd can be used: >
704 au CursorMoved * silent! LspDiag! current
708 :LspDiag first Jumps to the location of the first diagnostic message
709 for the current file.
712 :LspDiag here Jumps to the location of the diagnostic message in
713 the current line (start from current column).
715 :LspDiag highlight disable *:LspDiag-highlight-disable*
716 Disable highlighting lines with a diagnostic message
717 for the current Vim session.
718 To always disable the highlighting, set the
719 autoHighlightDiags option to false.
721 :LspDiag highlight enable *:LspDiag-highlight-enable*
722 Enable highlighting lines with a diagnostic message
723 for the current Vim session. Note that highlighting
724 lines with a diagnostic message is enabled by default.
727 :LspDiag last Jumps to the location of the first diagnostic message
728 for the current file.
731 :[count]LspDiag next Go to the [count] diagnostic message after the current
732 cursor position. If [count] is omitted, then 1 is
733 used. If [count] exceeds the number of diagnostics
734 after the current position, then the last diagnostic
738 :[count]LspDiag prev Go to the [count] diagnostic message before the
739 current cursor position. If [count] is omitted, then
740 1 is used. If [count] exceeds the number of
741 diagnostics before the current position, then first
742 last diagnostic is selected.
745 :LspDiag show Creates a new location list with the diagnostics
746 messages (if any) from the language server for the
747 current file and opens the location list window. You
748 can use the Vim location list commands to browse the
752 :LspDocumentSymbol Display the symbols in the current file in a popup
753 menu. When a symbol is selected in the popup menu by
754 pressing <Enter> or <Space>, jump to the location of
757 The <Up>, <Down>, <C-F>, <C-B>, <PageUp>, <PageDown>,
758 <C-Home>, <C-End>, <C-N>, <C-P> keys can be used to
759 scroll the popup menu. The <Esc> or <Ctrl-C> keys can
760 be used to cancel the popup menu.
762 If one or more keyword characters are typed, then only
763 the symbols containing the keyword characters are
764 displayed in the popup menu. Fuzzy searching is used
765 to get the list of matching symbols. The <BS> key can
766 be used to erase the last typed character. The <C-U>
767 key can be used to erase all the characters.
769 When scrolling through the symbols in the popup menu,
770 the corresponding range of lines is highlighted.
773 :LspFold Create folds for the current buffer.
776 :LspFormat Format the current file using the language server. The
777 'shiftwidth' and 'expandtab' values set for the
778 current buffer are used when format is applied.
780 :{range}LspFormat Format the specified range of lines in the current
781 file using the language server.
783 *:LspGotoDeclaration*
784 :[count]LspGotoDeclaration
785 Jumps to the declaration of the symbol under the
786 cursor. The behavior of this command is similar to the
787 |:LspGotoDefinition| command.
790 :[count]LspGotoDefinition
791 Jumps to the [count] definition of the symbol under
792 the cursor. If there are multiple matches and [count]
793 isn't specified, then a location list will be created
794 with the list of locations.
796 If there is only one location, or [count] is provided
797 then the following will apply:
799 If the file is already present in a window, then jumps
800 to that window. Otherwise, opens the file in a new
801 window. If the current buffer is modified and
802 'hidden' is not set or if the current buffer is a
803 special buffer, then a new window is opened. If the
804 jump is successful, then the current cursor location
805 is pushed onto the tag stack. The |CTRL-T| command
806 can be used to go back up the tag stack. Also the
807 |``| mark is set to the position before the jump.
809 This command supports |:command-modifiers|. You can
810 use the modifiers to specify whether a new window or
811 a new tab page is used and where the window is opened.
814 # Open a horizontally split window
815 :topleft LspGotoDefinition
816 # Open a vertically split window
817 :vert LspGotoDefinition
818 # Open a new tab page
819 :tab LspGotoDefinition
821 You may want to map a key to invoke this command: >
823 nnoremap <buffer> gd <Cmd>LspGotoDefinition<CR>
824 nnoremap <buffer> <C-W>gd <Cmd>topleft LspGotoDefinition<CR>
826 Or if you want to support [count]gd >
828 nnoremap <buffer> gd <Cmd>execute v:count .. 'LspGotoDefinition'<CR>
829 nnoremap <buffer> <C-W>gd <Cmd>execute 'topleft ' .. v:count .. 'LspGotoDefinition'<CR>
832 :[count]LspGotoImpl Jumps to the implementation of the symbol under the
833 cursor. The behavior of this command is similar to the
834 |:LspGotoDefinition| command. Note that not all the
835 language servers support this feature.
837 You may want to map a key to invoke this command: >
839 nnoremap <buffer> gi <Cmd>LspGotoImpl<CR>
842 :[count]LspGotoTypeDef Jumps to the type definition of the symbol under the
843 cursor. The behavior of this command is similar to the
844 |:LspGotoDefinition| command. Note that not all the
845 language servers support this feature.
847 You may want to map a key to invoke this command: >
849 nnoremap <buffer> gt <Cmd>LspGotoTypeDef<CR>
852 :LspHighlight Highlights all the matches for the symbol under
853 cursor. The text, read and write references to the
854 symbol are highlighted using Search, DiffChange and
855 DiffDelete highlight groups respectively.
858 :LspHighlightClear Clears all the symbol matches highlighted by the
859 |:LspHighlight| command.
862 :LspHover Show the documentation for the symbol under the cursor
863 in a popup window. If you want to show the symbol
864 documentation in the |preview-window| instead of in a
867 LspOptionsSet({'hoverInPreview': true})
869 You can use the |:pclose| command to close the preview
872 You can use the |K| key in normal mode to display the
873 documentation for the keyword under the cursor by
874 setting the 'keywordprg' Vim option: >
876 :set keywordprg=:LspHover
879 :LspIncomingCalls Display a hierarchy of symbols calling the symbol
880 under the cursor in a window. See
881 |lsp-call-hierarchy| for more information. Note that
882 not all the language servers support this feature.
885 :LspInlayHints Enable or disable inlay hints. Supports the "enable"
886 and "disable" arguments. When "enable" is specified,
887 enables the inlay hints for all the buffers with a
888 language server that supports inlay hints. When
889 "disable" is specified, disables the inlay hints.
892 :LspOutoingCalls Display a hierarchy of symbols called by the symbol
893 under the cursor in a window. See
894 |lsp-call-hierarchy| for more information. Note that
895 not all the language servers support this feature.
898 :[count]LspOutline Opens a vertically split window with the list of
899 symbols defined in the current file. The current
900 symbol is highlighted. The symbols are grouped by
901 their type. You can select a symbol and press <Enter>
902 to jump to the position of the symbol. As you move the
903 cursor in a file, the current symbol is automatically
904 highlighted in the outline window. If you open a new
905 file, the outline window is automatically updated with
906 the symbols in the new file. Folds are created in the
907 outline window for the various group of symbols.
909 You can use |lsp-opt-outlineOnRight| and
910 |lsp-opt-outlineWinSize| to customize the placement
911 and size of the window.
913 This command also supports |:command-modifiers|. You
914 can use the modifiers specify the position of the
915 window. Note that the default is ":vert :topleft" or
916 ":vert :botright" depending on
917 |lsp-opt-outlineOnRight|
919 This command also supports providing a [count] to
920 specify the size of the window. Note that this
921 overrides the values defined in
922 |lsp-opt-outlineWinSize|.
925 # Open the outline window just above the current
927 :aboveleft LspOutline
929 # Open the outline window just next to the current
930 # window, this is different from the default, when
931 # you have multiple splits already
932 :vert aboveleft LspOutline
934 # Same as above, but with a width of 50
935 :vert aboveleft 50LspOutline
937 *:LspPeekDeclaration*
938 :[count]LspPeekDeclaration
939 Displays the line where the symbol under the
940 cursor is declared in a popup window. The
941 behavior of this command is similar to the
942 |:LspPeekDefinition| command.
945 :[count]LspPeekDefinition
946 Displays the line where the symbol under the cursor is
947 defined in a popup window. The symbol is highlighted
948 in the popup window. Moving the cursor or pressing
949 <Esc> will close the popup window.
950 When more than one symbol is found all of them will be
951 shown. The corresponding file for the symbol is
952 displayed in another popup window. As the selection
953 in the symbol popup menu changes, the file in the
955 When [count] is provided only the [count] symbol will
959 :[count]LspPeekImpl Displays the implementation of the symbol under the
960 cursor in a popup window. The behavior of this
961 command is similar to the |:LspPeekDefinition|
962 command. Note that not all the language servers
963 support this feature.
966 :LspPeekReferences Displays the list of references to the symbol under
967 cursor in a popup menu. The corresponding file for
968 the reference is displayed in another popup window.
969 As the selection in the reference popup menu changes,
970 the file in the popup is updated.
973 :[count]LspPeekTypeDef Displays the line where the type of the symbol under
974 the cursor is defined in a popup window. The
975 behavior of this command is similar to the
976 |:LspPeekDefinition| command. Note that not all the
977 language servers support this feature.
980 :LspRename [newName] Rename the current symbol.
982 When [newName] is not given, then you will be prompted
983 to enter the new name for the symbol. You can press
984 <Esc> or enter an empty string in the prompt to cancel
987 *:LspSelectionExpand*
988 :LspSelectionExpand Visually select the region of the symbol under the
989 cursor. In visual mode, expands the current symbol
990 visual region selection to include the next level.
992 For example, if the cursor is on a "for" statement,
993 this command selects the "for" statement and the body
994 of the "for" statement.
996 It is useful to create a visual map to use this
999 xnoremap <silent> <Leader>e <Cmd>LspSelectionExpand<CR>
1001 With the above map, you can press "\e" in visual mode
1002 successively to expand the current symbol visual
1005 *:LspSelectionShrink*
1006 :LspSelectionShrink Shrink the current symbol range visual selection. It
1007 is useful to create a visual map to use this command.
1010 xnoremap <silent> <Leader>s <Cmd>LspSelectionShrink<CR>
1012 With the above map, you can press "\s" in visual mode
1013 successively to shrink the current symbol visual
1017 :LspServer { debug | restart | show | trace }
1018 Command to display and control the language server for
1019 the current buffer. Each argument has additional
1020 sub-commands which are described below.
1022 debug { on | off | messages | errors }
1023 Command to enable or disable the language server
1024 debug messages and to display the debug messages
1025 and error messages received from the language
1026 server. The following sub-commands are supported:
1027 errors Open the log file containing the
1028 language server error messages.
1030 Open the log file containing the
1031 language server debug messages.
1032 off Disable the logging of the language
1034 on Enable the logging of the messages
1035 emitted by the language server in the
1036 standard output and standard error.
1037 By default, the language server messages are not
1038 logged. On a Unix-like system, when enabled,
1039 these messages are logged to the
1040 /tmp/lsp-<server-name>.log and
1041 /tmp/lsp-<server-name>.err file respectively. On
1042 MS-Windows, the %TEMP%/lsp-<server-name>.log and
1043 %TEMP%/lsp-<server-name>.err% files are used. See
1044 |lsp-debug| for more information.
1047 Restart (stop and then start) the language server
1048 for the current buffer. All the loaded buffers
1049 with the same filetype as the current buffer are
1050 added back to the server.
1052 show {capabilities | initializeRequest | messages
1054 The following sub-commands are supported:
1056 Display the list of language server
1057 capabilities for the current buffer.
1058 The server capabilities are described
1059 in the LSP protocol specification
1060 under the "ServerCapabilities"
1063 Display the contents of the language
1064 server initialization request message
1067 Display the log messages received from
1068 the language server. This includes
1069 the messages received using the
1070 "window/logMessage" and "$/logTrace"
1073 Display the language server status for
1074 the current buffer. The output shows
1075 the path to the language server
1076 executable and the server status.
1078 trace { off | messages | verbose }
1079 Set the language server debug trace value using
1080 the "$/setTrace" command.
1082 *:LspShowAllServers*
1083 :LspShowAllServers Displays the list of registered language servers and
1084 their status. The language servers are registered
1085 using the LspAddServer() function. The output is
1086 displayed in a scratch buffer. The output shows the
1087 Vim file type, the corresponding language server
1088 status and the path to the language server executable.
1089 The language server information for each buffer is
1092 *:LspShowReferences*
1093 :LspShowReferences Creates a new location list with the list of locations
1094 where the symbol under the cursor is referenced and
1095 opens the location window. If you want to show the
1096 references in a quickfix list instead of in a location
1099 LspOptionsSet({'useQuickfixForLocations': true})
1102 :LspShowSignature Displays the signature of the symbol (e.g. a function
1103 or method) before the cursor in a popup.
1105 The popup is also automatically displayed in insert
1106 mode after entering a symbol name followed by a
1107 separator (e.g. a opening parenthesis). To disable
1108 this, you can set the showSignature option to false in
1111 LspOptionsSet({'showSignature': false})
1115 You can get the function signature echoed in cmdline
1116 rather than displayed in popup if you use >
1118 LspOptionsSet({'echoSignature': true})
1122 *:LspSubTypeHierarchy*
1123 :LspSubTypeHierarchy Show the sub type hierarchy for the symbol under the
1124 cursor in a popup window. The file containing the
1125 type is shown in another popup window. You can jump
1126 to the location where a type is defined by browsing
1127 the popup menu and selecting an entry.
1129 *:LspSuperTypeHierarchy*
1130 :LspSuperTypeHierarchy Show the super type hierarchy for the symbol under the
1131 cursor in a popup window. The file containing the
1132 type is shown in another popup window. As the current
1133 entry in the type hierarchy popup menu changes, the
1134 file popup window is updated to show the location
1135 where the type is defined. You can jump to the
1136 location where a type is defined by selecting the
1137 entry in the popup menu.
1139 Note that the type hierarchy support is based on the
1140 protocol supported by clangd. This is different from
1141 the one specified in the 3.17 of the LSP standard.
1143 *:LspSwitchSourceHeader*
1144 :LspSwitchSourceHeader Switch between source and header files. This is a
1145 Clangd specific extension and only works with C/C++
1149 :LspSymbolSearch <sym> Perform a workspace wide search for the symbol <sym>.
1150 If <sym> is not supplied, then you will be prompted to
1151 enter the symbol name (the keyword under the cursor is
1152 used as the default). If there is only one matching
1153 symbol, then the cursor will be positioned at the
1154 symbol location. Otherwise a popup window is opened
1155 with the list of matching symbols. You can enter a
1156 few characters to narrow down the list of matches. The
1157 displayed symbol name can be erased by pressing
1158 <Backspace> or <C-U> and a new symbol search pattern
1159 can be entered. You can close the popup menu by
1160 pressing the escape key or by pressing CTRL-C.
1162 In the popup menu, the following keys can be used:
1164 CTRL-F - Scroll one page forward
1166 CTRL-B - Scroll one page backward
1168 CTRL-Home - Jump to the first entry
1169 CTRL-End - Jump to the last entry
1170 <Up> - Go up one entry
1172 <Down> - Go down one entry
1174 <Enter> - Open the selected file
1175 <Esc> - Close the popup menu
1177 <BS> - Erase one character from the
1180 <C-U> - Erase the filter text
1182 Any other alphanumeric key will be used to narrow down
1183 the list of names displayed in the popup menu. When
1184 you type a filter string, then only the symbols fuzzy
1185 matching the string are displayed in the popup menu.
1186 You can enter a new search pattern to do a workspace
1189 This command accepts |:command-modifiers| which can be
1190 used to jump to a symbol in a horizontally or
1191 vertically split window or a new tab page: >
1193 :topleft LspSymbolSearch foo
1194 :vert LspSymbolSearch bar
1195 :tab LspSymbolSearch baz
1197 *:LspWorkspaceAddFolder*
1198 :LspWorkspaceAddFolder {folder}
1199 Add a folder to the workspace
1201 :LspWorkspaceListFolders *:LspWorkspaceListFolders*
1202 Show the list of folders in the workspace.
1204 *:LspWorkspaceRemoveFolder*
1205 :LspWorkspaceRemoveFolder {folder}
1206 Remove a folder from the workspace
1208 ==============================================================================
1209 6. Insert mode completion *lsp-ins-mode-completion*
1211 By default, in insert mode, the LSP plugin automatically displays the matches
1212 for the symbol under the cursor in an insert-completion popup menu. You can
1213 use the keys described in |popupmenu-keys| with this menu.
1215 To disable the auto-completion for all the files, you can set the
1216 'autoComplete' option to false in your .vimrc file: >
1218 LspOptionsSet({'autoComplete': false})
1220 If this variable is set, then the LSP plugin will not automatically start
1221 completion in insert mode and instead supports omni-completion (|compl-omni|).
1222 It sets the 'omnifunc' option for the buffers which have a registered language
1223 server. To complete a symbol in insert mode manually, you can press CTRL-X
1224 CTRL-O to invoke completion using the items suggested by the language server.
1226 You can also enable or disable omni-completion for a specific language
1227 server by setting the 'omnicompl' item to 'false' when registering a lsp
1228 server for the filetype. If this item is not specified, then omni-completion
1229 is enabled by default. The following example disables omni-completion for
1237 path: '/usr/local/bin/pyls',
1238 args: ['--check-parent-process', '-v']
1242 If you want to use omni completion, in addition to the automatic completion,
1243 then you can set the 'omnifunc' option to the "g:LspOmniFunc" function: >
1245 set omnifunc=g:LspOmniFunc
1247 To use omni completion, press CTRL-X CTRL-O in insert mode. Refer to
1248 |compl-omni| for more information.
1250 When doing insert-mode completion, the plugin sends a request message to the
1251 language server to return a list of possible completion matches for the
1252 current cursor position. The plugin retrieves the keyword before the cursor
1253 (see 'iskeyword') and then filters the returned list of completion items
1254 against this keyword and displays the completion menu. Some language servers
1255 does completion filtering in the server, while other relies on the client to
1256 do the filtering. By default, case sensitive comparison is used to filter the
1257 returned items. You can modify the 'completionMatcher' option to use either
1258 case insensitive or fuzzy comparison.
1260 ==============================================================================
1261 7. Diagnostics *lsp-diagnostics*
1263 When a source file has syntax errors or warnings or static analysis warnings,
1264 the LSP plugin highlights them by placing |signs| in the |sign-column|. You
1265 can use the ":LspDiag show" command to display all the diagnostic messages for
1266 the current file in a |location-list-window|. You can use the
1267 ":LspDiag first" command to jump to the line with the first diagnostic
1268 message, the ":LspDiag next" command to jump to the next nearest line with the
1269 diagnostic message, the ":LspDiag prev" command to jump to the previous
1270 nearest line with the diagnostic message, the ":LspDiag here" command to jump
1271 to the diagnostic message in the current line. You can use the ":LspDiag
1272 current" command to display the entire diagnostic message from the language
1273 server for the current line.
1275 By default, the lines with a diagnostic message have a sign placed on them and
1276 the range of text with the diagnostic is highlighted. You can disable the
1277 automatic sign placement by setting the "showDiagWithSign" option to v:false.
1278 By default, this option is set to v:true. You can disable the diagnostic text
1279 highlighting by setting the "highlightDiagInline" option to v:false. The line
1280 with the diagnostics is highlighted using the "LspDiagLine" highlight group.
1281 By default this highlight group is not set.
1283 You can also display the diagnostic message as a virtual text near the
1284 location of the diagnostics by setting the "showDiagWithVirtualText" option to
1285 v:true. This needs Vim version 9.0.1157 or later. By default this option is
1286 set to v:false. The position of the virtual text is controlled by the
1287 "diagVirtualTextAlign" option. By default, this is set to 'above'. The other
1288 supported values are 'below' and 'after'.
1290 The range of text for a diagnostic message can be automatically highlighted by
1291 setting the "highlightDiagInline" option to v:true. By default, this option
1292 is set to v:true. The text is highlighted using the "LspDiagInlineError" or
1293 "LspDiagInlineHint" or "LspDiagInlineInfo" or "LspDiagInlineWarning" highlight
1296 You can temporarily disable the automatic diagnostic highlighting for the
1297 current Vim session using the ":LspDiag highlight disable" command and
1298 re-enable them using the ":LspDiag highlight enable" command.
1300 To disable the automatic highlighting of the diagnostics, you can set the
1301 'autoHighlightDiags' option to v:false: >
1303 LspOptionsSet({'autoHighlightDiags': false})
1305 By default the 'autoHighlightDiags' option is set to v:true.
1307 The function lsp#lsp#ErrorCount() function can be used to get the count of the
1308 diagnostic messages in the current buffer by type. This function returns a
1309 Dictionary with the following keys: Info, Hint, Warn and Error. The value for
1310 these keys is the number of diagnostic messages of the corresponding type.
1311 This function can be used to display the number of diagnostics in the current
1312 buffer in a 'statusline'.
1314 For some diagnostic errors/warnings, the language server may provide an
1315 automatic fix. To apply this fix, you can use the |:LspCodeAction| command.
1316 This command applies the action provided by the language server (if any) for
1319 The ":LspDiag show" command creates a new location list with the current list
1320 of diagnostics for the current buffer. To automatically add the diagnostics
1321 messages to the location list, you can set the 'autoPopulateDiags' option to
1322 true. Â By default this option is set to false. Â When new diagnostics are
1323 received for a buffer, if a location list with the diagnostics is already
1324 present, then it is refreshed with the new diagnostics.
1326 When using GUI Vim or in a terminal Vim with 'balloonevalterm' option set,
1327 when the mouse is moved over the range of text referenced by a diagnostic,
1328 then the diagnostic message is displayed in a popup. If the
1329 "showDiagInBalloon" option is set to false, then the balloon popup will not be
1330 displayed. By default, this option is set to true.
1332 To display the diagnostic message for the current line in the status area, you
1333 can set the 'showDiagOnStatusLine' option to true. By default, this option
1336 By default, the ":LspDiag current" command displays the diagnostic message
1337 for the current line in a popup window. To display the message in the status
1338 message area instead, you can set the 'showDiagInPopup' option to false. By
1339 default this is set to true.
1341 The lsp#diag#GetDiagsForBuf() function can be used to get all the LSP
1342 diagnostics in a buffer. Â This function optionally accepts a buffer number.
1343 If the buffer number argument is not specified, then the current buffer is
1344 used. Â This function returns a |List| of diagnostics sorted by their line and
1345 column number. Â Each diagnostic is a |Dict| returned by the language server.
1347 ==============================================================================
1348 8. Tag Function *lsp-tagfunc*
1350 The |:LspGotoDefinition| command can be used jump to the location where a
1351 symbol is defined. To jump to the symbol definition using the Vim
1352 |tag-commands|, you can set the 'tagfunc' option to the 'lsp#lsp#TagFunc'
1355 setlocal tagfunc=lsp#lsp#TagFunc
1357 After setting the above option, you can use |Ctrl-]| and other tag related
1358 commands to jump to the symbol definition.
1360 Note that most of the language servers return only one symbol location even if
1361 the symbol is defined in multiple places in the code.
1363 ==============================================================================
1364 9. Code Formatting *lsp-format*
1366 The |:LspFormat| command can be used to format either the entire file or a
1367 selected range of lines using the language server. The 'shiftwidth' and
1368 'expandtab' values set for the current buffer are used when format is applied.
1370 To format code using the 'gq' command, you can set the 'formatexpr' option: >
1372 setlocal formatexpr=lsp#lsp#FormatExpr()
1374 ==============================================================================
1375 10. Call Hierarchy *lsp-call-hierarchy*
1377 The |:LspIncomingCalls| and the |:LspOutoingCalls| commands can be used to
1378 display the call hierarchy of a symbol. For example, the functions calling a
1379 function or the functions called by a function. These two commands open a
1380 window containing the call hierarchy tree. You can use the Vim motion
1381 commands to browse the call hierarchy.
1383 In the call hierarchy tree window, the following keys are supported:
1385 <Enter> Jump to the location of the symbol under the
1387 - Expand and show the symbols calling or called
1388 by the symbol under the cursor.
1389 + Close the call hierarchy for the symbol under
1392 You can display either the incoming call hierarchy or the outgoing call
1393 hierarchy in this window. You cannot display both at the same time.
1395 In the call hierarchy tree window, the following commands are supported:
1397 *:LspCallHierarchyRefresh*
1398 :LspCallHierarchyRefresh Query the language server again for the top
1399 level symbol and refresh the call hierarchy
1401 *:LspCallHierarchyIncoming*
1402 :LspCallHierarchyIncoming Display the incoming call hierarchy for the
1403 top level symbol. If the window is currently
1404 displaying the outgoing calls, then it is
1405 refreshed to display the incoming calls.
1406 *:LspCallHierarchyOutgoing*
1407 :LspCallHierarchyOutgoing Display the outgoing call hierarchy for the
1408 top level symbol. If the window is currently
1409 displaying the incoming calls, then it is
1410 refreshed to display the outgoing calls.
1412 ==============================================================================
1413 11. Autocommands *lsp-autocmds*
1416 LspAttached A |User| autocommand fired when the LSP client
1417 attaches to a buffer. Can be used to configure
1418 buffer-local mappings or options.
1421 LspDiagsUpdated A |User| autocommand invoked when new
1422 diagnostics are received from the language
1423 server. This is invoked after the LSP client
1424 has processed the diagnostics. Â The function
1425 lsp#diag#GetDiagsForBuf() can be used to get
1426 all the diagnostics for a buffer.
1428 ==============================================================================
1429 12. Highlight Groups *lsp-highlight-groups*
1431 The following highlight groups are used by the LSP plugin. You can define
1432 these highlight groups in your .vimrc file before sourcing this plugin to
1435 *LspDiagInlineError* Used to highlight inline error diagnostics.
1436 By default, linked to the "SpellBad" highlight
1438 *LspDiagInlineHint* Used to highlight inline hint diagnostics.
1439 By default, linked to the "SpellLocal"
1441 *LspDiagInlineInfo* Used to highlight inline info diagnostics.
1442 By default, linked to the "SpellRare"
1444 *LspDiagInlineWarning* Used to highlight inline warning diagnostics.
1445 By default, linked to the "SpellCap" highlight
1447 *LspDiagLine* Used to highlight a line with one or more
1448 diagnostics. By default linked to "NONE"
1449 (cleared). You can link this to a highlight
1450 group to highlight the line.
1451 *LspDiagSignErrorText* Used to highlight the sign text for error
1452 diags. By default linked to 'ErrorMsg'.
1453 *LspDiagSignHintText* Used to highlight the sign text for hint
1454 diags. By default linked to 'Question'.
1455 *LspDiagSignInfoText* Used to highlight the sign text for info
1456 diags. By default linked to 'Pmenu'.
1457 *LspDiagSignWarningText* Used to highlight the sign text for warning
1458 diags. By default linked to 'Search'.
1459 *LspDiagVirtualText* Used to highlight diagnostic virtual text.
1460 By default, linked to the "LineNr" highlight
1462 *LspDiagVirtualTextError* Used to highlight virtual text for error diags.
1463 By default, linked to the "SpellBad" highlight
1465 *LspDiagVirtualTextHint* Used to highlight virtual text for hint
1466 diags. By default, linked to the "SpellLocal"
1468 *LspDiagVirtualTextInfo* Used to highlight virtual text for info
1469 diags. By default, linked to the "SpellRare"
1471 *LspDiagVirtualTextWarning* Used to highlight virtual text for warning
1472 diags. By default, linked to the "SpellCap"
1474 *LspInlayHintsParam* Used to highlight inlay hints of kind
1475 "parameter". By default, linked to the
1476 "Label" highlight group.
1477 *LspInlayHintsType* Used to highlight inlay hints of kind "type".
1478 By default, linked to the "Conceal" highlight
1480 *LspSigActiveParameter* Used to highlight the active signature
1481 parameter. By default, linked to the "LineNr"
1483 *LspSymbolName* Used to highlight the symbol name when using
1484 the |:LspDocumentSymbol| command. By default,
1485 linked to the "Search" highlight group.
1486 *LspSymbolRange* Used to highlight the range of lines
1487 containing a symbol when using the
1488 |:LspDocumentSymbol| command. By default,
1489 linked to the "Visual" highlight group.
1491 For example, to override the highlight used for diagnostics virtual text, you
1492 can use the following: >
1494 highlight LspDiagVirtualText ctermfg=Cyan guifg=Blue
1498 highlight link LspDiagLine DiffAdd
1499 highlight link LspDiagVirtualText WarningMsg
1501 ==============================================================================
1502 13. Debugging *lsp-debug*
1504 To debug this plugin, you can log the language server protocol messages sent
1505 and received by the plugin from the language server. The following command
1506 enables the logging of the messages from the language server for the current
1511 This command also clears the log files. The following command disables the
1512 logging of the messages from the language server for the current buffer: >
1514 :LspServer debug off
1516 By default, the messages are not logged. Another method to enable the debug
1517 is to set the "debug" field to true when adding a language server
1518 using |LspAddServer()|.
1520 The messages printed by the language server in the stdout are logged to the
1521 lsp-<server-name>.log file and the messages printed in the stderr are logged
1522 to the lsp-<server-name>.err file. On a Unix-like system, these files are
1523 created in the /tmp directory. On MS-Windows, these files are created in the
1526 The following command opens the file containing the messages printed by the
1527 language server in the stdout: >
1529 :LspServer debug messages
1531 The following command opens the file containing the messages printed by the
1532 language server in the stderr: >
1534 :LspServer debug errors
1536 To debug language server initialization problems, after enabling the above
1537 server debug, you can restart the server for the file type in the current
1538 buffer using the following command: >
1542 The language servers typically support command line options to enable debug
1543 messages and to increase the verbosity of the messages. You can refer to the
1544 language server documentation for information about this. You can include
1545 these options when registering the language server with this plugin.
1547 If a language server supports the "$/logTrace" LSP notification, then you can
1548 use the :LspServerTrace command to set the server trace value: >
1550 :LspServer trace { off | messages | verbose }
1552 ==============================================================================
1553 14. Custom Command Handlers *lsp-custom-commands*
1555 When applying a code action, the language server may issue a non-standard
1556 command. For example, the Java language server uses non-standard commands
1557 (e.g. java.apply.workspaceEdit). To handle these commands, you can register a
1558 callback function for each command using the LspRegisterCmdHandler() function.
1562 import autoload "lsp/textedit.vim"
1564 def WorkspaceEdit(cmd: dict<any>)
1565 for editAct in cmd.arguments
1566 textedit.ApplyWorkspaceEdit(editAct)
1569 g:LspRegisterCmdHandler('java.apply.workspaceEdit', WorkspaceEdit)
1571 Place the above code in a file named lsp_java/plugin/lsp_java.vim and load
1574 The callback function should accept a Dict argument. The Dict argument
1575 contains the LSP Command interface fields. Refer to the LSP specification for
1576 more information about the "Command" interface.
1578 ==============================================================================
1579 15. Custom LSP Completion Kinds *lsp-custom-kinds*
1581 When a completion popup is triggered, the LSP client will use a default kind
1582 list to show in the completion "kind" section, to customize it, you need to
1583 use the option |lsp-opt-customCompletionKinds| and set all custom kinds in the
1584 option |lsp-opt-completionKinds| . There is a table with all default LSP
1588 ------------------------|--------------------
1616 For example, if you want to change the "Method" kind to the kind "method()": >
1621 customCompletionKinds: true,
1623 "Method": "method()"
1627 In the completion popup, will show something like this: >
1629 var file = new File()
1633 | createIfNotExists method() |
1636 ==============================================================================
1637 16. Multiple Language Servers for a buffer *lsp-multiple-servers*
1639 It's possible to run multiple language servers for a given buffer.
1641 By default the language server defined first will be used for as much as it
1642 supports, then the next and so on. With the exception that diagnostics from
1643 all running language servers will be combined.
1645 This means that you can define a language server that only supports a subset
1646 of features at first and then define the general purpose language server after
1652 # This language server reports that it only supports
1653 # textDocument/documentFormatting, so it will be used
1654 # for :LspFormat but nothing else.
1657 path: 'html-pretty-lsp',
1660 # This language server also supports
1661 # textDocument/documentFormatting, but since it's been
1662 # defined later, the one above will be used instead.
1663 # However this server also supports
1664 # textDocument/definition, textDocument/declaration,
1665 # etc, so it will be used for :LspGotoDefinition,
1666 # :LspGotoDeclaration, etc
1669 path: 'html-language-server',
1674 As shown in the example above the order of when the language servers are being
1675 defined is taken into account for a given method. However sometimes the
1676 language server that you want to use for formatting also reports that it
1677 supports other features. In such a case you can do one of two things:
1679 1. change the order of language servers, and specify that a given language
1680 server should be used for a given method.
1682 2. set the unwanted features to |false| in the features |Dictionary| >
1684 features: { 'codeAction': false }
1686 For example, if you want to use the efm-langserver for formatting, but the
1687 typescript-language-server for everything else: >
1692 # this language server will be used by default, as it's defined
1693 # as the first LSP for 'javascript' and 'typescript'
1695 filetype: ['javascript', 'typescript'],
1696 path: '/usr/local/bin/typescript-language-server',
1699 # this language server will be used for documentFormatting
1701 filetype: ['efm-langserver'],
1702 path: '/usr/local/bin/efm-langserver',
1705 documentFormatting: true
1710 Another way is to disable the unwanted features: for example if you don't want
1711 diagnostics from the typescript-language-server, but want to use it for
1718 filetype: ['javascript', 'typescript'],
1719 path: '/usr/local/bin/typescript-language-server',
1727 ==============================================================================
1728 17. Language Server Features *lsp-features*
1730 When using multiple language servers for a given file type, by providing the
1731 configuration |lsp-cfg-features| it is possible to specify which language
1732 server should be used for a given method/functionality. The following feature
1733 flags are supported: See |lsp-multiple-servers| for examples.
1735 *lsp-features-callHierarchy*
1736 callHierarchy Used by the|:LspIncomingCalls| and the
1737 |:LspOutgoingCalls| commands.
1738 *lsp-features-codeAction*
1739 codeAction Used by the |:LspCodeAction| command.
1740 *lsp-features-codeLens*
1741 codeLens Used by the |:LspCodeLens| command.
1742 *lsp-features-completion*
1743 completion Used by 24/7 Completion and 'omnifunc'
1744 *lsp-features-declaration*
1745 declaration Used by the |:LspGotoDeclaration|, and
1746 the |:LspPeekDeclaration| commands.
1747 *lsp-features-definition*
1748 definition Used by the|:LspGotoDefinition|, and
1749 the |:LspPeekDefinition| commands.
1750 *lsp-features-diagnostics*
1751 diagnostics Used to disable diagnostics for a single
1752 language server, by default diagnostics are
1753 combined from all running servers, by setting
1754 this to |false| you can ignore diagnostics
1755 from a specific server.
1756 *lsp-features-documentFormatting*
1757 documentFormatting Used by the |:LspFormat| command, and
1759 *lsp-features-documentHighlight*
1760 documentHighlight Used by the |:LspHighlight| and the
1761 |:LspHighlightClear| commands.
1762 *lsp-features-documentSymbol*
1763 documentSymbol Used by the |:LspDocumentSymbol| and the
1764 |:LspOutline| commands.
1765 *lsp-features-foldingRange*
1766 foldingRange Used by the|:LspFold| command.
1767 *lsp-features-hover*
1768 hover Used by the |:LspHover| command.
1769 *lsp-features-implementation*
1770 implementation Used by the |:LspGotoImpl| and the
1771 |:LspPeekImpl| commands.
1772 *lsp-features-inlayHint*
1773 inlayHint Used to show the inlay hints for
1774 function/method arguments.
1775 *lsp-features-references*
1776 references Used by the |:LspShowReferences| command.
1777 *lsp-features-rename*
1778 rename Used by the |:LspRename| command.
1779 *lsp-features-selectionRange*
1780 selectionRange Used by the |:LspSelectionExpand| and the
1781 |:LspSelectionShrink| commands.
1782 *lsp-features-signatureHelp*
1783 signatureHelp Used by the |:LspShowSignature| command.
1784 *lsp-features-typeDefinition*
1785 typeDefinition Used by the |:LspGotoTypeDef| and the
1786 |:LspPeekTypeDef| commands.
1787 typeHierarchy Used by the |:LspSubTypeHierarchy| and the
1788 |:LspSuperTypeHiearchy| commands.
1789 workspaceSymbol Used by the |:LspSymbolSearch| command.
1791 ==============================================================================
1793 License: MIT License
1794 Copyright (c) 2020-2023 Yegappan Lakshmanan
1796 Permission is hereby granted, free of charge, to any person obtaining a copy
1797 of this software and associated documentation files (the "Software"), to
1798 deal in the Software without restriction, including without limitation the
1799 rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
1800 sell copies of the Software, and to permit persons to whom the Software is
1801 furnished to do so, subject to the following conditions:
1803 The above copyright notice and this permission notice shall be included in
1804 all copies or substantial portions of the Software.
1806 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1807 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1808 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1809 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1810 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
1811 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
1814 ==============================================================================
1816 vim:tw=78:ts=8:noet:ft=help:norl: