lsp.txt 111 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573
  1. *lsp.txt* LSP
  2. NVIM REFERENCE MANUAL
  3. LSP client/framework *lsp* *LSP*
  4. Nvim supports the Language Server Protocol (LSP), which means it acts as
  5. a client to LSP servers and includes a Lua framework `vim.lsp` for building
  6. enhanced LSP tools.
  7. https://microsoft.github.io/language-server-protocol/
  8. LSP facilitates features like go-to-definition, find references, hover,
  9. completion, rename, format, refactor, etc., using semantic whole-project
  10. analysis (unlike |ctags|).
  11. Type |gO| to see the table of contents.
  12. ==============================================================================
  13. QUICKSTART *lsp-quickstart*
  14. Nvim provides an LSP client, but the servers are provided by third parties.
  15. Follow these steps to get LSP features:
  16. 1. Install language servers using your package manager or by following the
  17. upstream installation instructions. You can find language servers here:
  18. https://microsoft.github.io/language-server-protocol/implementors/servers/
  19. 2. Use |vim.lsp.config()| to define a configuration for an LSP client.
  20. Example: >lua
  21. vim.lsp.config['luals'] = {
  22. -- Command and arguments to start the server.
  23. cmd = { 'lua-language-server' },
  24. -- Filetypes to automatically attach to.
  25. filetypes = { 'lua' },
  26. -- Sets the "root directory" to the parent directory of the file in the
  27. -- current buffer that contains either a ".luarc.json" or a
  28. -- ".luarc.jsonc" file. Files that share a root directory will reuse
  29. -- the connection to the same LSP server.
  30. root_markers = { '.luarc.json', '.luarc.jsonc' },
  31. -- Specific settings to send to the server. The schema for this is
  32. -- defined by the server. For example the schema for lua-language-server
  33. -- can be found here https://raw.githubusercontent.com/LuaLS/vscode-lua/master/setting/schema.json
  34. settings = {
  35. Lua = {
  36. runtime = {
  37. version = 'LuaJIT',
  38. }
  39. }
  40. }
  41. }
  42. <
  43. 3. Use |vim.lsp.enable()| to enable a configuration.
  44. Example: >lua
  45. vim.lsp.enable('luals')
  46. <
  47. 4. Check that the buffer is attached to the server: >vim
  48. :checkhealth vim.lsp
  49. <
  50. 5. (Optional) Configure keymaps and autocommands to use LSP features.
  51. |lsp-attach|
  52. *lsp-config*
  53. Configurations for LSP clients is done via |vim.lsp.config()|.
  54. When an LSP client starts, it resolves a configuration by merging
  55. configurations, in increasing priority, from the following:
  56. 1. Configuration defined for the `'*'` name.
  57. 2. Configuration from the result of merging all tables returned by
  58. `lsp/<name>.lua` files in 'runtimepath' for a server of name `name`.
  59. 3. Configurations defined anywhere else.
  60. Note: The merge semantics of configurations follow the behaviour of
  61. |vim.tbl_deep_extend()|.
  62. Example:
  63. Given: >lua
  64. -- Defined in init.lua
  65. vim.lsp.config('*', {
  66. capabilities = {
  67. textDocument = {
  68. semanticTokens = {
  69. multilineTokenSupport = true,
  70. }
  71. }
  72. },
  73. root_markers = { '.git' },
  74. })
  75. -- Defined in ../lsp/clangd.lua
  76. return {
  77. cmd = { 'clangd' },
  78. root_markers = { '.clangd', 'compile_commands.json' },
  79. filetypes = { 'c', 'cpp' },
  80. }
  81. -- Defined in init.lua
  82. vim.lsp.config('clangd', {
  83. filetypes = { 'c' },
  84. })
  85. <
  86. Results in the configuration: >lua
  87. {
  88. -- From the clangd configuration in <rtp>/lsp/clangd.lua
  89. cmd = { 'clangd' },
  90. -- From the clangd configuration in <rtp>/lsp/clangd.lua
  91. -- Overrides the * configuration in init.lua
  92. root_markers = { '.clangd', 'compile_commands.json' },
  93. -- From the clangd configuration in init.lua
  94. -- Overrides the * configuration in init.lua
  95. filetypes = { 'c' },
  96. -- From the * configuration in init.lua
  97. capabilities = {
  98. textDocument = {
  99. semanticTokens = {
  100. multilineTokenSupport = true,
  101. }
  102. }
  103. }
  104. }
  105. <
  106. *lsp-defaults*
  107. When the Nvim LSP client starts it enables diagnostics |vim.diagnostic| (see
  108. |vim.diagnostic.config()| to customize). It also sets various default options,
  109. listed below, if (1) the language server supports the functionality and (2)
  110. the options are empty or were set by the builtin runtime (ftplugin) files. The
  111. options are not restored when the LSP client is stopped or detached.
  112. - 'omnifunc' is set to |vim.lsp.omnifunc()|, use |i_CTRL-X_CTRL-O| to trigger
  113. completion.
  114. - 'tagfunc' is set to |vim.lsp.tagfunc()|. This enables features like
  115. go-to-definition, |:tjump|, and keymaps like |CTRL-]|, |CTRL-W_]|,
  116. |CTRL-W_}| to utilize the language server.
  117. - 'formatexpr' is set to |vim.lsp.formatexpr()|, so you can format lines via
  118. |gq| if the language server supports it.
  119. - To opt out of this use |gw| instead of gq, or clear 'formatexpr' on |LspAttach|.
  120. - |K| is mapped to |vim.lsp.buf.hover()| unless |'keywordprg'| is customized or
  121. a custom keymap for `K` exists.
  122. *grr* *gra* *grn* *gri* *i_CTRL-S*
  123. Some keymaps are created unconditionally when Nvim starts:
  124. - "grn" is mapped in Normal mode to |vim.lsp.buf.rename()|
  125. - "gra" is mapped in Normal and Visual mode to |vim.lsp.buf.code_action()|
  126. - "grr" is mapped in Normal mode to |vim.lsp.buf.references()|
  127. - "gri" is mapped in Normal mode to |vim.lsp.buf.implementation()|
  128. - "gO" is mapped in Normal mode to |vim.lsp.buf.document_symbol()|
  129. - CTRL-S is mapped in Insert mode to |vim.lsp.buf.signature_help()|
  130. If not wanted, these keymaps can be removed at any time using
  131. |vim.keymap.del()| or |:unmap| (see also |gr-default|).
  132. *lsp-defaults-disable*
  133. To override or delete any of the above defaults, set or unset the options on
  134. |LspAttach|: >lua
  135. vim.api.nvim_create_autocmd('LspAttach', {
  136. callback = function(args)
  137. -- Unset 'formatexpr'
  138. vim.bo[args.buf].formatexpr = nil
  139. -- Unset 'omnifunc'
  140. vim.bo[args.buf].omnifunc = nil
  141. -- Unmap K
  142. vim.keymap.del('n', 'K', { buffer = args.buf })
  143. end,
  144. })
  145. <
  146. *lsp-attach*
  147. To use other LSP features, set keymaps and other buffer options on
  148. |LspAttach|. Not all language servers provide the same capabilities. Use
  149. capability checks to ensure you only use features supported by the language
  150. server. Example: >lua
  151. vim.api.nvim_create_autocmd('LspAttach', {
  152. callback = function(args)
  153. local client = vim.lsp.get_client_by_id(args.data.client_id)
  154. if client:supports_method('textDocument/implementation') then
  155. -- Create a keymap for vim.lsp.buf.implementation
  156. end
  157. if client:supports_method('textDocument/completion') then
  158. -- Enable auto-completion
  159. vim.lsp.completion.enable(true, client.id, args.buf, {autotrigger = true})
  160. end
  161. if client:supports_method('textDocument/formatting') then
  162. -- Format the current buffer on save
  163. vim.api.nvim_create_autocmd('BufWritePre', {
  164. buffer = args.buf,
  165. callback = function()
  166. vim.lsp.buf.format({bufnr = args.buf, id = client.id})
  167. end,
  168. })
  169. end
  170. end,
  171. })
  172. <
  173. To learn what capabilities are available you can run the following command in
  174. a buffer with a started LSP client: >vim
  175. :lua =vim.lsp.get_clients()[1].server_capabilities
  176. Full list of features provided by default can be found in |lsp-buf|.
  177. ================================================================================
  178. FAQ *lsp-faq*
  179. - Q: How to force-reload LSP?
  180. - A: Stop all clients, then reload the buffer. >vim
  181. :lua vim.lsp.stop_client(vim.lsp.get_clients())
  182. :edit
  183. - Q: Why isn't completion working?
  184. - A: In the buffer where you want to use LSP, check that 'omnifunc' is set to
  185. "v:lua.vim.lsp.omnifunc": `:verbose set omnifunc?`
  186. - Some other plugin may be overriding the option. To avoid that you could
  187. set the option in an |after-directory| ftplugin, e.g.
  188. "after/ftplugin/python.vim".
  189. - Q: How do I run a request synchronously (e.g. for formatting on file save)?
  190. - A: Check if the function has an `async` parameter and set the value to
  191. false. E.g. code formatting: >vim
  192. " Auto-format *.rs (rust) files prior to saving them
  193. " (async = false is the default for format)
  194. autocmd BufWritePre *.rs lua vim.lsp.buf.format({ async = false })
  195. <
  196. *lsp-vs-treesitter*
  197. - Q: How do LSP and Treesitter compare?
  198. - A: LSP requires a client and language server. The language server uses
  199. semantic analysis to understand code at a project level. This provides
  200. language servers with the ability to rename across files, find
  201. definitions in external libraries and more.
  202. Treesitter is a language parsing library that provides excellent tools
  203. for incrementally parsing text and handling errors. This makes it a great
  204. fit for editors to understand the contents of the current file for things
  205. like syntax highlighting, simple goto-definitions, scope analysis and
  206. more.
  207. LSP and Treesitter are both great tools for editing and inspecting code.
  208. ================================================================================
  209. LSP API *lsp-api*
  210. LSP core API is described at |lsp-core|. Those are the core functions for
  211. creating and managing clients.
  212. The `vim.lsp.buf_…` functions perform operations for all LSP clients attached
  213. to the given buffer. |lsp-buf|
  214. LSP request/response handlers are implemented as Lua functions (see
  215. |lsp-handler|).
  216. *lsp-method*
  217. Requests and notifications defined by the LSP specification are referred to as
  218. "LSP methods". The Nvim LSP client provides default handlers in the global
  219. |vim.lsp.handlers| table, you can list them with this command: >vim
  220. :lua vim.print(vim.tbl_keys(vim.lsp.handlers))
  221. <
  222. They are also listed below. Note that handlers depend on server support: they
  223. won't run if your server doesn't support them.
  224. - `'callHierarchy/incomingCalls'`
  225. - `'callHierarchy/outgoingCalls'`
  226. - `'textDocument/codeAction'`
  227. - `'textDocument/completion'`
  228. - `'textDocument/declaration'`
  229. - `'textDocument/definition'`
  230. - `'textDocument/diagnostic'`
  231. - `'textDocument/documentHighlight'`
  232. - `'textDocument/documentSymbol'`
  233. - `'textDocument/foldingRange'`
  234. - `'textDocument/formatting'`
  235. - `'textDocument/hover'`
  236. - `'textDocument/implementation'`
  237. - `'textDocument/inlayHint'`
  238. - `'textDocument/prepareTypeHierarchy'`
  239. - `'textDocument/publishDiagnostics'`
  240. - `'textDocument/rangeFormatting'`
  241. - `'textDocument/rangesFormatting'`
  242. - `'textDocument/references'`
  243. - `'textDocument/rename'`
  244. - `'textDocument/semanticTokens/full'`
  245. - `'textDocument/semanticTokens/full/delta'`
  246. - `'textDocument/signatureHelp'`
  247. - `'textDocument/typeDefinition*'`
  248. - `'typeHierarchy/subtypes'`
  249. - `'typeHierarchy/supertypes'`
  250. - `'window/logMessage'`
  251. - `'window/showMessage'`
  252. - `'window/showDocument'`
  253. - `'window/showMessageRequest'`
  254. - `'workspace/applyEdit'`
  255. - `'workspace/configuration'`
  256. - `'workspace/executeCommand'`
  257. - `'workspace/inlayHint/refresh'`
  258. - `'workspace/symbol'`
  259. - `'workspace/workspaceFolders'`
  260. *lsp-handler*
  261. LSP handlers are functions that handle |lsp-response|s to requests made by Nvim
  262. to the server. (Notifications, as opposed to requests, are fire-and-forget:
  263. there is no response, so they can't be handled. |lsp-notification|)
  264. Each response handler has this signature: >
  265. function(err, result, ctx)
  266. <
  267. Parameters: ~
  268. • {err} (`table|nil`) Error info dict, or `nil` if the request
  269. completed.
  270. • {result} (`Result|Params|nil`) `result` key of the |lsp-response| or
  271. `nil` if the request failed.
  272. • {ctx} (`table`) Table of calling state associated with the
  273. handler, with these keys:
  274. • {method} (`string`) |lsp-method| name.
  275. • {client_id} (`number`) |vim.lsp.Client| identifier.
  276. • {bufnr} (`Buffer`) Buffer handle.
  277. • {params} (`table|nil`) Request parameters table.
  278. • {version} (`number`) Document version at time of
  279. request. Handlers can compare this to the
  280. current document version to check if the
  281. response is "stale". See also |b:changedtick|.
  282. Returns: ~
  283. Two values `result, err` where `err` is shaped like an RPC error: >
  284. { code, message, data? }
  285. < You can use |vim.lsp.rpc.rpc_response_error()| to create this object.
  286. *lsp-handler-resolution*
  287. Handlers can be set by (in increasing priority):
  288. *vim.lsp.handlers*
  289. - Setting a field in `vim.lsp.handlers`. This global table contains the
  290. default mappings of |lsp-method| names to handlers. (Note: only for
  291. server-to-client requests/notifications, not client-to-server.)
  292. Example: >lua
  293. vim.lsp.handlers['textDocument/publishDiagnostics'] = my_custom_diagnostics_handler
  294. <
  295. - Passing a {handlers} parameter to |vim.lsp.start()|. This sets the default
  296. |lsp-handler| for a specific server. (Note: only for server-to-client
  297. requests/notifications, not client-to-server.)
  298. Example: >lua
  299. vim.lsp.start {
  300. ..., -- Other configuration omitted.
  301. handlers = {
  302. ['textDocument/publishDiagnostics'] = my_custom_server_definition
  303. },
  304. }
  305. <
  306. - Passing a {handler} parameter to |vim.lsp.buf_request_all()|. This sets the
  307. |lsp-handler| ONLY for the given request(s).
  308. Example: >lua
  309. vim.lsp.buf_request_all(
  310. 0,
  311. 'textDocument/publishDiagnostics',
  312. my_request_params,
  313. my_handler
  314. )
  315. <
  316. *vim.lsp.log_levels*
  317. Log levels are defined in |vim.log.levels|
  318. VIM.LSP.PROTOCOL *vim.lsp.protocol*
  319. Module `vim.lsp.protocol` defines constants dictated by the LSP specification,
  320. and helper functions for creating protocol-related objects.
  321. https://github.com/microsoft/language-server-protocol/raw/gh-pages/_specifications/specification-3-14.md
  322. For example `vim.lsp.protocol.ErrorCodes` allows reverse lookup by number or
  323. name: >lua
  324. vim.lsp.protocol.TextDocumentSyncKind.Full == 1
  325. vim.lsp.protocol.TextDocumentSyncKind[1] == "Full"
  326. <
  327. *lsp-response*
  328. LSP response shape:
  329. https://microsoft.github.io/language-server-protocol/specifications/specification-current/#responseMessage
  330. *lsp-notification*
  331. LSP notification shape:
  332. https://microsoft.github.io/language-server-protocol/specifications/specification-current/#notificationMessage
  333. ================================================================================
  334. LSP HIGHLIGHT *lsp-highlight*
  335. Reference Highlights:
  336. Highlight groups that are meant to be used by |vim.lsp.buf.document_highlight()|.
  337. You can see more about the differences in types here:
  338. https://microsoft.github.io/language-server-protocol/specification#textDocument_documentHighlight
  339. *hl-LspReferenceText*
  340. LspReferenceText used for highlighting "text" references
  341. *hl-LspReferenceRead*
  342. LspReferenceRead used for highlighting "read" references
  343. *hl-LspReferenceWrite*
  344. LspReferenceWrite used for highlighting "write" references
  345. *hl-LspReferenceTarget*
  346. LspReferenceTarget used for highlighting reference targets (e.g. in a
  347. hover range)
  348. *hl-LspInlayHint*
  349. LspInlayHint used for highlighting inlay hints
  350. *lsp-highlight-codelens*
  351. Highlight groups related to |lsp-codelens| functionality.
  352. *hl-LspCodeLens*
  353. LspCodeLens
  354. Used to color the virtual text of the codelens. See
  355. |nvim_buf_set_extmark()|.
  356. LspCodeLensSeparator *hl-LspCodeLensSeparator*
  357. Used to color the separator between two or more code lenses.
  358. *lsp-highlight-signature*
  359. Highlight groups related to |vim.lsp.handlers.signature_help()|.
  360. *hl-LspSignatureActiveParameter*
  361. LspSignatureActiveParameter
  362. Used to highlight the active parameter in the signature help. See
  363. |vim.lsp.handlers.signature_help()|.
  364. ------------------------------------------------------------------------------
  365. LSP SEMANTIC HIGHLIGHTS *lsp-semantic-highlight*
  366. When available, the LSP client highlights code using |lsp-semantic_tokens|,
  367. which are another way that LSP servers can provide information about source
  368. code. Note that this is in addition to treesitter syntax highlighting;
  369. semantic highlighting does not replace syntax highlighting.
  370. The server will typically provide one token per identifier in the source code.
  371. The token will have a `type` such as "function" or "variable", and 0 or more
  372. `modifier`s such as "readonly" or "deprecated." The standard types and
  373. modifiers are described here:
  374. https://microsoft.github.io/language-server-protocol/specification/#textDocument_semanticTokens
  375. LSP servers may also use off-spec types and modifiers.
  376. The LSP client adds one or more highlights for each token. The highlight
  377. groups are derived from the token's type and modifiers:
  378. • `@lsp.type.<type>.<ft>` for the type
  379. • `@lsp.mod.<mod>.<ft>` for each modifier
  380. • `@lsp.typemod.<type>.<mod>.<ft>` for each modifier
  381. Use |:Inspect| to view the highlights for a specific token. Use |:hi| or
  382. |nvim_set_hl()| to change the appearance of semantic highlights: >vim
  383. hi @lsp.type.function guifg=Yellow " function names are yellow
  384. hi @lsp.type.variable.lua guifg=Green " variables in lua are green
  385. hi @lsp.mod.deprecated gui=strikethrough " deprecated is crossed out
  386. hi @lsp.typemod.function.async guifg=Blue " async functions are blue
  387. <
  388. The value |vim.hl.priorities|`.semantic_tokens` is the priority of the
  389. `@lsp.type.*` highlights. The `@lsp.mod.*` and `@lsp.typemod.*` highlights
  390. have priorities one and two higher, respectively.
  391. You can disable semantic highlights by clearing the highlight groups: >lua
  392. -- Hide semantic highlights for functions
  393. vim.api.nvim_set_hl(0, '@lsp.type.function', {})
  394. -- Hide all semantic highlights
  395. for _, group in ipairs(vim.fn.getcompletion("@lsp", "highlight")) do
  396. vim.api.nvim_set_hl(0, group, {})
  397. end
  398. <
  399. You probably want these inside a |ColorScheme| autocommand.
  400. Use |LspTokenUpdate| and |vim.lsp.semantic_tokens.highlight_token()| for more
  401. complex highlighting.
  402. The following is a list of standard captures used in queries for Nvim,
  403. highlighted according to the current colorscheme (use |:Inspect| on one to see
  404. the exact definition):
  405. @lsp.type.class Identifiers that declare or reference a class type
  406. @lsp.type.comment Tokens that represent a comment
  407. @lsp.type.decorator Identifiers that declare or reference decorators and annotations
  408. @lsp.type.enum Identifiers that declare or reference an enumeration type
  409. @lsp.type.enumMember Identifiers that declare or reference an enumeration property, constant, or member
  410. @lsp.type.event Identifiers that declare an event property
  411. @lsp.type.function Identifiers that declare a function
  412. @lsp.type.interface Identifiers that declare or reference an interface type
  413. @lsp.type.keyword Tokens that represent a language keyword
  414. @lsp.type.macro Identifiers that declare a macro
  415. @lsp.type.method Identifiers that declare a member function or method
  416. @lsp.type.modifier Tokens that represent a modifier
  417. @lsp.type.namespace Identifiers that declare or reference a namespace, module, or package
  418. @lsp.type.number Tokens that represent a number literal
  419. @lsp.type.operator Tokens that represent an operator
  420. @lsp.type.parameter Identifiers that declare or reference a function or method parameters
  421. @lsp.type.property Identifiers that declare or reference a member property, member field, or member variable
  422. @lsp.type.regexp Tokens that represent a regular expression literal
  423. @lsp.type.string Tokens that represent a string literal
  424. @lsp.type.struct Identifiers that declare or reference a struct type
  425. @lsp.type.type Identifiers that declare or reference a type that is not covered above
  426. @lsp.type.typeParameter Identifiers that declare or reference a type parameter
  427. @lsp.type.variable Identifiers that declare or reference a local or global variable
  428. @lsp.mod.abstract Types and member functions that are abstract
  429. @lsp.mod.async Functions that are marked async
  430. @lsp.mod.declaration Declarations of symbols
  431. @lsp.mod.defaultLibrary Symbols that are part of the standard library
  432. @lsp.mod.definition Definitions of symbols, for example, in header files
  433. @lsp.mod.deprecated Symbols that should no longer be used
  434. @lsp.mod.documentation Occurrences of symbols in documentation
  435. @lsp.mod.modification Variable references where the variable is assigned to
  436. @lsp.mod.readonly Readonly variables and member fields (constants)
  437. @lsp.mod.static Class members (static members)
  438. ==============================================================================
  439. EVENTS *lsp-events*
  440. LspAttach *LspAttach*
  441. After an LSP client attaches to a buffer. The |autocmd-pattern| is the
  442. name of the buffer. When used from Lua, the client ID is passed to the
  443. callback in the "data" table. See |lsp-attach| for an example.
  444. LspDetach *LspDetach*
  445. Just before an LSP client detaches from a buffer. The |autocmd-pattern|
  446. is the name of the buffer. When used from Lua, the client ID is passed
  447. to the callback in the "data" table. Example: >lua
  448. vim.api.nvim_create_autocmd('LspDetach', {
  449. callback = function(args)
  450. -- Get the detaching client
  451. local client = vim.lsp.get_client_by_id(args.data.client_id)
  452. -- Remove the autocommand to format the buffer on save, if it exists
  453. if client:supports_method('textDocument/formatting') then
  454. vim.api.nvim_clear_autocmds({
  455. event = 'BufWritePre',
  456. buffer = args.buf,
  457. })
  458. end
  459. end,
  460. })
  461. <
  462. LspNotify *LspNotify*
  463. This event is triggered after each successful notification sent to an
  464. LSP server.
  465. When used from Lua, the client_id, LSP method, and parameters are sent
  466. in the "data" table. Example: >lua
  467. vim.api.nvim_create_autocmd('LspNotify', {
  468. callback = function(args)
  469. local bufnr = args.buf
  470. local client_id = args.data.client_id
  471. local method = args.data.method
  472. local params = args.data.params
  473. -- do something with the notification
  474. if method == 'textDocument/...' then
  475. update_buffer(bufnr)
  476. end
  477. end,
  478. })
  479. <
  480. LspProgress *LspProgress*
  481. Upon receipt of a progress notification from the server. Notifications can
  482. be polled from a `progress` ring buffer of a |vim.lsp.Client| or use
  483. |vim.lsp.status()| to get an aggregate message.
  484. If the server sends a "work done progress", the `pattern` is set to `kind`
  485. (one of `begin`, `report` or `end`).
  486. When used from Lua, the event contains a `data` table with `client_id` and
  487. `params` properties. `params` will contain the request params sent by the
  488. server (see `lsp.ProgressParams`).
  489. Example: >vim
  490. autocmd LspProgress * redrawstatus
  491. <
  492. LspRequest *LspRequest*
  493. For each request sent to an LSP server, this event is triggered for
  494. every change to the request's status. The status can be one of
  495. `pending`, `complete`, or `cancel` and is sent as the {type} on the
  496. "data" table passed to the callback function.
  497. It triggers when the initial request is sent ({type} == `pending`) and
  498. when the LSP server responds ({type} == `complete`). If a cancellation
  499. is requested using `client.cancel_request(request_id)`, then this event
  500. will trigger with {type} == `cancel`.
  501. When used from Lua, the client ID, request ID, and request are sent in
  502. the "data" table. See {requests} in |vim.lsp.Client| for details on the
  503. {request} value. If the request type is `complete`, the request will be
  504. deleted from the client's pending requests table immediately after
  505. calling the event's callbacks. Example: >lua
  506. vim.api.nvim_create_autocmd('LspRequest', {
  507. callback = function(args)
  508. local bufnr = args.buf
  509. local client_id = args.data.client_id
  510. local request_id = args.data.request_id
  511. local request = args.data.request
  512. if request.type == 'pending' then
  513. -- do something with pending requests
  514. track_pending(client_id, bufnr, request_id, request)
  515. elseif request.type == 'cancel' then
  516. -- do something with pending cancel requests
  517. track_canceling(client_id, bufnr, request_id, request)
  518. elseif request.type == 'complete' then
  519. -- do something with finished requests. this pending
  520. -- request entry is about to be removed since it is complete
  521. track_finish(client_id, bufnr, request_id, request)
  522. end
  523. end,
  524. })
  525. <
  526. LspTokenUpdate *LspTokenUpdate*
  527. When a visible semantic token is sent or updated by the LSP server, or
  528. when an existing token becomes visible for the first time. The
  529. |autocmd-pattern| is the name of the buffer. When used from Lua, the
  530. token and client ID are passed to the callback in the "data" table. The
  531. token fields are documented in |vim.lsp.semantic_tokens.get_at_pos()|.
  532. Example:
  533. >lua
  534. vim.api.nvim_create_autocmd('LspTokenUpdate', {
  535. callback = function(args)
  536. local token = args.data.token
  537. if token.type == 'variable' and not token.modifiers.readonly then
  538. vim.lsp.semantic_tokens.highlight_token(
  539. token, args.buf, args.data.client_id, 'MyMutableVariableHighlight'
  540. )
  541. end
  542. end,
  543. })
  544. <
  545. Note: doing anything other than calling
  546. |vim.lsp.semantic_tokens.highlight_token()| is considered experimental.
  547. ==============================================================================
  548. Lua module: vim.lsp *lsp-core*
  549. *vim.lsp.Config*
  550. Extends: |vim.lsp.ClientConfig|
  551. Fields: ~
  552. • {cmd}? (`string[]|fun(dispatchers: vim.lsp.rpc.Dispatchers): vim.lsp.rpc.PublicClient`)
  553. See `cmd` in |vim.lsp.ClientConfig|.
  554. • {filetypes}? (`string[]`) Filetypes the client will attach to, if
  555. activated by `vim.lsp.enable()`. If not provided,
  556. then the client will attach to all filetypes.
  557. • {root_markers}? (`string[]`) Directory markers (.e.g. '.git/') where
  558. the LSP server will base its workspaceFolders,
  559. rootUri, and rootPath on initialization. Unused if
  560. `root_dir` is provided.
  561. • {root_dir}? (`string|fun(cb:fun(string))`) Directory where the
  562. LSP server will base its workspaceFolders, rootUri,
  563. and rootPath on initialization. If a function, it
  564. accepts a single callback argument which must be
  565. called with the value of root_dir to use. The LSP
  566. server will not be started until the callback is
  567. called.
  568. • {reuse_client}? (`fun(client: vim.lsp.Client, config: vim.lsp.ClientConfig): boolean`)
  569. Predicate used to decide if a client should be
  570. re-used. Used on all running clients. The default
  571. implementation re-uses a client if name and root_dir
  572. matches.
  573. buf_attach_client({bufnr}, {client_id}) *vim.lsp.buf_attach_client()*
  574. Implements the `textDocument/did…` notifications required to track a
  575. buffer for any language server.
  576. Without calling this, the server won't be notified of changes to a buffer.
  577. Parameters: ~
  578. • {bufnr} (`integer`) Buffer handle, or 0 for current
  579. • {client_id} (`integer`) Client id
  580. Return: ~
  581. (`boolean`) success `true` if client was attached successfully;
  582. `false` otherwise
  583. buf_detach_client({bufnr}, {client_id}) *vim.lsp.buf_detach_client()*
  584. Detaches client from the specified buffer. Note: While the server is
  585. notified that the text document (buffer) was closed, it is still able to
  586. send notifications should it ignore this notification.
  587. Parameters: ~
  588. • {bufnr} (`integer`) Buffer handle, or 0 for current
  589. • {client_id} (`integer`) Client id
  590. buf_is_attached({bufnr}, {client_id}) *vim.lsp.buf_is_attached()*
  591. Checks if a buffer is attached for a particular client.
  592. Parameters: ~
  593. • {bufnr} (`integer`) Buffer handle, or 0 for current
  594. • {client_id} (`integer`) the client id
  595. buf_notify({bufnr}, {method}, {params}) *vim.lsp.buf_notify()*
  596. Send a notification to a server
  597. Parameters: ~
  598. • {bufnr} (`integer?`) The number of the buffer
  599. • {method} (`string`) Name of the request method
  600. • {params} (`any`) Arguments to send to the server
  601. Return: ~
  602. (`boolean`) success true if any client returns true; false otherwise
  603. *vim.lsp.buf_request_all()*
  604. buf_request_all({bufnr}, {method}, {params}, {handler})
  605. Sends an async request for all active clients attached to the buffer and
  606. executes the `handler` callback with the combined result.
  607. Parameters: ~
  608. • {bufnr} (`integer`) Buffer handle, or 0 for current.
  609. • {method} (`string`) LSP method name
  610. • {params} (`table|(fun(client: vim.lsp.Client, bufnr: integer): table?)?`)
  611. Parameters to send to the server. Can also be passed as a
  612. function that returns the params table for cases where
  613. parameters are specific to the client.
  614. • {handler} (`function`) Handler called after all requests are
  615. completed. Server results are passed as a
  616. `client_id:result` map.
  617. Return: ~
  618. (`function`) cancel Function that cancels all requests.
  619. *vim.lsp.buf_request_sync()*
  620. buf_request_sync({bufnr}, {method}, {params}, {timeout_ms})
  621. Sends a request to all server and waits for the response of all of them.
  622. Calls |vim.lsp.buf_request_all()| but blocks Nvim while awaiting the
  623. result. Parameters are the same as |vim.lsp.buf_request_all()| but the
  624. result is different. Waits a maximum of {timeout_ms}.
  625. Parameters: ~
  626. • {bufnr} (`integer`) Buffer handle, or 0 for current.
  627. • {method} (`string`) LSP method name
  628. • {params} (`table?`) Parameters to send to the server
  629. • {timeout_ms} (`integer?`, default: `1000`) Maximum time in
  630. milliseconds to wait for a result.
  631. Return (multiple): ~
  632. (`table<integer, {error: lsp.ResponseError?, result: any}>?`) result
  633. Map of client_id:request_result.
  634. (`string?`) err On timeout, cancel, or error, `err` is a string
  635. describing the failure reason, and `result` is nil.
  636. client_is_stopped({client_id}) *vim.lsp.client_is_stopped()*
  637. Checks whether a client is stopped.
  638. Parameters: ~
  639. • {client_id} (`integer`)
  640. Return: ~
  641. (`boolean`) stopped true if client is stopped, false otherwise.
  642. commands *vim.lsp.commands*
  643. Registry for client side commands. This is an extension point for plugins
  644. to handle custom commands which are not part of the core language server
  645. protocol specification.
  646. The registry is a table where the key is a unique command name, and the
  647. value is a function which is called if any LSP action (code action, code
  648. lenses, ...) triggers the command.
  649. If an LSP response contains a command for which no matching entry is
  650. available in this registry, the command will be executed via the LSP
  651. server using `workspace/executeCommand`.
  652. The first argument to the function will be the `Command`: Command title:
  653. String command: String arguments?: any[]
  654. The second argument is the `ctx` of |lsp-handler|
  655. config({name}, {cfg}) *vim.lsp.config()*
  656. Update the configuration for an LSP client.
  657. Use name '*' to set default configuration for all clients.
  658. Can also be table-assigned to redefine the configuration for a client.
  659. Examples:
  660. • Add a root marker for all clients: >lua
  661. vim.lsp.config('*', {
  662. root_markers = { '.git' },
  663. })
  664. <
  665. • Add additional capabilities to all clients: >lua
  666. vim.lsp.config('*', {
  667. capabilities = {
  668. textDocument = {
  669. semanticTokens = {
  670. multilineTokenSupport = true,
  671. }
  672. }
  673. }
  674. })
  675. <
  676. • (Re-)define the configuration for clangd: >lua
  677. vim.lsp.config.clangd = {
  678. cmd = {
  679. 'clangd',
  680. '--clang-tidy',
  681. '--background-index',
  682. '--offset-encoding=utf-8',
  683. },
  684. root_markers = { '.clangd', 'compile_commands.json' },
  685. filetypes = { 'c', 'cpp' },
  686. }
  687. <
  688. • Get configuration for luals: >lua
  689. local cfg = vim.lsp.config.luals
  690. <
  691. Parameters: ~
  692. • {name} (`string`)
  693. • {cfg} (`vim.lsp.Config`) See |vim.lsp.Config|.
  694. enable({name}, {enable}) *vim.lsp.enable()*
  695. Enable an LSP server to automatically start when opening a buffer.
  696. Uses configuration defined with `vim.lsp.config`.
  697. Examples: >lua
  698. vim.lsp.enable('clangd')
  699. vim.lsp.enable({'luals', 'pyright'})
  700. <
  701. Parameters: ~
  702. • {name} (`string|string[]`) Name(s) of client(s) to enable.
  703. • {enable} (`boolean?`) `true|nil` to enable, `false` to disable.
  704. foldclose({kind}, {winid}) *vim.lsp.foldclose()*
  705. Close all {kind} of folds in the the window with {winid}.
  706. To automatically fold imports when opening a file, you can use an autocmd: >lua
  707. vim.api.nvim_create_autocmd('LspNotify', {
  708. callback = function(args)
  709. if args.data.method == 'textDocument/didOpen' then
  710. vim.lsp.foldclose('imports', vim.fn.bufwinid(args.buf))
  711. end
  712. end,
  713. })
  714. <
  715. Parameters: ~
  716. • {kind} (`lsp.FoldingRangeKind`) Kind to close, one of "comment",
  717. "imports" or "region".
  718. • {winid} (`integer?`) Defaults to the current window.
  719. foldexpr({lnum}) *vim.lsp.foldexpr()*
  720. Provides an interface between the built-in client and a `foldexpr`
  721. function.
  722. To use, check for the "textDocument/foldingRange" capability in an
  723. |LspAttach| autocommand. Example: >lua
  724. vim.api.nvim_create_autocmd('LspAttach', {
  725. callback = function(args)
  726. local client = vim.lsp.get_client_by_id(args.data.client_id)
  727. if client:supports_method('textDocument/foldingRange') then
  728. vim.wo.foldmethod = 'expr'
  729. vim.wo.foldexpr = 'v:lua.vim.lsp.foldexpr()'
  730. end
  731. end,
  732. })
  733. <
  734. Parameters: ~
  735. • {lnum} (`integer`) line number
  736. foldtext() *vim.lsp.foldtext()*
  737. Provides a `foldtext` function that shows the `collapsedText` retrieved,
  738. defaults to the first folded line if `collapsedText` is not provided.
  739. formatexpr({opts}) *vim.lsp.formatexpr()*
  740. Provides an interface between the built-in client and a `formatexpr`
  741. function.
  742. Currently only supports a single client. This can be set via
  743. `setlocal formatexpr=v:lua.vim.lsp.formatexpr()` or (more typically) in
  744. `on_attach` via
  745. `vim.bo[bufnr].formatexpr = 'v:lua.vim.lsp.formatexpr(#{timeout_ms:250})'`.
  746. Parameters: ~
  747. • {opts} (`table?`) A table with the following fields:
  748. • {timeout_ms} (`integer`, default: 500ms) The timeout period
  749. for the formatting request..
  750. *vim.lsp.get_buffers_by_client_id()*
  751. get_buffers_by_client_id({client_id})
  752. Returns list of buffers attached to client_id.
  753. Parameters: ~
  754. • {client_id} (`integer`) client id
  755. Return: ~
  756. (`integer[]`) buffers list of buffer ids
  757. get_client_by_id({client_id}) *vim.lsp.get_client_by_id()*
  758. Gets a client by id, or nil if the id is invalid. The returned client may
  759. not yet be fully initialized.
  760. Parameters: ~
  761. • {client_id} (`integer`) client id
  762. Return: ~
  763. (`vim.lsp.Client?`) client rpc object
  764. get_clients({filter}) *vim.lsp.get_clients()*
  765. Get active clients.
  766. Parameters: ~
  767. • {filter} (`table?`) Key-value pairs used to filter the returned
  768. clients.
  769. • {id}? (`integer`) Only return clients with the given id
  770. • {bufnr}? (`integer`) Only return clients attached to this
  771. buffer
  772. • {name}? (`string`) Only return clients with the given name
  773. • {method}? (`string`) Only return clients supporting the
  774. given method
  775. Return: ~
  776. (`vim.lsp.Client[]`) List of |vim.lsp.Client| objects
  777. get_log_path() *vim.lsp.get_log_path()*
  778. Gets the path of the logfile used by the LSP client.
  779. Return: ~
  780. (`string`) path to log file
  781. omnifunc({findstart}, {base}) *vim.lsp.omnifunc()*
  782. Implements 'omnifunc' compatible LSP completion.
  783. Parameters: ~
  784. • {findstart} (`integer`) 0 or 1, decides behavior
  785. • {base} (`integer`) findstart=0, text to match against
  786. Return: ~
  787. (`integer|table`) Decided by {findstart}:
  788. • findstart=0: column where the completion starts, or -2 or -3
  789. • findstart=1: list of matches (actually just calls |complete()|)
  790. See also: ~
  791. • |complete-functions|
  792. • |complete-items|
  793. • |CompleteDone|
  794. set_log_level({level}) *vim.lsp.set_log_level()*
  795. Sets the global log level for LSP logging.
  796. Levels by name: "TRACE", "DEBUG", "INFO", "WARN", "ERROR", "OFF"
  797. Level numbers begin with "TRACE" at 0
  798. Use `lsp.log_levels` for reverse lookup.
  799. Parameters: ~
  800. • {level} (`integer|string`) the case insensitive level name or number
  801. See also: ~
  802. • |vim.lsp.log_levels|
  803. start({config}, {opts}) *vim.lsp.start()*
  804. Create a new LSP client and start a language server or reuses an already
  805. running client if one is found matching `name` and `root_dir`. Attaches
  806. the current buffer to the client.
  807. Example: >lua
  808. vim.lsp.start({
  809. name = 'my-server-name',
  810. cmd = {'name-of-language-server-executable'},
  811. root_dir = vim.fs.root(0, {'pyproject.toml', 'setup.py'}),
  812. })
  813. <
  814. See |vim.lsp.ClientConfig| for all available options. The most important
  815. are:
  816. • `name` arbitrary name for the LSP client. Should be unique per language
  817. server.
  818. • `cmd` command string[] or function.
  819. • `root_dir` path to the project root. By default this is used to decide
  820. if an existing client should be re-used. The example above uses
  821. |vim.fs.root()| to detect the root by traversing the file system upwards
  822. starting from the current directory until either a `pyproject.toml` or
  823. `setup.py` file is found.
  824. • `workspace_folders` list of `{ uri:string, name: string }` tables
  825. specifying the project root folders used by the language server. If
  826. `nil` the property is derived from `root_dir` for convenience.
  827. Language servers use this information to discover metadata like the
  828. dependencies of your project and they tend to index the contents within
  829. the project folder.
  830. To ensure a language server is only started for languages it can handle,
  831. make sure to call |vim.lsp.start()| within a |FileType| autocmd. Either
  832. use |:au|, |nvim_create_autocmd()| or put the call in a
  833. `ftplugin/<filetype_name>.lua` (See |ftplugin-name|)
  834. Parameters: ~
  835. • {config} (`vim.lsp.ClientConfig`) Configuration for the server. See
  836. |vim.lsp.ClientConfig|.
  837. • {opts} (`table?`) Optional keyword arguments.
  838. • {reuse_client}?
  839. (`fun(client: vim.lsp.Client, config: vim.lsp.ClientConfig): boolean`)
  840. Predicate used to decide if a client should be re-used.
  841. Used on all running clients. The default implementation
  842. re-uses a client if it has the same name and if the given
  843. workspace folders (or root_dir) are all included in the
  844. client's workspace folders.
  845. • {bufnr}? (`integer`) Buffer handle to attach to if
  846. starting or re-using a client (0 for current).
  847. • {attach}? (`boolean`) Whether to attach the client to a
  848. buffer (default true). If set to `false`, `reuse_client`
  849. and `bufnr` will be ignored.
  850. • {silent}? (`boolean`) Suppress error reporting if the LSP
  851. server fails to start (default false).
  852. Return: ~
  853. (`integer?`) client_id
  854. status() *vim.lsp.status()*
  855. Consumes the latest progress messages from all clients and formats them as
  856. a string. Empty if there are no clients or if no new messages
  857. Return: ~
  858. (`string`)
  859. stop_client({client_id}, {force}) *vim.lsp.stop_client()*
  860. Stops a client(s).
  861. You can also use the `stop()` function on a |vim.lsp.Client| object. To
  862. stop all clients: >lua
  863. vim.lsp.stop_client(vim.lsp.get_clients())
  864. <
  865. By default asks the server to shutdown, unless stop was requested already
  866. for this client, then force-shutdown is attempted.
  867. Parameters: ~
  868. • {client_id} (`integer|integer[]|vim.lsp.Client[]`) id, list of id's,
  869. or list of |vim.lsp.Client| objects
  870. • {force} (`boolean?`) shutdown forcefully
  871. tagfunc({pattern}, {flags}) *vim.lsp.tagfunc()*
  872. Provides an interface between the built-in client and 'tagfunc'.
  873. When used with normal mode commands (e.g. |CTRL-]|) this will invoke the
  874. "textDocument/definition" LSP method to find the tag under the cursor.
  875. Otherwise, uses "workspace/symbol". If no results are returned from any
  876. LSP servers, falls back to using built-in tags.
  877. Parameters: ~
  878. • {pattern} (`string`) Pattern used to find a workspace symbol
  879. • {flags} (`string`) See |tag-function|
  880. Return: ~
  881. (`table[]`) tags A list of matching tags
  882. ==============================================================================
  883. Lua module: vim.lsp.client *lsp-client*
  884. *vim.lsp.Client*
  885. Fields: ~
  886. • {id} (`integer`) The id allocated to the client.
  887. • {name} (`string`) If a name is specified on creation,
  888. that will be used. Otherwise it is just the
  889. client id. This is used for logs and messages.
  890. • {rpc} (`vim.lsp.rpc.PublicClient`) RPC client
  891. object, for low level interaction with the
  892. client. See |vim.lsp.rpc.start()|.
  893. • {offset_encoding} (`string`) Called "position encoding" in LSP
  894. spec, the encoding used for communicating with
  895. the server. You can modify this in the
  896. `config`'s `on_init` method before text is
  897. sent to the server.
  898. • {handlers} (`table<string,lsp.Handler>`) The handlers
  899. used by the client as described in
  900. |lsp-handler|.
  901. • {requests} (`table<integer,{ type: string, bufnr: integer, method: string}?>`)
  902. The current pending requests in flight to the
  903. server. Entries are key-value pairs with the
  904. key being the request id while the value is a
  905. table with `type`, `bufnr`, and `method`
  906. key-value pairs. `type` is either "pending"
  907. for an active request, or "cancel" for a
  908. cancel request. It will be "complete"
  909. ephemerally while executing |LspRequest|
  910. autocmds when replies are received from the
  911. server.
  912. • {config} (`vim.lsp.ClientConfig`) copy of the table
  913. that was passed by the user to
  914. |vim.lsp.start()|. See |vim.lsp.ClientConfig|.
  915. • {server_capabilities} (`lsp.ServerCapabilities?`) Response from the
  916. server sent on `initialize` describing the
  917. server's capabilities.
  918. • {server_info} (`lsp.ServerInfo?`) Response from the server
  919. sent on `initialize` describing information
  920. about the server.
  921. • {progress} (`vim.lsp.Client.Progress`) A ring buffer
  922. (|vim.ringbuf()|) containing progress messages
  923. sent by the server. See
  924. |vim.lsp.Client.Progress|.
  925. • {initialized} (`true?`)
  926. • {workspace_folders} (`lsp.WorkspaceFolder[]?`) The workspace
  927. folders configured in the client when the
  928. server starts. This property is only available
  929. if the client supports workspace folders. It
  930. can be `null` if the client supports workspace
  931. folders but none are configured.
  932. • {root_dir} (`string?`)
  933. • {attached_buffers} (`table<integer,true>`)
  934. • {commands} (`table<string,fun(command: lsp.Command, ctx: table)>`)
  935. Table of command name to function which is
  936. called if any LSP action (code action, code
  937. lenses, ...) triggers the command. Client
  938. commands take precedence over the global
  939. command registry.
  940. • {settings} (`lsp.LSPObject`) Map with language server
  941. specific settings. These are returned to the
  942. language server if requested via
  943. `workspace/configuration`. Keys are
  944. case-sensitive.
  945. • {flags} (`table`) A table with flags for the client.
  946. The current (experimental) flags are:
  947. • {allow_incremental_sync}? (`boolean`,
  948. default: `true`) Allow using incremental
  949. sync for buffer edits
  950. • {debounce_text_changes} (`integer`, default:
  951. `150`) Debounce `didChange` notifications to
  952. the server by the given number in
  953. milliseconds. No debounce occurs if `nil`.
  954. • {exit_timeout} (`integer|false`, default:
  955. `false`) Milliseconds to wait for server to
  956. exit cleanly after sending the "shutdown"
  957. request before sending kill -15. If set to
  958. false, nvim exits immediately after sending
  959. the "shutdown" request to the server.
  960. • {get_language_id} (`fun(bufnr: integer, filetype: string): string`)
  961. • {capabilities} (`lsp.ClientCapabilities`) The capabilities
  962. provided by the client (editor or tool)
  963. • {dynamic_capabilities} (`lsp.DynamicCapabilities`)
  964. • {request} (`fun(self: vim.lsp.Client, method: string, params: table?, handler: lsp.Handler?, bufnr: integer?): boolean, integer?`)
  965. See |Client:request()|.
  966. • {request_sync} (`fun(self: vim.lsp.Client, method: string, params: table, timeout_ms: integer?, bufnr: integer?): {err: lsp.ResponseError?, result:any}?, string?`)
  967. See |Client:request_sync()|.
  968. • {notify} (`fun(self: vim.lsp.Client, method: string, params: table?): boolean`)
  969. See |Client:notify()|.
  970. • {cancel_request} (`fun(self: vim.lsp.Client, id: integer): boolean`)
  971. See |Client:cancel_request()|.
  972. • {stop} (`fun(self: vim.lsp.Client, force: boolean?)`)
  973. See |Client:stop()|.
  974. • {is_stopped} (`fun(self: vim.lsp.Client): boolean`) See
  975. |Client:is_stopped()|.
  976. • {exec_cmd} (`fun(self: vim.lsp.Client, command: lsp.Command, context: {bufnr?: integer}?, handler: lsp.Handler?)`)
  977. See |Client:exec_cmd()|.
  978. • {on_attach} (`fun(self: vim.lsp.Client, bufnr: integer)`)
  979. See |Client:on_attach()|.
  980. • {supports_method} (`fun(self: vim.lsp.Client, method: string, bufnr: integer?)`)
  981. See |Client:supports_method()|.
  982. *vim.lsp.Client.Progress*
  983. Extends: |vim.Ringbuf|
  984. Fields: ~
  985. • {pending} (`table<lsp.ProgressToken,lsp.LSPAny>`)
  986. *vim.lsp.ClientConfig*
  987. Fields: ~
  988. • {cmd} (`string[]|fun(dispatchers: vim.lsp.rpc.Dispatchers): vim.lsp.rpc.PublicClient`)
  989. command string[] that launches the language
  990. server (treated as in |jobstart()|, must be
  991. absolute or on `$PATH`, shell constructs like
  992. "~" are not expanded), or function that creates
  993. an RPC client. Function receives a `dispatchers`
  994. table and returns a table with member functions
  995. `request`, `notify`, `is_closing` and
  996. `terminate`. See |vim.lsp.rpc.request()|,
  997. |vim.lsp.rpc.notify()|. For TCP there is a
  998. builtin RPC client factory:
  999. |vim.lsp.rpc.connect()|
  1000. • {cmd_cwd}? (`string`, default: cwd) Directory to launch the
  1001. `cmd` process. Not related to `root_dir`.
  1002. • {cmd_env}? (`table`) Environment flags to pass to the LSP
  1003. on spawn. Must be specified using a table.
  1004. Non-string values are coerced to string.
  1005. Example: >lua
  1006. { PORT = 8080; HOST = "0.0.0.0"; }
  1007. <
  1008. • {detached}? (`boolean`, default: true) Daemonize the server
  1009. process so that it runs in a separate process
  1010. group from Nvim. Nvim will shutdown the process
  1011. on exit, but if Nvim fails to exit cleanly this
  1012. could leave behind orphaned server processes.
  1013. • {workspace_folders}? (`lsp.WorkspaceFolder[]`) List of workspace
  1014. folders passed to the language server. For
  1015. backwards compatibility rootUri and rootPath
  1016. will be derived from the first workspace folder
  1017. in this list. See `workspaceFolders` in the LSP
  1018. spec.
  1019. • {capabilities}? (`lsp.ClientCapabilities`) Map overriding the
  1020. default capabilities defined by
  1021. |vim.lsp.protocol.make_client_capabilities()|,
  1022. passed to the language server on initialization.
  1023. Hint: use make_client_capabilities() and modify
  1024. its result.
  1025. • Note: To send an empty dictionary use
  1026. |vim.empty_dict()|, else it will be encoded as
  1027. an array.
  1028. • {handlers}? (`table<string,function>`) Map of language
  1029. server method names to |lsp-handler|
  1030. • {settings}? (`lsp.LSPObject`) Map with language server
  1031. specific settings. See the {settings} in
  1032. |vim.lsp.Client|.
  1033. • {commands}? (`table<string,fun(command: lsp.Command, ctx: table)>`)
  1034. Table that maps string of clientside commands to
  1035. user-defined functions. Commands passed to
  1036. `start()` take precedence over the global
  1037. command registry. Each key must be a unique
  1038. command name, and the value is a function which
  1039. is called if any LSP action (code action, code
  1040. lenses, ...) triggers the command.
  1041. • {init_options}? (`lsp.LSPObject`) Values to pass in the
  1042. initialization request as
  1043. `initializationOptions`. See `initialize` in the
  1044. LSP spec.
  1045. • {name}? (`string`, default: client-id) Name in log
  1046. messages.
  1047. • {get_language_id}? (`fun(bufnr: integer, filetype: string): string`)
  1048. Language ID as string. Defaults to the buffer
  1049. filetype.
  1050. • {offset_encoding}? (`'utf-8'|'utf-16'|'utf-32'`) Called "position
  1051. encoding" in LSP spec, the encoding that the LSP
  1052. server expects. Client does not verify this is
  1053. correct.
  1054. • {on_error}? (`fun(code: integer, err: string)`) Callback
  1055. invoked when the client operation throws an
  1056. error. `code` is a number describing the error.
  1057. Other arguments may be passed depending on the
  1058. error kind. See `vim.lsp.rpc.client_errors` for
  1059. possible errors. Use
  1060. `vim.lsp.rpc.client_errors[code]` to get
  1061. human-friendly name.
  1062. • {before_init}? (`fun(params: lsp.InitializeParams, config: vim.lsp.ClientConfig)`)
  1063. Callback invoked before the LSP "initialize"
  1064. phase, where `params` contains the parameters
  1065. being sent to the server and `config` is the
  1066. config that was passed to |vim.lsp.start()|. You
  1067. can use this to modify parameters before they
  1068. are sent.
  1069. • {on_init}? (`elem_or_list<fun(client: vim.lsp.Client, initialize_result: lsp.InitializeResult)>`)
  1070. Callback invoked after LSP "initialize", where
  1071. `result` is a table of `capabilities` and
  1072. anything else the server may send. For example,
  1073. clangd sends `initialize_result.offsetEncoding`
  1074. if `capabilities.offsetEncoding` was sent to it.
  1075. You can only modify the `client.offset_encoding`
  1076. here before any notifications are sent.
  1077. • {on_exit}? (`elem_or_list<fun(code: integer, signal: integer, client_id: integer)>`)
  1078. Callback invoked on client exit.
  1079. • code: exit code of the process
  1080. • signal: number describing the signal used to
  1081. terminate (if any)
  1082. • client_id: client handle
  1083. • {on_attach}? (`elem_or_list<fun(client: vim.lsp.Client, bufnr: integer)>`)
  1084. Callback invoked when client attaches to a
  1085. buffer.
  1086. • {trace}? (`'off'|'messages'|'verbose'`, default: "off")
  1087. Passed directly to the language server in the
  1088. initialize request. Invalid/empty values will
  1089. • {flags}? (`table`) A table with flags for the client. The
  1090. current (experimental) flags are:
  1091. • {allow_incremental_sync}? (`boolean`, default:
  1092. `true`) Allow using incremental sync for
  1093. buffer edits
  1094. • {debounce_text_changes} (`integer`, default:
  1095. `150`) Debounce `didChange` notifications to
  1096. the server by the given number in
  1097. milliseconds. No debounce occurs if `nil`.
  1098. • {exit_timeout} (`integer|false`, default:
  1099. `false`) Milliseconds to wait for server to
  1100. exit cleanly after sending the "shutdown"
  1101. request before sending kill -15. If set to
  1102. false, nvim exits immediately after sending
  1103. the "shutdown" request to the server.
  1104. • {root_dir}? (`string`) Directory where the LSP server will
  1105. base its workspaceFolders, rootUri, and rootPath
  1106. on initialization.
  1107. Client:cancel_request({id}) *Client:cancel_request()*
  1108. Cancels a request with a given request id.
  1109. Parameters: ~
  1110. • {id} (`integer`) id of request to cancel
  1111. Return: ~
  1112. (`boolean`) status indicating if the notification was successful.
  1113. See also: ~
  1114. • |Client:notify()|
  1115. Client:exec_cmd({command}, {context}, {handler}) *Client:exec_cmd()*
  1116. Execute a lsp command, either via client command function (if available)
  1117. or via workspace/executeCommand (if supported by the server)
  1118. Parameters: ~
  1119. • {command} (`lsp.Command`)
  1120. • {context} (`{bufnr?: integer}?`)
  1121. • {handler} (`lsp.Handler?`) only called if a server command
  1122. Client:is_stopped() *Client:is_stopped()*
  1123. Checks whether a client is stopped.
  1124. Return: ~
  1125. (`boolean`) true if client is stopped or in the process of being
  1126. stopped; false otherwise
  1127. Client:notify({method}, {params}) *Client:notify()*
  1128. Sends a notification to an LSP server.
  1129. Parameters: ~
  1130. • {method} (`string`) LSP method name.
  1131. • {params} (`table?`) LSP request params.
  1132. Return: ~
  1133. (`boolean`) status indicating if the notification was successful. If
  1134. it is false, then the client has shutdown.
  1135. Client:on_attach({bufnr}) *Client:on_attach()*
  1136. Runs the on_attach function from the client's config if it was defined.
  1137. Useful for buffer-local setup.
  1138. Parameters: ~
  1139. • {bufnr} (`integer`) Buffer number
  1140. *Client:request()*
  1141. Client:request({method}, {params}, {handler}, {bufnr})
  1142. Sends a request to the server.
  1143. This is a thin wrapper around {client.rpc.request} with some additional
  1144. checks for capabilities and handler availability.
  1145. Parameters: ~
  1146. • {method} (`string`) LSP method name.
  1147. • {params} (`table?`) LSP request params.
  1148. • {handler} (`lsp.Handler?`) Response |lsp-handler| for this method.
  1149. • {bufnr} (`integer?`) (default: 0) Buffer handle, or 0 for current.
  1150. Return (multiple): ~
  1151. (`boolean`) status indicates whether the request was successful. If it
  1152. is `false`, then it will always be `false` (the client has shutdown).
  1153. (`integer?`) request_id Can be used with |Client:cancel_request()|.
  1154. `nil` is request failed.
  1155. See also: ~
  1156. • |vim.lsp.buf_request_all()|
  1157. *Client:request_sync()*
  1158. Client:request_sync({method}, {params}, {timeout_ms}, {bufnr})
  1159. Sends a request to the server and synchronously waits for the response.
  1160. This is a wrapper around |Client:request()|
  1161. Parameters: ~
  1162. • {method} (`string`) LSP method name.
  1163. • {params} (`table`) LSP request params.
  1164. • {timeout_ms} (`integer?`) Maximum time in milliseconds to wait for a
  1165. result. Defaults to 1000
  1166. • {bufnr} (`integer?`) (default: 0) Buffer handle, or 0 for
  1167. current.
  1168. Return (multiple): ~
  1169. (`{err: lsp.ResponseError?, result:any}?`) `result` and `err` from the
  1170. |lsp-handler|. `nil` is the request was unsuccessful
  1171. (`string?`) err On timeout, cancel or error, where `err` is a string
  1172. describing the failure reason.
  1173. See also: ~
  1174. • |vim.lsp.buf_request_sync()|
  1175. Client:stop({force}) *Client:stop()*
  1176. Stops a client, optionally with force.
  1177. By default, it will just request the server to shutdown without force. If
  1178. you request to stop a client which has previously been requested to
  1179. shutdown, it will automatically escalate and force shutdown.
  1180. Parameters: ~
  1181. • {force} (`boolean?`)
  1182. Client:supports_method({method}, {bufnr}) *Client:supports_method()*
  1183. Checks if a client supports a given method. Always returns true for
  1184. unknown off-spec methods.
  1185. Note: Some language server capabilities can be file specific.
  1186. Parameters: ~
  1187. • {method} (`string`)
  1188. • {bufnr} (`integer?`)
  1189. ==============================================================================
  1190. Lua module: vim.lsp.buf *lsp-buf*
  1191. *vim.lsp.ListOpts*
  1192. Fields: ~
  1193. • {on_list}? (`fun(t: vim.lsp.LocationOpts.OnList)`) list-handler
  1194. replacing the default handler. Called for any non-empty
  1195. result. This table can be used with |setqflist()| or
  1196. |setloclist()|. E.g.: >lua
  1197. local function on_list(options)
  1198. vim.fn.setqflist({}, ' ', options)
  1199. vim.cmd.cfirst()
  1200. end
  1201. vim.lsp.buf.definition({ on_list = on_list })
  1202. vim.lsp.buf.references(nil, { on_list = on_list })
  1203. <
  1204. • {loclist}? (`boolean`) Whether to use the |location-list| or the
  1205. |quickfix| list. >lua
  1206. vim.lsp.buf.definition({ loclist = true })
  1207. vim.lsp.buf.references(nil, { loclist = false })
  1208. <
  1209. *vim.lsp.LocationOpts*
  1210. Extends: |vim.lsp.ListOpts|
  1211. Fields: ~
  1212. • {reuse_win}? (`boolean`) Jump to existing window if buffer is already
  1213. open.
  1214. *vim.lsp.LocationOpts.OnList*
  1215. Fields: ~
  1216. • {items} (`table[]`) Structured like |setqflist-what|
  1217. • {title}? (`string`) Title for the list.
  1218. • {context}? (`table`) `ctx` from |lsp-handler|
  1219. *vim.lsp.buf.hover.Opts*
  1220. Extends: |vim.lsp.util.open_floating_preview.Opts|
  1221. Fields: ~
  1222. • {silent}? (`boolean`)
  1223. *vim.lsp.buf.signature_help.Opts*
  1224. Extends: |vim.lsp.util.open_floating_preview.Opts|
  1225. Fields: ~
  1226. • {silent}? (`boolean`)
  1227. *vim.lsp.buf.add_workspace_folder()*
  1228. add_workspace_folder({workspace_folder})
  1229. Add the folder at path to the workspace folders. If {path} is not
  1230. provided, the user will be prompted for a path using |input()|.
  1231. Parameters: ~
  1232. • {workspace_folder} (`string?`)
  1233. clear_references() *vim.lsp.buf.clear_references()*
  1234. Removes document highlights from current buffer.
  1235. code_action({opts}) *vim.lsp.buf.code_action()*
  1236. Selects a code action available at the current cursor position.
  1237. Parameters: ~
  1238. • {opts} (`table?`) A table with the following fields:
  1239. • {context}? (`lsp.CodeActionContext`) Corresponds to
  1240. `CodeActionContext` of the LSP specification:
  1241. • {diagnostics}? (`table`) LSP `Diagnostic[]`. Inferred from
  1242. the current position if not provided.
  1243. • {only}? (`table`) List of LSP `CodeActionKind`s used to
  1244. filter the code actions. Most language servers support
  1245. values like `refactor` or `quickfix`.
  1246. • {triggerKind}? (`integer`) The reason why code actions
  1247. were requested.
  1248. • {filter}? (`fun(x: lsp.CodeAction|lsp.Command):boolean`)
  1249. Predicate taking an `CodeAction` and returning a boolean.
  1250. • {apply}? (`boolean`) When set to `true`, and there is just
  1251. one remaining action (after filtering), the action is
  1252. applied without user query.
  1253. • {range}? (`{start: integer[], end: integer[]}`) Range for
  1254. which code actions should be requested. If in visual mode
  1255. this defaults to the active selection. Table must contain
  1256. `start` and `end` keys with {row,col} tuples using mark-like
  1257. indexing. See |api-indexing|
  1258. See also: ~
  1259. • https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_codeAction
  1260. • vim.lsp.protocol.CodeActionTriggerKind
  1261. declaration({opts}) *vim.lsp.buf.declaration()*
  1262. Jumps to the declaration of the symbol under the cursor.
  1263. Note: ~
  1264. • Many servers do not implement this method. Generally, see
  1265. |vim.lsp.buf.definition()| instead.
  1266. Parameters: ~
  1267. • {opts} (`vim.lsp.LocationOpts?`) See |vim.lsp.LocationOpts|.
  1268. definition({opts}) *vim.lsp.buf.definition()*
  1269. Jumps to the definition of the symbol under the cursor.
  1270. Parameters: ~
  1271. • {opts} (`vim.lsp.LocationOpts?`) See |vim.lsp.LocationOpts|.
  1272. document_highlight() *vim.lsp.buf.document_highlight()*
  1273. Send request to the server to resolve document highlights for the current
  1274. text document position. This request can be triggered by a key mapping or
  1275. by events such as `CursorHold`, e.g.: >vim
  1276. autocmd CursorHold <buffer> lua vim.lsp.buf.document_highlight()
  1277. autocmd CursorHoldI <buffer> lua vim.lsp.buf.document_highlight()
  1278. autocmd CursorMoved <buffer> lua vim.lsp.buf.clear_references()
  1279. <
  1280. Note: Usage of |vim.lsp.buf.document_highlight()| requires the following
  1281. highlight groups to be defined or you won't be able to see the actual
  1282. highlights. |hl-LspReferenceText| |hl-LspReferenceRead|
  1283. |hl-LspReferenceWrite|
  1284. document_symbol({opts}) *vim.lsp.buf.document_symbol()*
  1285. Lists all symbols in the current buffer in the |location-list|.
  1286. Parameters: ~
  1287. • {opts} (`vim.lsp.ListOpts?`) See |vim.lsp.ListOpts|.
  1288. format({opts}) *vim.lsp.buf.format()*
  1289. Formats a buffer using the attached (and optionally filtered) language
  1290. server clients.
  1291. Parameters: ~
  1292. • {opts} (`table?`) A table with the following fields:
  1293. • {formatting_options}? (`table`) Can be used to specify
  1294. FormattingOptions. Some unspecified options will be
  1295. automatically derived from the current Nvim options. See
  1296. https://microsoft.github.io/language-server-protocol/specification/#formattingOptions
  1297. • {timeout_ms}? (`integer`, default: `1000`) Time in
  1298. milliseconds to block for formatting requests. No effect if
  1299. async=true.
  1300. • {bufnr}? (`integer`, default: current buffer) Restrict
  1301. formatting to the clients attached to the given buffer.
  1302. • {filter}? (`fun(client: vim.lsp.Client): boolean?`)
  1303. Predicate used to filter clients. Receives a client as
  1304. argument and must return a boolean. Clients matching the
  1305. predicate are included. Example: >lua
  1306. -- Never request typescript-language-server for formatting
  1307. vim.lsp.buf.format {
  1308. filter = function(client) return client.name ~= "ts_ls" end
  1309. }
  1310. <
  1311. • {async}? (`boolean`, default: false) If true the method
  1312. won't block. Editing the buffer while formatting
  1313. asynchronous can lead to unexpected changes.
  1314. • {id}? (`integer`) Restrict formatting to the client with ID
  1315. (client.id) matching this field.
  1316. • {name}? (`string`) Restrict formatting to the client with
  1317. name (client.name) matching this field.
  1318. • {range}?
  1319. (`{start:[integer,integer],end:[integer, integer]}|{start:[integer,integer],end:[integer,integer]}[]`,
  1320. default: current selection in visual mode, `nil` in other
  1321. modes, formatting the full buffer) Range to format. Table
  1322. must contain `start` and `end` keys with {row,col} tuples
  1323. using (1,0) indexing. Can also be a list of tables that
  1324. contain `start` and `end` keys as described above, in which
  1325. case `textDocument/rangesFormatting` support is required.
  1326. hover({config}) *vim.lsp.buf.hover()*
  1327. Displays hover information about the symbol under the cursor in a floating
  1328. window. The window will be dismissed on cursor move. Calling the function
  1329. twice will jump into the floating window (thus by default, "KK" will open
  1330. the hover window and focus it). In the floating window, all commands and
  1331. mappings are available as usual, except that "q" dismisses the window. You
  1332. can scroll the contents the same as you would any other buffer.
  1333. Note: to disable hover highlights, add the following to your config: >lua
  1334. vim.api.nvim_create_autocmd('ColorScheme', {
  1335. callback = function()
  1336. vim.api.nvim_set_hl(0, 'LspReferenceTarget', {})
  1337. end,
  1338. })
  1339. <
  1340. Parameters: ~
  1341. • {config} (`vim.lsp.buf.hover.Opts?`) See |vim.lsp.buf.hover.Opts|.
  1342. implementation({opts}) *vim.lsp.buf.implementation()*
  1343. Lists all the implementations for the symbol under the cursor in the
  1344. quickfix window.
  1345. Parameters: ~
  1346. • {opts} (`vim.lsp.LocationOpts?`) See |vim.lsp.LocationOpts|.
  1347. incoming_calls() *vim.lsp.buf.incoming_calls()*
  1348. Lists all the call sites of the symbol under the cursor in the |quickfix|
  1349. window. If the symbol can resolve to multiple items, the user can pick one
  1350. in the |inputlist()|.
  1351. list_workspace_folders() *vim.lsp.buf.list_workspace_folders()*
  1352. List workspace folders.
  1353. outgoing_calls() *vim.lsp.buf.outgoing_calls()*
  1354. Lists all the items that are called by the symbol under the cursor in the
  1355. |quickfix| window. If the symbol can resolve to multiple items, the user
  1356. can pick one in the |inputlist()|.
  1357. references({context}, {opts}) *vim.lsp.buf.references()*
  1358. Lists all the references to the symbol under the cursor in the quickfix
  1359. window.
  1360. Parameters: ~
  1361. • {context} (`lsp.ReferenceContext?`) Context for the request
  1362. • {opts} (`vim.lsp.ListOpts?`) See |vim.lsp.ListOpts|.
  1363. See also: ~
  1364. • https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_references
  1365. *vim.lsp.buf.remove_workspace_folder()*
  1366. remove_workspace_folder({workspace_folder})
  1367. Remove the folder at path from the workspace folders. If {path} is not
  1368. provided, the user will be prompted for a path using |input()|.
  1369. Parameters: ~
  1370. • {workspace_folder} (`string?`)
  1371. rename({new_name}, {opts}) *vim.lsp.buf.rename()*
  1372. Renames all references to the symbol under the cursor.
  1373. Parameters: ~
  1374. • {new_name} (`string?`) If not provided, the user will be prompted for
  1375. a new name using |vim.ui.input()|.
  1376. • {opts} (`table?`) Additional options:
  1377. • {filter}? (`fun(client: vim.lsp.Client): boolean?`)
  1378. Predicate used to filter clients. Receives a client as
  1379. argument and must return a boolean. Clients matching the
  1380. predicate are included.
  1381. • {name}? (`string`) Restrict clients used for rename to
  1382. ones where client.name matches this field.
  1383. • {bufnr}? (`integer`) (default: current buffer)
  1384. signature_help({config}) *vim.lsp.buf.signature_help()*
  1385. Displays signature information about the symbol under the cursor in a
  1386. floating window.
  1387. Parameters: ~
  1388. • {config} (`vim.lsp.buf.signature_help.Opts?`) See
  1389. |vim.lsp.buf.signature_help.Opts|.
  1390. type_definition({opts}) *vim.lsp.buf.type_definition()*
  1391. Jumps to the definition of the type of the symbol under the cursor.
  1392. Parameters: ~
  1393. • {opts} (`vim.lsp.LocationOpts?`) See |vim.lsp.LocationOpts|.
  1394. typehierarchy({kind}) *vim.lsp.buf.typehierarchy()*
  1395. Lists all the subtypes or supertypes of the symbol under the cursor in the
  1396. |quickfix| window. If the symbol can resolve to multiple items, the user
  1397. can pick one using |vim.ui.select()|.
  1398. Parameters: ~
  1399. • {kind} (`"subtypes"|"supertypes"`)
  1400. workspace_symbol({query}, {opts}) *vim.lsp.buf.workspace_symbol()*
  1401. Lists all symbols in the current workspace in the quickfix window.
  1402. The list is filtered against {query}; if the argument is omitted from the
  1403. call, the user is prompted to enter a string on the command line. An empty
  1404. string means no filtering is done.
  1405. Parameters: ~
  1406. • {query} (`string?`) optional
  1407. • {opts} (`vim.lsp.ListOpts?`) See |vim.lsp.ListOpts|.
  1408. ==============================================================================
  1409. Lua module: vim.lsp.diagnostic *lsp-diagnostic*
  1410. from({diagnostics}) *vim.lsp.diagnostic.from()*
  1411. Converts the input `vim.Diagnostic`s to LSP diagnostics.
  1412. Parameters: ~
  1413. • {diagnostics} (`vim.Diagnostic[]`)
  1414. Return: ~
  1415. (`lsp.Diagnostic[]`)
  1416. *vim.lsp.diagnostic.get_namespace()*
  1417. get_namespace({client_id}, {is_pull})
  1418. Get the diagnostic namespace associated with an LSP client
  1419. |vim.diagnostic| for diagnostics
  1420. Parameters: ~
  1421. • {client_id} (`integer`) The id of the LSP client
  1422. • {is_pull} (`boolean?`) Whether the namespace is for a pull or push
  1423. client. Defaults to push
  1424. *vim.lsp.diagnostic.on_diagnostic()*
  1425. on_diagnostic({error}, {result}, {ctx})
  1426. |lsp-handler| for the method "textDocument/diagnostic"
  1427. See |vim.diagnostic.config()| for configuration options.
  1428. Parameters: ~
  1429. • {error} (`lsp.ResponseError?`)
  1430. • {result} (`lsp.DocumentDiagnosticReport`)
  1431. • {ctx} (`lsp.HandlerContext`)
  1432. *vim.lsp.diagnostic.on_publish_diagnostics()*
  1433. on_publish_diagnostics({_}, {result}, {ctx})
  1434. |lsp-handler| for the method "textDocument/publishDiagnostics"
  1435. See |vim.diagnostic.config()| for configuration options.
  1436. Parameters: ~
  1437. • {result} (`lsp.PublishDiagnosticsParams`)
  1438. • {ctx} (`lsp.HandlerContext`)
  1439. ==============================================================================
  1440. Lua module: vim.lsp.codelens *lsp-codelens*
  1441. clear({client_id}, {bufnr}) *vim.lsp.codelens.clear()*
  1442. Clear the lenses
  1443. Parameters: ~
  1444. • {client_id} (`integer?`) filter by client_id. All clients if nil
  1445. • {bufnr} (`integer?`) filter by buffer. All buffers if nil, 0 for
  1446. current buffer
  1447. display({lenses}, {bufnr}, {client_id}) *vim.lsp.codelens.display()*
  1448. Display the lenses using virtual text
  1449. Parameters: ~
  1450. • {lenses} (`lsp.CodeLens[]?`) lenses to display
  1451. • {bufnr} (`integer`)
  1452. • {client_id} (`integer`)
  1453. get({bufnr}) *vim.lsp.codelens.get()*
  1454. Return all lenses for the given buffer
  1455. Parameters: ~
  1456. • {bufnr} (`integer`) Buffer number. 0 can be used for the current
  1457. buffer.
  1458. Return: ~
  1459. (`lsp.CodeLens[]`)
  1460. on_codelens({err}, {result}, {ctx}) *vim.lsp.codelens.on_codelens()*
  1461. |lsp-handler| for the method `textDocument/codeLens`
  1462. Parameters: ~
  1463. • {err} (`lsp.ResponseError?`)
  1464. • {result} (`lsp.CodeLens[]`)
  1465. • {ctx} (`lsp.HandlerContext`)
  1466. refresh({opts}) *vim.lsp.codelens.refresh()*
  1467. Refresh the lenses.
  1468. It is recommended to trigger this using an autocmd or via keymap.
  1469. Example: >vim
  1470. autocmd BufEnter,CursorHold,InsertLeave <buffer> lua vim.lsp.codelens.refresh({ bufnr = 0 })
  1471. <
  1472. Parameters: ~
  1473. • {opts} (`table?`) Optional fields
  1474. • {bufnr} (`integer?`) filter by buffer. All buffers if nil, 0
  1475. for current buffer
  1476. run() *vim.lsp.codelens.run()*
  1477. Run the code lens in the current line
  1478. save({lenses}, {bufnr}, {client_id}) *vim.lsp.codelens.save()*
  1479. Store lenses for a specific buffer and client
  1480. Parameters: ~
  1481. • {lenses} (`lsp.CodeLens[]?`) lenses to store
  1482. • {bufnr} (`integer`)
  1483. • {client_id} (`integer`)
  1484. ==============================================================================
  1485. Lua module: vim.lsp.completion *lsp-completion*
  1486. *vim.lsp.completion.BufferOpts*
  1487. Fields: ~
  1488. • {autotrigger}? (`boolean`) Default: false When true, completion
  1489. triggers automatically based on the server's
  1490. `triggerCharacters`.
  1491. • {convert}? (`fun(item: lsp.CompletionItem): table`) Transforms an
  1492. LSP CompletionItem to |complete-items|.
  1493. *vim.lsp.completion.enable()*
  1494. enable({enable}, {client_id}, {bufnr}, {opts})
  1495. Enables or disables completions from the given language client in the
  1496. given buffer.
  1497. Parameters: ~
  1498. • {enable} (`boolean`) True to enable, false to disable
  1499. • {client_id} (`integer`) Client ID
  1500. • {bufnr} (`integer`) Buffer handle, or 0 for the current buffer
  1501. • {opts} (`vim.lsp.completion.BufferOpts?`) See
  1502. |vim.lsp.completion.BufferOpts|.
  1503. trigger() *vim.lsp.completion.trigger()*
  1504. Trigger LSP completion in the current buffer.
  1505. ==============================================================================
  1506. Lua module: vim.lsp.inlay_hint *lsp-inlay_hint*
  1507. enable({enable}, {filter}) *vim.lsp.inlay_hint.enable()*
  1508. Enables or disables inlay hints for the {filter}ed scope.
  1509. To "toggle", pass the inverse of `is_enabled()`: >lua
  1510. vim.lsp.inlay_hint.enable(not vim.lsp.inlay_hint.is_enabled())
  1511. <
  1512. Attributes: ~
  1513. Since: 0.10.0
  1514. Parameters: ~
  1515. • {enable} (`boolean?`) true/nil to enable, false to disable
  1516. • {filter} (`table?`) Optional filters |kwargs|, or `nil` for all.
  1517. • {bufnr} (`integer?`) Buffer number, or 0 for current
  1518. buffer, or nil for all.
  1519. get({filter}) *vim.lsp.inlay_hint.get()*
  1520. Get the list of inlay hints, (optionally) restricted by buffer or range.
  1521. Example usage: >lua
  1522. local hint = vim.lsp.inlay_hint.get({ bufnr = 0 })[1] -- 0 for current buffer
  1523. local client = vim.lsp.get_client_by_id(hint.client_id)
  1524. local resp = client:request_sync('inlayHint/resolve', hint.inlay_hint, 100, 0)
  1525. local resolved_hint = assert(resp and resp.result, resp.err)
  1526. vim.lsp.util.apply_text_edits(resolved_hint.textEdits, 0, client.encoding)
  1527. location = resolved_hint.label[1].location
  1528. client:request('textDocument/hover', {
  1529. textDocument = { uri = location.uri },
  1530. position = location.range.start,
  1531. })
  1532. <
  1533. Attributes: ~
  1534. Since: 0.10.0
  1535. Parameters: ~
  1536. • {filter} (`table?`) Optional filters |kwargs|:
  1537. • {bufnr} (`integer?`)
  1538. • {range} (`lsp.Range?`)
  1539. Return: ~
  1540. (`table[]`) A list of objects with the following fields:
  1541. • {bufnr} (`integer`)
  1542. • {client_id} (`integer`)
  1543. • {inlay_hint} (`lsp.InlayHint`)
  1544. is_enabled({filter}) *vim.lsp.inlay_hint.is_enabled()*
  1545. Query whether inlay hint is enabled in the {filter}ed scope
  1546. Attributes: ~
  1547. Since: 0.10.0
  1548. Parameters: ~
  1549. • {filter} (`table?`) Optional filters |kwargs|, or `nil` for all.
  1550. • {bufnr} (`integer?`) Buffer number, or 0 for current
  1551. buffer, or nil for all.
  1552. Return: ~
  1553. (`boolean`)
  1554. ==============================================================================
  1555. Lua module: vim.lsp.semantic_tokens *lsp-semantic_tokens*
  1556. force_refresh({bufnr}) *vim.lsp.semantic_tokens.force_refresh()*
  1557. Force a refresh of all semantic tokens
  1558. Only has an effect if the buffer is currently active for semantic token
  1559. highlighting (|vim.lsp.semantic_tokens.start()| has been called for it)
  1560. Parameters: ~
  1561. • {bufnr} (`integer?`) filter by buffer. All buffers if nil, current
  1562. buffer if 0
  1563. *vim.lsp.semantic_tokens.get_at_pos()*
  1564. get_at_pos({bufnr}, {row}, {col})
  1565. Return the semantic token(s) at the given position. If called without
  1566. arguments, returns the token under the cursor.
  1567. Parameters: ~
  1568. • {bufnr} (`integer?`) Buffer number (0 for current buffer, default)
  1569. • {row} (`integer?`) Position row (default cursor position)
  1570. • {col} (`integer?`) Position column (default cursor position)
  1571. Return: ~
  1572. (`table?`) List of tokens at position. Each token has the following
  1573. fields:
  1574. • line (integer) line number, 0-based
  1575. • start_col (integer) start column, 0-based
  1576. • end_col (integer) end column, 0-based
  1577. • type (string) token type as string, e.g. "variable"
  1578. • modifiers (table) token modifiers as a set. E.g., { static = true,
  1579. readonly = true }
  1580. • client_id (integer)
  1581. *vim.lsp.semantic_tokens.highlight_token()*
  1582. highlight_token({token}, {bufnr}, {client_id}, {hl_group}, {opts})
  1583. Highlight a semantic token.
  1584. Apply an extmark with a given highlight group for a semantic token. The
  1585. mark will be deleted by the semantic token engine when appropriate; for
  1586. example, when the LSP sends updated tokens. This function is intended for
  1587. use inside |LspTokenUpdate| callbacks.
  1588. Parameters: ~
  1589. • {token} (`table`) A semantic token, found as `args.data.token` in
  1590. |LspTokenUpdate|
  1591. • {bufnr} (`integer`) The buffer to highlight, or `0` for current
  1592. buffer
  1593. • {client_id} (`integer`) The ID of the |vim.lsp.Client|
  1594. • {hl_group} (`string`) Highlight group name
  1595. • {opts} (`table?`) Optional parameters:
  1596. • {priority}? (`integer`, default:
  1597. `vim.hl.priorities.semantic_tokens + 3`) Priority for
  1598. the applied extmark.
  1599. start({bufnr}, {client_id}, {opts}) *vim.lsp.semantic_tokens.start()*
  1600. Start the semantic token highlighting engine for the given buffer with the
  1601. given client. The client must already be attached to the buffer.
  1602. NOTE: This is currently called automatically by
  1603. |vim.lsp.buf_attach_client()|. To opt-out of semantic highlighting with a
  1604. server that supports it, you can delete the semanticTokensProvider table
  1605. from the {server_capabilities} of your client in your |LspAttach| callback
  1606. or your configuration's `on_attach` callback: >lua
  1607. client.server_capabilities.semanticTokensProvider = nil
  1608. <
  1609. Parameters: ~
  1610. • {bufnr} (`integer`) Buffer number, or `0` for current buffer
  1611. • {client_id} (`integer`) The ID of the |vim.lsp.Client|
  1612. • {opts} (`table?`) Optional keyword arguments
  1613. • debounce (integer, default: 200): Debounce token
  1614. requests to the server by the given number in
  1615. milliseconds
  1616. stop({bufnr}, {client_id}) *vim.lsp.semantic_tokens.stop()*
  1617. Stop the semantic token highlighting engine for the given buffer with the
  1618. given client.
  1619. NOTE: This is automatically called by a |LspDetach| autocmd that is set up
  1620. as part of `start()`, so you should only need this function to manually
  1621. disengage the semantic token engine without fully detaching the LSP client
  1622. from the buffer.
  1623. Parameters: ~
  1624. • {bufnr} (`integer`) Buffer number, or `0` for current buffer
  1625. • {client_id} (`integer`) The ID of the |vim.lsp.Client|
  1626. ==============================================================================
  1627. Lua module: vim.lsp.util *lsp-util*
  1628. *vim.lsp.util.open_floating_preview.Opts*
  1629. Fields: ~
  1630. • {height}? (`integer`) Height of floating window
  1631. • {width}? (`integer`) Width of floating window
  1632. • {wrap}? (`boolean`, default: `true`) Wrap long lines
  1633. • {wrap_at}? (`integer`) Character to wrap at for computing height
  1634. when wrap is enabled
  1635. • {max_width}? (`integer`) Maximal width of floating window
  1636. • {max_height}? (`integer`) Maximal height of floating window
  1637. • {focus_id}? (`string`) If a popup with this id is opened, then
  1638. focus it
  1639. • {close_events}? (`table`) List of events that closes the floating
  1640. window
  1641. • {focusable}? (`boolean`, default: `true`) Make float focusable.
  1642. • {focus}? (`boolean`, default: `true`) If `true`, and if
  1643. {focusable} is also `true`, focus an existing
  1644. floating window with the same {focus_id}
  1645. • {offset_x}? (`integer`) offset to add to `col`
  1646. • {offset_y}? (`integer`) offset to add to `row`
  1647. • {border}? (`string|(string|[string,string])[]`) override
  1648. `border`
  1649. • {zindex}? (`integer`) override `zindex`, defaults to 50
  1650. • {title}? (`string`)
  1651. • {title_pos}? (`'left'|'center'|'right'`)
  1652. • {relative}? (`'mouse'|'cursor'|'editor'`) (default: `'cursor'`)
  1653. • {anchor_bias}? (`'auto'|'above'|'below'`, default: `'auto'`) -
  1654. "auto": place window based on which side of the
  1655. cursor has more lines
  1656. • "above": place the window above the cursor unless
  1657. there are not enough lines to display the full
  1658. window height.
  1659. • "below": place the window below the cursor unless
  1660. there are not enough lines to display the full
  1661. window height.
  1662. *vim.lsp.util.apply_text_document_edit()*
  1663. apply_text_document_edit({text_document_edit}, {index}, {position_encoding})
  1664. Applies a `TextDocumentEdit`, which is a list of changes to a single
  1665. document.
  1666. Parameters: ~
  1667. • {text_document_edit} (`lsp.TextDocumentEdit`)
  1668. • {index} (`integer?`) Optional index of the edit, if from
  1669. a list of edits (or nil, if not from a list)
  1670. • {position_encoding} (`'utf-8'|'utf-16'|'utf-32'?`)
  1671. See also: ~
  1672. • https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocumentEdit
  1673. *vim.lsp.util.apply_text_edits()*
  1674. apply_text_edits({text_edits}, {bufnr}, {position_encoding})
  1675. Applies a list of text edits to a buffer.
  1676. Parameters: ~
  1677. • {text_edits} (`lsp.TextEdit[]`)
  1678. • {bufnr} (`integer`) Buffer id
  1679. • {position_encoding} (`'utf-8'|'utf-16'|'utf-32'`)
  1680. See also: ~
  1681. • https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textEdit
  1682. *vim.lsp.util.apply_workspace_edit()*
  1683. apply_workspace_edit({workspace_edit}, {position_encoding})
  1684. Applies a `WorkspaceEdit`.
  1685. Parameters: ~
  1686. • {workspace_edit} (`lsp.WorkspaceEdit`)
  1687. • {position_encoding} (`'utf-8'|'utf-16'|'utf-32'`) (required)
  1688. See also: ~
  1689. • https://microsoft.github.io/language-server-protocol/specifications/specification-current/#workspace_applyEdit
  1690. buf_clear_references({bufnr}) *vim.lsp.util.buf_clear_references()*
  1691. Removes document highlights from a buffer.
  1692. Parameters: ~
  1693. • {bufnr} (`integer?`) Buffer id
  1694. *vim.lsp.util.buf_highlight_references()*
  1695. buf_highlight_references({bufnr}, {references}, {position_encoding})
  1696. Shows a list of document highlights for a certain buffer.
  1697. Parameters: ~
  1698. • {bufnr} (`integer`) Buffer id
  1699. • {references} (`lsp.DocumentHighlight[]`) objects to highlight
  1700. • {position_encoding} (`'utf-8'|'utf-16'|'utf-32'`)
  1701. See also: ~
  1702. • https://microsoft.github.io/language-server-protocol/specification/#textDocumentContentChangeEvent
  1703. *vim.lsp.util.character_offset()*
  1704. character_offset({buf}, {row}, {col}, {offset_encoding})
  1705. Returns the UTF-32 and UTF-16 offsets for a position in a certain buffer.
  1706. Parameters: ~
  1707. • {buf} (`integer`) buffer number (0 for current)
  1708. • {row} (`integer`) 0-indexed line
  1709. • {col} (`integer`) 0-indexed byte offset in line
  1710. • {offset_encoding} (`'utf-8'|'utf-16'|'utf-32'?`) defaults to
  1711. `offset_encoding` of first client of `buf`
  1712. Return: ~
  1713. (`integer`) `offset_encoding` index of the character in line {row}
  1714. column {col} in buffer {buf}
  1715. *vim.lsp.util.convert_input_to_markdown_lines()*
  1716. convert_input_to_markdown_lines({input}, {contents})
  1717. Converts any of `MarkedString` | `MarkedString[]` | `MarkupContent` into a
  1718. list of lines containing valid markdown. Useful to populate the hover
  1719. window for `textDocument/hover`, for parsing the result of
  1720. `textDocument/signatureHelp`, and potentially others.
  1721. Note that if the input is of type `MarkupContent` and its kind is
  1722. `plaintext`, then the corresponding value is returned without further
  1723. modifications.
  1724. Parameters: ~
  1725. • {input} (`lsp.MarkedString|lsp.MarkedString[]|lsp.MarkupContent`)
  1726. • {contents} (`string[]?`) List of strings to extend with converted
  1727. lines. Defaults to {}.
  1728. Return: ~
  1729. (`string[]`) extended with lines of converted markdown.
  1730. See also: ~
  1731. • https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_hover
  1732. *vim.lsp.util.convert_signature_help_to_markdown_lines()*
  1733. convert_signature_help_to_markdown_lines({signature_help}, {ft}, {triggers})
  1734. Converts `textDocument/signatureHelp` response to markdown lines.
  1735. Parameters: ~
  1736. • {signature_help} (`lsp.SignatureHelp`) Response of
  1737. `textDocument/SignatureHelp`
  1738. • {ft} (`string?`) filetype that will be use as the `lang`
  1739. for the label markdown code block
  1740. • {triggers} (`string[]?`) list of trigger characters from the
  1741. lsp server. used to better determine parameter
  1742. offsets
  1743. Return (multiple): ~
  1744. (`string[]?`) lines of converted markdown.
  1745. (`Range4?`) highlight range for the active parameter
  1746. See also: ~
  1747. • https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_signatureHelp
  1748. get_effective_tabstop({bufnr}) *vim.lsp.util.get_effective_tabstop()*
  1749. Returns indentation size.
  1750. Parameters: ~
  1751. • {bufnr} (`integer?`) Buffer handle, defaults to current
  1752. Return: ~
  1753. (`integer`) indentation size
  1754. See also: ~
  1755. • 'shiftwidth'
  1756. *vim.lsp.util.locations_to_items()*
  1757. locations_to_items({locations}, {position_encoding})
  1758. Returns the items with the byte position calculated correctly and in
  1759. sorted order, for display in quickfix and location lists.
  1760. The `user_data` field of each resulting item will contain the original
  1761. `Location` or `LocationLink` it was computed from.
  1762. The result can be passed to the {list} argument of |setqflist()| or
  1763. |setloclist()|.
  1764. Parameters: ~
  1765. • {locations} (`lsp.Location[]|lsp.LocationLink[]`)
  1766. • {position_encoding} (`'utf-8'|'utf-16'|'utf-32'?`) default to first
  1767. client of buffer
  1768. Return: ~
  1769. (`vim.quickfix.entry[]`) See |setqflist()| for the format
  1770. *vim.lsp.util.make_floating_popup_options()*
  1771. make_floating_popup_options({width}, {height}, {opts})
  1772. Creates a table with sensible default options for a floating window. The
  1773. table can be passed to |nvim_open_win()|.
  1774. Parameters: ~
  1775. • {width} (`integer`) window width (in character cells)
  1776. • {height} (`integer`) window height (in character cells)
  1777. • {opts} (`vim.lsp.util.open_floating_preview.Opts?`) See
  1778. |vim.lsp.util.open_floating_preview.Opts|.
  1779. Return: ~
  1780. (`vim.api.keyset.win_config`)
  1781. *vim.lsp.util.make_formatting_params()*
  1782. make_formatting_params({options})
  1783. Creates a `DocumentFormattingParams` object for the current buffer and
  1784. cursor position.
  1785. Parameters: ~
  1786. • {options} (`lsp.FormattingOptions?`) with valid `FormattingOptions`
  1787. entries
  1788. Return: ~
  1789. (`lsp.DocumentFormattingParams`) object
  1790. See also: ~
  1791. • https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_formatting
  1792. *vim.lsp.util.make_given_range_params()*
  1793. make_given_range_params({start_pos}, {end_pos}, {bufnr}, {position_encoding})
  1794. Using the given range in the current buffer, creates an object that is
  1795. similar to |vim.lsp.util.make_range_params()|.
  1796. Parameters: ~
  1797. • {start_pos} (`[integer,integer]?`) {row,col} mark-indexed
  1798. position. Defaults to the start of the last
  1799. visual selection.
  1800. • {end_pos} (`[integer,integer]?`) {row,col} mark-indexed
  1801. position. Defaults to the end of the last visual
  1802. selection.
  1803. • {bufnr} (`integer?`) buffer handle or 0 for current,
  1804. defaults to current
  1805. • {position_encoding} (`'utf-8'|'utf-16'|'utf-32'`)
  1806. Return: ~
  1807. (`{ textDocument: { uri: lsp.DocumentUri }, range: lsp.Range }`)
  1808. *vim.lsp.util.make_position_params()*
  1809. make_position_params({window}, {position_encoding})
  1810. Creates a `TextDocumentPositionParams` object for the current buffer and
  1811. cursor position.
  1812. Parameters: ~
  1813. • {window} (`integer?`) window handle or 0 for current,
  1814. defaults to current
  1815. • {position_encoding} (`'utf-8'|'utf-16'|'utf-32'`)
  1816. Return: ~
  1817. (`lsp.TextDocumentPositionParams`)
  1818. See also: ~
  1819. • https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocumentPositionParams
  1820. *vim.lsp.util.make_range_params()*
  1821. make_range_params({window}, {position_encoding})
  1822. Using the current position in the current buffer, creates an object that
  1823. can be used as a building block for several LSP requests, such as
  1824. `textDocument/codeAction`, `textDocument/colorPresentation`,
  1825. `textDocument/rangeFormatting`.
  1826. Parameters: ~
  1827. • {window} (`integer?`) window handle or 0 for current,
  1828. defaults to current
  1829. • {position_encoding} (`"utf-8"|"utf-16"|"utf-32"`)
  1830. Return: ~
  1831. (`{ textDocument: { uri: lsp.DocumentUri }, range: lsp.Range }`)
  1832. *vim.lsp.util.make_text_document_params()*
  1833. make_text_document_params({bufnr})
  1834. Creates a `TextDocumentIdentifier` object for the current buffer.
  1835. Parameters: ~
  1836. • {bufnr} (`integer?`) Buffer handle, defaults to current
  1837. Return: ~
  1838. (`lsp.TextDocumentIdentifier`)
  1839. See also: ~
  1840. • https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocumentIdentifier
  1841. *vim.lsp.util.make_workspace_params()*
  1842. make_workspace_params({added}, {removed})
  1843. Create the workspace params
  1844. Parameters: ~
  1845. • {added} (`lsp.WorkspaceFolder[]`)
  1846. • {removed} (`lsp.WorkspaceFolder[]`)
  1847. Return: ~
  1848. (`lsp.WorkspaceFoldersChangeEvent`)
  1849. *vim.lsp.util.open_floating_preview()*
  1850. open_floating_preview({contents}, {syntax}, {opts})
  1851. Shows contents in a floating window.
  1852. Parameters: ~
  1853. • {contents} (`table`) of lines to show in window
  1854. • {syntax} (`string`) of syntax to set for opened buffer
  1855. • {opts} (`vim.lsp.util.open_floating_preview.Opts?`) with optional
  1856. fields (additional keys are filtered with
  1857. |vim.lsp.util.make_floating_popup_options()| before they
  1858. are passed on to |nvim_open_win()|). See
  1859. |vim.lsp.util.open_floating_preview.Opts|.
  1860. Return (multiple): ~
  1861. (`integer`) bufnr of newly created float window
  1862. (`integer`) winid of newly created float window preview window
  1863. preview_location({location}, {opts}) *vim.lsp.util.preview_location()*
  1864. Previews a location in a floating window
  1865. behavior depends on type of location:
  1866. • for Location, range is shown (e.g., function definition)
  1867. • for LocationLink, targetRange is shown (e.g., body of function
  1868. definition)
  1869. Parameters: ~
  1870. • {location} (`lsp.Location|lsp.LocationLink`)
  1871. • {opts} (`vim.lsp.util.open_floating_preview.Opts?`) See
  1872. |vim.lsp.util.open_floating_preview.Opts|.
  1873. Return (multiple): ~
  1874. (`integer?`) buffer id of float window
  1875. (`integer?`) window id of float window
  1876. rename({old_fname}, {new_fname}, {opts}) *vim.lsp.util.rename()*
  1877. Rename old_fname to new_fname
  1878. Existing buffers are renamed as well, while maintaining their bufnr.
  1879. It deletes existing buffers that conflict with the renamed file name only
  1880. when
  1881. • `opts` requests overwriting; or
  1882. • the conflicting buffers are not loaded, so that deleting them does not
  1883. result in data loss.
  1884. Parameters: ~
  1885. • {old_fname} (`string`)
  1886. • {new_fname} (`string`)
  1887. • {opts} (`table?`) Options:
  1888. • {overwrite}? (`boolean`)
  1889. • {ignoreIfExists}? (`boolean`)
  1890. *vim.lsp.util.show_document()*
  1891. show_document({location}, {position_encoding}, {opts})
  1892. Shows document and optionally jumps to the location.
  1893. Parameters: ~
  1894. • {location} (`lsp.Location|lsp.LocationLink`)
  1895. • {position_encoding} (`'utf-8'|'utf-16'|'utf-32'?`)
  1896. • {opts} (`table?`) A table with the following fields:
  1897. • {reuse_win}? (`boolean`) Jump to existing
  1898. window if buffer is already open.
  1899. • {focus}? (`boolean`) Whether to focus/jump to
  1900. location if possible. (defaults: true)
  1901. Return: ~
  1902. (`boolean`) `true` if succeeded
  1903. *vim.lsp.util.stylize_markdown()*
  1904. stylize_markdown({bufnr}, {contents}, {opts})
  1905. Converts markdown into syntax highlighted regions by stripping the code
  1906. blocks and converting them into highlighted code. This will by default
  1907. insert a blank line separator after those code block regions to improve
  1908. readability.
  1909. This method configures the given buffer and returns the lines to set.
  1910. If you want to open a popup with fancy markdown, use
  1911. `open_floating_preview` instead
  1912. Parameters: ~
  1913. • {bufnr} (`integer`)
  1914. • {contents} (`string[]`) of lines to show in window
  1915. • {opts} (`table?`) with optional fields
  1916. • height of floating window
  1917. • width of floating window
  1918. • wrap_at character to wrap at for computing height
  1919. • max_width maximal width of floating window
  1920. • max_height maximal height of floating window
  1921. • separator insert separator after code block
  1922. Return: ~
  1923. (`table`) stripped content
  1924. symbols_to_items({symbols}, {bufnr}) *vim.lsp.util.symbols_to_items()*
  1925. Converts symbols to quickfix list items.
  1926. Parameters: ~
  1927. • {symbols} (`lsp.DocumentSymbol[]|lsp.SymbolInformation[]`)
  1928. • {bufnr} (`integer?`)
  1929. Return: ~
  1930. (`vim.quickfix.entry[]`) See |setqflist()| for the format
  1931. ==============================================================================
  1932. Lua module: vim.lsp.log *lsp-log*
  1933. get_filename() *vim.lsp.log.get_filename()*
  1934. Returns the log filename.
  1935. Return: ~
  1936. (`string`) log filename
  1937. get_level() *vim.lsp.log.get_level()*
  1938. Gets the current log level.
  1939. Return: ~
  1940. (`integer`) current log level
  1941. set_format_func({handle}) *vim.lsp.log.set_format_func()*
  1942. Sets formatting function used to format logs
  1943. Parameters: ~
  1944. • {handle} (`function`) function to apply to logging arguments, pass
  1945. vim.inspect for multi-line formatting
  1946. set_level({level}) *vim.lsp.log.set_level()*
  1947. Sets the current log level.
  1948. Parameters: ~
  1949. • {level} (`string|integer`) One of `vim.lsp.log.levels`
  1950. should_log({level}) *vim.lsp.log.should_log()*
  1951. Checks whether the level is sufficient for logging.
  1952. Parameters: ~
  1953. • {level} (`integer`) log level
  1954. Return: ~
  1955. (`boolean`) true if would log, false if not
  1956. ==============================================================================
  1957. Lua module: vim.lsp.rpc *lsp-rpc*
  1958. *vim.lsp.rpc.PublicClient*
  1959. Client RPC object
  1960. Fields: ~
  1961. • {request} (`fun(method: string, params: table?, callback: fun(err?: lsp.ResponseError, result: any), notify_reply_callback?: fun(message_id: integer)):boolean,integer?`)
  1962. See |vim.lsp.rpc.request()|
  1963. • {notify} (`fun(method: string, params: any): boolean`) See
  1964. |vim.lsp.rpc.notify()|
  1965. • {is_closing} (`fun(): boolean`) Indicates if the RPC is closing.
  1966. • {terminate} (`fun()`) Terminates the RPC client.
  1967. connect({host_or_path}, {port}) *vim.lsp.rpc.connect()*
  1968. Create a LSP RPC client factory that connects to either:
  1969. • a named pipe (windows)
  1970. • a domain socket (unix)
  1971. • a host and port via TCP
  1972. Return a function that can be passed to the `cmd` field for
  1973. |vim.lsp.start()|.
  1974. Parameters: ~
  1975. • {host_or_path} (`string`) host to connect to or path to a pipe/domain
  1976. socket
  1977. • {port} (`integer?`) TCP port to connect to. If absent the
  1978. first argument must be a pipe
  1979. Return: ~
  1980. (`fun(dispatchers: vim.lsp.rpc.Dispatchers): vim.lsp.rpc.PublicClient`)
  1981. format_rpc_error({err}) *vim.lsp.rpc.format_rpc_error()*
  1982. Constructs an error message from an LSP error object.
  1983. Parameters: ~
  1984. • {err} (`table`) The error object
  1985. Return: ~
  1986. (`string`) error_message The formatted error message
  1987. notify({method}, {params}) *vim.lsp.rpc.notify()*
  1988. Sends a notification to the LSP server.
  1989. Parameters: ~
  1990. • {method} (`string`) The invoked LSP method
  1991. • {params} (`table?`) Parameters for the invoked LSP method
  1992. Return: ~
  1993. (`boolean`) `true` if notification could be sent, `false` if not
  1994. *vim.lsp.rpc.request()*
  1995. request({method}, {params}, {callback}, {notify_reply_callback})
  1996. Sends a request to the LSP server and runs {callback} upon response.
  1997. Parameters: ~
  1998. • {method} (`string`) The invoked LSP method
  1999. • {params} (`table?`) Parameters for the invoked LSP
  2000. method
  2001. • {callback} (`fun(err: lsp.ResponseError?, result: any)`)
  2002. Callback to invoke
  2003. • {notify_reply_callback} (`fun(message_id: integer)?`) Callback to
  2004. invoke as soon as a request is no longer
  2005. pending
  2006. Return (multiple): ~
  2007. (`boolean`) success `true` if request could be sent, `false` if not
  2008. (`integer?`) message_id if request could be sent, `nil` if not
  2009. *vim.lsp.rpc.rpc_response_error()*
  2010. rpc_response_error({code}, {message}, {data})
  2011. Creates an RPC response table `error` to be sent to the LSP response.
  2012. Parameters: ~
  2013. • {code} (`integer`) RPC error code defined, see
  2014. `vim.lsp.protocol.ErrorCodes`
  2015. • {message} (`string?`) arbitrary message to send to server
  2016. • {data} (`any?`) arbitrary data to send to server
  2017. Return: ~
  2018. (`lsp.ResponseError`)
  2019. See also: ~
  2020. • lsp.ErrorCodes See `vim.lsp.protocol.ErrorCodes`
  2021. start({cmd}, {dispatchers}, {extra_spawn_params}) *vim.lsp.rpc.start()*
  2022. Starts an LSP server process and create an LSP RPC client object to
  2023. interact with it. Communication with the spawned process happens via
  2024. stdio. For communication via TCP, spawn a process manually and use
  2025. |vim.lsp.rpc.connect()|
  2026. Parameters: ~
  2027. • {cmd} (`string[]`) Command to start the LSP server.
  2028. • {dispatchers} (`table?`) Dispatchers for LSP message types.
  2029. • {notification}
  2030. (`fun(method: string, params: table)`)
  2031. • {server_request}
  2032. (`fun(method: string, params: table): any?, lsp.ResponseError?`)
  2033. • {on_exit}
  2034. (`fun(code: integer, signal: integer)`)
  2035. • {on_error} (`fun(code: integer, err: any)`)
  2036. • {extra_spawn_params} (`table?`) Additional context for the LSP server
  2037. process.
  2038. • {cwd}? (`string`) Working directory for the
  2039. LSP server process
  2040. • {detached}? (`boolean`) Detach the LSP server
  2041. process from the current process
  2042. • {env}? (`table<string,string>`) Additional
  2043. environment variables for LSP server process.
  2044. See |vim.system()|
  2045. Return: ~
  2046. (`vim.lsp.rpc.PublicClient`) See |vim.lsp.rpc.PublicClient|.
  2047. ==============================================================================
  2048. Lua module: vim.lsp.protocol *lsp-protocol*
  2049. *vim.lsp.protocol.make_client_capabilities()*
  2050. make_client_capabilities()
  2051. Gets a new ClientCapabilities object describing the LSP client
  2052. capabilities.
  2053. Return: ~
  2054. (`lsp.ClientCapabilities`)
  2055. Methods *vim.lsp.protocol.Methods*
  2056. LSP method names.
  2057. See also: ~
  2058. • https://microsoft.github.io/language-server-protocol/specification/#metaModel
  2059. *vim.lsp.protocol.resolve_capabilities()*
  2060. resolve_capabilities({server_capabilities})
  2061. Creates a normalized object describing LSP server capabilities.
  2062. Parameters: ~
  2063. • {server_capabilities} (`table`) Table of capabilities supported by
  2064. the server
  2065. Return: ~
  2066. (`lsp.ServerCapabilities?`) Normalized table of capabilities
  2067. vim:tw=78:ts=8:sw=4:sts=4:et:ft=help:norl: