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 18, 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 :LspDiagCurrent Display the diagnostic message for the current line.
77 :LspDiagFirst Jump to the first diagnostic message for the current
79 :LspDiagHere Jump to the next diagnostic message in the current
81 :LspDiagHighlightDisable
82 Disable highlighting lines with a diagnostic message
83 for the current Vim session.
84 :LspDiagHighlightEnable Enable highlighting lines with a diagnostic message
85 for the current Vim session.
86 :LspDiagLast Jump to the last diagnostic message for the current
88 :LspDiagNext Jump to the next diagnostic message for the current
89 buffer after the current cursor position.
90 :LspDiagPrev Jump to the previous diagnostic message for the
91 current buffer before the current current position.
92 :LspDiagShow Display the diagnostics messages from the language
93 server for the current buffer in a location list.
94 :LspDocumentSymbol Display the symbols in the current file in a popup
95 menu and jump to the location of a selected symbol.
96 :LspFold Fold the current file
97 :LspFormat Format a range of lines in the current file using the
98 language server. The default range is the entire
99 file. See |lsp-format| for more information.
100 :LspGotoDeclaration Go to the declaration of the symbol under cursor
101 :LspGotoDefinition Go to the definition of the symbol under cursor
102 :LspGotoImpl Go to the implementation of the symbol under cursor
103 :LspGotoTypeDef Go to the type definition of the symbol under cursor
104 :LspHighlight Highlight all the matches for the keyword under cursor
105 :LspHighlightClear Clear all the matches highlighted by :LspHighlight
106 :LspHover Show the documentation for the symbol under the cursor
108 :LspIncomingCalls Display the list of symbols calling the current symbol
110 :LspOutgoingCalls Display the list of symbols called by the current
112 :LspOutline Show the list of symbols defined in the current file
113 in a separate window.
114 :LspPeekDeclaration Open the declaration of the symbol under cursor in a
116 :LspPeekDefinition Open the definition of the symbol under cursor in a
118 :LspPeekImpl Open the implementation of the symbol under cursor in
120 :LspPeekReferences Display the list of references to the symbol under
121 cursor in a popup window.
122 :LspPeekTypeDef Open the type definition of the symbol under cursor in
124 :LspRename Rename the current symbol
125 :LspSelectionExpand Expand the current symbol range visual selection
126 :LspSelectionShrink Shrink the current symbol range visual selection
127 :LspServer Command to display the status and messages from a
128 language server and to restart the language server.
129 :LspShowAllServers Display the status of all the registered language
131 :LspShowReferences Display the list of references to the keyword under
132 cursor in a new location list.
133 :LspShowSignature Display the signature of the symbol under cursor.
134 :LspSubTypeHierarchy Display the sub type hierarchy in a popup window.
135 :LspSuperTypeHierarchy Display the super type hierarchy in a popup window.
136 :LspSwitchSourceHeader Switch between a source and a header file.
137 :LspSymbolSearch Perform a workspace wide search for a symbol
138 :LspWorkspaceAddFolder {folder}
139 Add a folder to the workspace
140 :LspWorkspaceListFolders
141 Show the list of folders in the workspace
142 :LspWorkspaceRemoveFolder {folder}
143 Remove a folder from the workspace
145 ==============================================================================
146 4. Configuration *lsp-configuration*
147 *LspAddServer()* *g:LspAddServer()*
149 To use the plugin features with a particular file type(s), you need to first
150 register a language server for that file type(s).
152 To register one or more language servers, use the LspAddServer() function with
153 a list of lanaguge server details in the .vimrc file.
155 To register a language server, add the following lines to your .vimrc file
156 (use only the language servers that you need from the below list).
157 If you used [vim-plug](https://github.com/junegunn/vim-plug) to install the
158 LSP plugin, the steps are described later in this section: >
163 name: 'typescriptls',
164 filetype: ['javascript', 'typescript'],
165 path: '/usr/local/bin/typescript-language-server',
171 path: '/usr/local/bin/pyls',
172 args: ['--check-parent-process', '-v']
175 LspAddServer(lspServers)
177 Depending on the location of the typescript and python pyls language servers
178 installed in your system, update the "path" in the above snippet
181 Another example, for adding the language servers for the C, C++, Golang, Rust,
182 Shell script, Vim script and PHP file types: >
188 filetype: ['c', 'cpp'],
189 path: '/usr/local/bin/clangd',
190 args: ['--background-index']
194 filetype: ['go', 'gomod', 'gohtmltmpl', 'gotexttmpl'],
195 path: '/path/to/.go/bin/gopls',
202 path: '/path/to/.cargo/bin/rust-analyzer',
209 path: '/usr/local/bin/bash-language-server',
215 path: '/usr/local/bin/vim-language-server',
221 path': '/usr/local/bin/intelephense',
224 initializationOptions: {
225 licenceKey: 'xxxxxxxxxxxxxxx'
229 LspAddServer(lspServers)
231 To add a language server, the following information is needed:
234 name (Optional) name of the language server. Can by any
235 string. Used in LSP messages and log files.
237 path complete path to the language server executable
238 (without any arguments).
240 args a |List| of command-line arguments passed to the
241 language server. Each space separated language server
242 command-line argument is a separate List item.
244 filetype One or more file types supported by the language
245 server. This can be a |String| or a |List|. To
246 specify multiple file types, use a List.
247 *lsp-cfg-initializationOptions*
248 initializationOptions
249 (Optional) for lsp servers (e.g. intelephense) some
250 additional initialization options may be required
251 or useful for initialization. Those can be provided in
252 this dictionary and if present will be transmitted to
254 *lsp-cfg-workspaceConfig*
255 workspaceConfig (Optional) a json encodable value that will be sent to
256 the language server after initialization as the
257 "settings" in a "workspace/didChangeConfiguration"
258 notification. Refer to the language server
259 documentation for the values that will be accepted in
260 this notification. This configuration is also used to
261 respond to the "workspace/configuration" request
262 message from the language server.
264 rootSearch (Optional) a List of file and directory names used to
265 locate the root path or uri of the workspace. The
266 directory names in "rootSearch" must end in "/" or
267 "\". Each file and directory name in "rootSearch" is
268 searched upwards in all the parent directories. If
269 multiple directories are found, then the directory
270 closest to the directory of the current buffer is used
271 as the workspace root.
273 If this parameter is not specified or the files are
274 not found, then the current working directory is used
275 as the workspace root for decendent files, for any
276 other files the parent directory of the file is used.
278 *lsp-cfg-runIfSearch*
279 runIfSearch (Optional) a List of file and directory names used to
280 determinate if a server should run or not. The
281 directory names in "runIfSearch" must end in "/" or
282 "\". Each file and directory name in "runIfSearch" is
283 searched upwards in all the parent directories.
284 Exactly like |lsp-cfg-rootSearch|.
286 If a file or directory is found then the server will
287 be started, otherwise it will not.
289 If this parameter is not specified or is an empty
290 list, then the server will be started unless
291 |lsp-cfg-runUnlessSearch| prevents it.
293 *lsp-cfg-runUnlessSearch*
294 runUnlessSearch (Optional) Opposite of |lsp-cfg-runIfSearch|.
296 Additionally the following configurations can be made:
298 *lsp-cfg-customNotificationHandlers*
299 customNotificationHandlers
300 (Optional) some lsp servers (e.g.
301 typescript-language-server) will send additional
302 notifications which you might want to silence or
303 handle. The provided notification handlers will be
304 called with a reference to the "lspserver" and the
309 filetype: ['javascript', 'typescript'],
310 path: '/usr/local/bin/typescript-language-server',
312 customNotificationHandlers: {
313 '$/typescriptVersion': (lspserver, reply) => {
314 echom printf("TypeScript Version = %s",
315 reply.params.version)
320 *lsp-cfg-customRequestHandlers*
321 customRequestHandlers
322 (Optional) some lsp servers will send additional
323 request replies which you might want to silence or
324 handle. The provided request handlers will be called
325 with a reference to the "lspserver" and the "request".
327 features *lsp-cfg-features*
328 (Optional) toggle which features should be enabled for
329 a given language server. See |lsp-multiple-servers|
330 and |lsp-features| for more information.
332 forceOffsetEncoding *lsp-cfg-forceOffsetEncoding*
333 (Optional) a |String| value that forces the use of a
334 specific offset encoding in LSP messages. If this
335 option is not specified, then the UTF offset encoding
336 is negotiated with the server during initialization.
337 Supported values are 'utf-8' or 'utf-16' or 'utf-32'.
338 The Vim native offset encoding is 'utf-32'. For the
339 'utf-8' and 'utf-16' encodings, the offsets need to be
340 encoded and decoded in every LSP message and will
344 omnicompl (Optional) a boolean value that enables (true)
345 or disables (false) omni-completion for these file
346 types. By default this is set to "v:true". This value
347 is applicable only if auto completion is disabled
348 (|lsp-opt-autoComplete|).
350 *lsp-cfg-processDiagHandler*
352 (Optional) A |Funcref| or |lambda| that takes a list
353 of language server diagnostics and returns a new list
354 of filtered, or otherwise changed diagnostics. Can be
355 used to remove unwanted diagnostics, prefix the
356 diagnostics text, etc. The following example will
357 remove all but errors and warnings: >
361 filetype: ['javascript', 'typescript'],
362 path: '/usr/local/bin/typescript-language-server',
364 processDiagHandler: (diags: list<dict<any>>) => {
365 # Only include errors and warnings
366 return diags->filter((diag, ix) => {
367 return diag.severity <= 2
372 And this example will prefix the diagnostic message
373 with the string "TypeScript: ": >
377 filetype: ['javascript', 'typescript'],
378 path: '/usr/local/bin/typescript-language-server',
380 processDiagHandler: (diags: list<dict<any>>) => {
381 return diags->map((diag, ix) => {
382 diag.message = $'TypeScript: {diag.message}'
389 syncInit (Optional) for language servers (e.g. rust analyzer,
390 gopls, etc.) that take time to initialize and reply to
391 a "initialize" request message this should be set to
392 "true". If this is set to true, then a synchronous
393 call is used to initialize the language server,
394 otherwise the server is initialized asynchronously.
395 By default this is set to "false".
398 debug (Optional) log the messages printed by this language
399 server in stdout and stderr to a file. Useful for
400 debugging a language server. By default the
401 messages are not logged. See |lsp-debug| for more
405 traceLevel (Optional) set the debug trace level for this language
406 server. Â Supported values are: "off", "debug" and
407 "verbose". By default this is seto "off".
409 The language servers are added using the LspAddServer() function. This
410 function accepts a list of language servers with the above information.
412 If you used [vim-plug](https://github.com/junegunn/vim-plug) to install the
413 LSP plugin, then you need to use the VimEnter autocmd to initialize the
414 language server and to set the language server options. For example: >
420 filetype: ['c', 'cpp'],
421 path: '/usr/local/bin/clangd',
422 args: ['--background-index']
425 autocmd VimEnter * LspAddServer(lspServers)
427 var lspOpts = {'autoHighlightDiags': true}
428 autocmd VimEnter * LspOptionsSet(lspOpts)
430 *lsp-options* *LspOptionsSet*
433 Some of the LSP plugin features can be enabled or disabled by using the
434 LspOptionsSet() function. This function accepts a dictionary argument with the
435 following optional items:
438 aleSupport |Boolean| option. If true, diagnostics will be sent to
439 Ale, instead of being displayed by this plugin.
440 This is useful to combine all LSP and linter
441 diagnostics. By default this is set to false.
442 *lsp-opt-autoComplete*
443 autoComplete |Boolean| option. In insert mode, automatically
444 complete the current symbol. Otherwise use
445 omni-completion. By default this is set to true.
446 *lsp-opt-autoHighlight*
447 autoHighlight |Boolean| option. In normal mode, automatically
448 highlight all the occurrences of the symbol under the
449 cursor. By default this is set to false.
450 *lsp-opt-autoHighlightDiags*
451 autoHighlightDiags |Boolean| option. Automatically place signs on the
452 lines with a diagnostic message from the language
453 server. By default this is set to true.
454 *lsp-opt-autoPopulateDiags*
455 autoPopulateDiags |Boolean| option. Automatically populate the location
456 list with diagnostics from the language server.
457 By default this is set to false.
458 *lsp-opt-completionMatcher*
459 completionMatcher |String| option. Enable fuzzy or case insensitive
460 completion for language servers that replies with a
461 full list of completion items. Some language servers
462 does completion filtering in the server, while other
463 relies on the client to do the filtering.
465 This option only works for language servers that
466 expect the client to filter the completion items.
468 This option accepts one of the following values:
469 case - case sensitive matching (default).
470 fuzzy - fuzzy match completion items.
471 icase - ignore case when matching items.
472 *lsp-opt-completionTextEdit*
473 completionTextEdit |Boolean| option. If true, apply the LSP server
474 supplied text edits after a completion. If a snippet
475 plugin is going to apply the text edits, then set
476 this to false to avoid applying the text edits twice.
477 By default this is set to true.
478 *lsp-opt-completionKinds*
479 completionKinds |Dictionary| option. See |lsp-custom-kinds| for all
480 completion kind names.
481 *lsp-opt-customCompletionKinds*
482 customCompletionKinds |Boolean| option. If you set this to true, you can
483 set custom completion kinds using the option
485 *lsp-opt-diagSignErrorText*
486 diagSignErrorText |String| option. Change diag sign text for errors
488 *lsp-opt-diagSignHintText*
489 diagSignHintText |String| option. Change diag sign text for hints
491 *lsp-opt-diagSignInfoText*
492 diagSignInfoText |String| option. Change diag sign text for info
494 *lsp-opt-diagSignWarningText*
495 diagSignWarningText |String| option. Change diag sign text for warnings
497 *lsp-opt-diagVirtualTextAlign*
498 diagVirtualTextAlign |String| option. Alignment of diagnostics messages
499 if |lsp-opt-showDiagWithVirtualText| is set to true.
500 Allowed values are 'above', 'below' or 'after'
501 By default this is set to 'above',
502 *lsp-opt-echoSignature*
503 echoSignature |Boolean| option. In insert mode, echo the current
504 symbol signature instead of showing it in a popup.
505 By default this is set to false.
506 *lsp-opt-hideDisabledCodeActions*
507 hideDisabledCodeActions |Boolean| option. Hide all the disabled code actions.
508 By default this is set to false.
509 *lsp-opt-highlightDiagInline*
510 highlightDiagInline |Boolean| option. Highlight the diagnostics inline
511 By default this is set to false.
512 *lsp-opt-hoverInPreview*
513 hoverInPreview |Boolean| option. Show |:LspHover| in a preview window
515 By default this is set to false.
516 *lsp-opt-ignoreMissingServer*
517 ignoreMissingServer |Boolean| option. Do not print a missing language
518 server executable. By default this is set to false.
519 *lsp-opt-keepFocusInDiags*
520 keepFocusInDiags |Boolean| option. Focus on the location list window
522 By default this is set to true.
523 *lsp-opt-keepFocusInReferences*
524 keepFocusInReferences |Boolean| option. Focus on the location list window
525 after LspShowReferences.
526 By default this is set to true.
527 *lsp-opt-noDiagHoverOnLine*
528 noDiagHoverOnLine |Boolean| option. Suppress diagnostic hover from
529 appearing when the mouse is over the line instead of
531 By default this is set to true.
532 *lsp-opt-noNewlineInCompletion*
533 noNewlineInCompletion |Boolean| option. Suppress adding a new line on
534 completion selection with <CR>.
535 By default this is set to false.
536 *lsp-opt-outlineOnRight*
537 outlineOnRight |Boolean| option. Open the outline window on the
538 right side, by default this is false.
539 *lsp-opt-outlineWinSize*
540 outlineWinSize |Number| option. The size of the symbol Outline
541 window. By default this is set to 20.
542 *lsp-opt-showDiagInPopup*
543 showDiagInPopup |Boolean| option. When using the |:LspDiagCurrent|
544 command to display the diagnostic message for the
545 current line, use a popup window to display the
546 message instead of echoing in the status area.
547 By default this is set to true.
548 *lsp-opt-showDiagOnStatusLine*
549 showDiagOnStatusLine |Boolean| option. Show a diagnostic message on a
550 status line. By default this is set to false.
551 *lsp-opt-showDiagWithVirtualText*
552 showDiagWithVirtualText |Boolean| option. Show diagnostic message text from
553 the language server with virtual text. By default
554 this is set to false. The "autoHighlightDiags" option
555 should be set to true.
556 Needs Vim version 9.0.1157 or later.
557 *lsp-opt-showInlayHints*
558 showInlayHints |Boolean| option. Show inlay hints from the language
559 server. By default this is set to false. The inlay
560 hint text is displayed as a virtual text. Needs Vim
561 version 9.0.0178 or later.
562 *lsp-opt-showSignature*
563 showSignature |Boolean| option. In insert mode, automatically show
564 the current symbol signature in a popup.
565 By default this is set to true.
566 *lsp-opt-snippetSupport*
567 snippetSupport |Boolean| option. Enable snippet completion support.
568 Need a snippet completion plugin like vim-vsnip.
569 By default this is set to false.
570 *lsp-opt-ultisnipsSupport*
571 ultisnipsSupport |Boolean| option. Enable SirVer/ultisnips support.
572 Need a snippet completion plugin SirVer/ultisnips.
573 By default this is set to false.
574 *lsp-opt-vssnipSupport*
575 vsnipSupport |Boolean| option. Enable hrsh7th/vim-vsnip support.
576 Need snippet completion plugins hrsh7th/vim-vsnip
577 and hrsh7th/vim-vsnip-integ. Make sure
578 ultisnipsSupport is set to false before enabling this.
579 By default this option is set to false.
580 *lsp-opt-usePopupInCodeAction*
581 usePopupInCodeAction |Boolean| option. When using the |:LspCodeAction|
582 command to display the code action for the current
583 line, use a popup menu instead of echoing.
584 By default this is set to false.
585 *lsp-opt-useQuickfixForLocations*
586 useQuickfixForLocations |Boolean| option. Show |:LspShowReferences| in a
587 quickfix list instead of a location list.
588 By default this is set to false.
589 *lsp-opt-useBufferCompletion*
590 useBufferCompletion |Boolean| option. If enabled, the words from the
591 current buffer are added to the auto completion list.
592 By default this is set to false.
593 *lsp-opt-bufferCompletionTimeout*
594 bufferCompletionTimeout |Number| option. Specifies how long (in milliseconds)
595 to wait while processing current buffer for
596 autocompletion words. If set too high Vim performance
597 may degrade as the current buffer contents are
598 processed every time the completion menu is displayed.
599 If set to 0 the entire buffer is processed without
601 By default this is set to 100 ms (good for scanning
602 a file of about 6000 lines on M1 Macbook).
604 For example, to disable the automatic placement of signs for the LSP
605 diagnostic messages, you can add the following line to your .vimrc file: >
607 LspOptionsSet({'autoHighlightDiags': false})
609 The LspOptionsGet() function returns a |Dict| of all the LSP plugin options,
610 To get a particular option value you can use the following: >
612 echo LspOptionsGet()['autoHighlightDiags']
614 ==============================================================================
615 5. Commands *lsp-commands*
617 A description of the various commands provided by this plugin is below. You
618 can map these commands to keys and make it easier to invoke them.
621 :LspCodeAction [query] Apply the code action supplied by the language server
622 to the diagnostic in the current line. This works only
623 if there is a diagnostic message for the current line.
624 You can use the |:LspDiagCurrent| command to display
625 the diagnostic for the current line.
627 When [query] is given the code action starting with
628 [query] will be applied. [query] can be a regexp
629 pattern, or a digit corresponding to the index of the
630 code actions in the created prompt.
632 When [query] is not given you will be prompted to
633 select one of the actions supplied by the language
637 :LspCodeLens Display a list of code lens commands available for the
638 current buffer and apply the selected code lens
642 :LspDiagCurrent Displays the diagnostic message (if any) for the
643 current line. If the option 'showDiagInPopup' is set
644 to true (default), then the message is displayed in
645 a popup window. Otherwise the message is displayed in
646 the status message area.
648 :LspDiagCurrent! Only display a diagnostic message if it's directly
649 under the cursor. Otherwise works exactly like
652 To show the current diagnotic under the cursor while
653 moving around the following autocmd can be used: >
657 au CursorMoved * silent! LspDiagCurrent!
661 :LspDiagFirst Jumps to the location of the first diagnostic message
662 for the current file.
665 :LspDiagHere Jumps to the location of the diagnostic message in
666 the current line (start from current column).
668 :LspDiagHighlightDisable *:LspDiagHighlightDisable*
669 Disable highlighting lines with a diagnostic message
670 for the current Vim session.
671 To always disable the highlighting, set the
672 autoHighlightDiags option to false.
674 *:LspDiagHighlightEnable*
675 :LspDiagHighlightEnable Enable highlighting lines with a diagnostic message
676 for the current Vim session. Note that highlighting
677 lines with a diagnostic message is enabled by default.
680 :LspDiagLast Jumps to the location of the first diagnostic message
681 for the current file.
684 :[count]LspDiagNext Go to the [count] diagnostic message after the current
685 cursor position. If [count] is omitted, then 1 is
686 used. If [count] exceeds the number of diagnostics
687 after the current position, then the last diagnostic
691 :[count]LspDiagPrev Go to the [count] diagnostic message before the
692 current cursor position. If [count] is omitted, then
693 1 is used. If [count] exceeds the number of
694 diagnostics before the current position, then first
695 last diagnostic is selected.
698 :LspDiagShow Creates a new location list with the diagnostics
699 messages (if any) from the language server for the
700 current file and opens the location list window. You
701 can use the Vim location list commands to browse the
705 :LspDocumentSymbol Display the symbols in the current file in a popup
706 menu. When a symbol is selected in the popup menu by
707 pressing <Enter> or <Space>, jump to the location of
710 The <Up>, <Down>, <C-F>, <C-B>, <PageUp>, <PageDown>,
711 <C-Home>, <C-End>, <C-N>, <C-P> keys can be used to
712 scroll the popup menu. The <Esc> or <Ctrl-C> keys can
713 be used to cancel the popup menu.
715 If one or more keyword characters are typed, then only
716 the symbols containing the keyword characters are
717 displayed in the popup menu. Fuzzy searching is used
718 to get the list of matching symbols. The <BS> key can
719 be used to erase the last typed character. The <C-U>
720 key can be used to erase all the characters.
722 When scrolling through the symbols in the popup menu,
723 the corresponding range of lines is highlighted.
726 :LspFold Create folds for the current buffer.
729 :LspFormat Format the current file using the language server. The
730 'shiftwidth' and 'expandtab' values set for the
731 current buffer are used when format is applied.
733 :{range}LspFormat Format the specified range of lines in the current
734 file using the language server.
736 *:LspGotoDeclaration*
737 :[count]LspGotoDeclaration
738 Jumps to the declaration of the symbol under the
739 cursor. The behavior of this command is similar to the
740 |:LspGotoDefinition| command.
743 :[count]LspGotoDefinition
744 Jumps to the [count] definition of the symbol under
745 the cursor. If there are multiple matches and [count]
746 isn't specified, then a location list will be created
747 with the list of locations.
749 If there is only one location, or [count] is provided
750 then the following will apply:
752 If the file is already present in a window, then jumps
753 to that window. Otherwise, opens the file in a new
754 window. If the current buffer is modified and
755 'hidden' is not set or if the current buffer is a
756 special buffer, then a new window is opened. If the
757 jump is successful, then the current cursor location
758 is pushed onto the tag stack. The |CTRL-T| command
759 can be used to go back up the tag stack. Also the
760 |``| mark is set to the position before the jump.
762 This command supports |:command-modifiers|. You can
763 use the modifiers to specify whether a new window or
764 a new tab page is used and where the window is opened.
767 # Open a horizontally split window
768 :topleft LspGotoDefinition
769 # Open a vertically split window
770 :vert LspGotoDefinition
771 # Open a new tab page
772 :tab LspGotoDefinition
774 You may want to map a key to invoke this command: >
776 nnoremap <buffer> gd <Cmd>LspGotoDefinition<CR>
777 nnoremap <buffer> <C-W>gd <Cmd>topleft LspGotoDefinition<CR>
779 Or if you want to support [count]gd >
781 nnoremap <buffer> gd <Cmd>execute v:count .. 'LspGotoDefinition'<CR>
782 nnoremap <buffer> <C-W>gd <Cmd>execute 'topleft ' .. v:count .. 'LspGotoDefinition'<CR>
785 :[count]LspGotoImpl Jumps to the implementation of the symbol under the
786 cursor. The behavior of this command is similar to the
787 |:LspGotoDefinition| command. Note that not all the
788 language servers support this feature.
790 You may want to map a key to invoke this command: >
792 nnoremap <buffer> gi <Cmd>LspGotoImpl<CR>
795 :[count]LspGotoTypeDef Jumps to the type definition of the symbol under the
796 cursor. The behavior of this command is similar to the
797 |:LspGotoDefinition| command. Note that not all the
798 language servers support this feature.
800 You may want to map a key to invoke this command: >
802 nnoremap <buffer> gt <Cmd>LspGotoTypeDef<CR>
805 :LspHighlight Highlights all the matches for the symbol under
806 cursor. The text, read and write references to the
807 symbol are highlighted using Search, DiffChange and
808 DiffDelete highlight groups respectively.
811 :LspHighlightClear Clears all the symbol matches highlighted by the
812 |:LspHighlight| command.
815 :LspHover Show the documentation for the symbol under the cursor
816 in a popup window. If you want to show the symbol
817 documentation in the preview window instead of in a
820 LspOptionsSet({'hoverInPreview': true})
822 You can use the |K| key in normal mode to display the
823 documentation for the keyword under the cursor by
824 setting the 'keywordprg' Vim option: >
826 :set keywordprg=:LspHover
829 :LspIncomingCalls Display a hierarchy of symbols calling the symbol
830 under the cursor in a window. See
831 |lsp-call-hierarchy| for more information. Note that
832 not all the language servers support this feature.
835 :LspOutoingCalls Display a hierarchy of symbols called by the symbol
836 under the cursor in a window. See
837 |lsp-call-hierarchy| for more information. Note that
838 not all the language servers support this feature.
841 :[count]LspOutline Opens a vertically split window with the list of
842 symbols defined in the current file. The current
843 symbol is highlighted. The symbols are grouped by
844 their type. You can select a symbol and press <Enter>
845 to jump to the position of the symbol. As you move the
846 cursor in a file, the current symbol is automatically
847 highlighted in the outline window. If you open a new
848 file, the outline window is automatically updated with
849 the symbols in the new file. Folds are created in the
850 outline window for the various group of symbols.
852 You can use |lsp-opt-outlineOnRight| and
853 |lsp-opt-outlineWinSize| to customize the placement
854 and size of the window.
856 This command also supports |:command-modifiers|. You
857 can use the modifiers specify the position of the
858 window. Note that the default is ":vert :topleft" or
859 ":vert :botright" depending on
860 |lsp-opt-outlineOnRight|
862 This command also supports providing a [count] to
863 specify the size of the window. Note that this
864 overrides the values defined in
865 |lsp-opt-outlineWinSize|.
868 # Open the outline window just above the current
870 :aboveleft LspOutline
872 # Open the outline window just next to the current
873 # window, this is different from the default, when
874 # you have multiple splits already
875 :vert aboveleft LspOutline
877 # Same as above, but with a width of 50
878 :vert aboveleft 50LspOutline
880 *:LspPeekDeclaration*
881 :[count]LspPeekDeclaration
882 Displays the line where the symbol under the
883 cursor is declared in a popup window. The
884 behavior of this command is similar to the
885 |:LspPeekDefinition| command.
888 :[count]LspPeekDefinition
889 Displays the line where the symbol under the cursor is
890 defined in a popup window. The symbol is highlighted
891 in the popup window. Moving the cursor or pressing
892 <Esc> will close the popup window.
893 When more than one symbol is found all of them will be
894 shown. The corresponding file for the symbol is
895 displayed in another popup window. As the selection
896 in the symbol popup menu changes, the file in the
898 When [count] is provided only the [count] symbol will
902 :[count]LspPeekImpl Displays the implementation of the symbol under the
903 cursor in a popup window. The behavior of this
904 command is similar to the |:LspPeekDefinition|
905 command. Note that not all the language servers
906 support this feature.
909 :LspPeekReferences Displays the list of references to the symbol under
910 cursor in a popup menu. The corresponding file for
911 the reference is displayed in another popup window.
912 As the selection in the reference popup menu changes,
913 the file in the popup is updated.
916 :[count]LspPeekTypeDef Displays the line where the type of the symbol under
917 the cursor is defined in a popup window. The
918 behavior of this command is similar to the
919 |:LspPeekDefinition| command. Note that not all the
920 language servers support this feature.
923 :LspRename [newName] Rename the current symbol.
925 When [newName] is not given, then you will be prompted
926 to enter the new name for the symbol. You can press
927 <Esc> or enter an empty string in the prompt to cancel
930 *:LspSelectionExpand*
931 :LspSelectionExpand Visually select the region of the symbol under the
932 cursor. In visual mode, expands the current symbol
933 visual region selection to include the next level.
935 For example, if the cursor is on a "for" statement,
936 this command selects the "for" statement and the body
937 of the "for" statement.
939 It is useful to create a visual map to use this
942 xnoremap <silent> <Leader>e <Cmd>LspSelectionExpand<CR>
944 With the above map, you can press "\e" in visual mode
945 successively to expand the current symbol visual
948 *:LspSelectionShrink*
949 :LspSelectionShrink Shrink the current symbol range visual selection. It
950 is useful to create a visual map to use this command.
953 xnoremap <silent> <Leader>s <Cmd>LspSelectionShrink<CR>
955 With the above map, you can press "\s" in visual mode
956 successively to shrink the current symbol visual
960 :LspServer { debug | restart | show | trace }
961 Command to display and control the language server for
962 the current buffer. Each argument has additional
963 sub-commands which are described below.
965 debug { on | off | messages | errors }
966 Command to enable or disable the language server
967 debug messages and to display the debug messages
968 and error messages received from the language
969 server. The following sub-commands are supported:
970 errors Open the log file containing the
971 language server error messages.
973 Open the log file containing the
974 language server debug messages.
975 off Disable the logging of the language
977 on Enable the logging of the messages
978 emitted by the language server in the
979 standard output and standard error.
980 By default, the language server messages are not
981 logged. On a Unix-like system, when enabled,
982 these messages are logged to the
983 /tmp/lsp-<server-name>.log and
984 /tmp/lsp-<server-name>.err file respectively. On
985 MS-Windows, the %TEMP%/lsp-<server-name>.log and
986 %TEMP%/lsp-<server-name>.err% files are used. See
987 |lsp-debug| for more information.
990 Restart (stop and then start) the language server
991 for the current buffer. All the loaded buffers
992 with the same filetype as the current buffer are
993 added back to the server.
995 show {capabilities | initializeRequest | messages
997 The following sub-commands are supported:
999 Display the list of language server
1000 capabilities for the current buffer.
1001 The server capabilities are described
1002 in the LSP protocol specification
1003 under the "ServerCapabilities"
1006 Display the contents of the language
1007 server initialization request message
1010 Display the log messages received from
1011 the language server. This includes
1012 the messages received using the
1013 "window/logMessage" and "$/logTrace"
1016 Display the language server status for
1017 the current buffer. The output shows
1018 the path to the language server
1019 executable and the server status.
1021 trace { off | messages | verbose }
1022 Set the language server debug trace value using
1023 the "$/setTrace" command.
1025 *:LspShowAllServers*
1026 :LspShowAllServers Displays the list of registered language servers and
1027 their status. The language servers are registered
1028 using the LspAddServer() function. The output is
1029 displayed in a scratch buffer. The output shows the
1030 Vim file type, the corresponding language server
1031 status and the path to the language server executable.
1032 The language server information for each buffer is
1035 *:LspShowReferences*
1036 :LspShowReferences Creates a new location list with the list of locations
1037 where the symbol under the cursor is referenced and
1038 opens the location window. If you want to show the
1039 references in a quickfix list instead of in a location
1042 LspOptionsSet({'useQuickfixForLocations': true})
1045 :LspShowSignature Displays the signature of the symbol (e.g. a function
1046 or method) before the cursor in a popup.
1048 The popup is also automatically displayed in insert
1049 mode after entering a symbol name followed by a
1050 separator (e.g. a opening parenthesis). To disable
1051 this, you can set the showSignature option to false in
1054 LspOptionsSet({'showSignature': false})
1058 You can get the function signature echoed in cmdline
1059 rather than displayed in popup if you use >
1061 LspOptionsSet({'echoSignature': true})
1065 *:LspSubTypeHierarchy*
1066 :LspSubTypeHierarchy Show the sub type hierarchy for the symbol under the
1067 cursor in a popup window. The file containing the
1068 type is shown in another popup window. You can jump
1069 to the location where a type is defined by browsing
1070 the popup menu and selecting an entry.
1072 *:LspSuperTypeHierarchy*
1073 :LspSuperTypeHierarchy Show the super type hierarchy for the symbol under the
1074 cursor in a popup window. The file containing the
1075 type is shown in another popup window. As the current
1076 entry in the type hierarchy popup menu changes, the
1077 file popup window is updated to show the location
1078 where the type is defined. You can jump to the
1079 location where a type is defined by selecting the
1080 entry in the popup menu.
1082 Note that the type hierarchy support is based on the
1083 protocol supported by clangd. This is different from
1084 the one specified in the 3.17 of the LSP standard.
1086 *:LspSwitchSourceHeader*
1087 :LspSwitchSourceHeader Switch between source and header files. This is a
1088 Clangd specific extension and only works with C/C++
1092 :LspSymbolSearch <sym> Perform a workspace wide search for the symbol <sym>.
1093 If <sym> is not supplied, then you will be prompted to
1094 enter the symbol name (the keyword under the cursor is
1095 used as the default). If there is only one matching
1096 symbol, then the cursor will be positioned at the
1097 symbol location. Otherwise a popup window is opened
1098 with the list of matching symbols. You can enter a
1099 few characters to narrow down the list of matches. The
1100 displayed symbol name can be erased by pressing
1101 <Backspace> or <C-U> and a new symbol search pattern
1102 can be entered. You can close the popup menu by
1103 pressing the escape key or by pressing CTRL-C.
1105 In the popup menu, the following keys can be used:
1107 CTRL-F - Scroll one page forward
1109 CTRL-B - Scroll one page backward
1111 CTRL-Home - Jump to the first entry
1112 CTRL-End - Jump to the last entry
1113 <Up> - Go up one entry
1115 <Down> - Go down one entry
1117 <Enter> - Open the selected file
1118 <Esc> - Close the popup menu
1120 <BS> - Erase one character from the
1123 <C-U> - Erase the filter text
1125 Any other alphanumeric key will be used to narrow down
1126 the list of names displayed in the popup menu. When
1127 you type a filter string, then only the symbols fuzzy
1128 matching the string are displayed in the popup menu.
1129 You can enter a new search pattern to do a workspace
1132 This command accepts |:command-modifiers| which can be
1133 used to jump to a symbol in a horizontally or
1134 vertically split window or a new tab page: >
1136 :topleft LspSymbolSearch foo
1137 :vert LspSymbolSearch bar
1138 :tab LspSymbolSearch baz
1140 *:LspWorkspaceAddFolder*
1141 :LspWorkspaceAddFolder {folder}
1142 Add a folder to the workspace
1144 :LspWorkspaceListFolders *:LspWorkspaceListFolders*
1145 Show the list of folders in the workspace.
1147 *:LspWorkspaceRemoveFolder*
1148 :LspWorkspaceRemoveFolder {folder}
1149 Remove a folder from the workspace
1151 ==============================================================================
1152 6. Insert mode completion *lsp-ins-mode-completion*
1154 By default, in insert mode, the LSP plugin automatically displays the matches
1155 for the symbol under the cursor in an insert-completion popup menu. You can
1156 use the keys described in |popupmenu-keys| with this menu.
1158 To disable the auto-completion for all the files, you can set the
1159 'autoComplete' option to false in your .vimrc file: >
1161 LspOptionsSet({'autoComplete': false})
1163 If this variable is set, then the LSP plugin will not automatically start
1164 completion in insert mode and instead supports omni-completion (|compl-omni|).
1165 It sets the 'omnifunc' option for the buffers which have a registered language
1166 server. To complete a symbol in insert mode manually, you can press CTRL-X
1167 CTRL-O to invoke completion using the items suggested by the language server.
1169 You can also enable or disable omni-completion for a specific language
1170 server by setting the 'omnicompl' item to 'false' when registering a lsp
1171 server for the filetype. If this item is not specified, then omni-completion
1172 is enabled by default. The following example disables omni-completion for
1180 path: '/usr/local/bin/pyls',
1181 args: ['--check-parent-process', '-v']
1185 If you want to use omni completion, in addition to the automatic completion,
1186 then you can set the 'omnifunc' option to the "g:LspOmniFunc" function: >
1188 set omnifunc=g:LspOmniFunc
1190 To use omni completion, press CTRL-X CTRL-O in insert mode. Refer to
1191 |compl-omni| for more information.
1193 When doing insert-mode completion, the plugin sends a request message to the
1194 language server to return a list of possible completion matches for the
1195 current cursor position. The plugin retrieves the keyword before the cursor
1196 (see 'iskeyword') and then filters the returned list of completion items
1197 against this keyword and displays the completion menu. Some language servers
1198 does completion filtering in the server, while other relies on the client to
1199 do the filtering. By default, case sensitive comparison is used to filter the
1200 returned items. You can modify the 'completionMatcher' option to use either
1201 case insensitive or fuzzy comparison.
1203 ==============================================================================
1204 7. Diagnostics *lsp-diagnostics*
1206 When a source file has syntax errors or warnings or static analysis warnings,
1207 the LSP plugin highlights them by placing |signs| in the |sign-column|. You
1208 can use the |:LspDiagShow| command to display all the diagnostic messages for
1209 the current file in a |location-list-window|. You can use the |:LspDiagFirst|
1210 command to jump to the line with the first diagnostic message, the
1211 |:LspDiagNext| command to jump to the next nearest line with the diagnostic
1212 message, the |:LspDiagPrev| command to jump to the previous nearest line with
1213 the diagnostic message, the |:LspDiagHere| command to jump to the diagnostic
1214 message in the current line. You can use the |:LspDiagCurrent| command to
1215 display the entire diagnostic message from the language server for the current
1218 By default, the lines with a diagnostic message have a sign placed on them and
1219 are highlighted. You can temporarily disable them for the current Vim session
1220 using the |:LspDiagHighlightDisable| command and re-enable them using the
1221 |:LspDiagHighlightEnable| command.
1223 To disable the automatic placement of signs on the lines with a diagnostic
1224 message, you can set the 'autoHighlightDiags' option to false: >
1226 LspOptionsSet({'autoHighlightDiags': false})
1228 By default the 'autoHighlightDiags' option is set to true.
1230 The function lsp#lsp#ErrorCount() function can be used to get the count of the
1231 diagnostic messages in the current buffer by type. This function returns a
1232 Dictionary with the following keys: Info, Hint, Warn and Error. The value for
1233 these keys is the number of diagnostic messages of the corresponding type.
1234 This function can be used to display the number of diagnostics in the current
1235 buffer in a 'statusline'.
1237 For some diagnostic errors/warnings, the language server may provide an
1238 automatic fix. To apply this fix, you can use the |:LspCodeAction| command.
1239 This command applies the action provided by the language server (if any) for
1242 The |:LspDiagShow| command creates a new location list with the current list
1243 of diagnostics for the current buffer. To automatically add the diagnostics
1244 messages to the location list, you can set the 'autoPopulateDiags' option to
1245 true. Â By default this option is set to false. Â When new diagnostics are
1246 received for a buffer, if a location list with the diagnostics is already
1247 present, then it is refreshed with the new diagnostics.
1249 When using GUI Vim or in a terminal Vim with 'ballooneval' option set, when
1250 the mouse is moved over the diagnostic sign displayed in the sign column, then
1251 the diagnostic message is displayed in a popup. By default, the diagnostic
1252 message popup is not displayed when the mouse is moved over the text in the
1253 line. To display the diagnostic message when hovering the mouse over the text
1254 of the line, you can set the 'noDiagHoverOnLine' option to false. By
1255 default, this option is set to true.
1257 To display the diagnostic message for the current line in the status area, you
1258 can set the 'showDiagOnStatusLine' option to true. By default, this option
1261 By default, the |:LspDiagCurrent| command displays the diagnostic message for
1262 the current line in a popup window. To display the message in the status
1263 message area instead, you can set the 'showDiagInPopup' option to false. By
1264 default this is set to true.
1266 The lsp#diag#GetDiagsForBuf() function can be used to get all the LSP
1267 diagnostics in a buffer. Â This function optionally accepts a buffer number.
1268 If the buffer number argument is not specified, then the current buffer is
1269 used. Â This function returns a |List| of diagnostics sorted by their line and
1270 column number. Â Each diagnostic is a |Dict| returned by the language server.
1272 ==============================================================================
1273 8. Tag Function *lsp-tagfunc*
1275 The |:LspGotoDefinition| command can be used jump to the location where a
1276 symbol is defined. To jump to the symbol definition using the Vim
1277 |tag-commands|, you can set the 'tagfunc' option to the 'lsp#lsp#TagFunc'
1280 setlocal tagfunc=lsp#lsp#TagFunc
1282 After setting the above option, you can use |Ctrl-]| and other tag related
1283 commands to jump to the symbol definition.
1285 Note that most of the language servers return only one symbol location even if
1286 the symbol is defined in multiple places in the code.
1288 ==============================================================================
1289 9. Code Formatting *lsp-format*
1291 The |:LspFormat| command can be used to format either the entire file or a
1292 selected range of lines using the language server. The 'shiftwidth' and
1293 'expandtab' values set for the current buffer are used when format is applied.
1295 To format code using the 'gq' command, you can set the 'formatexpr' option: >
1297 setlocal formatexpr=lsp#lsp#FormatExpr()
1299 ==============================================================================
1300 10. Call Hierarchy *lsp-call-hierarchy*
1302 The |:LspIncomingCalls| and the |:LspOutoingCalls| commands can be used to
1303 display the call hierarchy of a symbol. For example, the functions calling a
1304 function or the functions called by a function. These two commands open a
1305 window containing the call hierarchy tree. You can use the Vim motion
1306 commands to browse the call hierarchy.
1308 In the call hierarchy tree window, the following keys are supported:
1310 <Enter> Jump to the location of the symbol under the
1312 - Expand and show the symbols calling or called
1313 by the symbol under the cursor.
1314 + Close the call hierarchy for the symbol under
1317 You can display either the incoming call hierarchy or the outgoing call
1318 hierarchy in this window. You cannot display both at the same time.
1320 In the call hierarchy tree window, the following commands are supported:
1322 *:LspCallHierarchyRefresh*
1323 :LspCallHierarchyRefresh Query the language server again for the top
1324 level symbol and refresh the call hierarchy
1326 *:LspCallHierarchyIncoming*
1327 :LspCallHierarchyIncoming Display the incoming call hierarchy for the
1328 top level symbol. If the window is currently
1329 displaying the outgoing calls, then it is
1330 refreshed to display the incoming calls.
1331 *:LspCallHierarchyOutgoing*
1332 :LspCallHierarchyOutgoing Display the outgoing call hierarchy for the
1333 top level symbol. If the window is currently
1334 displaying the incoming calls, then it is
1335 refreshed to display the outgoing calls.
1337 ==============================================================================
1338 11. Autocommands *lsp-autocmds*
1341 LspAttached A |User| autocommand fired when the LSP client
1342 attaches to a buffer. Can be used to configure
1343 buffer-local mappings or options.
1346 LspDiagsUpdated A |User| autocommand invoked when new
1347 diagnostics are received from the language
1348 server. This is invoked after the LSP client
1349 has processed the diagnostics. Â The function
1350 lsp#diag#GetDiagsForBuf() can be used to get
1351 all the diagnostics for a buffer.
1353 ==============================================================================
1354 12. Highlight Groups *lsp-highlight-groups*
1356 The following highlight groups are used by the LSP plugin. You can define
1357 these highlight groups in your .vimrc file before sourcing this plugin to
1360 *LspDiagInlineError* Used to highlight inline error diagnostics.
1361 By default, linked to the "SpellBad" highlight
1363 *LspDiagInlineHint* Used to highlight inline hint diagnostics.
1364 By default, linked to the "SpellLocal"
1366 *LspDiagInlineInfo* Used to highlight inline info diagnostics.
1367 By default, linked to the "SpellRare"
1369 *LspDiagInlineWarning* Used to highlight inline warning diagnostics.
1370 By default, linked to the "SpellCap" highlight
1372 *LspDiagLine* Used to highlight a line with one or more
1373 diagnostics. By default linked to the
1374 "DiffAdd" highlight group. Use "NONE" to
1376 *LspDiagSignErrorText* Used to highlight the sign text for error
1377 diags. By default linked to 'ErrorMsg'.
1378 *LspDiagSignHintText* Used to highlight the sign text for hint
1379 diags. By default linked to 'Question'.
1380 *LspDiagSignInfoText* Used to highlight the sign text for info
1381 diags. By default linked to 'Pmenu'.
1382 *LspDiagSignWarningText* Used to highlight the sign text for warning
1383 diags. By default linked to 'Search'.
1384 *LspDiagVirtualText* Used to highlight diagnostic virtual text.
1385 By default, linked to the "LineNr" highlight
1387 *LspInlayHintsParam* Used to highlight inlay hints of kind
1388 "parameter". By default, linked to the
1389 "Label" highlight group.
1390 *LspInlayHintsType* Used to highlight inlay hints of kind "type".
1391 By default, linked to the "Conceal" highlight
1393 *LspSigActiveParameter* Used to highlight the active signature
1394 parameter. By default, linked to the "LineNr"
1396 *LspSymbolName* Used to highlight the symbol name when using
1397 the |:LspDocumentSymbol| command. By default,
1398 linked to the "Search" highlight group.
1399 *LspSymbolRange* Used to highlight the range of lines
1400 containing a symbol when using the
1401 |:LspDocumentSymbol| command. By default,
1402 linked to the "Visual" highlight group.
1404 For example, to override the highlight used for diagnostics virtual text, you
1405 can use the following: >
1407 highlight LspDiagVirtualText ctermfg=Cyan guifg=Blue
1411 highlight link LspDiagLine NONE
1412 highlight link LspDiagVirtualText WarningMsg
1414 ==============================================================================
1415 13. Debugging *lsp-debug*
1417 To debug this plugin, you can log the language server protocol messages sent
1418 and received by the plugin from the language server. The following command
1419 enables the logging of the messages from the language server for the current
1424 This command also clears the log files. The following command disables the
1425 logging of the messages from the language server for the current buffer: >
1427 :LspServer debug off
1429 By default, the messages are not logged. Another method to enable the debug
1430 is to set the "debug" field to true when adding a language server
1431 using |LspAddServer()|.
1433 The messages printed by the language server in the stdout are logged to the
1434 lsp-<server-name>.log file and the messages printed in the stderr are logged
1435 to the lsp-<server-name>.err file. On a Unix-like system, these files are
1436 created in the /tmp directory. On MS-Windows, these files are created in the
1439 The following command opens the file containing the messages printed by the
1440 language server in the stdout: >
1442 :LspServer debug messages
1444 The following command opens the file containing the messages printed by the
1445 language server in the stderr: >
1447 :LspServer debug errors
1449 To debug language server initialization problems, after enabling the above
1450 server debug, you can restart the server for the file type in the current
1451 buffer using the following command: >
1455 The language servers typically support command line options to enable debug
1456 messages and to increase the verbosity of the messages. You can refer to the
1457 language server documentation for information about this. You can include
1458 these options when registering the language server with this plugin.
1460 If a language server supports the "$/logTrace" LSP notification, then you can
1461 use the :LspServerTrace command to set the server trace value: >
1463 :LspServer trace { off | messages | verbose }
1465 ==============================================================================
1466 14. Custom Command Handlers *lsp-custom-commands*
1468 When applying a code action, the language server may issue a non-standard
1469 command. For example, the Java language server uses non-standard commands
1470 (e.g. java.apply.workspaceEdit). To handle these commands, you can register a
1471 callback function for each command using the LspRegisterCmdHandler() function.
1475 import autoload "lsp/textedit.vim"
1477 def WorkspaceEdit(cmd: dict<any>)
1478 for editAct in cmd.arguments
1479 textedit.ApplyWorkspaceEdit(editAct)
1482 g:LspRegisterCmdHandler('java.apply.workspaceEdit', WorkspaceEdit)
1484 Place the above code in a file named lsp_java/plugin/lsp_java.vim and load
1487 The callback function should accept a Dict argument. The Dict argument
1488 contains the LSP Command interface fields. Refer to the LSP specification for
1489 more information about the "Command" interface.
1491 ==============================================================================
1492 15. Custom LSP Completion Kinds *lsp-custom-kinds*
1494 When a completion popup is triggered, the LSP client will use a default kind
1495 list to show in the completion "kind" section, to customize it, you need to
1496 use the option |lsp-opt-customCompletionKinds| and set all custom kinds in the
1497 option |lsp-opt-completionKinds| . There is a table with all default LSP
1501 ------------------------|--------------------
1529 For example, if you want to change the "Method" kind to the kind "method()": >
1534 customCompletionKinds: true,
1536 "Method": "method()"
1540 In the completion popup, will show something like this: >
1542 var file = new File()
1546 | createIfNotExists method() |
1549 ==============================================================================
1550 16. Multiple Language Servers for a buffer *lsp-multiple-servers*
1552 It's possible to run multiple language servers for a given buffer.
1554 By default the language server defined first will be used for as much as it
1555 supports, then the next and so on. With the exception that diagnostics from
1556 all running language servers will be combined.
1558 This means that you can define a language server that only supports a subset
1559 of features at first and then define the general purpose language server after
1565 # This language server reports that it only supports
1566 # textDocument/documentFormatting, so it will be used
1567 # for :LspFormat but nothing else.
1570 path: 'html-pretty-lsp',
1573 # This language server also supports
1574 # textDocument/documentFormatting, but since it's been
1575 # defined later, the one above will be used instead.
1576 # However this server also supports
1577 # textDocument/definition, textDocument/declaration,
1578 # etc, so it will be used for :LspGotoDefinition,
1579 # :LspGotoDeclaration, etc
1582 path: 'html-language-server',
1587 As shown in the example above the order of when the language servers are being
1588 defined is taken into account for a given method. However sometimes the
1589 language server that you want to use for formatting also reports that it
1590 supports other features. In such a case you can do one of two things:
1592 1. change the order of language servers, and specify that a given language
1593 server should be used for a given method.
1595 2. set the unwanted features to |false| in the features |Dictionary| >
1597 features: { 'codeAction': false }
1599 For example, if you want to use the efm-langserver for formatting, but the
1600 typescript-language-server for everything else: >
1605 # this language server will be used by default, as it's defined
1606 # as the first LSP for 'javascript' and 'typescript'
1608 filetype: ['javascript', 'typescript'],
1609 path: '/usr/local/bin/typescript-language-server',
1612 # this language server will be used for documentFormatting
1614 filetype: ['efm-langserver'],
1615 path: '/usr/local/bin/efm-langserver',
1618 documentFormatting: true
1623 Another way is to disable the unwanted features: for example if you don't want
1624 diagnostics from the typescript-language-server, but want to use it for
1631 filetype: ['javascript', 'typescript'],
1632 path: '/usr/local/bin/typescript-language-server',
1640 ==============================================================================
1641 17. Language Server Features *lsp-features*
1643 By providing the configuration |lsp-cfg-features| it's possible to specify
1644 which servers should be used for a given method. The following feature flags
1645 are supported: See |lsp-multiple-servers| for examples.
1647 *lsp-features-codeAction*
1648 codeAction Used by |:LspCodeAction|
1649 *lsp-features-codeLens*
1650 codeLens Used by |:LspCodeLens|
1651 *lsp-features-completion*
1652 completion Used by 24/7 Completion and 'omnifunc'
1653 *lsp-features-declaration*
1654 declaration Used by |:LspGotoDeclaration|, and
1655 |:LspPeekDeclaration|
1656 *lsp-features-definition*
1657 definition Used by |:LspGotoDefinition|, and
1658 |:LspPeekDefinition|
1659 *lsp-features-diagnostics*
1660 diagnostics Used to disable diagnostics for a single
1661 language server, by default diagnostics are
1662 combined from all running servers, by setting
1663 this to |false| you can ignore diagnostics
1664 from a specific server.
1665 *lsp-features-documentFormatting*
1666 documentFormatting Used by |:LspFormat|, and 'formatexpr'
1667 *lsp-features-documentHighlight*
1668 documentHighlight Used by the |:LspHighlight| and the
1669 |:LspHighlightClear| commands.
1670 *lsp-features-foldingRange*
1671 foldingRange Used by |:LspFold|
1672 *lsp-features-hover*
1673 hover Used by |:LspHover|
1674 *lsp-features-implementation*
1675 implementation Used by |:LspGotoImpl|, and |:LspPeekImpl|
1676 *lsp-features-references*
1677 references Used by |:LspShowReferences|
1678 *lsp-features-rename*
1679 rename Used by |:LspRename|
1680 *lsp-features-selectionRange*
1681 selectionRange Used by the |:LspSelectionExpand| and the
1682 |:LspSelectionShrink| commands.
1683 *lsp-features-typeDefinition*
1684 typeDefinition Used by the |:LspGotoTypeDef| and the
1685 |:LspPeekTypeDef| commands.
1687 ==============================================================================
1689 License: MIT License
1690 Copyright (c) 2020-2023 Yegappan Lakshmanan
1692 Permission is hereby granted, free of charge, to any person obtaining a copy
1693 of this software and associated documentation files (the "Software"), to
1694 deal in the Software without restriction, including without limitation the
1695 rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
1696 sell copies of the Software, and to permit persons to whom the Software is
1697 furnished to do so, subject to the following conditions:
1699 The above copyright notice and this permission notice shall be included in
1700 all copies or substantial portions of the Software.
1702 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1703 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1704 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1705 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1706 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
1707 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
1710 ==============================================================================
1712 vim:tw=78:ts=8:noet:ft=help:norl: