]> Sergey Matveev's repositories - vim-lsp.git/blob - doc/lsp.txt
Update diags location list when the diags for the buffer changes. Update comments
[vim-lsp.git] / doc / lsp.txt
1 *lsp.txt*       Language Server Protocol (LSP) Plugin for Vim9
2
3
4 Author: Yegappan Lakshmanan  (yegappan AT yahoo DOT com)
5 For Vim version 9.0 and above
6 Last change: June 7, 2023
7
8 ==============================================================================
9 CONTENTS                                                     *lsp-contents*
10
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|
29
30 ==============================================================================
31 1. Overview                                     *lsp-overview*
32
33 The Language Server Protocol (LSP) plugin implements a LSP client for Vim9.
34 Refer to the following pages for more information about LSP:
35
36     https://microsoft.github.io/language-server-protocol/
37     https://langserver.org/
38
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
42 languages.
43
44 The Github repository for this plugin is available at:
45
46       http://github.com/yegappan/lsp
47
48 ==============================================================================
49 2. Installation                                 *lsp-installation*
50
51 You can install this plugin directly from github using the following steps:
52
53     $ mkdir -p $HOME/.vim/pack/downloads/opt
54     $ cd $HOME/.vim/pack/downloads/opt
55     $ git clone https://github.com/yegappan/lsp
56
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.
59
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.
62
63 To use this plugin, add the following line to your .vimrc file:
64
65     packadd lsp
66
67 ==============================================================================
68 3. Usage                                        *lsp-usage*
69
70 The following commands are provided:
71
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
78                         buffer.
79 :LspDiagHere            Jump to the next diagnostic message in the current
80                         line.
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
87                         buffer.
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 :LspFold                Fold the current file
95 :LspFormat              Format a range of lines in the current file using the
96                         language server.  The default range is the entire
97                         file.  See |lsp-format| for more information.
98 :LspGotoDeclaration     Go to the declaration of the symbol under cursor
99 :LspGotoDefinition      Go to the definition of the symbol under cursor
100 :LspGotoImpl            Go to the implementation of the symbol under cursor
101 :LspGotoTypeDef         Go to the type definition of the symbol under cursor
102 :LspHighlight           Highlight all the matches for the keyword under cursor
103 :LspHighlightClear      Clear all the matches highlighted by :LspHighlight
104 :LspHover               Show the documentation for the symbol under the cursor
105                         in a popup window.
106 :LspIncomingCalls       Display the list of symbols calling the current symbol
107                         in a window.
108 :LspOutgoingCalls       Display the list of symbols called by the current
109                         symbol in a window.
110 :LspOutline             Show the list of symbols defined in the current file
111                         in a separate window.
112 :LspPeekDeclaration     Open the declaration of the symbol under cursor in a
113                         popup window.
114 :LspPeekDefinition      Open the definition of the symbol under cursor in a
115                         popup window.
116 :LspPeekImpl            Open the implementation of the symbol under cursor in
117                         a popup window.
118 :LspPeekReferences      Display the list of references to the symbol under
119                         cursor in a popup window.
120 :LspPeekTypeDef         Open the type definition of the symbol under cursor in
121                         a popup window.
122 :LspRename              Rename the current symbol
123 :LspSelectionExpand     Expand the current symbol range visual selection
124 :LspSelectionShrink     Shrink the current symbol range visual selection
125 :LspServer              Command to display the status and messages from a
126                         language server and to restart the language server.
127 :LspShowAllServers      Display the status of all the registered language
128                         servers.
129 :LspShowReferences      Display the list of references to the keyword under
130                         cursor in a new location list.
131 :LspShowSignature       Display the signature of the symbol under cursor.
132 :LspSubTypeHierarchy    Display the sub type hierarchy in a popup window.
133 :LspSuperTypeHierarchy  Display the super type hierarchy in a popup window.
134 :LspSwitchSourceHeader  Switch between a source and a header file.
135 :LspSymbolSearch        Perform a workspace wide search for a symbol
136 :LspWorkspaceAddFolder {folder}
137                         Add a folder to the workspace
138 :LspWorkspaceListFolders
139                         Show the list of folders in the workspace
140 :LspWorkspaceRemoveFolder {folder}
141                         Remove a folder from the workspace
142
143 ==============================================================================
144 4. Configuration                                *lsp-configuration*
145                                         *LspAddServer()* *g:LspAddServer()*
146
147 To use the plugin features with a particular file type(s), you need to first
148 register a language server for that file type(s).
149
150 To register one or more language servers, use the LspAddServer() function with
151 a list of lanaguge server details in the .vimrc file.
152
153 To register a language server, add the following lines to your .vimrc file
154 (use only the language servers that you need from the below list).
155 If you used [vim-plug](https://github.com/junegunn/vim-plug) to install the
156 LSP plugin, the steps are described later in this section: >
157
158    vim9script
159    var lspServers = [
160                      {
161                          name: 'typescriptls',
162                          filetype: ['javascript', 'typescript'],
163                          path: '/usr/local/bin/typescript-language-server',
164                          args: ['--stdio']
165                       },
166                      {
167                          name: 'pythonls',
168                          filetype: 'python',
169                          path: '/usr/local/bin/pyls',
170                          args: ['--check-parent-process', '-v']
171                       }
172                    ]
173    LspAddServer(lspServers)
174 <
175 Depending on the location of the typescript and python pyls language servers
176 installed in your system, update the "path" in the above snippet
177 appropriately.
178
179 Another example, for adding the language servers for the C, C++, Golang, Rust,
180 Shell script, Vim script and PHP file types: >
181
182    vim9script
183    var lspServers = [
184                      {
185                         name: 'clangd',
186                         filetype: ['c', 'cpp'],
187                         path: '/usr/local/bin/clangd',
188                         args: ['--background-index']
189                      },
190                      {
191                         name: 'golang',
192                         filetype: ['go', 'gomod', 'gohtmltmpl', 'gotexttmpl'],
193                         path: '/path/to/.go/bin/gopls',
194                         args: [],
195                         syncInit: true,
196                       },
197                      {
198                         name: 'rustls',
199                         filetype: ['rust'],
200                         path: '/path/to/.cargo/bin/rust-analyzer',
201                         args: [],
202                         syncInit: true,
203                       },
204                      {
205                         name: 'bashls',
206                         filetype: 'sh',
207                         path: '/usr/local/bin/bash-language-server',
208                         args: ['start']
209                      },
210                      {
211                         name: 'vimls',
212                         filetype: ['vim'],
213                         path: '/usr/local/bin/vim-language-server',
214                         args: ['--stdio']
215                      },
216                      {
217                         name: 'phpls',
218                         filetype: ['php'],
219                         path': '/usr/local/bin/intelephense',
220                         args: ['--stdio'],
221                         syncInit: true,
222                         initializationOptions: {
223                         licenceKey: 'xxxxxxxxxxxxxxx'
224                         }
225                       }
226                    ]
227    LspAddServer(lspServers)
228 <
229 To add a language server, the following information is needed:
230
231                                                 *lsp-cfg-name*
232         name            (Optional) name of the language server.  Can by any
233                         string.  Used in LSP messages and log files.
234                                                 *lsp-cfg-path*
235         path            complete path to the language server executable
236                         (without any arguments).
237                                                 *lsp-cfg-args*
238         args            a |List| of command-line arguments passed to the
239                         language server.  Each space separated language server
240                         command-line argument is a separate List item.
241                                                 *lsp-cfg-filetype*
242         filetype        One or more file types supported by the language
243                         server.  This can be a |String| or a |List|. To
244                         specify multiple file types, use a List.
245                                         *lsp-cfg-initializationOptions*
246         initializationOptions
247                         (Optional) for lsp servers (e.g. intelephense) some
248                         additional initialization options may be required
249                         or useful for initialization. Those can be provided in
250                         this dictionary and if present will be transmitted to
251                         the lsp server.
252                                                 *lsp-cfg-workspaceConfig*
253         workspaceConfig (Optional) a json encodable value that will be sent to
254                         the language server after initialization as the
255                         "settings" in a "workspace/didChangeConfiguration"
256                         notification.  Refer to the language server
257                         documentation for the values that will be accepted in
258                         this notification.  This configuration is also used to
259                         respond to the "workspace/configuration" request
260                         message from the language server.
261                                                 *lsp-cfg-rootSearch*
262         rootSearch      (Optional) a List of file and directory names used to
263                         locate the root path or uri of the workspace.  The
264                         directory names in "rootSearch" must end in "/" or
265                         "\".  Each file and directory name in "rootSearch" is
266                         searched upwards in all the parent directories.  If
267                         multiple directories are found, then the directory
268                         closest to the directory of the current buffer is used
269                         as the workspace root.
270
271                         If this parameter is not specified or the files are
272                         not found, then the current working directory is used
273                         as the workspace root for decendent files, for any
274                         other files the parent directory of the file is used.
275
276                                                 *lsp-cfg-runIfSearch*
277         runIfSearch     (Optional) a List of file and directory names used to
278                         determinate if a server should run or not. The
279                         directory names in "runIfSearch" must end in "/" or
280                         "\".  Each file and directory name in "runIfSearch" is
281                         searched upwards in all the parent directories.
282                         Exactly like |lsp-cfg-rootSearch|.
283
284                         If a file or directory is found then the server will
285                         be started, otherwise it will not.
286
287                         If this parameter is not specified or is an empty
288                         list, then the server will be started unless
289                         |lsp-cfg-runUnlessSearch| prevents it.
290
291                                                 *lsp-cfg-runUnlessSearch*
292         runUnlessSearch (Optional) Opposite of |lsp-cfg-runIfSearch|.
293
294 Additionally the following configurations can be made:
295
296                                         *lsp-cfg-customNotificationHandlers*
297         customNotificationHandlers
298                         (Optional) some lsp servers (e.g.
299                         typescript-language-server) will send additional
300                         notifications which you might want to silence or
301                         handle.  The provided notification handlers will be
302                         called with a reference to the "lspserver" and the
303                         "reply". >
304
305                 vim9script
306                 g:LspAddServer([{
307                         filetype: ['javascript', 'typescript'],
308                         path: '/usr/local/bin/typescript-language-server',
309                         args: ['--stdio'],
310                         customNotificationHandlers: {
311                                 '$/typescriptVersion': (lspserver, reply) => {
312                                         echom printf("TypeScript Version = %s",
313                                                 reply.params.version)
314                                 }
315                         }
316                 }])
317 <
318                                         *lsp-cfg-customRequestHandlers*
319         customRequestHandlers
320                         (Optional) some lsp servers will send additional
321                         request replies which you might want to silence or
322                         handle.  The provided request handlers will be called
323                         with a reference to the "lspserver" and the "request".
324                                                 *lsp-cfg-features*
325         features
326                         (Optional) toggle which features should be enabled for
327                         a given language server. See |lsp-multiple-servers|
328                         and |lsp-features| for more information.
329                                                 *lsp-cfg-omnicompl*
330         omnicompl       (Optional) a boolean value that enables (true)
331                         or disables (false) omni-completion for these file
332                         types. By default this is set to "v:true".  This value
333                         is applicable only if auto completion is disabled
334                         (|lsp-opt-autoComplete|).
335                                                 *lsp-cfg-processDiagHandler*
336         processDiagHandler
337                         (Optional) A |Funcref| or |lambda| that takes a list
338                         of language server diagnostics and returns a new list
339                         of filtered, or otherwise changed diagnostics.  Can be
340                         used to remove unwanted diagnostics, prefix the
341                         diagnostics text, etc.  The following example will
342                         remove all but errors and warnings: >
343
344                 vim9script
345                 g:LspAddServer([{
346                         filetype: ['javascript', 'typescript'],
347                         path: '/usr/local/bin/typescript-language-server',
348                         args: ['--stdio'],
349                         processDiagHandler: (diags: list<dict<any>>) => {
350                                 # Only include errors and warnings
351                                 return diags->filter((diag, ix) => {
352                                         return diag.severity <= 2
353                                 })
354                         },
355                 }])
356 <
357                         And this example will prefix the diagnostic message
358                         with the string "TypeScript: ": >
359
360                 vim9script
361                 g:LspAddServer([{
362                         filetype: ['javascript', 'typescript'],
363                         path: '/usr/local/bin/typescript-language-server',
364                         args: ['--stdio'],
365                         processDiagHandler: (diags: list<dict<any>>) => {
366                                 return diags->map((diag, ix) => {
367                                         diag.message = $'TypeScript: {diag.message}'
368                                         return diag
369                                 })
370                         },
371                 }])
372 <
373                                                 *lsp-cfg-syncInit*
374         syncInit        (Optional) for language servers (e.g. rust analyzer,
375                         gopls, etc.) that take time to initialize and reply to
376                         a "initialize" request message this should be set to
377                         "true". If this is set to true, then a synchronous
378                         call is used to initialize the language server,
379                         otherwise the server is initialized asynchronously.
380                         By default this is set to "false".
381                                                 *lsp-cfg-debug*
382         debug           (Optional) log the messages printed by this language
383                         server in stdout and stderr to a file.  Useful for
384                         debugging a language server.  By default the
385                         messages are not logged.  See |lsp-debug| for more
386                         information.
387
388 The language servers are added using the LspAddServer() function. This
389 function accepts a list of language servers with the above information.
390
391 If you used [vim-plug](https://github.com/junegunn/vim-plug) to install the
392 LSP plugin, then you need to use the VimEnter autocmd to initialize the
393 language server and to set the language server options.  For example: >
394
395     vim9script
396     var lspServers = [
397                      {
398                         name: 'clangd',
399                         filetype: ['c', 'cpp'],
400                         path: '/usr/local/bin/clangd',
401                         args: ['--background-index']
402                       }
403                    ]
404     autocmd VimEnter * LspAddServer(lspServers)
405
406     var lspOpts = {'autoHighlightDiags': true}
407     autocmd VimEnter * LspOptionsSet(lspOpts)
408 <
409                                                 *lsp-options* *LspOptionsSet*
410                                                 *g:LspOptionsSet*
411
412 Some of the LSP plugin features can be enabled or disabled by using the
413 LspOptionsSet() function. This function accepts a dictionary argument with the
414 following optional items:
415
416                                                 *lsp-opt-aleSupport*
417 aleSupport              |Boolean| option. If true, diagnostics will be sent to
418                         Ale, instead of being displayed by this plugin.
419                         This is useful to combine all LSP and linter
420                         diagnostics. By default this is set to false.
421                                                 *lsp-opt-autoComplete*
422 autoComplete            |Boolean| option. In insert mode, automatically
423                         complete the current symbol. Otherwise use
424                         omni-completion. By default this is set to true.
425                                                 *lsp-opt-autoHighlight*
426 autoHighlight           |Boolean| option. In normal mode, automatically
427                         highlight all the occurrences of the symbol under the
428                         cursor. By default this is set to false.
429                                                 *lsp-opt-autoHighlightDiags*
430 autoHighlightDiags      |Boolean| option. Automatically place signs on the
431                         lines with a diagnostic message from the language
432                         server. By default this is set to true.
433                                                 *lsp-opt-autoPopulateDiags*
434 autoPopulateDiags       |Boolean| option. Automatically populate the location
435                         list with diagnostics from the language server.
436                         By default this is set to false.
437                                                 *lsp-opt-completionMatcher*
438 completionMatcher       |String| option.  Enable fuzzy or case insensitive
439                         completion for language servers that replies with a
440                         full list of completion items.  Some language servers
441                         does completion filtering in the server, while other
442                         relies on the client to do the filtering.
443
444                         This option only works for language servers that
445                         expect the client to filter the completion items.
446
447                         This option accepts one of the following values:
448                             case  - case sensitive matching (default).
449                             fuzzy - fuzzy match completion items.
450                             icase - ignore case when matching items.
451                                                 *lsp-opt-completionTextEdit*
452 completionTextEdit      |Boolean| option.  If true, apply the LSP server
453                         supplied text edits after a completion.  If a snippet
454                         plugin is going to apply the text edits, then set
455                         this to false to avoid applying the text edits twice.
456                         By default this is set to true.
457                                                 *lsp-opt-completionKinds*
458 completionKinds         |Dictionary| option. See |lsp-custom-kinds| for all
459                         completion kind names.
460                                         *lsp-opt-customCompletionKinds*
461 customCompletionKinds   |Boolean| option.  If you set this to true, you can
462                         set custom completion kinds using the option
463                         completionKinds.
464                                                 *lsp-opt-diagSignErrorText*
465 diagSignErrorText       |String| option. Change diag sign text for errors
466                         By default 'E>'
467                                                 *lsp-opt-diagSignHintText*
468 diagSignHintText        |String| option. Change diag sign text for hints
469                         By default 'H>',
470                                                 *lsp-opt-diagSignInfoText*
471 diagSignInfoText        |String| option. Change diag sign text for info
472                         By default 'I>',
473                                                 *lsp-opt-diagSignWarningText*
474 diagSignWarningText     |String| option. Change diag sign text for warnings
475                         By default 'W>',
476                                                 *lsp-opt-diagVirtualTextAlign*
477 diagVirtualTextAlign    |String| option.   Alignment of diagnostics messages
478                         if |lsp-opt-showDiagWithVirtualText| is set to true.
479                         Allowed values are 'above', 'below' or 'after'
480                         By default this is set to 'above',
481                                                 *lsp-opt-echoSignature*
482 echoSignature           |Boolean| option.  In insert mode, echo the current
483                         symbol signature instead of showing it in a popup.
484                         By default this is set to false.
485                                         *lsp-opt-hideDisabledCodeActions*
486 hideDisabledCodeActions |Boolean| option. Hide all the disabled code actions.
487                         By default this is set to false.
488                                                 *lsp-opt-highlightDiagInline*
489 highlightDiagInline     |Boolean| option.  Highlight the diagnostics inline
490                         By default this is set to false.
491                                                 *lsp-opt-hoverInPreview*
492 hoverInPreview          |Boolean| option. Show |:LspHover| in a preview window
493                         instead of a popup.
494                         By default this is set to false.
495                                                 *lsp-opt-ignoreMissingServer*
496 ignoreMissingServer     |Boolean| option.  Do not print a missing language
497                         server executable.  By default this is set to false.
498                                                 *lsp-opt-keepFocusInDiags*
499 keepFocusInDiags        |Boolean| option.  Focus on the location list window
500                         after LspDiagShow.
501                         By default this is set to true.
502                                         *lsp-opt-keepFocusInReferences*
503 keepFocusInReferences   |Boolean| option.  Focus on the location list window
504                         after LspShowReferences.
505                         By default this is set to true.
506                                                 *lsp-opt-noDiagHoverOnLine*
507 noDiagHoverOnLine       |Boolean| option.  Suppress diagnostic hover from
508                         appearing when the mouse is over the line instead of
509                         the signature.
510                         By default this is set to true.
511                                         *lsp-opt-noNewlineInCompletion*
512 noNewlineInCompletion   |Boolean| option.  Suppress adding a new line on
513                         completion selection with <CR>.
514                         By default this is set to false.
515                                                 *lsp-opt-outlineOnRight*
516 outlineOnRight          |Boolean| option.  Open the outline window on the
517                         right side, by default this is false.
518                                                 *lsp-opt-outlineWinSize*
519 outlineWinSize          |Number| option.  The size of the symbol Outline
520                         window.  By default this is set to 20.
521                                                 *lsp-opt-showDiagInPopup*
522 showDiagInPopup         |Boolean| option.  When using the |:LspDiagCurrent|
523                         command to display the diagnostic message for the
524                         current line, use a popup window to display the
525                         message instead of echoing in the status area.
526                         By default this is set to true.
527                                                 *lsp-opt-showDiagOnStatusLine*
528 showDiagOnStatusLine    |Boolean| option.  Show a diagnostic message on a
529                         status line.  By default this is set to false.
530                                         *lsp-opt-showDiagWithVirtualText*
531 showDiagWithVirtualText |Boolean| option.  Show diagnostic message text from
532                         the language server with virtual text.  By default
533                         this is set to false.  The "autoHighlightDiags" option
534                         should be set to true.
535                         Needs Vim version 9.0.1157 or later.
536                                                 *lsp-opt-showInlayHints*
537 showInlayHints          |Boolean| option.  Show inlay hints from the language
538                         server.  By default this is set to false.  The inlay
539                         hint text is displayed as a virtual text.  Needs Vim
540                         version 9.0.0178 or later.
541                                                 *lsp-opt-showSignature*
542 showSignature           |Boolean| option.  In insert mode, automatically show
543                         the current symbol signature in a popup.
544                         By default this is set to true.
545                                                 *lsp-opt-snippetSupport*
546 snippetSupport          |Boolean| option.  Enable snippet completion support.
547                         Need a snippet completion plugin like vim-vsnip.
548                         By default this is set to false.
549                                                 *lsp-opt-ultisnipsSupport*
550 ultisnipsSupport        |Boolean| option.  Enable SirVer/ultisnips support.
551                         Need a snippet completion plugin SirVer/ultisnips.
552                         By default this is set to false.
553                                                 *lsp-opt-vssnipSupport*
554 vsnipSupport            |Boolean| option.  Enable hrsh7th/vim-vsnip support.
555                         Need snippet completion plugins hrsh7th/vim-vsnip
556                         and hrsh7th/vim-vsnip-integ.  Make sure
557                         ultisnipsSupport is set to false before enabling this.
558                         By default this option is set to false.
559                                                 *lsp-opt-usePopupInCodeAction*
560 usePopupInCodeAction    |Boolean| option.  When using the |:LspCodeAction|
561                         command to display the code action for the current
562                         line, use a popup menu instead of echoing.
563                         By default this is set to false.
564                                         *lsp-opt-useQuickfixForLocations*
565 useQuickfixForLocations |Boolean| option.  Show |:LspShowReferences| in a
566                         quickfix list instead of a location list.
567                         By default this is set to false.
568                                                 *lsp-opt-useBufferCompletion*
569 useBufferCompletion     |Boolean| option. If enabled, the words from the
570                         current buffer are added to the auto completion list.
571                         This may degrade Vim performance as the current buffer
572                         contents are processed every time the completion menu
573                         is displayed.
574                         By default this is set to false.
575
576 For example, to disable the automatic placement of signs for the LSP
577 diagnostic messages, you can add the following line to your .vimrc file: >
578
579         LspOptionsSet({'autoHighlightDiags': false})
580 <
581 The LspOptionsGet() function returns a |Dict| of all the LSP plugin options,
582 To get a particular option value you can use the following: >
583
584         echo LspOptionsGet()['autoHighlightDiags']
585 <
586 ==============================================================================
587 5. Commands                                     *lsp-commands*
588
589 A description of the various commands provided by this plugin is below.  You
590 can map these commands to keys and make it easier to invoke them.
591
592                                                 *:LspCodeAction*
593 :LspCodeAction [query]  Apply the code action supplied by the language server
594                         to the diagnostic in the current line. This works only
595                         if there is a diagnostic message for the current line.
596                         You can use the |:LspDiagCurrent| command to display
597                         the diagnostic for the current line.
598
599                         When [query] is given the code action starting with
600                         [query] will be applied. [query] can be a regexp
601                         pattern, or a digit corresponding to the index of the
602                         code actions in the created prompt.
603
604                         When [query] is not given you will be prompted to
605                         select one of the actions supplied by the language
606                         server.
607
608                                                 *:LspCodeLens*
609 :LspCodeLens            Display a list of code lens commands available for the
610                         current buffer and apply the selected code lens
611                         command.
612
613                                                 *:LspDiagCurrent*
614 :LspDiagCurrent         Displays the diagnostic message (if any) for the
615                         current line.  If the option 'showDiagInPopup' is set
616                         to true (default), then the message is displayed in
617                         a popup window.  Otherwise the message is displayed in
618                         the status message area.
619
620 :LspDiagCurrent!        Only display a diagnostic message if it's directly
621                         under the cursor.  Otherwise works exactly like
622                         |:LspDiagCurrent|
623
624                         To show the current diagnotic under the cursor while
625                         moving around the following autocmd can be used: >
626
627                             augroup LspCustom
628                             au!
629                             au CursorMoved * silent! LspDiagCurrent!
630                             augroup END
631 <
632                                                 *:LspDiagFirst*
633 :LspDiagFirst           Jumps to the location of the first diagnostic message
634                         for the current file.
635
636                                                 *:LspDiagHere*
637 :LspDiagHere            Jumps to the location of the diagnostic message in
638                         the current line (start from current column).
639
640 :LspDiagHighlightDisable                        *:LspDiagHighlightDisable*
641                         Disable highlighting lines with a diagnostic message
642                         for the current Vim session.
643                         To always disable the highlighting, set the
644                         autoHighlightDiags option to false.
645
646                                                 *:LspDiagHighlightEnable*
647 :LspDiagHighlightEnable Enable highlighting lines with a diagnostic message
648                         for the current Vim session.  Note that highlighting
649                         lines with a diagnostic message is enabled by default.
650
651                                                 *:LspDiagLast*
652 :LspDiagLast            Jumps to the location of the first diagnostic message
653                         for the current file.
654
655                                                 *:LspDiagNext*
656 :[count]LspDiagNext     Go to the [count] diagnostic message after the current
657                         cursor position.  If [count] is omitted, then 1 is
658                         used.  If [count] exceeds the number of diagnostics
659                         after the current position, then the last diagnostic
660                         is selected.
661
662                                                 *:LspDiagPrev*
663 :[count]LspDiagPrev     Go to the [count] diagnostic message before the
664                         current cursor position.  If [count] is omitted, then
665                         1 is used.  If [count] exceeds the number of
666                         diagnostics before the current position, then first
667                         last diagnostic is selected.
668
669                                                 *:LspDiagShow*
670 :LspDiagShow            Creates a new location list with the diagnostics
671                         messages (if any) from the language server for the
672                         current file and opens the location list window. You
673                         can use the Vim location list commands to browse the
674                         list.
675
676                                                 *:LspFold*
677 :LspFold                Create folds for the current buffer.
678
679                                                 *:LspFormat*
680 :LspFormat              Format the current file using the language server. The
681                         'shiftwidth' and 'expandtab' values set for the
682                         current buffer are used when format is applied.
683
684 :{range}LspFormat       Format the specified range of lines in the current
685                         file using the language server.
686
687                                                 *:LspGotoDeclaration*
688 :[count]LspGotoDeclaration
689                         Jumps to the declaration of the symbol under the
690                         cursor. The behavior of this command is similar to the
691                         |:LspGotoDefinition| command.
692
693                                                 *:LspGotoDefinition*
694 :[count]LspGotoDefinition
695                         Jumps to the [count] definition of the symbol under
696                         the cursor.  If there are multiple matches and [count]
697                         isn't specified, then a location list will be created
698                         with the list of locations.
699
700                         If there is only one location, or [count] is provided
701                         then the following will apply:
702
703                         If the file is already present in a window, then jumps
704                         to that window.  Otherwise, opens the file in a new
705                         window.  If the current buffer is modified and
706                         'hidden' is not set or if the current buffer is a
707                         special buffer, then a new window is opened.  If the
708                         jump is successful, then the current cursor location
709                         is pushed onto the tag stack.  The |CTRL-T| command
710                         can be used to go back up the tag stack.  Also the
711                         |``| mark is set to the position before the jump.
712
713                         This command supports |:command-modifiers|.  You can
714                         use the modifiers to specify whether a new window or
715                         a new tab page is used and where the window is opened.
716                         Example(s): >
717
718                             # Open a horizontally split window
719                             :topleft LspGotoDefinition
720                             # Open a vertically split window
721                             :vert LspGotoDefinition
722                             # Open a new tab page
723                             :tab LspGotoDefinition
724 <
725                         You may want to map a key to invoke this command: >
726
727             nnoremap <buffer> gd <Cmd>LspGotoDefinition<CR>
728             nnoremap <buffer> <C-W>gd <Cmd>topleft LspGotoDefinition<CR>
729 <
730                         Or if you want to support [count]gd >
731
732             nnoremap <buffer> gd <Cmd>execute v:count .. 'LspGotoDefinition'<CR>
733             nnoremap <buffer> <C-W>gd <Cmd>execute 'topleft ' .. v:count .. 'LspGotoDefinition'<CR>
734 <
735                                                 *:LspGotoImpl*
736 :[count]LspGotoImpl     Jumps to the implementation of the symbol under the
737                         cursor. The behavior of this command is similar to the
738                         |:LspGotoDefinition| command. Note that not all the
739                         language servers support this feature.
740
741                         You may want to map a key to invoke this command: >
742
743                             nnoremap <buffer> gi <Cmd>LspGotoImpl<CR>
744 <
745                                                 *:LspGotoTypeDef*
746 :[count]LspGotoTypeDef  Jumps to the type definition of the symbol under the
747                         cursor. The behavior of this command is similar to the
748                         |:LspGotoDefinition| command. Note that not all the
749                         language servers support this feature.
750
751                         You may want to map a key to invoke this command: >
752
753                             nnoremap <buffer> gt <Cmd>LspGotoTypeDef<CR>
754 <
755                                                 *:LspHighlight*
756 :LspHighlight           Highlights all the matches for the symbol under
757                         cursor. The text, read and write references to the
758                         symbol are highlighted using Search, DiffChange and
759                         DiffDelete highlight groups respectively.
760
761                                                 *:LspHighlightClear*
762 :LspHighlightClear      Clears all the symbol matches highlighted by the
763                         |:LspHighlight| command.
764
765                                                 *:LspHover*
766 :LspHover               Show the documentation for the symbol under the cursor
767                         in a popup window. If you want to show the symbol
768                         documentation in the preview window instead of in a
769                         popup set >
770
771                             LspOptionsSet({'hoverInPreview': true})
772 <
773                         You can use the |K| key in normal mode to display the
774                         documentation for the keyword under the cursor by
775                         setting the 'keywordprg' Vim option: >
776
777                             :set keywordprg=:LspHover
778 <
779                                                 *:LspIncomingCalls*
780 :LspIncomingCalls       Display a hierarchy of symbols calling the symbol
781                         under the cursor in a window.  See
782                         |lsp-call-hierarchy| for more information.  Note that
783                         not all the language servers support this feature.
784
785                                                 *:LspOutoingCalls*
786 :LspOutoingCalls        Display a hierarchy of symbols called by the symbol
787                         under the cursor in a window.  See
788                         |lsp-call-hierarchy| for more information.  Note that
789                         not all the language servers support this feature.
790
791                                                 *:LspOutline*
792 :[count]LspOutline      Opens a vertically split window with the list of
793                         symbols defined in the current file. The current
794                         symbol is highlighted. The symbols are grouped by
795                         their type. You can select a symbol and press <Enter>
796                         to jump to the position of the symbol. As you move the
797                         cursor in a file, the current symbol is automatically
798                         highlighted in the outline window. If you open a new
799                         file, the outline window is automatically updated with
800                         the symbols in the new file.  Folds are created in the
801                         outline window for the various group of symbols.
802
803                         You can use |lsp-opt-outlineOnRight| and
804                         |lsp-opt-outlineWinSize| to customize the placement
805                         and size of the window.
806
807                         This command also supports |:command-modifiers|.  You
808                         can use the modifiers specify the position of the
809                         window.  Note that the default is ":vert :topleft" or
810                         ":vert :botright" depending on
811                         |lsp-opt-outlineOnRight|
812
813                         This command also supports providing a [count] to
814                         specify the size of the window.  Note that this
815                         overrides the values defined in
816                         |lsp-opt-outlineWinSize|.
817                         Example: >
818
819                             # Open the outline window just above the current
820                             # window
821                             :aboveleft LspOutline
822
823                             # Open the outline window just next to the current
824                             # window, this is different from the default, when
825                             # you have multiple splits already
826                             :vert aboveleft LspOutline
827
828                             # Same as above, but with a width of 50
829                             :vert aboveleft 50LspOutline
830 <
831                                                 *:LspPeekDeclaration*
832 :[count]LspPeekDeclaration
833                         Displays the line where the symbol under the
834                         cursor is declared in a popup window. The
835                         behavior of this command is similar to the
836                         |:LspPeekDefinition| command.
837
838                                                 *:LspPeekDefinition*
839 :[count]LspPeekDefinition
840                         Displays the line where the symbol under the cursor is
841                         defined in a popup window. The symbol is highlighted
842                         in the popup window. Moving the cursor or pressing
843                         <Esc> will close the popup window.
844                         When more than one symbol is found all of them will be
845                         shown.  The corresponding file for the symbol is
846                         displayed in another popup window.  As the selection
847                         in the symbol popup menu changes, the file in the
848                         popup is updated.
849                         When [count] is provided only the [count] symbol will
850                         be shown.
851
852                                                 *:LspPeekImpl*
853 :[count]LspPeekImpl     Displays the implementation of the symbol under the
854                         cursor in a popup window. The behavior of this
855                         command is similar to the |:LspPeekDefinition|
856                         command. Note that not all the language servers
857                         support this feature.
858
859                                                 *:LspPeekReferences*
860 :LspPeekReferences      Displays the list of references to the symbol under
861                         cursor in a popup menu.  The corresponding file for
862                         the reference is displayed in another popup window.
863                         As the selection in the reference popup menu changes,
864                         the file in the popup is updated.
865
866                                                 *:LspPeekTypeDef*
867 :[count]LspPeekTypeDef  Displays the line where the type of the symbol under
868                         the cursor is defined in a popup window. The
869                         behavior of this command is similar to the
870                         |:LspPeekDefinition| command. Note that not all the
871                         language servers support this feature.
872
873                                                 *:LspRename*
874 :LspRename [newName]    Rename the current symbol.
875
876                         When [newName] is not given, then you will be prompted
877                         to enter the new name for the symbol. You can press
878                         <Esc> or enter an empty string in the prompt to cancel
879                         the operation.
880
881                                                 *:LspSelectionExpand*
882 :LspSelectionExpand     Visually select the region of the symbol under the
883                         cursor.  In visual mode, expands the current symbol
884                         visual region selection to include the next level.
885
886                         For example, if the cursor is on a "for" statement,
887                         this command selects the "for" statement and the body
888                         of the "for" statement.
889
890                         It is useful to create a visual map to use this
891                         command.  Example: >
892
893                         xnoremap <silent> <Leader>e <Cmd>LspSelectionExpand<CR>
894 <
895                         With the above map, you can press "\e" in visual mode
896                         successively to expand the current symbol visual
897                         region.
898
899                                                 *:LspSelectionShrink*
900 :LspSelectionShrink     Shrink the current symbol range visual selection. It
901                         is useful to create a visual map to use this command.
902                         Example: >
903
904                         xnoremap <silent> <Leader>s <Cmd>LspSelectionShrink<CR>
905 <
906                         With the above map, you can press "\s" in visual mode
907                         successively to shrink the current symbol visual
908                         region.
909
910                                                 *:LspServer*
911 :LspServer { debug | restart | show | trace }
912                         Command to display and control the language server for
913                         the current buffer.  Each argument has additional
914                         sub-commands which are described below.
915
916                         debug { on | off | messages | errors }
917                             Command to enable or disable the language server
918                             debug messages and to display the debug messages
919                             and error messages received from the language
920                             server.  The following sub-commands are supported:
921                                 errors  Open the log file containing the
922                                         language server error messages.
923                                 messages
924                                         Open the log file containing the
925                                         language server debug messages.
926                                 off     Disable the logging of the language
927                                         server messages.
928                                 on      Enable the logging of the messages
929                                         emitted by the language server in the
930                                         standard output and standard error.
931                             By default, the language server messages are not
932                             logged.  On a Unix-like system, when enabled,
933                             these messages are logged to the
934                             /tmp/lsp-<server-name>.log and
935                             /tmp/lsp-<server-name>.err file respectively.  On
936                             MS-Windows, the %TEMP%/lsp-<server-name>.log and
937                             %TEMP%/lsp-<server-name>.err% files are used. See
938                             |lsp-debug| for more information.
939
940                         restart
941                             Restart (stop and then start) the language server
942                             for the current buffer. All the loaded buffers
943                             with the same filetype as the current buffer are
944                             added back to the server.
945
946                         show {capabilities | initializeRequest | messages
947                                                                 | status}
948                             The following sub-commands are supported:
949                                 capabilities
950                                         Display the list of language server
951                                         capabilities for the current buffer.
952                                         The server capabilities are described
953                                         in the LSP protocol specification
954                                         under the "ServerCapabilities"
955                                         interface.
956                                 initializeRequest
957                                         Display the contents of the language
958                                         server initialization request message
959                                         (initialize).
960                                 messages
961                                         Display the log messages received from
962                                         the language server.  This includes
963                                         the messages received using the
964                                         "window/logMessage" and "$/logTrace"
965                                         LSP notifications.
966                                 status
967                                         Display the language server status for
968                                         the current buffer.  The output shows
969                                         the path to the language server
970                                         executable and the server status.
971
972                         trace { off | messages | verbose }
973                             Set the language server debug trace value using
974                             the "$/setTrace" command.
975
976                                                 *:LspShowAllServers*
977 :LspShowAllServers      Displays the list of registered language servers and
978                         their status.  The language servers are registered
979                         using the LspAddServer() function.  The output is
980                         displayed in a scratch buffer.  The output shows the
981                         Vim file type, the corresponding language server
982                         status and the path to the language server executable.
983                         The language server information for each buffer is
984                         also shown.
985
986                                                 *:LspShowReferences*
987 :LspShowReferences      Creates a new location list with the list of locations
988                         where the symbol under the cursor is referenced and
989                         opens the location window.  If you want to show the
990                         references in a quickfix list instead of in a location
991                         list set >
992
993                         LspOptionsSet({'useQuickfixForLocations': true})
994 <
995                                                 *:LspShowSignature*
996 :LspShowSignature       Displays the signature of the symbol (e.g. a function
997                         or method) before the cursor in a popup.
998
999                         The popup is also automatically displayed in insert
1000                         mode after entering a symbol name followed by a
1001                         separator (e.g. a opening parenthesis). To disable
1002                         this, you can set the showSignature option to false in
1003                         your .vimrc file: >
1004
1005                         LspOptionsSet({'showSignature': false})
1006 <
1007                         Default is true.
1008
1009                         You can get the function signature echoed in cmdline
1010                         rather than displayed in popup if you use >
1011
1012                         LspOptionsSet({'echoSignature': true})
1013 <
1014                         Default is false.
1015
1016                                                 *:LspSubTypeHierarchy*
1017 :LspSubTypeHierarchy    Show the sub type hierarchy for the symbol under the
1018                         cursor in a popup window.  The file containing the
1019                         type is shown in another popup window.  You can jump
1020                         to the location where a type is defined by browsing
1021                         the popup menu and selecting an entry.
1022
1023                                                 *:LspSuperTypeHierarchy*
1024 :LspSuperTypeHierarchy  Show the super type hierarchy for the symbol under the
1025                         cursor in a popup window.  The file containing the
1026                         type is shown in another popup window.  As the current
1027                         entry in the type hierarchy popup menu changes, the
1028                         file popup window is updated to show the location
1029                         where the type is defined.  You can jump to the
1030                         location where a type is defined by selecting the
1031                         entry in the popup menu.
1032
1033                         Note that the type hierarchy support is based on the
1034                         protocol supported by clangd.  This is different from
1035                         the one specified in the 3.17 of the LSP standard.
1036
1037                                                 *:LspSwitchSourceHeader*
1038 :LspSwitchSourceHeader  Switch between source and header files. This is a
1039                         Clangd specific extension and only works with C/C++
1040                         source files.
1041
1042                                                 *:LspSymbolSearch*
1043 :LspSymbolSearch <sym>  Perform a workspace wide search for the symbol <sym>.
1044                         If <sym> is not supplied, then you will be prompted to
1045                         enter the symbol name (the keyword under the cursor is
1046                         used as the default).  A popup window is opened with
1047                         the list of matching symbols.  You can enter a few
1048                         characters to narrow down the list of matches. The
1049                         displayed symbol name can be erased by pressing
1050                         <Backspace> or <C-U> and a new symbol search pattern
1051                         can be entered.  You can close the popup menu by
1052                         pressing the escape key or by pressing CTRL-C.
1053
1054                         In the popup menu, the following keys can be used:
1055
1056                                 CTRL-F     - Scroll one page forward
1057                                 <PageDown> - idem
1058                                 CTRL-B     - Scroll one page backward
1059                                 <PageUp>   - idem
1060                                 CTRL-Home  - Jump to the first entry
1061                                 CTRL-End   - Jump to the last entry
1062                                 <Up>       - Go up one entry
1063                                 <C-P>      - idem
1064                                 <Down>     - Go down one entry
1065                                 <C-N>      - idem
1066                                 <Enter>    - Open the selected file
1067                                 <Esc>      - Close the popup menu
1068                                 <CTRL-C>   - idem
1069                                 <BS>       - Erase one character from the
1070                                              filter text
1071                                 <C-H>      - idem
1072                                 <C-U>      - Erase the filter text
1073
1074                         Any other alphanumeric key will be used to narrow down
1075                         the list of names displayed in the popup menu. When
1076                         you type a filter string, then only the symbols fuzzy
1077                         matching the string are displayed in the popup menu.
1078                         You can enter a new search pattern to do a workspace
1079                         wide symbol search.
1080
1081                                                 *:LspWorkspaceAddFolder*
1082 :LspWorkspaceAddFolder {folder}
1083                         Add a folder to the workspace
1084
1085 :LspWorkspaceListFolders                        *:LspWorkspaceListFolders*
1086                         Show the list of folders in the workspace.
1087
1088                                                 *:LspWorkspaceRemoveFolder*
1089 :LspWorkspaceRemoveFolder {folder}
1090                         Remove a folder from the workspace
1091
1092 ==============================================================================
1093 6. Insert mode completion                   *lsp-ins-mode-completion*
1094
1095 By default, in insert mode, the LSP plugin automatically displays the matches
1096 for the symbol under the cursor in an insert-completion popup menu. You can
1097 use the keys described in |popupmenu-keys| with this menu.
1098
1099 To disable the auto-completion for all the files, you can set the
1100 'autoComplete' option to false in your .vimrc file: >
1101
1102         LspOptionsSet({'autoComplete': false})
1103 <
1104 If this variable is set, then the LSP plugin will not automatically start
1105 completion in insert mode and instead supports omni-completion (|compl-omni|).
1106 It sets the 'omnifunc' option for the buffers which have a registered language
1107 server. To complete a symbol in insert mode manually, you can press CTRL-X
1108 CTRL-O to invoke completion using the items suggested by the language server.
1109
1110 You can also enable or disable omni-completion for a specific language
1111 server by setting the 'omnicompl' item to 'false' when registering a lsp
1112 server for the filetype. If this item is not specified, then omni-completion
1113 is enabled by default. The following example disables omni-completion for
1114 python: >
1115
1116     vim9script
1117     var lspServers = [
1118                      {
1119                         filetype: 'python',
1120                         omnicompl: false,
1121                         path: '/usr/local/bin/pyls',
1122                         args: ['--check-parent-process', '-v']
1123                      }
1124                    ]
1125 <
1126 If you want to use omni completion, in addition to the automatic completion,
1127 then you can set the 'omnifunc' option to the "g:LspOmniFunc" function: >
1128
1129         set omnifunc=g:LspOmniFunc
1130 <
1131 To use omni completion, press CTRL-X CTRL-O in insert mode.  Refer to
1132 |compl-omni| for more information.
1133
1134 When doing insert-mode completion, the plugin sends a request message to the
1135 language server to return a list of possible completion matches for the
1136 current cursor position.  The plugin retrieves the keyword before the cursor
1137 (see 'iskeyword') and then filters the returned list of completion items
1138 against this keyword and displays the completion menu.  Some language servers
1139 does completion filtering in the server, while other relies on the client to
1140 do the filtering.  By default, case sensitive comparison is used to filter the
1141 returned items.  You can modify the 'completionMatcher' option to use either
1142 case insensitive or fuzzy comparison.
1143
1144 ==============================================================================
1145 7. Diagnostics                                          *lsp-diagnostics*
1146
1147 When a source file has syntax errors or warnings or static analysis warnings,
1148 the LSP plugin highlights them by placing |signs| in the |sign-column|.  You
1149 can use the |:LspDiagShow| command to display all the diagnostic messages for
1150 the current file in a |location-list-window|.  You can use the |:LspDiagFirst|
1151 command to jump to the line with the first diagnostic message, the
1152 |:LspDiagNext| command to jump to the next nearest line with the diagnostic
1153 message, the |:LspDiagPrev| command to jump to the previous nearest line with
1154 the diagnostic message, the |:LspDiagHere| command to jump to the diagnostic
1155 message in the current line.  You can use the |:LspDiagCurrent| command to
1156 display the entire diagnostic message from the language server for the current
1157 line.
1158
1159 By default, the lines with a diagnostic message have a sign placed on them and
1160 are highlighted.  You can temporarily disable them for the current Vim session
1161 using the |:LspDiagHighlightDisable| command and re-enable them using the
1162 |:LspDiagHighlightEnable| command.
1163
1164 To disable the automatic placement of signs on the lines with a diagnostic
1165 message, you can set the 'autoHighlightDiags' option to false: >
1166
1167         LspOptionsSet({'autoHighlightDiags': false})
1168 <
1169 By default the 'autoHighlightDiags' option is set to true.
1170
1171 The function lsp#lsp#ErrorCount() function can be used to get the count of the
1172 diagnostic messages in the current buffer by type.  This function returns a
1173 Dictionary with the following keys: Info, Hint, Warn and Error.  The value for
1174 these keys is the number of diagnostic messages of the corresponding type.
1175 This function can be used to display the number of diagnostics in the current
1176 buffer in a 'statusline'.
1177
1178 For some diagnostic errors/warnings, the language server may provide an
1179 automatic fix.  To apply this fix, you can use the |:LspCodeAction| command.
1180 This command applies the action provided by the language server (if any) for
1181 the current line.
1182
1183 The |:LspDiagShow| command creates a new location list with the current list
1184 of diagnostics for the current buffer.  To automatically add the diagnostics
1185 messages to the location list, you can set the 'autoPopulateDiags' option to
1186 true. Â By default this option is set to false. Â When new diagnostics are
1187 received for a buffer, if a location list with the diagnostics is already
1188 present, then it is refreshed with the new diagnostics.
1189
1190 When using GUI Vim or in a terminal Vim with 'ballooneval' option set, when
1191 the mouse is moved over the diagnostic sign displayed in the sign column, then
1192 the diagnostic message is displayed in a popup.  By default, the diagnostic
1193 message popup is not displayed when the mouse is moved over the text in the
1194 line. To display the diagnostic message when hovering the mouse over the text
1195 of the line, you can set the 'noDiagHoverOnLine' option to false.  By
1196 default, this option is set to true.
1197
1198 To display the diagnostic message for the current line in the status area, you
1199 can set the 'showDiagOnStatusLine' option to true.  By default, this option
1200 is set to false.
1201
1202 By default, the |:LspDiagCurrent| command displays the diagnostic message for
1203 the current line in a popup window.  To display the message in the status
1204 message area instead, you can set the 'showDiagInPopup' option to false.  By
1205 default this is set to true.
1206
1207 ==============================================================================
1208 8. Tag Function                                 *lsp-tagfunc*
1209
1210 The |:LspGotoDefinition| command can be used jump to the location where a
1211 symbol is defined.  To jump to the symbol definition using the Vim
1212 |tag-commands|, you can set the 'tagfunc' option to the 'lsp#lsp#TagFunc'
1213 function: >
1214
1215         setlocal tagfunc=lsp#lsp#TagFunc
1216 <
1217 After setting the above option, you can use |Ctrl-]| and other tag related
1218 commands to jump to the symbol definition.
1219
1220 Note that most of the language servers return only one symbol location even if
1221 the symbol is defined in multiple places in the code.
1222
1223 ==============================================================================
1224 9. Code Formatting                              *lsp-format*
1225
1226 The |:LspFormat| command can be used to format either the entire file or a
1227 selected range of lines using the language server.  The 'shiftwidth' and
1228 'expandtab' values set for the current buffer are used when format is applied.
1229
1230 To format code using the 'gq' command, you can set the 'formatexpr' option: >
1231
1232     setlocal formatexpr=lsp#lsp#FormatExpr()
1233 <
1234 ==============================================================================
1235 10. Call Hierarchy                              *lsp-call-hierarchy*
1236
1237 The |:LspIncomingCalls| and the |:LspOutoingCalls| commands can be used to
1238 display the call hierarchy of a symbol.  For example, the functions calling a
1239 function or the functions called by a function.  These two commands open a
1240 window containing the call hierarchy tree.  You can use the Vim motion
1241 commands to browse the call hierarchy.
1242
1243 In the call hierarchy tree window, the following keys are supported:
1244
1245 <Enter>                         Jump to the location of the symbol under the
1246                                 cursor.
1247 -                               Expand and show the symbols calling or called
1248                                 by the symbol under the cursor.
1249 +                               Close the call hierarchy for the symbol under
1250                                 the cursor.
1251
1252 You can display either the incoming call hierarchy or the outgoing call
1253 hierarchy in this window.  You cannot display both at the same time.
1254
1255 In the call hierarchy tree window, the following commands are supported:
1256
1257                                                 *:LspCallHierarchyRefresh*
1258 :LspCallHierarchyRefresh        Query the language server again for the top
1259                                 level symbol and refresh the call hierarchy
1260                                 tree.
1261                                                 *:LspCallHierarchyIncoming*
1262 :LspCallHierarchyIncoming       Display the incoming call hierarchy for the
1263                                 top level symbol.  If the window is currently
1264                                 displaying the outgoing calls, then it is
1265                                 refreshed to display the incoming calls.
1266                                                 *:LspCallHierarchyOutgoing*
1267 :LspCallHierarchyOutgoing       Display the outgoing call hierarchy for the
1268                                 top level symbol.  If the window is currently
1269                                 displaying the incoming calls, then it is
1270                                 refreshed to display the outgoing calls.
1271
1272 ==============================================================================
1273 11. Autocommands                                *lsp-autocmds*
1274
1275                                                 *LspAttached*
1276 LspAttached                     A |User| autocommand fired when the LSP client
1277                                 attaches to a buffer. Can be used to configure
1278                                 buffer-local mappings or options.
1279
1280                                                 *LspDiagsUpdated*
1281 LspDiagsUpdated                 A |User| autocommand invoked when new
1282                                 diagnostics are received from the language
1283                                 server.  This is invoked after the LSP client
1284                                 has processed the diagnostics.
1285
1286 ==============================================================================
1287 12. Highlight Groups                            *lsp-highlight-groups*
1288
1289 The following highlight groups are used by the LSP plugin.  You can define
1290 these highlight groups in your .vimrc file before sourcing this plugin to
1291 override them.
1292
1293 *LspDiagInlineError*            Used to highlight inline error diagnostics.
1294                                 By default, linked to the "SpellBad" highlight
1295                                 group.
1296 *LspDiagInlineHint*             Used to highlight inline hint diagnostics.
1297                                 By default, linked to the "SpellLocal"
1298                                 highlight group.
1299 *LspDiagInlineInfo*             Used to highlight inline info diagnostics.
1300                                 By default, linked to the "SpellRare"
1301                                 highlight group.
1302 *LspDiagInlineWarning*          Used to highlight inline warning diagnostics.
1303                                 By default, linked to the "SpellCap" highlight
1304                                 group.
1305 *LspDiagLine*                   Used to highlight a line with one or more
1306                                 diagnostics.  By default linked to the
1307                                 "DiffAdd" highlight group.  Use "NONE" to
1308                                 disable.
1309 *LspDiagSignErrorText*          Used to highlight the sign text for error
1310                                 diags.  By default linked to 'ErrorMsg'.
1311 *LspDiagSignHintText*           Used to highlight the sign text for hint
1312                                 diags.  By default linked to 'Question'.
1313 *LspDiagSignInfoText*           Used to highlight the sign text for info
1314                                 diags.  By default linked to 'Pmenu'.
1315 *LspDiagSignWarningText*        Used to highlight the sign text for warning
1316                                 diags.  By default linked to 'Search'.
1317 *LspDiagVirtualText*            Used to highlight diagnostic virtual text.
1318                                 By default, linked to the "LineNr" highlight
1319                                 group.
1320 *LspInlayHintsParam*            Used to highlight inlay hints of kind
1321                                 "parameter".  By default, linked to the
1322                                 "Label" highlight group.
1323 *LspInlayHintsType*             Used to highlight inlay hints of kind "type".
1324                                 By default, linked to the "Conceal" highlight
1325                                 group.
1326 *LspSigActiveParameter*         Used to highlight the active signature
1327                                 parameter.  By default, linked to the "LineNr"
1328                                 highlight group.
1329
1330 For example, to override the highlight used for diagnostics virtual text, you
1331 can use the following: >
1332
1333     highlight LspDiagVirtualText ctermfg=Cyan guifg=Blue
1334 <
1335 or >
1336
1337     highlight link LspDiagLine NONE
1338     highlight link LspDiagVirtualText WarningMsg
1339 <
1340 ==============================================================================
1341 13. Debugging                                   *lsp-debug*
1342
1343 To debug this plugin, you can log the language server protocol messages sent
1344 and received by the plugin from the language server.  The following command
1345 enables the logging of the messages from the language server for the current
1346 buffer: >
1347
1348     :LspServer debug on
1349 <
1350 This command also clears the log files.  The following command disables the
1351 logging of the messages from the language server for the current buffer: >
1352
1353     :LspServer debug off
1354 <
1355 By default, the messages are not logged.  Another method to enable the debug
1356 is to set the "debug" field to true when adding a language server
1357 using |LspAddServer()|.
1358
1359 The messages printed by the language server in the stdout are logged to the
1360 lsp-<server-name>.log file and the messages printed in the stderr are logged
1361 to the lsp-<server-name>.err file.  On a Unix-like system, these files are
1362 created in the /tmp directory.  On MS-Windows, these files are created in the
1363 %TEMP% directory.
1364
1365 The following command opens the file containing the messages printed by the
1366 language server in the stdout: >
1367
1368     :LspServer debug messages
1369 <
1370 The following command opens the file containing the messages printed by the
1371 language server in the stderr: >
1372
1373     :LspServer debug errors
1374 <
1375 To debug language server initialization problems, after enabling the above
1376 server debug, you can restart the server for the file type in the current
1377 buffer using the following command: >
1378
1379     :LspServer restart
1380 <
1381 The language servers typically support command line options to enable debug
1382 messages and to increase the verbosity of the messages.  You can refer to the
1383 language server documentation for information about this.  You can include
1384 these options when registering the language server with this plugin.
1385
1386 If a language server supports the "$/logTrace" LSP notification, then you can
1387 use the :LspServerTrace command to set the server trace value: >
1388
1389     :LspServer trace { off | messages | verbose }
1390 <
1391 ==============================================================================
1392 14. Custom Command Handlers                     *lsp-custom-commands*
1393
1394 When applying a code action, the language server may issue a non-standard
1395 command.  For example, the Java language server uses non-standard commands
1396 (e.g. java.apply.workspaceEdit).  To handle these commands, you can register a
1397 callback function for each command using the LspRegisterCmdHandler() function.
1398 For example: >
1399
1400     vim9script
1401     import autoload "lsp/textedit.vim"
1402
1403     def WorkspaceEdit(cmd: dict<any>)
1404       for editAct in cmd.arguments
1405           textedit.ApplyWorkspaceEdit(editAct)
1406       endfor
1407     enddef
1408     g:LspRegisterCmdHandler('java.apply.workspaceEdit', WorkspaceEdit)
1409 <
1410 Place the above code in a file named lsp_java/plugin/lsp_java.vim and load
1411 this plugin.
1412
1413 The callback function should accept a Dict argument.  The Dict argument
1414 contains the LSP Command interface fields.  Refer to the LSP specification for
1415 more information about the "Command" interface.
1416
1417 ==============================================================================
1418 15. Custom LSP Completion Kinds                 *lsp-custom-kinds*
1419
1420 When a completion popup is triggered, the LSP client will use a default kind
1421 list to show in the completion "kind" section, to customize it, you need to
1422 use the option |lsp-opt-customCompletionKinds| and set all custom kinds in the
1423 option |lsp-opt-completionKinds| . There is a table with all default LSP
1424 kinds:
1425
1426  Kind Name              | Value
1427 ------------------------|--------------------
1428  Text                   | t
1429  Method                 | m
1430  Function               | f
1431  Constructor            | C
1432  Field                  | F
1433  Variable               | v
1434  Class                  | c
1435  Interface              | i
1436  Module                 | M
1437  Property               | p
1438  Unit                   | u
1439  Value                  | V
1440  Enum                   | e
1441  Keyword                | k
1442  Snippet                | S
1443  Color                  | C
1444  File                   | f
1445  Reference              | r
1446  Folder                 | F
1447  EnumMember             | E
1448  Constant               | d
1449  Struct                 | s
1450  Event                  | E
1451  Operator               | o
1452  TypeParameter          | T
1453  Buffer                 | B
1454
1455 For example, if you want to change the "Method" kind to the kind "method()": >
1456
1457         vim9script
1458
1459         g:LspOptionsSet({
1460                 customCompletionKinds: true,
1461                 completionKinds: {
1462                         "Method": "method()"
1463                 }
1464         })
1465 <
1466 In the completion popup, will show something like this: >
1467
1468         var file = new File()
1469
1470         file.cre
1471                 | create                method() |
1472                 | createIfNotExists     method() |
1473                 | ...                            |
1474 <
1475 ==============================================================================
1476 16. Multiple Language Servers for a buffer      *lsp-multiple-servers*
1477
1478 It's possible to run multiple language servers for a given buffer.
1479
1480 By default the language server defined first will be used for as much as it
1481 supports, then the next and so on. With the exception that diagnostics from
1482 all running language servers will be combined.
1483
1484 This means that you can define a language server that only supports a subset
1485 of features at first and then define the general purpose language server after
1486 it:
1487 >
1488         vim9script
1489
1490         g:LspAddServer([
1491                 # This language server reports that it only supports
1492                 # textDocument/documentFormatting, so it will be used
1493                 # for :LspFormat but nothing else.
1494                 {
1495                         filetype: ['html'],
1496                         path: 'html-pretty-lsp',
1497                         args: ['--stdio']
1498                 },
1499                 # This language server also supports
1500                 # textDocument/documentFormatting, but since it's been
1501                 # defined later, the one above will be used instead.
1502                 # However this server also supports
1503                 # textDocument/definition, textDocument/declaration,
1504                 # etc, so it will be used for :LspGotoDefinition,
1505                 # :LspGotoDeclaration, etc
1506                 {
1507                         filetype: ['html'],
1508                         path: 'html-language-server',
1509                         args: ['--stdio']
1510                 }
1511         ])
1512 <
1513 As shown in the example above the order of when the language servers are being
1514 defined is taken into account for a given method.  However sometimes the
1515 language server that you want to use for formatting also reports that it
1516 supports other features. In such a case you can do one of two things:
1517
1518 1. change the order of language servers, and specify that a given language
1519 server should be used for a given method.
1520
1521 2. set the unwanted features to |false| in the features |Dictionary| >
1522
1523         features: { 'codeAction': false }
1524 <
1525 For example, if you want to use the efm-langserver for formatting, but the
1526 typescript-language-server for everything else: >
1527
1528         vim9script
1529
1530         g:LspAddServer([
1531                 # this language server will be used by default, as it's defined
1532                 # as the first LSP for 'javascript' and 'typescript'
1533                 {
1534                         filetype: ['javascript', 'typescript'],
1535                         path: '/usr/local/bin/typescript-language-server',
1536                         args: ['--stdio']
1537                 },
1538                 # this language server will be used for documentFormatting
1539                 {
1540                         filetype: ['efm-langserver'],
1541                         path: '/usr/local/bin/efm-langserver',
1542                         args: [],
1543                         features: {
1544                                 documentFormatting: true
1545                         }
1546                 }
1547         ])
1548 <
1549 Another way is to disable the unwanted features: for example if you don't want
1550 diagnostics from the typescript-language-server, but want to use it for
1551 everything else: >
1552
1553         vim9script
1554
1555         g:LspAddServer([
1556                 {
1557                         filetype: ['javascript', 'typescript'],
1558                         path: '/usr/local/bin/typescript-language-server',
1559                         args: ['--stdio'],
1560                         features: {
1561                                 diagnostics: false
1562                         }
1563                 },
1564         ])
1565 <
1566 ==============================================================================
1567 17. Language Server Features                    *lsp-features*
1568
1569 By providing the configuration |lsp-cfg-features| it's possible to specify
1570 which servers should be used for a given method.  The following feature flags
1571 are supported: See |lsp-multiple-servers| for examples.
1572
1573                                                 *lsp-features-codeAction*
1574 codeAction                      Used by |:LspCodeAction|
1575                                                 *lsp-features-codeLens*
1576 codeLens                        Used by |:LspCodeLens|
1577                                                 *lsp-features-completion*
1578 completion                      Used by 24/7 Completion and 'omnifunc'
1579                                                 *lsp-features-declaration*
1580 declaration                     Used by |:LspGotoDeclaration|, and
1581                                 |:LspPeekDeclaration|
1582                                                 *lsp-features-definition*
1583 definition                      Used by |:LspGotoDefinition|, and
1584                                 |:LspPeekDefinition|
1585                                                 *lsp-features-diagnostics*
1586 diagnostics                     Used to disable diagnostics for a single
1587                                 language server, by default diagnostics are
1588                                 combined from all running servers, by setting
1589                                 this to |false| you can ignore diagnostics
1590                                 from a specific server.
1591                                         *lsp-features-documentFormatting*
1592 documentFormatting              Used by |:LspFormat|, and 'formatexpr'
1593                                         *lsp-features-documentHighlight*
1594 documentHighlight               Used by the |:LspHighlight| and the
1595                                 |:LspHighlightClear| commands.
1596                                                 *lsp-features-foldingRange*
1597 foldingRange                    Used by |:LspFold|
1598                                                 *lsp-features-hover*
1599 hover                           Used by |:LspHover|
1600                                                 *lsp-features-implementation*
1601 implementation                  Used by |:LspGotoImpl|, and |:LspPeekImpl|
1602                                                 *lsp-features-references*
1603 references                      Used by |:LspShowReferences|
1604                                                 *lsp-features-rename*
1605 rename                          Used by |:LspRename|
1606                                                 *lsp-features-selectionRange*
1607 selectionRange                  Used by the |:LspSelectionExpand| and the
1608                                 |:LspSelectionShrink| commands.
1609                                                 *lsp-features-typeDefinition*
1610 typeDefinition                  Used by the |:LspGotoTypeDef| and the
1611                                 |:LspPeekTypeDef| commands.
1612
1613 ==============================================================================
1614                                                 *lsp-license*
1615 License: MIT License
1616 Copyright (c) 2020-2023 Yegappan Lakshmanan
1617
1618 Permission is hereby granted, free of charge, to any person obtaining a copy
1619 of this software and associated documentation files (the "Software"), to
1620 deal in the Software without restriction, including without limitation the
1621 rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
1622 sell copies of the Software, and to permit persons to whom the Software is
1623 furnished to do so, subject to the following conditions:
1624
1625 The above copyright notice and this permission notice shall be included in
1626 all copies or substantial portions of the Software.
1627
1628 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1629 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1630 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1631 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1632 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
1633 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
1634 IN THE SOFTWARE.
1635
1636 ==============================================================================
1637
1638 vim:tw=78:ts=8:noet:ft=help:norl: