lsp.txt (136100B)
1 *lsp.txt* LSP 2 3 4 NVIM REFERENCE MANUAL 5 6 7 LSP client/framework *lsp* *LSP* 8 9 Nvim supports the Language Server Protocol (LSP), which means it acts as 10 a client to LSP servers and includes a Lua framework `vim.lsp` for building 11 enhanced LSP tools. 12 13 https://microsoft.github.io/language-server-protocol/ 14 15 LSP facilitates features like go-to-definition, find references, hover, 16 completion, rename, format, refactor, etc., using semantic whole-project 17 analysis (unlike |ctags|). 18 19 Type |gO| to see the table of contents. 20 21 ============================================================================== 22 QUICKSTART *lsp-quickstart* 23 24 Nvim provides an LSP client, but the servers are provided by third parties. 25 Follow these steps to get LSP features: 26 27 1. Install language servers using your package manager or by following the 28 upstream installation instructions. You can find language servers here: 29 https://microsoft.github.io/language-server-protocol/implementors/servers/ 30 2. Define a new config |lsp-new-config| (or install https://github.com/neovim/nvim-lspconfig). 31 Example: >lua 32 vim.lsp.config['lua_ls'] = { 33 -- Command and arguments to start the server. 34 cmd = { 'lua-language-server' }, 35 -- Filetypes to automatically attach to. 36 filetypes = { 'lua' }, 37 -- Sets the "workspace" to the directory where any of these files is found. 38 -- Files that share a root directory will reuse the LSP server connection. 39 -- Nested lists indicate equal priority, see |vim.lsp.Config|. 40 root_markers = { { '.luarc.json', '.luarc.jsonc' }, '.git' }, 41 -- Specific settings to send to the server. The schema is server-defined. 42 -- Example: https://raw.githubusercontent.com/LuaLS/vscode-lua/master/setting/schema.json 43 settings = { 44 Lua = { 45 runtime = { 46 version = 'LuaJIT', 47 } 48 } 49 } 50 } 51 3. Use |vim.lsp.enable()| to enable the config. 52 Example: >lua 53 vim.lsp.enable('lua_ls') 54 4. Open a code file matching one of the `filetypes` specified in the config. 55 Note: Depending on the LSP server, you may need to ensure your project has 56 a |lsp-root_markers| file so the workspace can be recognized. 57 5. Check that LSP is active ("attached") for the buffer: >vim 58 :checkhealth vim.lsp 59 6. Please note that certain LSP features are disabled by default, 60 you may choose to enable them manually. See: 61 - |lsp-codelens| 62 - |lsp-document_color| 63 - |lsp-linked_editing_range| 64 - |lsp-inlay_hint| 65 - |lsp-inline_completion| 66 7. (Optional) Configure keymaps and autocommands to use LSP features. 67 |lsp-attach| 68 69 ============================================================================== 70 DEFAULTS *lsp-defaults* 71 72 When the Nvim LSP client starts it enables diagnostics |vim.diagnostic| (see 73 |vim.diagnostic.config()| to customize). It also sets various default options, 74 listed below, if (1) the language server supports the functionality and (2) 75 the options are empty or were set by the builtin runtime (ftplugin) files. The 76 options are not restored when the LSP client is stopped or detached. 77 78 GLOBAL DEFAULTS *gra* *gri* *grn* *grr* *grt* *i_CTRL-S* *v_an* *v_in* 79 80 These GLOBAL keymaps are created unconditionally when Nvim starts: 81 - "gra" (Normal and Visual mode) is mapped to |vim.lsp.buf.code_action()| 82 - "gri" is mapped to |vim.lsp.buf.implementation()| 83 - "grn" is mapped to |vim.lsp.buf.rename()| 84 - "grr" is mapped to |vim.lsp.buf.references()| 85 - "grt" is mapped to |vim.lsp.buf.type_definition()| 86 - "gO" is mapped to |vim.lsp.buf.document_symbol()| 87 - CTRL-S (Insert mode) is mapped to |vim.lsp.buf.signature_help()| 88 - "an" and "in" (Visual and Operator-pending mode) are mapped to outer and inner incremental 89 selections, respectively, using |vim.lsp.buf.selection_range()| 90 91 BUFFER-LOCAL DEFAULTS 92 93 - 'omnifunc' is set to |vim.lsp.omnifunc()|, use |i_CTRL-X_CTRL-O| to trigger 94 completion. 95 - 'tagfunc' is set to |vim.lsp.tagfunc()|. This enables features like 96 go-to-definition, |:tjump|, and keymaps like |CTRL-]|, |CTRL-W_]|, 97 |CTRL-W_}| to utilize the language server. 98 - 'formatexpr' is set to |vim.lsp.formatexpr()|, so you can format lines via 99 |gq| if the language server supports it. 100 - To opt out of this use |gw| instead of gq, or clear 'formatexpr' on |LspAttach|. 101 - |K| is mapped to |vim.lsp.buf.hover()| unless 'keywordprg' is customized or 102 a custom keymap for `K` exists. 103 - Document colors are enabled for highlighting color references in a document. 104 - To opt out call `vim.lsp.document_color.enable(false, args.buf)` on |LspAttach|. 105 106 DISABLING DEFAULTS *lsp-defaults-disable* 107 108 You can remove GLOBAL keymaps at any time using |vim.keymap.del()| or 109 |:unmap|. See also |gr-default|. 110 111 To remove or override BUFFER-LOCAL defaults, define a |LspAttach| handler: >lua 112 113 vim.api.nvim_create_autocmd('LspAttach', { 114 callback = function(args) 115 -- Unset 'formatexpr' 116 vim.bo[args.buf].formatexpr = nil 117 -- Unset 'omnifunc' 118 vim.bo[args.buf].omnifunc = nil 119 -- Unmap K 120 vim.keymap.del('n', 'K', { buffer = args.buf }) 121 -- Disable document colors 122 vim.lsp.document_color.enable(false, args.buf) 123 end, 124 }) 125 < 126 ============================================================================== 127 COMMANDS *:lsp* *lsp-commands* 128 129 :lsp enable [config_name] *:lsp-enable* 130 Activates LSP for current and future buffers. See |vim.lsp.enable()|. 131 132 :lsp disable [config_name] *:lsp-disable* 133 Disables LSP (and stops if running) for current and future buffers. See 134 |vim.lsp.enable()|. 135 136 :lsp restart [client_name] *:lsp-restart* 137 Restarts LSP clients and servers. If no client names are given, all active 138 clients attached to the current buffer are restarted. 139 140 :lsp stop [client_name] *:lsp-stop* 141 Stops LSP clients and servers. If no client names are given, all active 142 clients attached to the current buffer are stopped. Use |Client:stop()| 143 for non-interactive use. 144 145 ============================================================================== 146 CONFIG *lsp-config* 147 148 You can configure LSP behavior statically via vim.lsp.config(), and 149 dynamically via |lsp-attach| or |Client:on_attach()|. 150 151 Use |vim.lsp.config()| to define or modify LSP configurations, and 152 |vim.lsp.enable()| to auto-activate them. This is basically a wrapper around 153 |vim.lsp.start()| which allows you to share and merge configs (provided by 154 Nvim, plugins, and your local config). 155 156 NEW CONFIG *lsp-new-config* 157 To create a new config you can either use `vim.lsp.config()` or create 158 a `lsp/<config-name>.lua` file. 159 160 EXAMPLE: DEFINE A CONFIG AS CODE ~ 161 162 1. Run `:lua vim.lsp.config('foo', {cmd={'true'}})` 163 2. Run `:lua vim.lsp.enable('foo')` 164 3. Run `:checkhealth vim.lsp`, check "Enabled Configurations". 😎 165 166 EXAMPLE: DEFINE A CONFIG AS A FILE ~ 167 168 1. Create a file `lsp/foo.lua` somewhere on your 'runtimepath'. > 169 :exe 'edit' stdpath('config') .. '/lsp/foo.lua' 170 2. Add this code to the file (or copy an example from 171 https://github.com/neovim/nvim-lspconfig): > 172 return { 173 cmd = { 'true' }, 174 } 175 3. Save the file (with `++p` to ensure its parent directory is created). > 176 :write ++p 177 4. Enable the config. > 178 :lua vim.lsp.enable('foo') 179 5. Run `:checkhealth vim.lsp`, check "Enabled Configurations". 🌈 180 181 HOW CONFIGS ARE MERGED *lsp-config-merge* 182 When an LSP client starts, it resolves its configuration by merging the 183 following sources (merge semantics defined by |vim.tbl_deep_extend()| with 184 "force" behavior), in order of increasing priority: 185 186 1. Configuration defined for the `'*'` name. 187 2. The merged configuration of all `lsp/<config>.lua` files in 'runtimepath' 188 for the config named `<config>`. 189 3. The merged configuration of all `after/lsp/<config>.lua` files in 190 'runtimepath'. 191 - This behavior of the "after/" directory is a standard Vim feature 192 |after-directory| which allows you to override `lsp/*.lua` configs 193 provided by plugins (such as nvim-lspconfig). 194 4. Configurations defined anywhere else. 195 196 Example: given the following configs... >lua 197 198 -- Defined in init.lua 199 vim.lsp.config('*', { 200 capabilities = { 201 textDocument = { 202 semanticTokens = { 203 multilineTokenSupport = true, 204 } 205 } 206 }, 207 root_markers = { '.git' }, 208 }) 209 -- Defined in <rtp>/lsp/clangd.lua 210 return { 211 cmd = { 'clangd' }, 212 root_markers = { '.clangd', 'compile_commands.json' }, 213 filetypes = { 'c', 'cpp' }, 214 } 215 -- Defined in init.lua 216 vim.lsp.config('clangd', { 217 filetypes = { 'c' }, 218 }) 219 < 220 ...the merged result is: >lua 221 222 { 223 -- From the clangd configuration in <rtp>/lsp/clangd.lua 224 cmd = { 'clangd' }, 225 226 -- From the clangd configuration in <rtp>/lsp/clangd.lua 227 -- Overrides the "*" configuration in init.lua 228 root_markers = { '.clangd', 'compile_commands.json' }, 229 230 -- From the clangd configuration in init.lua 231 -- Overrides the clangd configuration in <rtp>/lsp/clangd.lua 232 filetypes = { 'c' }, 233 234 -- From the "*" configuration in init.lua 235 capabilities = { 236 textDocument = { 237 semanticTokens = { 238 multilineTokenSupport = true, 239 } 240 } 241 } 242 } 243 < 244 CONFIGURE ON ATTACH *lsp-attach* 245 To use LSP features beyond those provided by Nvim (see |lsp-buf|), you can set 246 keymaps and options on |Client:on_attach()| or |LspAttach|. Not all language 247 servers provide the same capabilities; check `supports_method()` in your 248 LspAttach handler. 249 *lsp-lint* *lsp-format* 250 Example: Enable auto-completion and auto-formatting ("linting"): >lua 251 252 vim.api.nvim_create_autocmd('LspAttach', { 253 group = vim.api.nvim_create_augroup('my.lsp', {}), 254 callback = function(args) 255 local client = assert(vim.lsp.get_client_by_id(args.data.client_id)) 256 if client:supports_method('textDocument/implementation') then 257 -- Create a keymap for vim.lsp.buf.implementation ... 258 end 259 260 -- Enable auto-completion. Note: Use CTRL-Y to select an item. |complete_CTRL-Y| 261 if client:supports_method('textDocument/completion') then 262 -- Optional: trigger autocompletion on EVERY keypress. May be slow! 263 -- local chars = {}; for i = 32, 126 do table.insert(chars, string.char(i)) end 264 -- client.server_capabilities.completionProvider.triggerCharacters = chars 265 266 vim.lsp.completion.enable(true, client.id, args.buf, {autotrigger = true}) 267 end 268 269 -- Auto-format ("lint") on save. 270 -- Usually not needed if server supports "textDocument/willSaveWaitUntil". 271 if not client:supports_method('textDocument/willSaveWaitUntil') 272 and client:supports_method('textDocument/formatting') then 273 vim.api.nvim_create_autocmd('BufWritePre', { 274 group = vim.api.nvim_create_augroup('my.lsp', {clear=false}), 275 buffer = args.buf, 276 callback = function() 277 vim.lsp.buf.format({ bufnr = args.buf, id = client.id, timeout_ms = 1000 }) 278 end, 279 }) 280 end 281 end, 282 }) 283 < 284 To see the capabilities for a given server, try this in a LSP-enabled buffer: >vim 285 286 :lua =vim.lsp.get_clients()[1].server_capabilities 287 288 ================================================================================ 289 FAQ *lsp-faq* 290 291 - Q: How to force-reload LSP? 292 - A: Use `:lsp restart`. You can also stop all clients, then reload the buffer: >vim 293 :lsp stop 294 :edit 295 < 296 - Q: Why isn't completion working? 297 - A: In the buffer where you want to use LSP, check that 'omnifunc' is set to 298 "v:lua.vim.lsp.omnifunc": `:verbose set omnifunc?` 299 - Some other plugin may be overriding the option. To avoid that you could 300 set the option in an |after-directory| ftplugin, e.g. 301 "after/ftplugin/python.vim". 302 303 - Q: How do I run a request synchronously (e.g. for formatting on file save)? 304 - A: Check if the function has an `async` parameter and set the value to 305 false. E.g. code formatting: >vim 306 307 " Auto-format *.rs (rust) files prior to saving them 308 " (async = false is the default for format) 309 autocmd BufWritePre *.rs lua vim.lsp.buf.format({ async = false }) 310 < 311 312 - Q: How to avoid my own lsp/ folder being overridden? 313 - A: Place your configs under "after/lsp/". Files in "after/lsp/" are loaded 314 after those in "nvim/lsp/", so your settings will take precedence over 315 the defaults provided by nvim-lspconfig. See also: |after-directory| 316 317 *lsp-vs-treesitter* 318 - Q: How do LSP, Treesitter and Ctags compare? 319 - A: LSP requires a client and language server. The language server uses 320 semantic analysis to understand code at a project level. This provides 321 language servers with the ability to rename across files, find 322 definitions in external libraries and more. 323 324 |treesitter| is a language parsing library that provides excellent tools 325 for incrementally parsing text and handling errors. This makes it a great 326 fit for editors to understand the contents of the current file for things 327 like syntax highlighting, simple goto-definitions, scope analysis and 328 more. 329 330 A |ctags|-like program can generate a |tags| file that allows Nvim to 331 jump to definitions, provide simple completions via |i_CTRL-X_CTRL-]| 332 command. It is not as featureful and doesn't have semantic understanding, 333 but it is fast, lightweight and useful for navigating polyglot projects. 334 335 ================================================================================ 336 LSP API *lsp-api* 337 338 The |lsp-core| API provides core functions for creating and managing clients. 339 The |lsp-buf| functions perform operations for LSP clients attached to the 340 current buffer. 341 342 *lsp-method* 343 Requests and notifications defined by the LSP specification are referred to as 344 "LSP methods". These are handled by Lua |lsp-handler| functions. 345 346 *lsp-handler* 347 LSP handlers are functions that handle |lsp-response|s to requests made by Nvim 348 to the server. (Notifications, as opposed to requests, are fire-and-forget: 349 there is no response, so they can't be handled. |lsp-notification|) 350 351 Each response handler has this signature: > 352 353 function(err, result, ctx) 354 < 355 Parameters: ~ 356 • {err} (`table|nil`) Error info dict, or `nil` if the request 357 completed. 358 • {result} (`Result|Params|nil`) `result` key of the |lsp-response| or 359 `nil` if the request failed. 360 • {ctx} (`table`) Table of calling state associated with the 361 handler, with these keys: 362 • {method} (`string`) |lsp-method| name. 363 • {client_id} (`number`) |vim.lsp.Client| identifier. 364 • {bufnr} (`Buffer`) Buffer handle. 365 • {params} (`table|nil`) Request parameters table. 366 • {version} (`number`) Document version at time of 367 request. Handlers can compare this to the 368 current document version to check if the 369 response is "stale". See also |b:changedtick|. 370 371 Returns: ~ 372 Two values `result, err` where `err` is shaped like an RPC error: > 373 { code, message, data? } 374 < You can use |vim.lsp.rpc.rpc_response_error()| to create this object. 375 376 *lsp-handler-resolution* 377 Handlers can be set by (in increasing priority): 378 379 *vim.lsp.handlers* 380 - Directly calling a LSP method via |Client:request()|. This is the only way 381 to "override" the default client-to-server request handling (by 382 side-stepping `vim.lsp.buf` and related interfaces). >lua 383 local client = assert(vim.lsp.get_clients()[1]) 384 client:request('textDocument/definition') 385 386 - Setting a field in `vim.lsp.handlers`. This global table contains the 387 default mappings of |lsp-method| names to handlers. (Note: only for 388 server-to-client requests/notifications, not client-to-server.) 389 Example: >lua 390 vim.lsp.handlers['textDocument/publishDiagnostics'] = my_custom_diagnostics_handler 391 392 - Passing a {handlers} parameter to |vim.lsp.start()|. This sets the default 393 |lsp-handler| for a specific server. (Note: only for server-to-client 394 requests/notifications, not client-to-server.) 395 Example: >lua 396 vim.lsp.start { 397 ..., -- Other configuration omitted. 398 handlers = { 399 ['textDocument/publishDiagnostics'] = my_custom_diagnostics_handler 400 }, 401 } 402 403 - Passing a {handler} parameter to |vim.lsp.buf_request_all()|. This sets the 404 |lsp-handler| ONLY for the given request(s). 405 Example: >lua 406 vim.lsp.buf_request_all( 407 0, 408 'textDocument/publishDiagnostics', 409 my_request_params, 410 my_handler 411 ) 412 < 413 414 *vim.lsp.log_levels* 415 Log levels are defined in |vim.log.levels| 416 417 418 VIM.LSP.PROTOCOL *vim.lsp.protocol* 419 420 Module `vim.lsp.protocol` defines constants dictated by the LSP specification, 421 and helper functions for creating protocol-related objects. 422 https://github.com/microsoft/language-server-protocol/raw/gh-pages/_specifications/specification-3-14.md 423 424 For example `vim.lsp.protocol.ErrorCodes` allows reverse lookup by number or 425 name: >lua 426 427 vim.lsp.protocol.TextDocumentSyncKind.Full == 1 428 vim.lsp.protocol.TextDocumentSyncKind[1] == "Full" 429 < 430 431 *lsp-response* 432 LSP response shape: 433 https://microsoft.github.io/language-server-protocol/specifications/specification-current/#responseMessage 434 435 *lsp-notification* 436 LSP notification shape: 437 https://microsoft.github.io/language-server-protocol/specifications/specification-current/#notificationMessage 438 439 ================================================================================ 440 LSP HIGHLIGHT *lsp-highlight* 441 442 Reference Highlights: 443 444 Highlight groups that are meant to be used by |vim.lsp.buf.document_highlight()|. 445 446 You can see more about the differences in types here: 447 https://microsoft.github.io/language-server-protocol/specification#textDocument_documentHighlight 448 449 *hl-LspReferenceText* 450 LspReferenceText used for highlighting "text" references 451 *hl-LspReferenceRead* 452 LspReferenceRead used for highlighting "read" references 453 *hl-LspReferenceWrite* 454 LspReferenceWrite used for highlighting "write" references 455 *hl-LspReferenceTarget* 456 LspReferenceTarget used for highlighting reference targets (e.g. in a 457 hover range) 458 *hl-LspInlayHint* 459 LspInlayHint used for highlighting inlay hints 460 461 462 *lsp-highlight-codelens* 463 464 Highlight groups related to |lsp-codelens| functionality. 465 466 *hl-LspCodeLens* 467 LspCodeLens 468 Used to color the virtual text of the codelens. See 469 |nvim_buf_set_extmark()|. 470 471 LspCodeLensSeparator *hl-LspCodeLensSeparator* 472 Used to color the separator between two or more code lenses. 473 474 *lsp-highlight-signature* 475 476 Highlight groups related to |vim.lsp.handlers.signature_help()|. 477 478 *hl-LspSignatureActiveParameter* 479 LspSignatureActiveParameter 480 Used to highlight the active parameter in the signature help. See 481 |vim.lsp.handlers.signature_help()|. 482 483 ------------------------------------------------------------------------------ 484 LSP SEMANTIC HIGHLIGHTS *lsp-semantic-highlight* 485 486 When available, the LSP client highlights code using |lsp-semantic_tokens|, 487 which are another way that LSP servers can provide information about source 488 code. Note that this is in addition to treesitter syntax highlighting; 489 semantic highlighting does not replace syntax highlighting. 490 491 The server will typically provide one token per identifier in the source code. 492 The token will have a `type` such as "function" or "variable", and 0 or more 493 `modifier`s such as "readonly" or "deprecated." The standard types and 494 modifiers are described here: 495 https://microsoft.github.io/language-server-protocol/specification/#textDocument_semanticTokens 496 LSP servers may also use off-spec types and modifiers. 497 498 The LSP client adds one or more highlights for each token. The highlight 499 groups are derived from the token's type and modifiers: 500 • `@lsp.type.<type>.<ft>` for the type 501 • `@lsp.mod.<mod>.<ft>` for each modifier 502 • `@lsp.typemod.<type>.<mod>.<ft>` for each modifier 503 Use |:Inspect| to view the highlights for a specific token. Use |:hi| or 504 |nvim_set_hl()| to change the appearance of semantic highlights: >vim 505 506 hi @lsp.type.function guifg=Yellow " function names are yellow 507 hi @lsp.type.variable.lua guifg=Green " variables in lua are green 508 hi @lsp.mod.deprecated gui=strikethrough " deprecated is crossed out 509 hi @lsp.typemod.function.async guifg=Blue " async functions are blue 510 < 511 The value |vim.hl.priorities|`.semantic_tokens` is the priority of the 512 `@lsp.type.*` highlights. The `@lsp.mod.*` and `@lsp.typemod.*` highlights 513 have priorities one and two higher, respectively. 514 515 You can disable semantic highlights by clearing the highlight groups: >lua 516 517 -- Hide semantic highlights for functions 518 vim.api.nvim_set_hl(0, '@lsp.type.function', {}) 519 520 -- Hide all semantic highlights 521 for _, group in ipairs(vim.fn.getcompletion("@lsp", "highlight")) do 522 vim.api.nvim_set_hl(0, group, {}) 523 end 524 < 525 You probably want these inside a |ColorScheme| autocommand. 526 527 Use |LspTokenUpdate| and |vim.lsp.semantic_tokens.highlight_token()| for more 528 complex highlighting. 529 530 The following is a list of standard captures used in queries for Nvim, 531 highlighted according to the current colorscheme (use |:Inspect| on one to see 532 the exact definition): 533 534 @lsp.type.class Identifiers that declare or reference a class type 535 @lsp.type.comment Tokens that represent a comment 536 @lsp.type.decorator Identifiers that declare or reference decorators and annotations 537 @lsp.type.enum Identifiers that declare or reference an enumeration type 538 @lsp.type.enumMember Identifiers that declare or reference an enumeration property, constant, or member 539 @lsp.type.event Identifiers that declare an event property 540 @lsp.type.function Identifiers that declare a function 541 @lsp.type.interface Identifiers that declare or reference an interface type 542 @lsp.type.keyword Tokens that represent a language keyword 543 @lsp.type.macro Identifiers that declare a macro 544 @lsp.type.method Identifiers that declare a member function or method 545 @lsp.type.modifier Tokens that represent a modifier 546 @lsp.type.namespace Identifiers that declare or reference a namespace, module, or package 547 @lsp.type.number Tokens that represent a number literal 548 @lsp.type.operator Tokens that represent an operator 549 @lsp.type.parameter Identifiers that declare or reference a function or method parameters 550 @lsp.type.property Identifiers that declare or reference a member property, member field, or member variable 551 @lsp.type.regexp Tokens that represent a regular expression literal 552 @lsp.type.string Tokens that represent a string literal 553 @lsp.type.struct Identifiers that declare or reference a struct type 554 @lsp.type.type Identifiers that declare or reference a type that is not covered above 555 @lsp.type.typeParameter Identifiers that declare or reference a type parameter 556 @lsp.type.variable Identifiers that declare or reference a local or global variable 557 558 @lsp.mod.abstract Types and member functions that are abstract 559 @lsp.mod.async Functions that are marked async 560 @lsp.mod.declaration Declarations of symbols 561 @lsp.mod.defaultLibrary Symbols that are part of the standard library 562 @lsp.mod.definition Definitions of symbols, for example, in header files 563 @lsp.mod.deprecated Symbols that should no longer be used 564 @lsp.mod.documentation Occurrences of symbols in documentation 565 @lsp.mod.modification Variable references where the variable is assigned to 566 @lsp.mod.readonly Readonly variables and member fields (constants) 567 @lsp.mod.static Class members (static members) 568 569 ============================================================================== 570 EVENTS *lsp-events* 571 572 LspAttach *LspAttach* 573 After an LSP client performs "initialize" and attaches to a buffer. The 574 |autocmd-pattern| is the buffer name. The client ID is passed in the 575 Lua handler |event-data| argument. 576 577 Example: >lua 578 vim.api.nvim_create_autocmd('LspAttach', { 579 callback = function(ev) 580 local client = vim.lsp.get_client_by_id(ev.data.client_id) 581 -- ... 582 end 583 }) 584 < 585 Note: If the LSP server performs dynamic registration, capabilities may be 586 registered any time _after_ LspAttach. In that case you may want to handle 587 the "registerCapability" event. 588 589 Example: >lua 590 vim.lsp.handlers['client/registerCapability'] = (function(overridden) 591 return function(err, res, ctx) 592 local result = overridden(err, res, ctx) 593 local client = vim.lsp.get_client_by_id(ctx.client_id) 594 if not client then 595 return 596 end 597 for bufnr, _ in pairs(client.attached_buffers) do 598 -- Call your custom on_attach logic... 599 -- my_on_attach(client, bufnr) 600 end 601 return result 602 end 603 end)(vim.lsp.handlers['client/registerCapability']) 604 605 LspDetach *LspDetach* 606 Just before an LSP client detaches from a buffer. The |autocmd-pattern| is 607 the buffer name. The client ID is passed in the Lua handler |event-data| 608 argument. 609 610 Example: >lua 611 vim.api.nvim_create_autocmd('LspDetach', { 612 callback = function(args) 613 -- Get the detaching client 614 local client = vim.lsp.get_client_by_id(args.data.client_id) 615 616 -- Remove the autocommand to format the buffer on save, if it exists 617 if client:supports_method('textDocument/formatting') then 618 vim.api.nvim_clear_autocmds({ 619 event = 'BufWritePre', 620 buffer = args.buf, 621 }) 622 end 623 end, 624 }) 625 < 626 627 LspNotify *LspNotify* 628 This event is triggered after each successful notification sent to an 629 LSP server. 630 631 The client_id, LSP method, and parameters are sent in the Lua handler 632 |event-data| table argument. 633 634 Example: >lua 635 vim.api.nvim_create_autocmd('LspNotify', { 636 callback = function(args) 637 local bufnr = args.buf 638 local client_id = args.data.client_id 639 local method = args.data.method 640 local params = args.data.params 641 642 -- do something with the notification 643 if method == 'textDocument/...' then 644 update_buffer(bufnr) 645 end 646 end, 647 }) 648 < 649 650 LspProgress *LspProgress* 651 Upon receipt of a progress notification from the server. Notifications can 652 be polled from a `progress` ring buffer of a |vim.lsp.Client| or use 653 |vim.lsp.status()| to get an aggregate message. 654 655 If the server sends a "work done progress", the `pattern` is set to `kind` 656 (one of `begin`, `report` or `end`). 657 658 The Lua handler |event-data| argument has `client_id` and `params` 659 properties, where `params` is the request params sent by the server (see 660 `lsp.ProgressParams`). 661 662 Examples: 663 664 Redraw the statusline whenever an LSP progress message arrives: >vim 665 autocmd LspProgress * redrawstatus 666 < 667 Emit a |progress-message| on LSP progress events: >lua 668 vim.api.nvim_create_autocmd('LspProgress', { buffer = buf, callback = function(ev) 669 local value = ev.data.params.value 670 vim.api.nvim_echo({ { value.message or 'done' } }, false, { 671 id = 'lsp', 672 kind = 'progress', 673 title = value.title, 674 status = value.kind ~= 'end' and 'running' or 'success', 675 percent = value.percentage, 676 }) 677 end, 678 }) 679 < 680 See also: ~ 681 • https://github.com/MicrosoftDocs/terminal/blob/main/TerminalDocs/tutorials/progress-bar-sequences.md 682 683 LspRequest *LspRequest* 684 For each request sent to an LSP server, this event is triggered for 685 every change to the request's status. The status can be one of 686 `pending`, `complete`, or `cancel` and is sent as the {type} on the 687 "data" table passed to the callback function. 688 689 It triggers when the initial request is sent ({type} == `pending`) and 690 when the LSP server responds ({type} == `complete`). If a cancellation 691 is requested using `client.cancel_request(request_id)`, then this event 692 will trigger with {type} == `cancel`. 693 694 The Lua handler |event-data| argument has the client ID, request ID, and 695 request (described at |vim.lsp.Client|, {requests} field). If the request 696 type is `complete`, the request will be deleted from the client's pending 697 requests table after processing the event handlers. 698 699 Example: >lua 700 vim.api.nvim_create_autocmd('LspRequest', { 701 callback = function(args) 702 local bufnr = args.buf 703 local client_id = args.data.client_id 704 local request_id = args.data.request_id 705 local request = args.data.request 706 if request.type == 'pending' then 707 -- do something with pending requests 708 track_pending(client_id, bufnr, request_id, request) 709 elseif request.type == 'cancel' then 710 -- do something with pending cancel requests 711 track_canceling(client_id, bufnr, request_id, request) 712 elseif request.type == 'complete' then 713 -- do something with finished requests. this pending 714 -- request entry is about to be removed since it is complete 715 track_finish(client_id, bufnr, request_id, request) 716 end 717 end, 718 }) 719 < 720 721 LspTokenUpdate *LspTokenUpdate* 722 When a visible semantic token is sent or updated by the LSP server, or 723 when an existing token becomes visible for the first time. The 724 |autocmd-pattern| is the buffer name. The Lua handler |event-data| 725 argument has the client ID and token (see 726 |vim.lsp.semantic_tokens.get_at_pos()|). 727 728 Example: >lua 729 vim.api.nvim_create_autocmd('LspTokenUpdate', { 730 callback = function(args) 731 local token = args.data.token 732 if token.type == 'variable' and not token.modifiers.readonly then 733 vim.lsp.semantic_tokens.highlight_token( 734 token, args.buf, args.data.client_id, 'MyMutableVariableHighlight' 735 ) 736 end 737 end, 738 }) 739 < 740 Note: doing anything other than calling 741 |vim.lsp.semantic_tokens.highlight_token()| is considered experimental. 742 743 ============================================================================== 744 Lua module: vim.lsp *lsp-core* 745 746 *vim.lsp.Config* 747 Extends: |vim.lsp.ClientConfig| 748 749 750 Fields: ~ 751 • {cmd}? (`string[]|fun(dispatchers: vim.lsp.rpc.Dispatchers, config: vim.lsp.ClientConfig): vim.lsp.rpc.PublicClient`) 752 See `cmd` in |vim.lsp.ClientConfig|. See also 753 `reuse_client` to dynamically decide (per-buffer) 754 when `cmd` should be re-invoked. 755 • {filetypes}? (`string[]`) Filetypes the client will attach to, or 756 `nil` for ALL filetypes. To match files by name, 757 pattern, or contents, you can define a custom 758 filetype using |vim.filetype.add()|: >lua 759 vim.filetype.add({ 760 filename = { 761 ['my_filename'] = 'my_filetype1', 762 }, 763 pattern = { 764 ['.*/etc/my_file_pattern/.*'] = 'my_filetype2', 765 }, 766 }) 767 vim.lsp.config('…', { 768 filetypes = { 'my_filetype1', 'my_filetype2' }, 769 } 770 < 771 • {reuse_client}? (`fun(client: vim.lsp.Client, config: vim.lsp.ClientConfig): boolean`) 772 Predicate which decides if a client should be 773 re-used. Used on all running clients. The default 774 implementation re-uses a client if name and root_dir 775 matches. 776 • {root_dir}? (`string|fun(bufnr: integer, on_dir:fun(root_dir?:string))`) 777 *lsp-root_dir()* Decides the workspace root: the 778 directory where the LSP server will base its 779 workspaceFolders, rootUri, and rootPath on 780 initialization. The function form must call the 781 `on_dir` callback to provide the root dir, or LSP 782 will not be activated for the buffer. Thus a 783 `root_dir()` function can dynamically decide 784 per-buffer whether to activate (or skip) LSP. See 785 example at |vim.lsp.enable()|. 786 • {root_markers}? (`(string|string[])[]`) *lsp-root_markers* 787 Filename(s) (".git/", "package.json", …) used to 788 decide the workspace root. Unused if `root_dir` is 789 defined. The list order decides priority. To indicate 790 "equal priority", specify names in a nested list 791 `{ { 'a.txt', 'b.lua' }, ... }`. 792 • For each item, Nvim will search upwards (from the 793 buffer file) for that marker, or list of markers; 794 search stops at the first directory containing that 795 marker, and the directory is used as the root dir 796 (workspace folder). 797 • Example: Find the first ancestor directory 798 containing file or directory "stylua.toml"; if not 799 found, find the first ancestor containing ".git": > 800 root_markers = { 'stylua.toml', '.git' } 801 < 802 • Example: Find the first ancestor directory 803 containing EITHER "stylua.toml" or ".luarc.json"; 804 if not found, find the first ancestor containing 805 ".git": > 806 root_markers = { { 'stylua.toml', '.luarc.json' }, '.git' } 807 < 808 809 810 buf_attach_client({bufnr}, {client_id}) *vim.lsp.buf_attach_client()* 811 Implements the `textDocument/did…` notifications required to track a 812 buffer for any language server. 813 814 Without calling this, the server won't be notified of changes to a buffer. 815 816 Parameters: ~ 817 • {bufnr} (`integer`) Buffer handle, or 0 for current 818 • {client_id} (`integer`) Client id 819 820 Return: ~ 821 (`boolean`) success `true` if client was attached successfully; 822 `false` otherwise 823 824 buf_detach_client({bufnr}, {client_id}) *vim.lsp.buf_detach_client()* 825 Detaches client from the specified buffer. Note: While the server is 826 notified that the text document (buffer) was closed, it is still able to 827 send notifications should it ignore this notification. 828 829 Parameters: ~ 830 • {bufnr} (`integer`) Buffer handle, or 0 for current 831 • {client_id} (`integer`) Client id 832 833 buf_is_attached({bufnr}, {client_id}) *vim.lsp.buf_is_attached()* 834 Checks if a buffer is attached for a particular client. 835 836 Parameters: ~ 837 • {bufnr} (`integer`) Buffer handle, or 0 for current 838 • {client_id} (`integer`) the client id 839 840 buf_notify({bufnr}, {method}, {params}) *vim.lsp.buf_notify()* 841 Send a notification to a server 842 843 Attributes: ~ 844 Since: 0.5.0 845 846 Parameters: ~ 847 • {bufnr} (`integer?`) The number of the buffer 848 • {method} (`string`) Name of the request method 849 • {params} (`any`) Arguments to send to the server 850 851 Return: ~ 852 (`boolean`) success true if any client returns true; false otherwise 853 854 *vim.lsp.buf_request_all()* 855 buf_request_all({bufnr}, {method}, {params}, {handler}) 856 Sends an async request for all active clients attached to the buffer and 857 executes the `handler` callback with the combined result. 858 859 Attributes: ~ 860 Since: 0.5.0 861 862 Parameters: ~ 863 • {bufnr} (`integer`) Buffer handle, or 0 for current. 864 • {method} (`string`) LSP method name 865 • {params} (`table|(fun(client: vim.lsp.Client, bufnr: integer): table?)?`) 866 Parameters to send to the server. Can also be passed as a 867 function that returns the params table for cases where 868 parameters are specific to the client. 869 • {handler} (`function`) Handler called after all requests are 870 completed. Server results are passed as a 871 `client_id:result` map. 872 873 Return: ~ 874 (`function`) cancel Function that cancels all requests. 875 876 *vim.lsp.buf_request_sync()* 877 buf_request_sync({bufnr}, {method}, {params}, {timeout_ms}) 878 Sends a request to all server and waits for the response of all of them. 879 880 Calls |vim.lsp.buf_request_all()| but blocks Nvim while awaiting the 881 result. Parameters are the same as |vim.lsp.buf_request_all()| but the 882 result is different. Waits a maximum of {timeout_ms}. 883 884 Attributes: ~ 885 Since: 0.5.0 886 887 Parameters: ~ 888 • {bufnr} (`integer`) Buffer handle, or 0 for current. 889 • {method} (`string`) LSP method name 890 • {params} (`table|(fun(client: vim.lsp.Client, bufnr: integer): table?)?`) 891 Parameters to send to the server. Can also be passed as 892 a function that returns the params table for cases where 893 parameters are specific to the client. 894 • {timeout_ms} (`integer?`, default: `1000`) Maximum time in 895 milliseconds to wait for a result. 896 897 Return (multiple): ~ 898 (`table<integer, {error: lsp.ResponseError?, result: any}>?`) result 899 Map of client_id:request_result. 900 (`string?`) err On timeout, cancel, or error, `err` is a string 901 describing the failure reason, and `result` is nil. 902 903 commands *vim.lsp.commands* 904 Map of client-defined handlers implementing custom (off-spec) commands 905 which a server may invoke. Each key is a unique command name; each value 906 is a function which is called when an LSP action (code action, code 907 lenses, …) requests it by name. 908 909 If an LSP response requests a command not defined client-side, Nvim will 910 forward it to the server as `workspace/executeCommand`. 911 • Argument 1 is the `Command`: > 912 Command 913 title: String 914 command: String 915 arguments?: any[] 916 < 917 • Argument 2 is the |lsp-handler| `ctx`. 918 919 Example: >lua 920 vim.lsp.commands['java.action.generateToStringPrompt'] = function(_, ctx) 921 require("jdtls.async").run(function() 922 local _, result = request(ctx.bufnr, 'java/checkToStringStatus', ctx.params) 923 local fields = ui.pick_many(result.fields, 'Include item in toString?', function(x) 924 return string.format('%s: %s', x.name, x.type) 925 end) 926 local _, edit = request(ctx.bufnr, 'java/generateToString', { context = ctx.params; fields = fields; }) 927 vim.lsp.util.apply_workspace_edit(edit, offset_encoding) 928 end) 929 end 930 < 931 932 config({name}, {cfg}) *vim.lsp.config()* 933 Sets the default configuration for an LSP client (or all clients if the 934 special name "*" is used). 935 936 Can also be accessed by table-indexing (`vim.lsp.config[…]`) to get the 937 resolved config, or redefine the config (instead of "merging" with the 938 config chain). 939 940 Examples: 941 • Add root markers for ALL clients: >lua 942 vim.lsp.config('*', { 943 root_markers = { '.git', '.hg' }, 944 }) 945 < 946 • Add capabilities to ALL clients: >lua 947 vim.lsp.config('*', { 948 capabilities = { 949 textDocument = { 950 semanticTokens = { 951 multilineTokenSupport = true, 952 } 953 } 954 } 955 }) 956 < 957 • Add root markers and capabilities for "clangd": >lua 958 vim.lsp.config('clangd', { 959 root_markers = { '.clang-format', 'compile_commands.json' }, 960 capabilities = { 961 textDocument = { 962 completion = { 963 completionItem = { 964 snippetSupport = true, 965 } 966 } 967 } 968 } 969 }) 970 < 971 • (Re-)define the "clangd" configuration (overrides the resolved chain): >lua 972 vim.lsp.config.clangd = { 973 cmd = { 974 'clangd', 975 '--clang-tidy', 976 '--background-index', 977 '--offset-encoding=utf-8', 978 }, 979 root_markers = { '.clangd', 'compile_commands.json' }, 980 filetypes = { 'c', 'cpp' }, 981 } 982 < 983 • Get the resolved configuration for "lua_ls": >lua 984 local cfg = vim.lsp.config.lua_ls 985 < 986 987 Attributes: ~ 988 Since: 0.11.0 989 990 Parameters: ~ 991 • {name} (`string`) 992 • {cfg} (`vim.lsp.Config`) See |vim.lsp.Config|. 993 994 enable({name}, {enable}) *vim.lsp.enable()* 995 Auto-activates LSP in each buffer based on the |lsp-config| `filetypes`, 996 `root_markers`, and `root_dir`. 997 998 To disable, pass `enable=false`: Stops related clients and servers 999 (force-stops servers after a timeout, unless `exit_timeout=false`). 1000 1001 Raises an error under the following conditions: 1002 • `{name}` is not a valid LSP config name (for example, `'*'`). 1003 • `{name}` corresponds to an LSP config file which raises an error. 1004 1005 If an error is raised when multiple names are provided, this function will 1006 have no side-effects; it will not enable/disable any configs, including 1007 ones which contain no errors. 1008 1009 Examples: >lua 1010 vim.lsp.enable('clangd') 1011 vim.lsp.enable({'lua_ls', 'pyright'}) 1012 < 1013 1014 Example: To dynamically decide whether LSP is activated, define a 1015 |lsp-root_dir()| function which calls `on_dir()` only when you want that 1016 config to activate: >lua 1017 vim.lsp.config('lua_ls', { 1018 root_dir = function(bufnr, on_dir) 1019 if not vim.fn.bufname(bufnr):match('%.txt$') then 1020 on_dir(vim.fn.getcwd()) 1021 end 1022 end 1023 }) 1024 < 1025 1026 Attributes: ~ 1027 Since: 0.11.0 1028 1029 Parameters: ~ 1030 • {name} (`string|string[]`) Name(s) of client(s) to enable. 1031 • {enable} (`boolean?`) If `true|nil`, enables auto-activation of the 1032 given LSP config on current and future buffers. If `false`, 1033 disables auto-activation and stops related LSP clients and 1034 servers (force-stops servers after `exit_timeout` 1035 milliseconds). 1036 1037 foldclose({kind}, {winid}) *vim.lsp.foldclose()* 1038 Close all {kind} of folds in the the window with {winid}. 1039 1040 To automatically fold imports when opening a file, you can use an autocmd: >lua 1041 vim.api.nvim_create_autocmd('LspNotify', { 1042 callback = function(args) 1043 if args.data.method == 'textDocument/didOpen' then 1044 vim.lsp.foldclose('imports', vim.fn.bufwinid(args.buf)) 1045 end 1046 end, 1047 }) 1048 < 1049 1050 Attributes: ~ 1051 Since: 0.11.0 1052 1053 Parameters: ~ 1054 • {kind} (`lsp.FoldingRangeKind`) Kind to close, one of "comment", 1055 "imports" or "region". 1056 • {winid} (`integer?`) Defaults to the current window. 1057 1058 foldexpr({lnum}) *vim.lsp.foldexpr()* 1059 Provides an interface between the built-in client and a `foldexpr` 1060 function. 1061 1062 To use, set 'foldmethod' to "expr" and set the value of 'foldexpr': >lua 1063 vim.o.foldmethod = 'expr' 1064 vim.o.foldexpr = 'v:lua.vim.lsp.foldexpr()' 1065 < 1066 1067 Or use it only when supported by checking for the 1068 "textDocument/foldingRange" capability in an |LspAttach| autocommand. 1069 Example: >lua 1070 vim.o.foldmethod = 'expr' 1071 -- Default to treesitter folding 1072 vim.o.foldexpr = 'v:lua.vim.treesitter.foldexpr()' 1073 -- Prefer LSP folding if client supports it 1074 vim.api.nvim_create_autocmd('LspAttach', { 1075 callback = function(args) 1076 local client = vim.lsp.get_client_by_id(args.data.client_id) 1077 if client:supports_method('textDocument/foldingRange') then 1078 local win = vim.api.nvim_get_current_win() 1079 vim.wo[win][0].foldexpr = 'v:lua.vim.lsp.foldexpr()' 1080 end 1081 end, 1082 }) 1083 < 1084 1085 Parameters: ~ 1086 • {lnum} (`integer`) line number 1087 1088 foldtext() *vim.lsp.foldtext()* 1089 Provides a `foldtext` function that shows the `collapsedText` retrieved, 1090 defaults to the first folded line if `collapsedText` is not provided. 1091 1092 formatexpr({opts}) *vim.lsp.formatexpr()* 1093 Provides an interface between the built-in client and a `formatexpr` 1094 function. 1095 1096 Currently only supports a single client. This can be set via 1097 `setlocal formatexpr=v:lua.vim.lsp.formatexpr()` or (more typically) in 1098 `on_attach` via 1099 `vim.bo[bufnr].formatexpr = 'v:lua.vim.lsp.formatexpr(#{timeout_ms:250})'`. 1100 1101 Parameters: ~ 1102 • {opts} (`table?`) A table with the following fields: 1103 • {timeout_ms} (`integer`, default: 500ms) The timeout period 1104 for the formatting request.. 1105 1106 get_client_by_id({client_id}) *vim.lsp.get_client_by_id()* 1107 Gets a client by id, or nil if the id is invalid or the client was 1108 stopped. The returned client may not yet be fully initialized. 1109 1110 Parameters: ~ 1111 • {client_id} (`integer`) client id 1112 1113 Return: ~ 1114 (`vim.lsp.Client?`) client rpc object. See |vim.lsp.Client|. 1115 1116 get_clients({filter}) *vim.lsp.get_clients()* 1117 Get active clients. 1118 1119 Attributes: ~ 1120 Since: 0.10.0 1121 1122 Parameters: ~ 1123 • {filter} (`table?`) Key-value pairs used to filter the returned 1124 clients. 1125 • {id}? (`integer`) Only return clients with the given id 1126 • {bufnr}? (`integer`) Only return clients attached to this 1127 buffer 1128 • {name}? (`string`) Only return clients with the given name 1129 • {method}? (`string`) Only return clients supporting the 1130 given method 1131 1132 Return: ~ 1133 (`vim.lsp.Client[]`) List of |vim.lsp.Client| objects 1134 1135 is_enabled({name}) *vim.lsp.is_enabled()* 1136 Checks if the given LSP config is enabled (globally, not per-buffer). 1137 1138 Unlike `vim.lsp.config['…']`, this does not have the side-effect of 1139 resolving the config. 1140 1141 Parameters: ~ 1142 • {name} (`string`) Config name 1143 1144 Return: ~ 1145 (`boolean`) 1146 1147 omnifunc({findstart}, {base}) *vim.lsp.omnifunc()* 1148 Implements 'omnifunc' compatible LSP completion. 1149 1150 Parameters: ~ 1151 • {findstart} (`integer`) 0 or 1, decides behavior 1152 • {base} (`integer`) findstart=0, text to match against 1153 1154 Return: ~ 1155 (`integer|table`) Decided by {findstart}: 1156 • findstart=0: column where the completion starts, or -2 or -3 1157 • findstart=1: list of matches (actually just calls |complete()|) 1158 1159 See also: ~ 1160 • |complete-functions| 1161 • |complete-items| 1162 • |CompleteDone| 1163 1164 start({config}, {opts}) *vim.lsp.start()* 1165 Create a new LSP client and start a language server or reuses an already 1166 running client if one is found matching `name` and `root_dir`. Attaches 1167 the current buffer to the client. 1168 1169 Example: >lua 1170 vim.lsp.start({ 1171 name = 'my-server-name', 1172 cmd = {'name-of-language-server-executable'}, 1173 root_dir = vim.fs.root(0, {'pyproject.toml', 'setup.py'}), 1174 }) 1175 < 1176 1177 See |vim.lsp.ClientConfig| for all available options. The most important 1178 are: 1179 • `name` arbitrary name for the LSP client. Should be unique per language 1180 server. 1181 • `cmd` command string[] or function. 1182 • `root_dir` path to the project root. By default this is used to decide 1183 if an existing client should be re-used. The example above uses 1184 |vim.fs.root()| to detect the root by traversing the file system upwards 1185 starting from the current directory until either a `pyproject.toml` or 1186 `setup.py` file is found. 1187 • `workspace_folders` list of `{ uri:string, name: string }` tables 1188 specifying the project root folders used by the language server. If 1189 `nil` the property is derived from `root_dir` for convenience. 1190 1191 Language servers use this information to discover metadata like the 1192 dependencies of your project and they tend to index the contents within 1193 the project folder. 1194 1195 To ensure a language server is only started for languages it can handle, 1196 make sure to call |vim.lsp.start()| within a |FileType| autocmd. Either 1197 use |:au|, |nvim_create_autocmd()| or put the call in a 1198 `ftplugin/<filetype_name>.lua` (See |ftplugin-name|) 1199 1200 Attributes: ~ 1201 Since: 0.8.0 1202 1203 Parameters: ~ 1204 • {config} (`vim.lsp.ClientConfig`) Configuration for the server. See 1205 |vim.lsp.ClientConfig|. 1206 • {opts} (`table?`) Optional keyword arguments. 1207 • {reuse_client}? 1208 (`fun(client: vim.lsp.Client, config: vim.lsp.ClientConfig): boolean`) 1209 Predicate used to decide if a client should be re-used. 1210 Used on all running clients. The default implementation 1211 re-uses a client if it has the same name and if the given 1212 workspace folders (or root_dir) are all included in the 1213 client's workspace folders. 1214 • {bufnr}? (`integer`) Buffer handle to attach to if 1215 starting or re-using a client (0 for current). 1216 • {attach}? (`boolean`) Whether to attach the client to a 1217 buffer (default true). If set to `false`, `reuse_client` 1218 and `bufnr` will be ignored. 1219 • {silent}? (`boolean`) Suppress error reporting if the LSP 1220 server fails to start (default false). 1221 1222 Return: ~ 1223 (`integer?`) client_id 1224 1225 status() *vim.lsp.status()* 1226 Consumes the latest progress messages from all clients and formats them as 1227 a string. Empty if there are no clients or if no new messages 1228 1229 Return: ~ 1230 (`string`) 1231 1232 tagfunc({pattern}, {flags}) *vim.lsp.tagfunc()* 1233 Provides an interface between the built-in client and 'tagfunc'. 1234 1235 When used with normal mode commands (e.g. |CTRL-]|) this will invoke the 1236 "textDocument/definition" LSP method to find the tag under the cursor. 1237 Otherwise, uses "workspace/symbol". If no results are returned from any 1238 LSP servers, falls back to using built-in tags. 1239 1240 Parameters: ~ 1241 • {pattern} (`string`) Pattern used to find a workspace symbol 1242 • {flags} (`string`) See |tag-function| 1243 1244 Return: ~ 1245 (`table[]`) tags A list of matching tags 1246 1247 1248 ============================================================================== 1249 Lua module: vim.lsp.buf *lsp-buf* 1250 1251 The `vim.lsp.buf_…` functions perform operations for LSP clients attached to 1252 the current buffer. 1253 1254 1255 *vim.lsp.ListOpts* 1256 1257 Fields: ~ 1258 • {on_list}? (`fun(t: vim.lsp.LocationOpts.OnList)`) list-handler 1259 replacing the default handler. Called for any non-empty 1260 result. This table can be used with |setqflist()| or 1261 |setloclist()|. E.g.: >lua 1262 local function on_list(options) 1263 vim.fn.setqflist({}, ' ', options) 1264 vim.cmd.cfirst() 1265 end 1266 1267 vim.lsp.buf.definition({ on_list = on_list }) 1268 vim.lsp.buf.references(nil, { on_list = on_list }) 1269 < 1270 • {loclist}? (`boolean`) Whether to use the |location-list| or the 1271 |quickfix| list in the default handler. >lua 1272 vim.lsp.buf.definition({ loclist = true }) 1273 vim.lsp.buf.references(nil, { loclist = false }) 1274 < 1275 1276 *vim.lsp.LocationOpts* 1277 Extends: |vim.lsp.ListOpts| 1278 1279 1280 Fields: ~ 1281 • {reuse_win}? (`boolean`) Jump to existing window if buffer is already 1282 open. 1283 1284 *vim.lsp.LocationOpts.OnList* 1285 1286 Fields: ~ 1287 • {items} (`vim.quickfix.entry[]`) See |setqflist-what| 1288 • {title}? (`string`) Title for the list. 1289 • {context}? (`{ bufnr: integer, method: string }`) Subset of `ctx` 1290 from |lsp-handler|. 1291 1292 *vim.lsp.buf.hover.Opts* 1293 Extends: |vim.lsp.util.open_floating_preview.Opts| 1294 1295 1296 Fields: ~ 1297 • {silent}? (`boolean`) 1298 1299 *vim.lsp.buf.signature_help.Opts* 1300 Extends: |vim.lsp.util.open_floating_preview.Opts| 1301 1302 1303 Fields: ~ 1304 • {silent}? (`boolean`) 1305 1306 1307 *vim.lsp.buf.add_workspace_folder()* 1308 add_workspace_folder({workspace_folder}) 1309 Add the folder at path to the workspace folders. If {path} is not 1310 provided, the user will be prompted for a path using |input()|. 1311 1312 Parameters: ~ 1313 • {workspace_folder} (`string?`) 1314 1315 clear_references() *vim.lsp.buf.clear_references()* 1316 Removes document highlights from current buffer. 1317 1318 code_action({opts}) *vim.lsp.buf.code_action()* 1319 Selects a code action (LSP: "textDocument/codeAction" request) available 1320 at cursor position. 1321 1322 Parameters: ~ 1323 • {opts} (`table?`) A table with the following fields: 1324 • {context}? (`lsp.CodeActionContext`) Corresponds to 1325 `CodeActionContext` of the LSP specification: 1326 • {diagnostics}? (`table`) LSP `Diagnostic[]`. Inferred from 1327 the current position if not provided. 1328 • {only}? (`table`) List of LSP `CodeActionKind`s used to 1329 filter the code actions. Most language servers support 1330 values like `refactor` or `quickfix`. 1331 • {triggerKind}? (`integer`) The reason why code actions 1332 were requested. 1333 • {filter}? 1334 (`fun(x: lsp.CodeAction|lsp.Command, client_id: integer):boolean`) 1335 Predicate taking a code action or command and the provider's 1336 ID. If it returns false, the action is filtered out. 1337 • {apply}? (`boolean`) When set to `true`, and there is just 1338 one remaining action (after filtering), the action is 1339 applied without user query. 1340 • {range}? (`{start: integer[], end: integer[]}`) Range for 1341 which code actions should be requested. If in visual mode 1342 this defaults to the active selection. Table must contain 1343 `start` and `end` keys with {row,col} tuples using mark-like 1344 indexing. See |api-indexing| 1345 1346 See also: ~ 1347 • https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_codeAction 1348 • vim.lsp.protocol.CodeActionTriggerKind 1349 1350 declaration({opts}) *vim.lsp.buf.declaration()* 1351 Jumps to the declaration of the symbol under the cursor. 1352 1353 Note: ~ 1354 • Many servers do not implement this method. Generally, see 1355 |vim.lsp.buf.definition()| instead. 1356 1357 Parameters: ~ 1358 • {opts} (`vim.lsp.LocationOpts?`) See |vim.lsp.LocationOpts|. 1359 1360 definition({opts}) *vim.lsp.buf.definition()* 1361 Jumps to the definition of the symbol under the cursor. 1362 1363 Parameters: ~ 1364 • {opts} (`vim.lsp.LocationOpts?`) See |vim.lsp.LocationOpts|. 1365 1366 document_highlight() *vim.lsp.buf.document_highlight()* 1367 Send request to the server to resolve document highlights for the current 1368 text document position. This request can be triggered by a key mapping or 1369 by events such as `CursorHold`, e.g.: >vim 1370 autocmd CursorHold <buffer> lua vim.lsp.buf.document_highlight() 1371 autocmd CursorHoldI <buffer> lua vim.lsp.buf.document_highlight() 1372 autocmd CursorMoved <buffer> lua vim.lsp.buf.clear_references() 1373 < 1374 1375 Note: Usage of |vim.lsp.buf.document_highlight()| requires the following 1376 highlight groups to be defined or you won't be able to see the actual 1377 highlights. |hl-LspReferenceText| |hl-LspReferenceRead| 1378 |hl-LspReferenceWrite| 1379 1380 document_symbol({opts}) *vim.lsp.buf.document_symbol()* 1381 Lists all symbols in the current buffer in the |location-list|. 1382 1383 Parameters: ~ 1384 • {opts} (`vim.lsp.ListOpts?`) See |vim.lsp.ListOpts|. 1385 1386 format({opts}) *vim.lsp.buf.format()* 1387 Formats a buffer using the attached (and optionally filtered) language 1388 server clients. 1389 1390 Parameters: ~ 1391 • {opts} (`table?`) A table with the following fields: 1392 • {formatting_options}? (`lsp.FormattingOptions`) Can be used 1393 to specify FormattingOptions. Some unspecified options will 1394 be automatically derived from the current Nvim options. See 1395 https://microsoft.github.io/language-server-protocol/specification/#formattingOptions 1396 • {timeout_ms}? (`integer`, default: `1000`) Time in 1397 milliseconds to block for formatting requests. No effect if 1398 async=true. 1399 • {bufnr}? (`integer`, default: current buffer) Restrict 1400 formatting to the clients attached to the given buffer. 1401 • {filter}? (`fun(client: vim.lsp.Client): boolean?`) 1402 Predicate used to filter clients. Receives a client as 1403 argument and must return a boolean. Clients matching the 1404 predicate are included. Example: >lua 1405 -- Never request typescript-language-server for formatting 1406 vim.lsp.buf.format { 1407 filter = function(client) return client.name ~= "ts_ls" end 1408 } 1409 < 1410 • {async}? (`boolean`, default: false) If true the method 1411 won't block. Editing the buffer while formatting 1412 asynchronous can lead to unexpected changes. 1413 • {id}? (`integer`) Restrict formatting to the client with ID 1414 (client.id) matching this field. 1415 • {name}? (`string`) Restrict formatting to the client with 1416 name (client.name) matching this field. 1417 • {range}? 1418 (`{start:[integer,integer],end:[integer, integer]}|{start:[integer,integer],end:[integer,integer]}[]`, 1419 default: current selection in visual mode, `nil` in other 1420 modes, formatting the full buffer) Range to format. Table 1421 must contain `start` and `end` keys with {row,col} tuples 1422 using (1,0) indexing. Can also be a list of tables that 1423 contain `start` and `end` keys as described above, in which 1424 case `textDocument/rangesFormatting` support is required. 1425 1426 hover({config}) *vim.lsp.buf.hover()* 1427 Displays hover information about the symbol under the cursor in a floating 1428 window. The window will be dismissed on cursor move. Calling the function 1429 twice will jump into the floating window (thus by default, "KK" will open 1430 the hover window and focus it). In the floating window, all commands and 1431 mappings are available as usual, except that "q" dismisses the window. You 1432 can scroll the contents the same as you would any other buffer. 1433 1434 Note: to disable hover highlights, add the following to your config: >lua 1435 vim.api.nvim_create_autocmd('ColorScheme', { 1436 callback = function() 1437 vim.api.nvim_set_hl(0, 'LspReferenceTarget', {}) 1438 end, 1439 }) 1440 < 1441 1442 Parameters: ~ 1443 • {config} (`vim.lsp.buf.hover.Opts?`) See |vim.lsp.buf.hover.Opts|. 1444 1445 implementation({opts}) *vim.lsp.buf.implementation()* 1446 Lists all the implementations for the symbol under the cursor in the 1447 quickfix window. 1448 1449 Parameters: ~ 1450 • {opts} (`vim.lsp.LocationOpts?`) See |vim.lsp.LocationOpts|. 1451 1452 incoming_calls() *vim.lsp.buf.incoming_calls()* 1453 Lists all the call sites of the symbol under the cursor in the |quickfix| 1454 window. If the symbol can resolve to multiple items, the user can pick one 1455 in the |inputlist()|. 1456 1457 list_workspace_folders() *vim.lsp.buf.list_workspace_folders()* 1458 List workspace folders. 1459 1460 outgoing_calls() *vim.lsp.buf.outgoing_calls()* 1461 Lists all the items that are called by the symbol under the cursor in the 1462 |quickfix| window. If the symbol can resolve to multiple items, the user 1463 can pick one in the |inputlist()|. 1464 1465 references({context}, {opts}) *vim.lsp.buf.references()* 1466 Lists all the references to the symbol under the cursor in the quickfix 1467 window. 1468 1469 Parameters: ~ 1470 • {context} (`lsp.ReferenceContext?`) Context for the request 1471 • {opts} (`vim.lsp.ListOpts?`) See |vim.lsp.ListOpts|. 1472 1473 See also: ~ 1474 • https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_references 1475 1476 *vim.lsp.buf.remove_workspace_folder()* 1477 remove_workspace_folder({workspace_folder}) 1478 Remove the folder at path from the workspace folders. If {path} is not 1479 provided, the user will be prompted for a path using |input()|. 1480 1481 Parameters: ~ 1482 • {workspace_folder} (`string?`) 1483 1484 rename({new_name}, {opts}) *vim.lsp.buf.rename()* 1485 Renames all references to the symbol under the cursor. 1486 1487 Parameters: ~ 1488 • {new_name} (`string?`) If not provided, the user will be prompted for 1489 a new name using |vim.ui.input()|. 1490 • {opts} (`table?`) Additional options: 1491 • {filter}? (`fun(client: vim.lsp.Client): boolean?`) 1492 Predicate used to filter clients. Receives a client as 1493 argument and must return a boolean. Clients matching the 1494 predicate are included. 1495 • {name}? (`string`) Restrict clients used for rename to 1496 ones where client.name matches this field. 1497 • {bufnr}? (`integer`) (default: current buffer) 1498 1499 *vim.lsp.buf.selection_range()* 1500 selection_range({direction}, {timeout_ms}) 1501 Perform an incremental selection at the cursor position based on ranges 1502 given by the LSP. The `direction` parameter specifies the number of times 1503 to expand the selection. Negative values will shrink the selection. 1504 1505 Parameters: ~ 1506 • {direction} (`integer`) 1507 • {timeout_ms} (`integer?`) (default: `1000`) Maximum time 1508 (milliseconds) to wait for a result. 1509 1510 signature_help({config}) *vim.lsp.buf.signature_help()* 1511 Displays signature information about the symbol under the cursor in a 1512 floating window. Allows cycling through signature overloads with `<C-s>`, 1513 which can be remapped via `<Plug>(nvim.lsp.ctrl-s)` 1514 1515 Example: >lua 1516 vim.keymap.set('n', '<C-b>', '<Plug>(nvim.lsp.ctrl-s)') 1517 < 1518 1519 Parameters: ~ 1520 • {config} (`vim.lsp.buf.signature_help.Opts?`) See 1521 |vim.lsp.buf.signature_help.Opts|. 1522 1523 type_definition({opts}) *vim.lsp.buf.type_definition()* 1524 Jumps to the definition of the type of the symbol under the cursor. 1525 1526 Parameters: ~ 1527 • {opts} (`vim.lsp.LocationOpts?`) See |vim.lsp.LocationOpts|. 1528 1529 typehierarchy({kind}) *vim.lsp.buf.typehierarchy()* 1530 Lists all the subtypes or supertypes of the symbol under the cursor in the 1531 |quickfix| window. If the symbol can resolve to multiple items, the user 1532 can pick one using |vim.ui.select()|. 1533 1534 Parameters: ~ 1535 • {kind} (`"subtypes"|"supertypes"`) 1536 1537 workspace_diagnostics({opts}) *vim.lsp.buf.workspace_diagnostics()* 1538 Request workspace-wide diagnostics. 1539 1540 Parameters: ~ 1541 • {opts} (`table?`) A table with the following fields: 1542 • {client_id}? (`integer`) Only request diagnostics from the 1543 indicated client. If nil, the request is sent to all 1544 clients. 1545 1546 See also: ~ 1547 • https://microsoft.github.io/language-server-protocol/specifications/specification-current/#workspace_dagnostics 1548 1549 workspace_symbol({query}, {opts}) *vim.lsp.buf.workspace_symbol()* 1550 Lists all symbols in the current workspace in the quickfix window. 1551 1552 The list is filtered against {query}; if the argument is omitted from the 1553 call, the user is prompted to enter a string on the command line. An empty 1554 string means no filtering is done. 1555 1556 Parameters: ~ 1557 • {query} (`string?`) optional 1558 • {opts} (`vim.lsp.ListOpts?`) See |vim.lsp.ListOpts|. 1559 1560 1561 ============================================================================== 1562 Lua module: vim.lsp.client *lsp-client* 1563 1564 *vim.lsp.Client* 1565 1566 Fields: ~ 1567 • {attached_buffers} (`table<integer,true>`) 1568 • {capabilities} (`lsp.ClientCapabilities`) Capabilities 1569 provided by the client (editor or tool), at 1570 startup. 1571 • {commands} (`table<string,fun(command: lsp.Command, ctx: table)>`) 1572 Client commands. See |vim.lsp.ClientConfig|. 1573 • {config} (`vim.lsp.ClientConfig`) Copy of the config 1574 passed to |vim.lsp.start()|. See 1575 |vim.lsp.ClientConfig|. 1576 • {dynamic_capabilities} (`lsp.DynamicCapabilities`) Capabilities 1577 provided at runtime (after startup). 1578 • {exit_timeout} (`integer|boolean`, default: `false`) 1579 Milliseconds to wait for server to exit 1580 cleanly after sending the "shutdown" request 1581 before sending kill -15. If set to false, 1582 waits indefinitely. If set to true, nvim will 1583 kill the server immediately. 1584 • {flags} (`table`) Experimental client flags: 1585 • {allow_incremental_sync}? (`boolean`, 1586 default: `true`) Allow using incremental 1587 sync for buffer edits 1588 • {debounce_text_changes}? (`integer`, 1589 default: `150`) Debounce `didChange` 1590 notifications to the server by the given 1591 number in milliseconds. 1592 • {get_language_id} (`fun(bufnr: integer, filetype: string): string`) 1593 See |vim.lsp.ClientConfig|. 1594 • {handlers} (`table<string,lsp.Handler>`) See 1595 |vim.lsp.ClientConfig|. 1596 • {id} (`integer`) The id allocated to the client. 1597 • {initialized} (`true?`) 1598 • {name} (`string`) See |vim.lsp.ClientConfig|. 1599 • {offset_encoding} (`'utf-8'|'utf-16'|'utf-32'`) See 1600 |vim.lsp.ClientConfig|. 1601 • {progress} (`vim.lsp.Client.Progress`) A ring buffer 1602 (|vim.ringbuf()|) containing progress messages 1603 sent by the server. See 1604 |vim.lsp.Client.Progress|. 1605 • {requests} (`table<integer,{ type: string, bufnr: integer, method: string}?>`) 1606 The current pending requests in flight to the 1607 server. Entries are key-value pairs with the 1608 key being the request id while the value is a 1609 table with `type`, `bufnr`, and `method` 1610 key-value pairs. `type` is either "pending" 1611 for an active request, or "cancel" for a 1612 cancel request. It will be "complete" 1613 ephemerally while executing |LspRequest| 1614 autocmds when replies are received from the 1615 server. 1616 • {root_dir} (`string?`) See |vim.lsp.ClientConfig|. 1617 • {rpc} (`vim.lsp.rpc.PublicClient`) RPC client 1618 object, for low level interaction with the 1619 client. See |vim.lsp.rpc.start()|. 1620 • {server_capabilities} (`lsp.ServerCapabilities?`) Response from the 1621 server sent on `initialize` describing the 1622 server's capabilities. 1623 • {server_info} (`lsp.ServerInfo?`) Response from the server 1624 sent on `initialize` describing server 1625 information (e.g. version). 1626 • {settings} (`lsp.LSPObject`) See |vim.lsp.ClientConfig|. 1627 • {workspace_folders} (`lsp.WorkspaceFolder[]?`) See 1628 |vim.lsp.ClientConfig|. 1629 • {request} (`fun(self: vim.lsp.Client, method: string, params: table?, handler: lsp.Handler?, bufnr: integer?): boolean, integer?`) 1630 See |Client:request()|. 1631 • {request_sync} (`fun(self: vim.lsp.Client, method: string, params: table, timeout_ms: integer?, bufnr: integer?): {err: lsp.ResponseError?, result:any}?, string?`) 1632 See |Client:request_sync()|. 1633 • {notify} (`fun(self: vim.lsp.Client, method: string, params: table?): boolean`) 1634 See |Client:notify()|. 1635 • {cancel_request} (`fun(self: vim.lsp.Client, id: integer): boolean`) 1636 See |Client:cancel_request()|. 1637 • {stop} (`fun(self: vim.lsp.Client, force: integer|boolean?)`) 1638 See |Client:stop()|. 1639 • {is_stopped} (`fun(self: vim.lsp.Client): boolean`) See 1640 |Client:is_stopped()|. 1641 • {exec_cmd} (`fun(self: vim.lsp.Client, command: lsp.Command, context: {bufnr?: integer}?, handler: lsp.Handler?)`) 1642 See |Client:exec_cmd()|. 1643 • {on_attach} (`fun(self: vim.lsp.Client, bufnr: integer)`) 1644 See |Client:on_attach()|. 1645 • {supports_method} (`fun(self: vim.lsp.Client, method: string|string, bufnr: integer?): boolean`) 1646 See |Client:supports_method()|. 1647 1648 *vim.lsp.Client.Progress* 1649 Extends: |vim.Ringbuf| 1650 1651 1652 Fields: ~ 1653 • {pending} (`table<lsp.ProgressToken,lsp.LSPAny>`) 1654 1655 *vim.lsp.ClientConfig* 1656 1657 Fields: ~ 1658 • {before_init}? (`fun(params: lsp.InitializeParams, config: vim.lsp.ClientConfig)`) 1659 Callback which can modify parameters before 1660 they are sent to the server. Invoked before LSP 1661 "initialize" phase (after `cmd` is invoked), 1662 where `params` is the parameters being sent to 1663 the server and `config` is the config passed to 1664 |vim.lsp.start()|. 1665 • {capabilities}? (`lsp.ClientCapabilities`) Map overriding the 1666 default capabilities defined by 1667 |vim.lsp.protocol.make_client_capabilities()|, 1668 passed to the language server on 1669 initialization. Hint: use 1670 make_client_capabilities() and modify its 1671 result. 1672 • Note: To send an empty dictionary use 1673 |vim.empty_dict()|, else it will be encoded 1674 as an array. 1675 • {cmd} (`string[]|fun(dispatchers: vim.lsp.rpc.Dispatchers, config: vim.lsp.ClientConfig): vim.lsp.rpc.PublicClient`) 1676 Command `string[]` that launches the language 1677 server (treated as in |jobstart()|, must be 1678 absolute or on `$PATH`, shell constructs like 1679 "~" are not expanded), or function that creates 1680 an RPC client. Function receives a 1681 `dispatchers` table and the resolved `config`, 1682 and must return a table with member functions 1683 `request`, `notify`, `is_closing` and 1684 `terminate`. See |vim.lsp.rpc.request()|, 1685 |vim.lsp.rpc.notify()|. For TCP there is a 1686 builtin RPC client factory: 1687 |vim.lsp.rpc.connect()| 1688 • {cmd_cwd}? (`string`, default: cwd) Directory to launch 1689 the `cmd` process. Not related to `root_dir`. 1690 • {cmd_env}? (`table`) Environment variables passed to the 1691 LSP process on spawn. Non-string values are 1692 coerced to string. Example: >lua 1693 { PORT = 8080; HOST = '0.0.0.0'; } 1694 < 1695 • {commands}? (`table<string,fun(command: lsp.Command, ctx: table)>`) 1696 Map of client-defined commands overriding the 1697 global |vim.lsp.commands|. 1698 • {detached}? (`boolean`, default: `true`) Daemonize the 1699 server process so that it runs in a separate 1700 process group from Nvim. Nvim will shutdown the 1701 process on exit, but if Nvim fails to exit 1702 cleanly this could leave behind orphaned server 1703 processes. 1704 • {exit_timeout}? (`integer|boolean`, default: `false`) 1705 Milliseconds to wait for server to exit cleanly 1706 after sending the "shutdown" request before 1707 sending kill -15. If set to false, waits 1708 indefinitely. If set to true, nvim will kill 1709 the server immediately. 1710 • {flags}? (`table`) Experimental client flags: 1711 • {allow_incremental_sync}? (`boolean`, 1712 default: `true`) Allow using incremental sync 1713 for buffer edits 1714 • {debounce_text_changes}? (`integer`, default: 1715 `150`) Debounce `didChange` notifications to 1716 the server by the given number in 1717 milliseconds. 1718 • {get_language_id}? (`fun(bufnr: integer, filetype: string): string`) 1719 Language ID as string. Defaults to the buffer 1720 filetype. 1721 • {handlers}? (`table<string,function>`) Map of LSP method 1722 names to |lsp-handler|s. 1723 • {init_options}? (`lsp.LSPObject`) Values to pass in the 1724 initialization request as 1725 `initializationOptions`. See `initialize` in 1726 the LSP spec. 1727 • {name}? (`string`, default: client-id) Name in logs and 1728 user messages. 1729 • {offset_encoding}? (`'utf-8'|'utf-16'|'utf-32'`) Called "position 1730 encoding" in LSP spec. The encoding that the 1731 LSP server expects, used for communication. Not 1732 validated. Can be modified in `on_init` before 1733 text is sent to the server. 1734 • {on_attach}? (`elem_or_list<fun(client: vim.lsp.Client, bufnr: integer)>`) 1735 Callback invoked when client attaches to a 1736 buffer. 1737 • {on_error}? (`fun(code: integer, err: string)`) Callback 1738 invoked when the client operation throws an 1739 error. `code` is a number describing the error. 1740 Other arguments may be passed depending on the 1741 error kind. See `vim.lsp.rpc.client_errors` for 1742 possible errors. Use 1743 `vim.lsp.rpc.client_errors[code]` to get 1744 human-friendly name. 1745 • {on_exit}? (`elem_or_list<fun(code: integer, signal: integer, client_id: integer)>`) 1746 Callback invoked on client exit. 1747 • code: exit code of the process 1748 • signal: number describing the signal used to 1749 terminate (if any) 1750 • client_id: client handle 1751 • {on_init}? (`elem_or_list<fun(client: vim.lsp.Client, init_result: lsp.InitializeResult)>`) 1752 Callback invoked after LSP "initialize", where 1753 `result` is a table of `capabilities` and 1754 anything else the server may send. For example, 1755 clangd sends `init_result.offsetEncoding` if 1756 `capabilities.offsetEncoding` was sent to it. 1757 You can only modify the 1758 `client.offset_encoding` here before any 1759 notifications are sent. 1760 • {root_dir}? (`string`) Directory where the LSP server will 1761 base its workspaceFolders, rootUri, and 1762 rootPath on initialization. 1763 • {settings}? (`lsp.LSPObject`) Map of language 1764 server-specific settings, decided by the 1765 client. Sent to the LS if requested via 1766 `workspace/configuration`. Keys are 1767 case-sensitive. 1768 • {trace}? (`'off'|'messages'|'verbose'`, default: "off") 1769 Passed directly to the language server in the 1770 initialize request. Invalid/empty values will 1771 • {workspace_folders}? (`lsp.WorkspaceFolder[]`) List of workspace 1772 folders passed to the language server. For 1773 backwards compatibility rootUri and rootPath 1774 are derived from the first workspace folder in 1775 this list. Can be `null` if the client supports 1776 workspace folders but none are configured. See 1777 `workspaceFolders` in LSP spec. 1778 • {workspace_required}? (`boolean`, default: `false`) Server requires a 1779 workspace (no "single file" support). Note: 1780 Without a workspace, cross-file features 1781 (navigation, hover) may or may not work 1782 depending on the language server, even if the 1783 server doesn't require a workspace. 1784 1785 1786 Client:cancel_request({id}) *Client:cancel_request()* 1787 Cancels a request with a given request id. 1788 1789 Parameters: ~ 1790 • {id} (`integer`) id of request to cancel 1791 1792 Return: ~ 1793 (`boolean`) status indicating if the notification was successful. 1794 1795 See also: ~ 1796 • |Client:notify()| 1797 1798 Client:exec_cmd({command}, {context}, {handler}) *Client:exec_cmd()* 1799 Execute a lsp command, either via client command function (if available) 1800 or via workspace/executeCommand (if supported by the server) 1801 1802 Parameters: ~ 1803 • {command} (`lsp.Command`) 1804 • {context} (`{bufnr?: integer}?`) 1805 • {handler} (`lsp.Handler?`) only called if a server command 1806 1807 Client:is_stopped() *Client:is_stopped()* 1808 Checks whether a client is stopped. 1809 1810 Return: ~ 1811 (`boolean`) true if client is stopped or in the process of being 1812 stopped; false otherwise 1813 1814 Client:notify({method}, {params}) *Client:notify()* 1815 Sends a notification to an LSP server. 1816 1817 Parameters: ~ 1818 • {method} (`string`) LSP method name. 1819 • {params} (`table?`) LSP request params. 1820 1821 Return: ~ 1822 (`boolean`) status indicating if the notification was successful. If 1823 it is false, then the client has shutdown. 1824 1825 Client:on_attach({bufnr}) *Client:on_attach()* 1826 Runs the on_attach function from the client's config if it was defined. 1827 Useful for buffer-local setup. 1828 1829 Parameters: ~ 1830 • {bufnr} (`integer`) Buffer number 1831 1832 *Client:request()* 1833 Client:request({method}, {params}, {handler}, {bufnr}) 1834 Sends a request to the server. 1835 1836 This is a thin wrapper around {client.rpc.request} with some additional 1837 checks for capabilities and handler availability. 1838 1839 Parameters: ~ 1840 • {method} (`string`) LSP method name. 1841 • {params} (`table?`) LSP request params. 1842 • {handler} (`lsp.Handler?`) Response |lsp-handler| for this method. 1843 • {bufnr} (`integer?`) (default: 0) Buffer handle, or 0 for current. 1844 1845 Return (multiple): ~ 1846 (`boolean`) status indicates whether the request was successful. If it 1847 is `false`, then it will always be `false` (the client has shutdown). 1848 (`integer?`) request_id Can be used with |Client:cancel_request()|. 1849 `nil` is request failed. 1850 1851 See also: ~ 1852 • |vim.lsp.buf_request_all()| 1853 1854 *Client:request_sync()* 1855 Client:request_sync({method}, {params}, {timeout_ms}, {bufnr}) 1856 Sends a request to the server and synchronously waits for the response. 1857 1858 This is a wrapper around |Client:request()| 1859 1860 Parameters: ~ 1861 • {method} (`string`) LSP method name. 1862 • {params} (`table`) LSP request params. 1863 • {timeout_ms} (`integer?`) Maximum time in milliseconds to wait for a 1864 result. Defaults to 1000 1865 • {bufnr} (`integer?`) (default: 0) Buffer handle, or 0 for 1866 current. 1867 1868 Return (multiple): ~ 1869 (`{err: lsp.ResponseError?, result:any}?`) `result` and `err` from the 1870 |lsp-handler|. `nil` is the request was unsuccessful 1871 (`string?`) err On timeout, cancel or error, where `err` is a string 1872 describing the failure reason. 1873 1874 See also: ~ 1875 • |vim.lsp.buf_request_sync()| 1876 1877 Client:stop({force}) *Client:stop()* 1878 Stops a client, optionally with force after a timeout. 1879 1880 By default, it will request the server to shutdown, then force a shutdown 1881 if the server has not exited after `self.exit_timeout` milliseconds. If 1882 you request to stop a client which has previously been requested to 1883 shutdown, it will automatically escalate and force shutdown immediately, 1884 regardless of the value of `force` (or `self.exit_timeout` if `nil`). 1885 1886 Note: Forcing shutdown while a server is busy writing out project or index 1887 files can lead to file corruption. 1888 1889 Parameters: ~ 1890 • {force} (`integer|boolean?`, default: `self.exit_timeout`) Time in 1891 milliseconds to wait before forcing a shutdown. If false, 1892 only request the server to shutdown, but don't force it. If 1893 true, force a shutdown immediately. 1894 1895 Client:supports_method({method}, {bufnr}) *Client:supports_method()* 1896 Checks if a client supports a given method. Always returns true for 1897 unknown off-spec methods. 1898 1899 Note: Some language server capabilities can be file specific. 1900 1901 Parameters: ~ 1902 • {method} (`string|string`) 1903 • {bufnr} (`integer?`) 1904 1905 Return: ~ 1906 (`boolean`) 1907 1908 1909 ============================================================================== 1910 Lua module: vim.lsp.codelens *lsp-codelens* 1911 1912 enable({enable}, {filter}) *vim.lsp.codelens.enable()* 1913 Enables or disables code lens for the {filter}ed scope. 1914 1915 To "toggle", pass the inverse of `is_enabled()`: >lua 1916 vim.lsp.codelens.enable(not vim.lsp.codelens.is_enabled()) 1917 < 1918 1919 To run a code lens, see |vim.lsp.codelens.run()|. 1920 1921 Parameters: ~ 1922 • {enable} (`boolean?`) true/nil to enable, false to disable 1923 • {filter} (`table?`) Optional filters |kwargs|, 1924 • {bufnr}? (`integer`, default: all) Buffer number, or 0 for 1925 current buffer, or nil for all. 1926 • {client_id}? (`integer`, default: all) Client ID, or nil 1927 for all. 1928 1929 get({filter}) *vim.lsp.codelens.get()* 1930 Get all code lenses in the {filter}ed scope. 1931 1932 Parameters: ~ 1933 • {filter} (`table?`) Optional filters |kwargs|: 1934 • {bufnr}? (`integer`, default: 0) Buffer handle, or 0 for 1935 current. 1936 • {client_id}? (`integer`, default: all) Client ID, or nil 1937 for all. 1938 1939 Return: ~ 1940 (`table[]`) A list of objects with the following fields: 1941 • {client_id} (`integer`) 1942 • {lens} (`lsp.CodeLens`) 1943 1944 is_enabled({filter}) *vim.lsp.codelens.is_enabled()* 1945 Query whether code lens is enabled in the {filter}ed scope 1946 1947 Parameters: ~ 1948 • {filter} (`table?`) Optional filters |kwargs|, 1949 • {bufnr}? (`integer`, default: all) Buffer number, or 0 for 1950 current buffer, or nil for all. 1951 • {client_id}? (`integer`, default: all) Client ID, or nil 1952 for all. 1953 1954 Return: ~ 1955 (`boolean`) whether code lens is enabled. 1956 1957 run({opts}) *vim.lsp.codelens.run()* 1958 Run code lens at the current cursor position. 1959 1960 Parameters: ~ 1961 • {opts} (`table?`) Optional parameters |kwargs|: 1962 • {client_id}? (`integer`, default: all) Client ID, or nil for 1963 all. 1964 1965 1966 ============================================================================== 1967 Lua module: vim.lsp.completion *lsp-completion* 1968 1969 The `vim.lsp.completion` module enables insert-mode completion driven by an 1970 LSP server. Call `enable()` to make it available through Nvim builtin 1971 completion (via the |CompleteDone| event). Specify `autotrigger=true` to 1972 activate "auto-completion" when you type any of the server-defined 1973 `triggerCharacters`. Use CTRL-Y to select an item from the completion menu. 1974 |complete_CTRL-Y| 1975 1976 Example: activate LSP-driven auto-completion: >lua 1977 -- Works best with completeopt=noselect. 1978 -- Use CTRL-Y to select an item. |complete_CTRL-Y| 1979 vim.cmd[[set completeopt+=menuone,noselect,popup]] 1980 vim.lsp.start({ 1981 name = 'ts_ls', 1982 cmd = …, 1983 on_attach = function(client, bufnr) 1984 vim.lsp.completion.enable(true, client.id, bufnr, { 1985 autotrigger = true, 1986 convert = function(item) 1987 return { abbr = item.label:gsub('%b()', '') } 1988 end, 1989 }) 1990 end, 1991 }) 1992 < 1993 1994 *lsp-autocompletion* 1995 1996 The LSP `triggerCharacters` field decides when to trigger autocompletion. If 1997 you want to trigger on EVERY keypress you can either: 1998 • Extend `client.server_capabilities.completionProvider.triggerCharacters` on 1999 `LspAttach`, before you call 2000 `vim.lsp.completion.enable(… {autotrigger=true})`. See the |lsp-attach| 2001 example. 2002 • Call `vim.lsp.completion.get()` from an |InsertCharPre| autocommand. 2003 2004 2005 *vim.lsp.completion.enable()* 2006 enable({enable}, {client_id}, {bufnr}, {opts}) 2007 Enables or disables completions from the given language client in the 2008 given buffer. Effects of enabling completions are: 2009 • Calling |vim.lsp.completion.get()| uses the enabled clients to retrieve 2010 completion candidates 2011 • Accepting a completion candidate using `<c-y>` applies side effects like 2012 expanding snippets, text edits (e.g. insert import statements) and 2013 executing associated commands. This works for completions triggered via 2014 autotrigger, omnifunc or completion.get() 2015 2016 Example: |lsp-attach| |lsp-completion| 2017 2018 Note: the behavior of `autotrigger=true` is controlled by the LSP 2019 `triggerCharacters` field. You can override it on LspAttach, see 2020 |lsp-autocompletion|. 2021 2022 Parameters: ~ 2023 • {enable} (`boolean`) True to enable, false to disable 2024 • {client_id} (`integer`) Client ID 2025 • {bufnr} (`integer`) Buffer handle, or 0 for the current buffer 2026 • {opts} (`table?`) A table with the following fields: 2027 • {autotrigger}? (`boolean`) (default: false) When true, 2028 completion triggers automatically based on the server's 2029 `triggerCharacters`. 2030 • {convert}? (`fun(item: lsp.CompletionItem): table`) 2031 Transforms an LSP CompletionItem to |complete-items|. 2032 • {cmp}? (`fun(a: table, b: table): boolean`) Comparator 2033 for sorting merged completion items from all servers. 2034 2035 get({opts}) *vim.lsp.completion.get()* 2036 Triggers LSP completion once in the current buffer, if LSP completion is 2037 enabled (see |lsp-attach| |lsp-completion|). 2038 2039 Used by the default LSP |omnicompletion| provider |vim.lsp.omnifunc()|, 2040 thus |i_CTRL-X_CTRL-O| invokes this in LSP-enabled buffers. Use CTRL-Y to 2041 select an item from the completion menu. |complete_CTRL-Y| 2042 2043 To invoke manually with CTRL-space, use this mapping: >lua 2044 -- Use CTRL-space to trigger LSP completion. 2045 -- Use CTRL-Y to select an item. |complete_CTRL-Y| 2046 vim.keymap.set('i', '<c-space>', function() 2047 vim.lsp.completion.get() 2048 end) 2049 < 2050 2051 Parameters: ~ 2052 • {opts} (`table?`) A table with the following fields: 2053 • {ctx}? (`lsp.CompletionContext`) Completion context. 2054 Defaults to a trigger kind of `invoked`. 2055 2056 2057 ============================================================================== 2058 Lua module: vim.lsp.diagnostic *lsp-diagnostic* 2059 2060 This module provides functionality for requesting LSP diagnostics for a 2061 document/workspace and populating them using |vim.Diagnostic|s. 2062 `DiagnosticRelatedInformation` is supported: it is included in the window 2063 shown by |vim.diagnostic.open_float()|. When the cursor is on a line with 2064 related information, |gf| jumps to the problem location. 2065 2066 2067 from({diagnostics}) *vim.lsp.diagnostic.from()* 2068 Converts the input `vim.Diagnostic`s to LSP diagnostics. 2069 2070 Parameters: ~ 2071 • {diagnostics} (`vim.Diagnostic[]`) 2072 2073 Return: ~ 2074 (`lsp.Diagnostic[]`) 2075 2076 *vim.lsp.diagnostic.get_namespace()* 2077 get_namespace({client_id}, {pull_id}) 2078 Get the diagnostic namespace associated with an LSP client 2079 |vim.diagnostic| for diagnostics 2080 2081 Parameters: ~ 2082 • {client_id} (`integer`) The id of the LSP client 2083 • {pull_id} (`(boolean|string)?`) (default: nil) Pull diagnostics 2084 provider id (indicates "pull" client), or `nil` for a 2085 "push" client. 2086 2087 *vim.lsp.diagnostic.on_diagnostic()* 2088 on_diagnostic({error}, {result}, {ctx}) 2089 |lsp-handler| for the method "textDocument/diagnostic" 2090 2091 See |vim.diagnostic.config()| for configuration options. 2092 2093 Parameters: ~ 2094 • {error} (`lsp.ResponseError?`) 2095 • {result} (`lsp.DocumentDiagnosticReport`) 2096 • {ctx} (`lsp.HandlerContext`) 2097 2098 *vim.lsp.diagnostic.on_publish_diagnostics()* 2099 on_publish_diagnostics({_}, {params}, {ctx}) 2100 |lsp-handler| for the method "textDocument/publishDiagnostics" 2101 2102 See |vim.diagnostic.config()| for configuration options. 2103 2104 Parameters: ~ 2105 • {params} (`lsp.PublishDiagnosticsParams`) 2106 • {ctx} (`lsp.HandlerContext`) 2107 2108 2109 ============================================================================== 2110 Lua module: vim.lsp.document_color *lsp-document_color* 2111 2112 This module provides LSP support for highlighting color references in a 2113 document. Highlighting is enabled by default. 2114 2115 2116 color_presentation() *vim.lsp.document_color.color_presentation()* 2117 Select from a list of presentations for the color under the cursor. 2118 2119 enable({enable}, {bufnr}, {opts}) *vim.lsp.document_color.enable()* 2120 Enables document highlighting from the given language client in the given 2121 buffer. 2122 2123 To "toggle", pass the inverse of `is_enabled()`: >lua 2124 vim.lsp.document_color.enable(not vim.lsp.document_color.is_enabled()) 2125 < 2126 2127 Parameters: ~ 2128 • {enable} (`boolean?`) True to enable, false to disable. (default: 2129 `true`) 2130 • {bufnr} (`integer?`) Buffer handle, or 0 for current. (default: 0) 2131 • {opts} (`table?`) A table with the following fields: 2132 • {style}? 2133 (`'background'|'foreground'|'virtual'|string|fun(bufnr: integer, range: Range4, hex_code: string)`) 2134 Highlight style. It can be one of the pre-defined styles, 2135 a string to be used as virtual text, or a function that 2136 receives the buffer handle, the range (start line, start 2137 col, end line, end col) and the resolved hex color. 2138 (default: `'background'`) 2139 2140 is_enabled({bufnr}) *vim.lsp.document_color.is_enabled()* 2141 Query whether document colors are enabled in the given buffer. 2142 2143 Parameters: ~ 2144 • {bufnr} (`integer?`) Buffer handle, or 0 for current. (default: 0) 2145 2146 Return: ~ 2147 (`boolean`) 2148 2149 2150 ============================================================================== 2151 Lua module: vim.lsp.inlay_hint *lsp-inlay_hint* 2152 2153 enable({enable}, {filter}) *vim.lsp.inlay_hint.enable()* 2154 Enables or disables inlay hints for the {filter}ed scope. 2155 2156 To "toggle", pass the inverse of `is_enabled()`: >lua 2157 vim.lsp.inlay_hint.enable(not vim.lsp.inlay_hint.is_enabled()) 2158 < 2159 2160 Attributes: ~ 2161 Since: 0.10.0 2162 2163 Parameters: ~ 2164 • {enable} (`boolean?`) true/nil to enable, false to disable 2165 • {filter} (`table?`) Optional filters |kwargs|, or `nil` for all. 2166 • {bufnr} (`integer?`) Buffer number, or 0 for current 2167 buffer, or nil for all. 2168 2169 get({filter}) *vim.lsp.inlay_hint.get()* 2170 Get the list of inlay hints, (optionally) restricted by buffer or range. 2171 2172 Example usage: >lua 2173 local hint = vim.lsp.inlay_hint.get({ bufnr = 0 })[1] -- 0 for current buffer 2174 2175 local client = vim.lsp.get_client_by_id(hint.client_id) 2176 local resp = client:request_sync('inlayHint/resolve', hint.inlay_hint, 100, 0) 2177 local resolved_hint = assert(resp and resp.result, resp.err) 2178 vim.lsp.util.apply_text_edits(resolved_hint.textEdits, 0, client.encoding) 2179 2180 location = resolved_hint.label[1].location 2181 client:request('textDocument/hover', { 2182 textDocument = { uri = location.uri }, 2183 position = location.range.start, 2184 }) 2185 < 2186 2187 Attributes: ~ 2188 Since: 0.10.0 2189 2190 Parameters: ~ 2191 • {filter} (`table?`) Optional filters |kwargs|: 2192 • {bufnr} (`integer?`) 2193 • {range} (`lsp.Range?`) 2194 2195 Return: ~ 2196 (`table[]`) A list of objects with the following fields: 2197 • {bufnr} (`integer`) 2198 • {client_id} (`integer`) 2199 • {inlay_hint} (`lsp.InlayHint`) 2200 2201 is_enabled({filter}) *vim.lsp.inlay_hint.is_enabled()* 2202 Query whether inlay hint is enabled in the {filter}ed scope 2203 2204 Attributes: ~ 2205 Since: 0.10.0 2206 2207 Parameters: ~ 2208 • {filter} (`table?`) Optional filters |kwargs|, or `nil` for all. 2209 • {bufnr} (`integer?`) Buffer number, or 0 for current 2210 buffer, or nil for all. 2211 2212 Return: ~ 2213 (`boolean`) 2214 2215 2216 ============================================================================== 2217 Lua module: vim.lsp.inline_completion *lsp-inline_completion* 2218 2219 This module provides the LSP "inline completion" feature, for completing 2220 multiline text (e.g., whole methods) instead of just a word or line, which may 2221 result in "syntactically or semantically incorrect" code. Unlike regular 2222 completion, this is typically presented as overlay text instead of a menu of 2223 completion candidates. 2224 2225 LSP spec: 2226 https://microsoft.github.io/language-server-protocol/specifications/lsp/3.18/specification/#textDocument_inlineCompletion 2227 2228 To try it out, here is a quickstart example using Copilot: *lsp-copilot* 2229 1. Install Copilot: >sh 2230 npm install --global @github/copilot-language-server 2231 < 2232 2233 2. Define a config, (or copy `lsp/copilot.lua` from 2234 https://github.com/neovim/nvim-lspconfig): >lua 2235 vim.lsp.config('copilot', { 2236 cmd = { 'copilot-language-server', '--stdio', }, 2237 root_markers = { '.git' }, 2238 }) 2239 < 2240 2241 3. Activate the config: >lua 2242 vim.lsp.enable('copilot') 2243 < 2244 2245 4. Sign in to Copilot, or use the `:LspCopilotSignIn` command from 2246 https://github.com/neovim/nvim-lspconfig 2247 2248 5. Enable inline completion: >lua 2249 vim.lsp.inline_completion.enable() 2250 < 2251 2252 6. Set a keymap for `vim.lsp.inline_completion.get()` and invoke the keymap. 2253 2254 2255 *vim.lsp.inline_completion.Item* 2256 2257 Fields: ~ 2258 • {client_id} (`integer`) Client ID 2259 • {insert_text} (`string|lsp.StringValue`) The text to be inserted, can 2260 be a snippet. 2261 • {range}? (`vim.Range`) Which range it be applied. 2262 • {command}? (`lsp.Command`) Corresponding server command. 2263 2264 2265 enable({enable}, {filter}) *vim.lsp.inline_completion.enable()* 2266 Enables or disables inline completion for the {filter}ed scope, inline 2267 completion will automatically be refreshed when you are in insert mode. 2268 2269 To "toggle", pass the inverse of `is_enabled()`: >lua 2270 vim.lsp.inline_completion.enable(not vim.lsp.inline_completion.is_enabled()) 2271 < 2272 2273 Parameters: ~ 2274 • {enable} (`boolean?`) true/nil to enable, false to disable 2275 • {filter} (`table?`) Optional filters |kwargs|, 2276 • {bufnr}? (`integer`, default: all) Buffer number, or 0 for 2277 current buffer, or nil for all. 2278 • {client_id}? (`integer`, default: all) Client ID, or nil 2279 for all. 2280 2281 get({opts}) *vim.lsp.inline_completion.get()* 2282 Accept the currently displayed completion candidate to the buffer. 2283 2284 It returns false when no candidate can be accepted, so you can use the 2285 return value to implement a fallback: >lua 2286 vim.keymap.set('i', '<Tab>', function() 2287 if not vim.lsp.inline_completion.get() then 2288 return '<Tab>' 2289 end 2290 end, { expr = true, desc = 'Accept the current inline completion' }) 2291 < 2292 2293 Parameters: ~ 2294 • {opts} (`table?`) A table with the following fields: 2295 • {bufnr}? (`integer`, default: 0) Buffer handle, or 0 for 2296 current. 2297 • {on_accept}? 2298 (`fun(item: vim.lsp.inline_completion.Item): vim.lsp.inline_completion.Item?`) 2299 A callback triggered when a completion item is accepted. You 2300 can use it to modify the completion item that is about to be 2301 accepted and return it to apply the changes, or return `nil` 2302 to prevent the changes from being applied to the buffer so 2303 you can implement custom behavior. 2304 2305 Return: ~ 2306 (`boolean`) `true` if a completion was applied, else `false`. 2307 2308 is_enabled({filter}) *vim.lsp.inline_completion.is_enabled()* 2309 Query whether inline completion is enabled in the {filter}ed scope 2310 2311 Parameters: ~ 2312 • {filter} (`table?`) Optional filters |kwargs|, 2313 • {bufnr}? (`integer`, default: all) Buffer number, or 0 for 2314 current buffer, or nil for all. 2315 • {client_id}? (`integer`, default: all) Client ID, or nil 2316 for all. 2317 2318 select({opts}) *vim.lsp.inline_completion.select()* 2319 Switch between available inline completion candidates. 2320 2321 Parameters: ~ 2322 • {opts} (`table?`) A table with the following fields: 2323 • {bufnr}? (`integer`) (default: current buffer) 2324 • {count}? (`integer`, default: v:count1) The number of 2325 candidates to move by. A positive integer moves forward by 2326 {count} candidates, while a negative integer moves backward 2327 by {count} candidates. 2328 • {wrap}? (`boolean`, default: `true`) Whether to loop around 2329 file or not. Similar to 'wrapscan'. 2330 2331 2332 ============================================================================== 2333 Lua module: vim.lsp.linked_editing_range *lsp-linked_editing_range* 2334 2335 The `vim.lsp.linked_editing_range` module enables "linked editing" via a 2336 language server's `textDocument/linkedEditingRange` request. Linked editing 2337 ranges are synchronized text regions, meaning changes in one range are 2338 mirrored in all the others. This is helpful in HTML files for example, where 2339 the language server can update the text of a closing tag if its opening tag 2340 was changed. 2341 2342 LSP spec: 2343 https://microsoft.github.io/language-server-protocol/specification/#textDocument_linkedEditingRange 2344 2345 2346 enable({enable}, {filter}) *vim.lsp.linked_editing_range.enable()* 2347 Enable or disable a linked editing session globally or for a specific 2348 client. The following is a practical usage example: >lua 2349 vim.lsp.start({ 2350 name = 'html', 2351 cmd = '…', 2352 on_attach = function(client) 2353 vim.lsp.linked_editing_range.enable(true, { client_id = client.id }) 2354 end, 2355 }) 2356 < 2357 2358 Parameters: ~ 2359 • {enable} (`boolean?`) `true` or `nil` to enable, `false` to disable. 2360 • {filter} (`table?`) Optional filters |kwargs|: 2361 • {client_id} (`integer?`) Client ID, or `nil` for all. 2362 2363 2364 ============================================================================== 2365 Lua module: vim.lsp.log *lsp-log* 2366 2367 The `vim.lsp.log` module provides logging for the Nvim LSP client. 2368 2369 When debugging language servers, it is helpful to enable extra-verbose logging 2370 of the LSP client RPC events. Example: >lua 2371 vim.lsp.log.set_level 'trace' 2372 require('vim.lsp.log').set_format_func(vim.inspect) 2373 < 2374 2375 Then try to run the language server, and open the log with: >vim 2376 :lua vim.cmd('tabnew ' .. vim.lsp.log.get_filename()) 2377 < 2378 2379 (Or use `:LspLog` if you have nvim-lspconfig installed.) 2380 2381 Note: 2382 • Remember to DISABLE verbose logging ("debug" or "trace" level), else you may 2383 encounter performance issues. 2384 • "ERROR" messages containing "stderr" only indicate that the log was sent to 2385 stderr. Many servers send harmless messages via stderr. 2386 2387 2388 get_filename() *vim.lsp.log.get_filename()* 2389 Returns the log filename. 2390 2391 Return: ~ 2392 (`string`) log filename 2393 2394 get_level() *vim.lsp.log.get_level()* 2395 Gets the current log level. 2396 2397 Return: ~ 2398 (`integer`) current log level 2399 2400 set_format_func({handle}) *vim.lsp.log.set_format_func()* 2401 Sets the formatting function used to format logs. If the formatting 2402 function returns nil, the entry won't be written to the log file. 2403 2404 Parameters: ~ 2405 • {handle} (`fun(level:string, ...): string?`) Function to apply to log 2406 entries. The default will log the level, date, source and 2407 line number of the caller, followed by the arguments. 2408 2409 set_level({level}) *vim.lsp.log.set_level()* 2410 Sets the current log level. 2411 2412 Parameters: ~ 2413 • {level} (`string|integer`) One of |vim.log.levels| 2414 2415 2416 ============================================================================== 2417 Lua module: vim.lsp.on_type_formatting *lsp-on_type_formatting* 2418 2419 enable({enable}, {filter}) *vim.lsp.on_type_formatting.enable()* 2420 Enables/disables on-type formatting globally or for the {filter}ed scope. 2421 The following are some practical usage examples: >lua 2422 -- Enable for all clients 2423 vim.lsp.on_type_formatting.enable() 2424 2425 -- Enable for a specific client 2426 vim.api.nvim_create_autocmd('LspAttach', { 2427 callback = function(args) 2428 local client_id = args.data.client_id 2429 local client = assert(vim.lsp.get_client_by_id(client_id)) 2430 if client.name == 'rust-analyzer' then 2431 vim.lsp.on_type_formatting.enable(true, { client_id = client_id }) 2432 end 2433 end, 2434 }) 2435 < 2436 2437 Parameters: ~ 2438 • {enable} (`boolean?`) true/nil to enable, false to disable. 2439 • {filter} (`table?`) Optional filters |kwargs|: 2440 • {client_id} (`integer?`) Client ID, or `nil` for all. 2441 2442 2443 ============================================================================== 2444 Lua module: vim.lsp.rpc *lsp-rpc* 2445 2446 *vim.lsp.rpc.PublicClient* 2447 Client RPC object 2448 2449 Fields: ~ 2450 • {request} (`fun(method: string, params: table?, callback: fun(err?: lsp.ResponseError, result: any, request_id: integer), notify_reply_callback?: fun(message_id: integer)):boolean,integer?`) 2451 See |vim.lsp.rpc.request()| 2452 • {notify} (`fun(method: string, params: any): boolean`) See 2453 |vim.lsp.rpc.notify()| 2454 • {is_closing} (`fun(): boolean`) Indicates if the RPC is closing. 2455 • {terminate} (`fun()`) Terminates the RPC client. 2456 2457 2458 connect({host_or_path}, {port}) *vim.lsp.rpc.connect()* 2459 Create a LSP RPC client factory that connects to either: 2460 • a named pipe (windows) 2461 • a domain socket (unix) 2462 • a host and port via TCP 2463 2464 Return a function that can be passed to the `cmd` field for 2465 |vim.lsp.start()|. 2466 2467 Parameters: ~ 2468 • {host_or_path} (`string`) host to connect to or path to a pipe/domain 2469 socket 2470 • {port} (`integer?`) TCP port to connect to. If absent the 2471 first argument must be a pipe 2472 2473 Return: ~ 2474 (`fun(dispatchers: vim.lsp.rpc.Dispatchers): vim.lsp.rpc.PublicClient`) 2475 2476 format_rpc_error({err}) *vim.lsp.rpc.format_rpc_error()* 2477 Constructs an error message from an LSP error object. 2478 2479 Parameters: ~ 2480 • {err} (`table`) The error object 2481 2482 Return: ~ 2483 (`string`) error_message The formatted error message 2484 2485 notify({method}, {params}) *vim.lsp.rpc.notify()* 2486 Sends a notification to the LSP server. 2487 2488 Parameters: ~ 2489 • {method} (`string`) The invoked LSP method 2490 • {params} (`table?`) Parameters for the invoked LSP method 2491 2492 Return: ~ 2493 (`boolean`) `true` if notification could be sent, `false` if not 2494 2495 *vim.lsp.rpc.request()* 2496 request({method}, {params}, {callback}, {notify_reply_callback}) 2497 Sends a request to the LSP server and runs {callback} upon response. 2498 2499 Parameters: ~ 2500 • {method} (`string`) The invoked LSP method 2501 • {params} (`table?`) Parameters for the invoked LSP 2502 method 2503 • {callback} (`fun(err: lsp.ResponseError?, result: any)`) 2504 Callback to invoke 2505 • {notify_reply_callback} (`fun(message_id: integer)?`) Callback to 2506 invoke as soon as a request is no longer 2507 pending 2508 2509 Return (multiple): ~ 2510 (`boolean`) success `true` if request could be sent, `false` if not 2511 (`integer?`) message_id if request could be sent, `nil` if not 2512 2513 *vim.lsp.rpc.rpc_response_error()* 2514 rpc_response_error({code}, {message}, {data}) 2515 Creates an RPC response table `error` to be sent to the LSP response. 2516 2517 Parameters: ~ 2518 • {code} (`integer`) RPC error code defined, see 2519 `vim.lsp.protocol.ErrorCodes` 2520 • {message} (`string?`) arbitrary message to send to server 2521 • {data} (`any?`) arbitrary data to send to server 2522 2523 Return: ~ 2524 (`lsp.ResponseError`) 2525 2526 See also: ~ 2527 • lsp.ErrorCodes See `vim.lsp.protocol.ErrorCodes` 2528 2529 start({cmd}, {dispatchers}, {extra_spawn_params}) *vim.lsp.rpc.start()* 2530 Starts an LSP server process and create an LSP RPC client object to 2531 interact with it. Communication with the spawned process happens via 2532 stdio. For communication via TCP, spawn a process manually and use 2533 |vim.lsp.rpc.connect()| 2534 2535 Parameters: ~ 2536 • {cmd} (`string[]`) Command to start the LSP server. 2537 • {dispatchers} (`table?`) Dispatchers for LSP message types. 2538 • {notification} 2539 (`fun(method: string, params: table)`) 2540 • {server_request} 2541 (`fun(method: string, params: table): any?, lsp.ResponseError?`) 2542 • {on_exit} 2543 (`fun(code: integer, signal: integer)`) 2544 • {on_error} (`fun(code: integer, err: any)`) 2545 • {extra_spawn_params} (`table?`) Additional context for the LSP server 2546 process. 2547 • {cwd}? (`string`) Working directory for the 2548 LSP server process 2549 • {detached}? (`boolean`) Detach the LSP server 2550 process from the current process 2551 • {env}? (`table<string,string>`) Additional 2552 environment variables for LSP server process. 2553 See |vim.system()| 2554 2555 Return: ~ 2556 (`vim.lsp.rpc.PublicClient`) See |vim.lsp.rpc.PublicClient|. 2557 2558 2559 ============================================================================== 2560 Lua module: vim.lsp.semantic_tokens *lsp-semantic_tokens* 2561 2562 enable({enable}, {filter}) *vim.lsp.semantic_tokens.enable()* 2563 Enables or disables semantic tokens for the {filter}ed scope. 2564 2565 To "toggle", pass the inverse of `is_enabled()`: >lua 2566 vim.lsp.semantic_tokens.enable(not vim.lsp.semantic_tokens.is_enabled()) 2567 < 2568 2569 Parameters: ~ 2570 • {enable} (`boolean?`) true/nil to enable, false to disable 2571 • {filter} (`table?`) Optional filters |kwargs|, 2572 • {bufnr}? (`integer`, default: all) Buffer number, or 0 for 2573 current buffer, or nil for all. 2574 • {client_id}? (`integer`, default: all) Client ID, or nil 2575 for all. 2576 2577 force_refresh({bufnr}) *vim.lsp.semantic_tokens.force_refresh()* 2578 Force a refresh of all semantic tokens 2579 2580 Only has an effect if the buffer is currently active for semantic token 2581 highlighting (|vim.lsp.semantic_tokens.enable()| has been called for it) 2582 2583 Parameters: ~ 2584 • {bufnr} (`integer?`) filter by buffer. All buffers if nil, current 2585 buffer if 0 2586 2587 *vim.lsp.semantic_tokens.get_at_pos()* 2588 get_at_pos({bufnr}, {row}, {col}) 2589 Return the semantic token(s) at the given position. If called without 2590 arguments, returns the token under the cursor. 2591 2592 Parameters: ~ 2593 • {bufnr} (`integer?`) Buffer number (0 for current buffer, default) 2594 • {row} (`integer?`) Position row (default cursor position) 2595 • {col} (`integer?`) Position column (default cursor position) 2596 2597 Return: ~ 2598 (`table?`) List of tokens at position. Each token has the following 2599 fields: 2600 • line (integer) line number, 0-based 2601 • start_col (integer) start column, 0-based 2602 • end_line (integer) end line number, 0-based 2603 • end_col (integer) end column, 0-based 2604 • type (string) token type as string, e.g. "variable" 2605 • modifiers (table) token modifiers as a set. E.g., { static = true, 2606 readonly = true } 2607 • client_id (integer) 2608 2609 *vim.lsp.semantic_tokens.highlight_token()* 2610 highlight_token({token}, {bufnr}, {client_id}, {hl_group}, {opts}) 2611 Highlight a semantic token. 2612 2613 Apply an extmark with a given highlight group for a semantic token. The 2614 mark will be deleted by the semantic token engine when appropriate; for 2615 example, when the LSP sends updated tokens. This function is intended for 2616 use inside |LspTokenUpdate| callbacks. 2617 2618 Parameters: ~ 2619 • {token} (`table`) A semantic token, found as `args.data.token` in 2620 |LspTokenUpdate| 2621 • {bufnr} (`integer`) The buffer to highlight, or `0` for current 2622 buffer 2623 • {client_id} (`integer`) The ID of the |vim.lsp.Client| 2624 • {hl_group} (`string`) Highlight group name 2625 • {opts} (`table?`) Optional parameters: 2626 • {priority}? (`integer`, default: 2627 `vim.hl.priorities.semantic_tokens + 3`) Priority for 2628 the applied extmark. 2629 2630 is_enabled({filter}) *vim.lsp.semantic_tokens.is_enabled()* 2631 Query whether semantic tokens is enabled in the {filter}ed scope 2632 2633 Parameters: ~ 2634 • {filter} (`table?`) Optional filters |kwargs|, 2635 • {bufnr}? (`integer`, default: all) Buffer number, or 0 for 2636 current buffer, or nil for all. 2637 • {client_id}? (`integer`, default: all) Client ID, or nil 2638 for all. 2639 2640 2641 ============================================================================== 2642 Lua module: vim.lsp.util *lsp-util* 2643 2644 *vim.lsp.util.open_floating_preview.Opts* 2645 2646 Fields: ~ 2647 • {height}? (`integer`) Height of floating window 2648 • {width}? (`integer`) Width of floating window 2649 • {wrap}? (`boolean`, default: `true`) Wrap long lines 2650 • {wrap_at}? (`integer`) Character to wrap at for computing height 2651 when wrap is enabled 2652 • {max_width}? (`integer`) Maximal width of floating window 2653 • {max_height}? (`integer`) Maximal height of floating window 2654 • {focus_id}? (`string`) If a popup with this id is opened, then 2655 focus it 2656 • {close_events}? (`table`) List of events that closes the floating 2657 window 2658 • {focusable}? (`boolean`, default: `true`) Make float focusable. 2659 • {focus}? (`boolean`, default: `true`) If `true`, and if 2660 {focusable} is also `true`, focus an existing 2661 floating window with the same {focus_id} 2662 • {offset_x}? (`integer`) offset to add to `col` 2663 • {offset_y}? (`integer`) offset to add to `row` 2664 • {border}? (`string|(string|[string,string])[]`) override 2665 `border` 2666 • {zindex}? (`integer`) override `zindex`, defaults to 50 2667 • {title}? (`string|[string,string][]`) 2668 • {title_pos}? (`'left'|'center'|'right'`) 2669 • {relative}? (`'mouse'|'cursor'|'editor'`) (default: `'cursor'`) 2670 • {anchor_bias}? (`'auto'|'above'|'below'`, default: `'auto'`) Adjusts 2671 placement relative to cursor. 2672 • "auto": place window based on which side of the 2673 cursor has more lines 2674 • "above": place the window above the cursor unless 2675 there are not enough lines to display the full 2676 window height. 2677 • "below": place the window below the cursor unless 2678 there are not enough lines to display the full 2679 window height. 2680 2681 2682 *vim.lsp.util.apply_text_document_edit()* 2683 apply_text_document_edit({text_document_edit}, {index}, {position_encoding}, 2684 {change_annotations}) 2685 Applies a `TextDocumentEdit`, which is a list of changes to a single 2686 document. 2687 2688 Parameters: ~ 2689 • {text_document_edit} (`lsp.TextDocumentEdit`) 2690 • {index} (`integer?`) Optional index of the edit, if from 2691 a list of edits (or nil, if not from a list) 2692 • {position_encoding} (`'utf-8'|'utf-16'|'utf-32'?`) 2693 • {change_annotations} (`table<string, lsp.ChangeAnnotation>?`) 2694 2695 See also: ~ 2696 • https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocumentEdit 2697 2698 *vim.lsp.util.apply_text_edits()* 2699 apply_text_edits({text_edits}, {bufnr}, {position_encoding}, 2700 {change_annotations}) 2701 Applies a list of text edits to a buffer. 2702 2703 Parameters: ~ 2704 • {text_edits} (`(lsp.TextEdit|lsp.AnnotatedTextEdit)[]`) 2705 • {bufnr} (`integer`) Buffer id 2706 • {position_encoding} (`'utf-8'|'utf-16'|'utf-32'`) 2707 • {change_annotations} (`table<string, lsp.ChangeAnnotation>?`) 2708 2709 See also: ~ 2710 • https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textEdit 2711 2712 *vim.lsp.util.apply_workspace_edit()* 2713 apply_workspace_edit({workspace_edit}, {position_encoding}) 2714 Applies a `WorkspaceEdit`. 2715 2716 Parameters: ~ 2717 • {workspace_edit} (`lsp.WorkspaceEdit`) 2718 • {position_encoding} (`'utf-8'|'utf-16'|'utf-32'`) (required) 2719 2720 See also: ~ 2721 • https://microsoft.github.io/language-server-protocol/specifications/specification-current/#workspace_applyEdit 2722 2723 buf_clear_references({bufnr}) *vim.lsp.util.buf_clear_references()* 2724 Removes document highlights from a buffer. 2725 2726 Parameters: ~ 2727 • {bufnr} (`integer?`) Buffer id 2728 2729 *vim.lsp.util.buf_highlight_references()* 2730 buf_highlight_references({bufnr}, {references}, {position_encoding}) 2731 Shows a list of document highlights for a certain buffer. 2732 2733 Parameters: ~ 2734 • {bufnr} (`integer`) Buffer id 2735 • {references} (`lsp.DocumentHighlight[]`) objects to highlight 2736 • {position_encoding} (`'utf-8'|'utf-16'|'utf-32'`) 2737 2738 See also: ~ 2739 • https://microsoft.github.io/language-server-protocol/specification/#textDocumentContentChangeEvent 2740 2741 *vim.lsp.util.character_offset()* 2742 character_offset({buf}, {row}, {col}, {offset_encoding}) 2743 Returns the UTF-32 and UTF-16 offsets for a position in a certain buffer. 2744 2745 Parameters: ~ 2746 • {buf} (`integer`) buffer number (0 for current) 2747 • {row} (`integer`) 0-indexed line 2748 • {col} (`integer`) 0-indexed byte offset in line 2749 • {offset_encoding} (`'utf-8'|'utf-16'|'utf-32'?`) defaults to 2750 `offset_encoding` of first client of `buf` 2751 2752 Return: ~ 2753 (`integer`) `offset_encoding` index of the character in line {row} 2754 column {col} in buffer {buf} 2755 2756 *vim.lsp.util.convert_input_to_markdown_lines()* 2757 convert_input_to_markdown_lines({input}, {contents}) 2758 Converts any of `MarkedString` | `MarkedString[]` | `MarkupContent` into a 2759 list of lines containing valid markdown. Useful to populate the hover 2760 window for `textDocument/hover`, for parsing the result of 2761 `textDocument/signatureHelp`, and potentially others. 2762 2763 Note that if the input is of type `MarkupContent` and its kind is 2764 `plaintext`, then the corresponding value is returned without further 2765 modifications. 2766 2767 Parameters: ~ 2768 • {input} (`lsp.MarkedString|lsp.MarkedString[]|lsp.MarkupContent`) 2769 • {contents} (`string[]?`) List of strings to extend with converted 2770 lines. Defaults to {}. 2771 2772 Return: ~ 2773 (`string[]`) extended with lines of converted markdown. 2774 2775 See also: ~ 2776 • https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_hover 2777 2778 *vim.lsp.util.convert_signature_help_to_markdown_lines()* 2779 convert_signature_help_to_markdown_lines({signature_help}, {ft}, {triggers}) 2780 Converts `textDocument/signatureHelp` response to markdown lines. 2781 2782 Parameters: ~ 2783 • {signature_help} (`lsp.SignatureHelp`) Response of 2784 `textDocument/SignatureHelp` 2785 • {ft} (`string?`) filetype that will be use as the `lang` 2786 for the label markdown code block 2787 • {triggers} (`string[]?`) list of trigger characters from the 2788 lsp server. used to better determine parameter 2789 offsets 2790 2791 Return (multiple): ~ 2792 (`string[]?`) lines of converted markdown. 2793 (`Range4?`) highlight range for the active parameter 2794 2795 See also: ~ 2796 • https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_signatureHelp 2797 2798 get_effective_tabstop({bufnr}) *vim.lsp.util.get_effective_tabstop()* 2799 Returns indentation size. 2800 2801 Parameters: ~ 2802 • {bufnr} (`integer?`) Buffer handle, defaults to current 2803 2804 Return: ~ 2805 (`integer`) indentation size 2806 2807 See also: ~ 2808 • 'shiftwidth' 2809 2810 *vim.lsp.util.locations_to_items()* 2811 locations_to_items({locations}, {position_encoding}) 2812 Returns the items with the byte position calculated correctly and in 2813 sorted order, for display in quickfix and location lists. 2814 2815 The `user_data` field of each resulting item will contain the original 2816 `Location` or `LocationLink` it was computed from. 2817 2818 The result can be passed to the {list} argument of |setqflist()| or 2819 |setloclist()|. 2820 2821 Parameters: ~ 2822 • {locations} (`lsp.Location[]|lsp.LocationLink[]`) 2823 • {position_encoding} (`'utf-8'|'utf-16'|'utf-32'?`) default to first 2824 client of buffer 2825 2826 Return: ~ 2827 (`vim.quickfix.entry[]`) See |setqflist()| for the format 2828 2829 *vim.lsp.util.make_floating_popup_options()* 2830 make_floating_popup_options({width}, {height}, {opts}) 2831 Creates a table with sensible default options for a floating window. The 2832 table can be passed to |nvim_open_win()|. 2833 2834 Parameters: ~ 2835 • {width} (`integer`) window width (in character cells) 2836 • {height} (`integer`) window height (in character cells) 2837 • {opts} (`vim.lsp.util.open_floating_preview.Opts?`) See 2838 |vim.lsp.util.open_floating_preview.Opts|. 2839 2840 Return: ~ 2841 (`vim.api.keyset.win_config`) 2842 2843 *vim.lsp.util.make_formatting_params()* 2844 make_formatting_params({options}) 2845 Creates a `DocumentFormattingParams` object for the current buffer and 2846 cursor position. 2847 2848 Parameters: ~ 2849 • {options} (`lsp.FormattingOptions?`) with valid `FormattingOptions` 2850 entries 2851 2852 Return: ~ 2853 (`lsp.DocumentFormattingParams`) object 2854 2855 See also: ~ 2856 • https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_formatting 2857 2858 *vim.lsp.util.make_given_range_params()* 2859 make_given_range_params({start_pos}, {end_pos}, {bufnr}, {position_encoding}) 2860 Using the given range in the current buffer, creates an object that is 2861 similar to |vim.lsp.util.make_range_params()|. 2862 2863 Parameters: ~ 2864 • {start_pos} (`[integer,integer]?`) {row,col} mark-indexed 2865 position. Defaults to the start of the last 2866 visual selection. 2867 • {end_pos} (`[integer,integer]?`) {row,col} mark-indexed 2868 position. Defaults to the end of the last visual 2869 selection. 2870 • {bufnr} (`integer?`) buffer handle or 0 for current, 2871 defaults to current 2872 • {position_encoding} (`'utf-8'|'utf-16'|'utf-32'`) 2873 2874 Return: ~ 2875 (`{ textDocument: { uri: lsp.DocumentUri }, range: lsp.Range }`) 2876 2877 *vim.lsp.util.make_position_params()* 2878 make_position_params({window}, {position_encoding}) 2879 Creates a `TextDocumentPositionParams` object for the current buffer and 2880 cursor position. 2881 2882 Parameters: ~ 2883 • {window} (`integer?`) |window-ID| or 0 for current, 2884 defaults to current 2885 • {position_encoding} (`'utf-8'|'utf-16'|'utf-32'`) 2886 2887 Return: ~ 2888 (`lsp.TextDocumentPositionParams`) 2889 2890 See also: ~ 2891 • https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocumentPositionParams 2892 2893 *vim.lsp.util.make_range_params()* 2894 make_range_params({window}, {position_encoding}) 2895 Using the current position in the current buffer, creates an object that 2896 can be used as a building block for several LSP requests, such as 2897 `textDocument/codeAction`, `textDocument/colorPresentation`, 2898 `textDocument/rangeFormatting`. 2899 2900 Parameters: ~ 2901 • {window} (`integer?`) |window-ID| or 0 for current, 2902 defaults to current 2903 • {position_encoding} (`"utf-8"|"utf-16"|"utf-32"`) 2904 2905 Return: ~ 2906 (`{ textDocument: { uri: lsp.DocumentUri }, range: lsp.Range }`) 2907 2908 *vim.lsp.util.make_text_document_params()* 2909 make_text_document_params({bufnr}) 2910 Creates a `TextDocumentIdentifier` object for the current buffer. 2911 2912 Parameters: ~ 2913 • {bufnr} (`integer?`) Buffer handle, defaults to current 2914 2915 Return: ~ 2916 (`lsp.TextDocumentIdentifier`) 2917 2918 See also: ~ 2919 • https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocumentIdentifier 2920 2921 *vim.lsp.util.make_workspace_params()* 2922 make_workspace_params({added}, {removed}) 2923 Create the workspace params 2924 2925 Parameters: ~ 2926 • {added} (`lsp.WorkspaceFolder[]`) 2927 • {removed} (`lsp.WorkspaceFolder[]`) 2928 2929 Return: ~ 2930 (`lsp.DidChangeWorkspaceFoldersParams`) 2931 2932 *vim.lsp.util.open_floating_preview()* 2933 open_floating_preview({contents}, {syntax}, {opts}) 2934 Shows contents in a floating window. 2935 2936 Parameters: ~ 2937 • {contents} (`table`) of lines to show in window 2938 • {syntax} (`string`) of syntax to set for opened buffer 2939 • {opts} (`vim.lsp.util.open_floating_preview.Opts?`) with optional 2940 fields (additional keys are filtered with 2941 |vim.lsp.util.make_floating_popup_options()| before they 2942 are passed on to |nvim_open_win()|). See 2943 |vim.lsp.util.open_floating_preview.Opts|. 2944 2945 Return (multiple): ~ 2946 (`integer`) bufnr of newly created float window 2947 (`integer`) winid of newly created float window preview window 2948 2949 preview_location({location}, {opts}) *vim.lsp.util.preview_location()* 2950 Previews a location in a floating window 2951 2952 behavior depends on type of location: 2953 • for Location, range is shown (e.g., function definition) 2954 • for LocationLink, targetRange is shown (e.g., body of function 2955 definition) 2956 2957 Parameters: ~ 2958 • {location} (`lsp.Location|lsp.LocationLink`) 2959 • {opts} (`vim.lsp.util.open_floating_preview.Opts?`) See 2960 |vim.lsp.util.open_floating_preview.Opts|. 2961 2962 Return (multiple): ~ 2963 (`integer?`) buffer id of float window 2964 (`integer?`) window id of float window 2965 2966 rename({old_fname}, {new_fname}, {opts}) *vim.lsp.util.rename()* 2967 Rename old_fname to new_fname 2968 2969 Existing buffers are renamed as well, while maintaining their bufnr. 2970 2971 It deletes existing buffers that conflict with the renamed file name only 2972 when 2973 • `opts` requests overwriting; or 2974 • the conflicting buffers are not loaded, so that deleting them does not 2975 result in data loss. 2976 2977 Parameters: ~ 2978 • {old_fname} (`string`) 2979 • {new_fname} (`string`) 2980 • {opts} (`table?`) Options: 2981 • {overwrite}? (`boolean`) 2982 • {ignoreIfExists}? (`boolean`) 2983 2984 *vim.lsp.util.show_document()* 2985 show_document({location}, {position_encoding}, {opts}) 2986 Shows document and optionally jumps to the location. 2987 2988 Parameters: ~ 2989 • {location} (`lsp.Location|lsp.LocationLink`) 2990 • {position_encoding} (`'utf-8'|'utf-16'|'utf-32'?`) 2991 • {opts} (`table?`) A table with the following fields: 2992 • {reuse_win}? (`boolean`) Jump to existing 2993 window if buffer is already open. 2994 • {focus}? (`boolean`) Whether to focus/jump to 2995 location if possible. (defaults: true) 2996 2997 Return: ~ 2998 (`boolean`) `true` if succeeded 2999 3000 *vim.lsp.util.symbols_to_items()* 3001 symbols_to_items({symbols}, {bufnr}, {position_encoding}) 3002 Converts symbols to quickfix list items. 3003 3004 Parameters: ~ 3005 • {symbols} (`lsp.DocumentSymbol[]|lsp.SymbolInformation[]|lsp.WorkspaceSymbol[]`) 3006 list of symbols 3007 • {bufnr} (`integer?`) buffer handle or 0 for current, 3008 defaults to current 3009 • {position_encoding} (`'utf-8'|'utf-16'|'utf-32'?`) default to first 3010 client of buffer 3011 3012 Return: ~ 3013 (`vim.quickfix.entry[]`) See |setqflist()| for the format 3014 3015 3016 ============================================================================== 3017 Lua module: vim.lsp.protocol *lsp-protocol* 3018 3019 *vim.lsp.protocol.make_client_capabilities()* 3020 make_client_capabilities() 3021 Gets a new ClientCapabilities object describing the LSP client 3022 capabilities. 3023 3024 Return: ~ 3025 (`lsp.ClientCapabilities`) 3026 3027 *vim.lsp.protocol.resolve_capabilities()* 3028 resolve_capabilities({server_capabilities}) 3029 Creates a normalized object describing LSP server capabilities. 3030 3031 Parameters: ~ 3032 • {server_capabilities} (`table`) Table of capabilities supported by 3033 the server 3034 3035 Return: ~ 3036 (`lsp.ServerCapabilities?`) Normalized table of capabilities 3037 3038 3039 vim:tw=78:ts=8:sw=4:sts=4:et:ft=help:norl: