lsp.txt 111 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574
  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. local win = vim.api.nvim_get_current_win()
  729. vim.wo[win][0].foldmethod = 'expr'
  730. vim.wo[win][0].foldexpr = 'v:lua.vim.lsp.foldexpr()'
  731. end
  732. end,
  733. })
  734. <
  735. Parameters: ~
  736. • {lnum} (`integer`) line number
  737. foldtext() *vim.lsp.foldtext()*
  738. Provides a `foldtext` function that shows the `collapsedText` retrieved,
  739. defaults to the first folded line if `collapsedText` is not provided.
  740. formatexpr({opts}) *vim.lsp.formatexpr()*
  741. Provides an interface between the built-in client and a `formatexpr`
  742. function.
  743. Currently only supports a single client. This can be set via
  744. `setlocal formatexpr=v:lua.vim.lsp.formatexpr()` or (more typically) in
  745. `on_attach` via
  746. `vim.bo[bufnr].formatexpr = 'v:lua.vim.lsp.formatexpr(#{timeout_ms:250})'`.
  747. Parameters: ~
  748. • {opts} (`table?`) A table with the following fields:
  749. • {timeout_ms} (`integer`, default: 500ms) The timeout period
  750. for the formatting request..
  751. *vim.lsp.get_buffers_by_client_id()*
  752. get_buffers_by_client_id({client_id})
  753. Returns list of buffers attached to client_id.
  754. Parameters: ~
  755. • {client_id} (`integer`) client id
  756. Return: ~
  757. (`integer[]`) buffers list of buffer ids
  758. get_client_by_id({client_id}) *vim.lsp.get_client_by_id()*
  759. Gets a client by id, or nil if the id is invalid. The returned client may
  760. not yet be fully initialized.
  761. Parameters: ~
  762. • {client_id} (`integer`) client id
  763. Return: ~
  764. (`vim.lsp.Client?`) client rpc object
  765. get_clients({filter}) *vim.lsp.get_clients()*
  766. Get active clients.
  767. Parameters: ~
  768. • {filter} (`table?`) Key-value pairs used to filter the returned
  769. clients.
  770. • {id}? (`integer`) Only return clients with the given id
  771. • {bufnr}? (`integer`) Only return clients attached to this
  772. buffer
  773. • {name}? (`string`) Only return clients with the given name
  774. • {method}? (`string`) Only return clients supporting the
  775. given method
  776. Return: ~
  777. (`vim.lsp.Client[]`) List of |vim.lsp.Client| objects
  778. get_log_path() *vim.lsp.get_log_path()*
  779. Gets the path of the logfile used by the LSP client.
  780. Return: ~
  781. (`string`) path to log file
  782. omnifunc({findstart}, {base}) *vim.lsp.omnifunc()*
  783. Implements 'omnifunc' compatible LSP completion.
  784. Parameters: ~
  785. • {findstart} (`integer`) 0 or 1, decides behavior
  786. • {base} (`integer`) findstart=0, text to match against
  787. Return: ~
  788. (`integer|table`) Decided by {findstart}:
  789. • findstart=0: column where the completion starts, or -2 or -3
  790. • findstart=1: list of matches (actually just calls |complete()|)
  791. See also: ~
  792. • |complete-functions|
  793. • |complete-items|
  794. • |CompleteDone|
  795. set_log_level({level}) *vim.lsp.set_log_level()*
  796. Sets the global log level for LSP logging.
  797. Levels by name: "TRACE", "DEBUG", "INFO", "WARN", "ERROR", "OFF"
  798. Level numbers begin with "TRACE" at 0
  799. Use `lsp.log_levels` for reverse lookup.
  800. Parameters: ~
  801. • {level} (`integer|string`) the case insensitive level name or number
  802. See also: ~
  803. • |vim.lsp.log_levels|
  804. start({config}, {opts}) *vim.lsp.start()*
  805. Create a new LSP client and start a language server or reuses an already
  806. running client if one is found matching `name` and `root_dir`. Attaches
  807. the current buffer to the client.
  808. Example: >lua
  809. vim.lsp.start({
  810. name = 'my-server-name',
  811. cmd = {'name-of-language-server-executable'},
  812. root_dir = vim.fs.root(0, {'pyproject.toml', 'setup.py'}),
  813. })
  814. <
  815. See |vim.lsp.ClientConfig| for all available options. The most important
  816. are:
  817. • `name` arbitrary name for the LSP client. Should be unique per language
  818. server.
  819. • `cmd` command string[] or function.
  820. • `root_dir` path to the project root. By default this is used to decide
  821. if an existing client should be re-used. The example above uses
  822. |vim.fs.root()| to detect the root by traversing the file system upwards
  823. starting from the current directory until either a `pyproject.toml` or
  824. `setup.py` file is found.
  825. • `workspace_folders` list of `{ uri:string, name: string }` tables
  826. specifying the project root folders used by the language server. If
  827. `nil` the property is derived from `root_dir` for convenience.
  828. Language servers use this information to discover metadata like the
  829. dependencies of your project and they tend to index the contents within
  830. the project folder.
  831. To ensure a language server is only started for languages it can handle,
  832. make sure to call |vim.lsp.start()| within a |FileType| autocmd. Either
  833. use |:au|, |nvim_create_autocmd()| or put the call in a
  834. `ftplugin/<filetype_name>.lua` (See |ftplugin-name|)
  835. Parameters: ~
  836. • {config} (`vim.lsp.ClientConfig`) Configuration for the server. See
  837. |vim.lsp.ClientConfig|.
  838. • {opts} (`table?`) Optional keyword arguments.
  839. • {reuse_client}?
  840. (`fun(client: vim.lsp.Client, config: vim.lsp.ClientConfig): boolean`)
  841. Predicate used to decide if a client should be re-used.
  842. Used on all running clients. The default implementation
  843. re-uses a client if it has the same name and if the given
  844. workspace folders (or root_dir) are all included in the
  845. client's workspace folders.
  846. • {bufnr}? (`integer`) Buffer handle to attach to if
  847. starting or re-using a client (0 for current).
  848. • {attach}? (`boolean`) Whether to attach the client to a
  849. buffer (default true). If set to `false`, `reuse_client`
  850. and `bufnr` will be ignored.
  851. • {silent}? (`boolean`) Suppress error reporting if the LSP
  852. server fails to start (default false).
  853. Return: ~
  854. (`integer?`) client_id
  855. status() *vim.lsp.status()*
  856. Consumes the latest progress messages from all clients and formats them as
  857. a string. Empty if there are no clients or if no new messages
  858. Return: ~
  859. (`string`)
  860. stop_client({client_id}, {force}) *vim.lsp.stop_client()*
  861. Stops a client(s).
  862. You can also use the `stop()` function on a |vim.lsp.Client| object. To
  863. stop all clients: >lua
  864. vim.lsp.stop_client(vim.lsp.get_clients())
  865. <
  866. By default asks the server to shutdown, unless stop was requested already
  867. for this client, then force-shutdown is attempted.
  868. Parameters: ~
  869. • {client_id} (`integer|integer[]|vim.lsp.Client[]`) id, list of id's,
  870. or list of |vim.lsp.Client| objects
  871. • {force} (`boolean?`) shutdown forcefully
  872. tagfunc({pattern}, {flags}) *vim.lsp.tagfunc()*
  873. Provides an interface between the built-in client and 'tagfunc'.
  874. When used with normal mode commands (e.g. |CTRL-]|) this will invoke the
  875. "textDocument/definition" LSP method to find the tag under the cursor.
  876. Otherwise, uses "workspace/symbol". If no results are returned from any
  877. LSP servers, falls back to using built-in tags.
  878. Parameters: ~
  879. • {pattern} (`string`) Pattern used to find a workspace symbol
  880. • {flags} (`string`) See |tag-function|
  881. Return: ~
  882. (`table[]`) tags A list of matching tags
  883. ==============================================================================
  884. Lua module: vim.lsp.client *lsp-client*
  885. *vim.lsp.Client*
  886. Fields: ~
  887. • {id} (`integer`) The id allocated to the client.
  888. • {name} (`string`) If a name is specified on creation,
  889. that will be used. Otherwise it is just the
  890. client id. This is used for logs and messages.
  891. • {rpc} (`vim.lsp.rpc.PublicClient`) RPC client
  892. object, for low level interaction with the
  893. client. See |vim.lsp.rpc.start()|.
  894. • {offset_encoding} (`string`) Called "position encoding" in LSP
  895. spec, the encoding used for communicating with
  896. the server. You can modify this in the
  897. `config`'s `on_init` method before text is
  898. sent to the server.
  899. • {handlers} (`table<string,lsp.Handler>`) The handlers
  900. used by the client as described in
  901. |lsp-handler|.
  902. • {requests} (`table<integer,{ type: string, bufnr: integer, method: string}?>`)
  903. The current pending requests in flight to the
  904. server. Entries are key-value pairs with the
  905. key being the request id while the value is a
  906. table with `type`, `bufnr`, and `method`
  907. key-value pairs. `type` is either "pending"
  908. for an active request, or "cancel" for a
  909. cancel request. It will be "complete"
  910. ephemerally while executing |LspRequest|
  911. autocmds when replies are received from the
  912. server.
  913. • {config} (`vim.lsp.ClientConfig`) copy of the table
  914. that was passed by the user to
  915. |vim.lsp.start()|. See |vim.lsp.ClientConfig|.
  916. • {server_capabilities} (`lsp.ServerCapabilities?`) Response from the
  917. server sent on `initialize` describing the
  918. server's capabilities.
  919. • {server_info} (`lsp.ServerInfo?`) Response from the server
  920. sent on `initialize` describing information
  921. about the server.
  922. • {progress} (`vim.lsp.Client.Progress`) A ring buffer
  923. (|vim.ringbuf()|) containing progress messages
  924. sent by the server. See
  925. |vim.lsp.Client.Progress|.
  926. • {initialized} (`true?`)
  927. • {workspace_folders} (`lsp.WorkspaceFolder[]?`) The workspace
  928. folders configured in the client when the
  929. server starts. This property is only available
  930. if the client supports workspace folders. It
  931. can be `null` if the client supports workspace
  932. folders but none are configured.
  933. • {root_dir} (`string?`)
  934. • {attached_buffers} (`table<integer,true>`)
  935. • {commands} (`table<string,fun(command: lsp.Command, ctx: table)>`)
  936. Table of command name to function which is
  937. called if any LSP action (code action, code
  938. lenses, ...) triggers the command. Client
  939. commands take precedence over the global
  940. command registry.
  941. • {settings} (`lsp.LSPObject`) Map with language server
  942. specific settings. These are returned to the
  943. language server if requested via
  944. `workspace/configuration`. Keys are
  945. case-sensitive.
  946. • {flags} (`table`) A table with flags for the client.
  947. The current (experimental) flags are:
  948. • {allow_incremental_sync}? (`boolean`,
  949. default: `true`) Allow using incremental
  950. sync for buffer edits
  951. • {debounce_text_changes} (`integer`, default:
  952. `150`) Debounce `didChange` notifications to
  953. the server by the given number in
  954. milliseconds. No debounce occurs if `nil`.
  955. • {exit_timeout} (`integer|false`, default:
  956. `false`) Milliseconds to wait for server to
  957. exit cleanly after sending the "shutdown"
  958. request before sending kill -15. If set to
  959. false, nvim exits immediately after sending
  960. the "shutdown" request to the server.
  961. • {get_language_id} (`fun(bufnr: integer, filetype: string): string`)
  962. • {capabilities} (`lsp.ClientCapabilities`) The capabilities
  963. provided by the client (editor or tool)
  964. • {dynamic_capabilities} (`lsp.DynamicCapabilities`)
  965. • {request} (`fun(self: vim.lsp.Client, method: string, params: table?, handler: lsp.Handler?, bufnr: integer?): boolean, integer?`)
  966. See |Client:request()|.
  967. • {request_sync} (`fun(self: vim.lsp.Client, method: string, params: table, timeout_ms: integer?, bufnr: integer?): {err: lsp.ResponseError?, result:any}?, string?`)
  968. See |Client:request_sync()|.
  969. • {notify} (`fun(self: vim.lsp.Client, method: string, params: table?): boolean`)
  970. See |Client:notify()|.
  971. • {cancel_request} (`fun(self: vim.lsp.Client, id: integer): boolean`)
  972. See |Client:cancel_request()|.
  973. • {stop} (`fun(self: vim.lsp.Client, force: boolean?)`)
  974. See |Client:stop()|.
  975. • {is_stopped} (`fun(self: vim.lsp.Client): boolean`) See
  976. |Client:is_stopped()|.
  977. • {exec_cmd} (`fun(self: vim.lsp.Client, command: lsp.Command, context: {bufnr?: integer}?, handler: lsp.Handler?)`)
  978. See |Client:exec_cmd()|.
  979. • {on_attach} (`fun(self: vim.lsp.Client, bufnr: integer)`)
  980. See |Client:on_attach()|.
  981. • {supports_method} (`fun(self: vim.lsp.Client, method: string, bufnr: integer?)`)
  982. See |Client:supports_method()|.
  983. *vim.lsp.Client.Progress*
  984. Extends: |vim.Ringbuf|
  985. Fields: ~
  986. • {pending} (`table<lsp.ProgressToken,lsp.LSPAny>`)
  987. *vim.lsp.ClientConfig*
  988. Fields: ~
  989. • {cmd} (`string[]|fun(dispatchers: vim.lsp.rpc.Dispatchers): vim.lsp.rpc.PublicClient`)
  990. command string[] that launches the language
  991. server (treated as in |jobstart()|, must be
  992. absolute or on `$PATH`, shell constructs like
  993. "~" are not expanded), or function that creates
  994. an RPC client. Function receives a `dispatchers`
  995. table and returns a table with member functions
  996. `request`, `notify`, `is_closing` and
  997. `terminate`. See |vim.lsp.rpc.request()|,
  998. |vim.lsp.rpc.notify()|. For TCP there is a
  999. builtin RPC client factory:
  1000. |vim.lsp.rpc.connect()|
  1001. • {cmd_cwd}? (`string`, default: cwd) Directory to launch the
  1002. `cmd` process. Not related to `root_dir`.
  1003. • {cmd_env}? (`table`) Environment flags to pass to the LSP
  1004. on spawn. Must be specified using a table.
  1005. Non-string values are coerced to string.
  1006. Example: >lua
  1007. { PORT = 8080; HOST = "0.0.0.0"; }
  1008. <
  1009. • {detached}? (`boolean`, default: true) Daemonize the server
  1010. process so that it runs in a separate process
  1011. group from Nvim. Nvim will shutdown the process
  1012. on exit, but if Nvim fails to exit cleanly this
  1013. could leave behind orphaned server processes.
  1014. • {workspace_folders}? (`lsp.WorkspaceFolder[]`) List of workspace
  1015. folders passed to the language server. For
  1016. backwards compatibility rootUri and rootPath
  1017. will be derived from the first workspace folder
  1018. in this list. See `workspaceFolders` in the LSP
  1019. spec.
  1020. • {capabilities}? (`lsp.ClientCapabilities`) Map overriding the
  1021. default capabilities defined by
  1022. |vim.lsp.protocol.make_client_capabilities()|,
  1023. passed to the language server on initialization.
  1024. Hint: use make_client_capabilities() and modify
  1025. its result.
  1026. • Note: To send an empty dictionary use
  1027. |vim.empty_dict()|, else it will be encoded as
  1028. an array.
  1029. • {handlers}? (`table<string,function>`) Map of language
  1030. server method names to |lsp-handler|
  1031. • {settings}? (`lsp.LSPObject`) Map with language server
  1032. specific settings. See the {settings} in
  1033. |vim.lsp.Client|.
  1034. • {commands}? (`table<string,fun(command: lsp.Command, ctx: table)>`)
  1035. Table that maps string of clientside commands to
  1036. user-defined functions. Commands passed to
  1037. `start()` take precedence over the global
  1038. command registry. Each key must be a unique
  1039. command name, and the value is a function which
  1040. is called if any LSP action (code action, code
  1041. lenses, ...) triggers the command.
  1042. • {init_options}? (`lsp.LSPObject`) Values to pass in the
  1043. initialization request as
  1044. `initializationOptions`. See `initialize` in the
  1045. LSP spec.
  1046. • {name}? (`string`, default: client-id) Name in log
  1047. messages.
  1048. • {get_language_id}? (`fun(bufnr: integer, filetype: string): string`)
  1049. Language ID as string. Defaults to the buffer
  1050. filetype.
  1051. • {offset_encoding}? (`'utf-8'|'utf-16'|'utf-32'`) Called "position
  1052. encoding" in LSP spec, the encoding that the LSP
  1053. server expects. Client does not verify this is
  1054. correct.
  1055. • {on_error}? (`fun(code: integer, err: string)`) Callback
  1056. invoked when the client operation throws an
  1057. error. `code` is a number describing the error.
  1058. Other arguments may be passed depending on the
  1059. error kind. See `vim.lsp.rpc.client_errors` for
  1060. possible errors. Use
  1061. `vim.lsp.rpc.client_errors[code]` to get
  1062. human-friendly name.
  1063. • {before_init}? (`fun(params: lsp.InitializeParams, config: vim.lsp.ClientConfig)`)
  1064. Callback invoked before the LSP "initialize"
  1065. phase, where `params` contains the parameters
  1066. being sent to the server and `config` is the
  1067. config that was passed to |vim.lsp.start()|. You
  1068. can use this to modify parameters before they
  1069. are sent.
  1070. • {on_init}? (`elem_or_list<fun(client: vim.lsp.Client, initialize_result: lsp.InitializeResult)>`)
  1071. Callback invoked after LSP "initialize", where
  1072. `result` is a table of `capabilities` and
  1073. anything else the server may send. For example,
  1074. clangd sends `initialize_result.offsetEncoding`
  1075. if `capabilities.offsetEncoding` was sent to it.
  1076. You can only modify the `client.offset_encoding`
  1077. here before any notifications are sent.
  1078. • {on_exit}? (`elem_or_list<fun(code: integer, signal: integer, client_id: integer)>`)
  1079. Callback invoked on client exit.
  1080. • code: exit code of the process
  1081. • signal: number describing the signal used to
  1082. terminate (if any)
  1083. • client_id: client handle
  1084. • {on_attach}? (`elem_or_list<fun(client: vim.lsp.Client, bufnr: integer)>`)
  1085. Callback invoked when client attaches to a
  1086. buffer.
  1087. • {trace}? (`'off'|'messages'|'verbose'`, default: "off")
  1088. Passed directly to the language server in the
  1089. initialize request. Invalid/empty values will
  1090. • {flags}? (`table`) A table with flags for the client. The
  1091. current (experimental) flags are:
  1092. • {allow_incremental_sync}? (`boolean`, default:
  1093. `true`) Allow using incremental sync for
  1094. buffer edits
  1095. • {debounce_text_changes} (`integer`, default:
  1096. `150`) Debounce `didChange` notifications to
  1097. the server by the given number in
  1098. milliseconds. No debounce occurs if `nil`.
  1099. • {exit_timeout} (`integer|false`, default:
  1100. `false`) Milliseconds to wait for server to
  1101. exit cleanly after sending the "shutdown"
  1102. request before sending kill -15. If set to
  1103. false, nvim exits immediately after sending
  1104. the "shutdown" request to the server.
  1105. • {root_dir}? (`string`) Directory where the LSP server will
  1106. base its workspaceFolders, rootUri, and rootPath
  1107. on initialization.
  1108. Client:cancel_request({id}) *Client:cancel_request()*
  1109. Cancels a request with a given request id.
  1110. Parameters: ~
  1111. • {id} (`integer`) id of request to cancel
  1112. Return: ~
  1113. (`boolean`) status indicating if the notification was successful.
  1114. See also: ~
  1115. • |Client:notify()|
  1116. Client:exec_cmd({command}, {context}, {handler}) *Client:exec_cmd()*
  1117. Execute a lsp command, either via client command function (if available)
  1118. or via workspace/executeCommand (if supported by the server)
  1119. Parameters: ~
  1120. • {command} (`lsp.Command`)
  1121. • {context} (`{bufnr?: integer}?`)
  1122. • {handler} (`lsp.Handler?`) only called if a server command
  1123. Client:is_stopped() *Client:is_stopped()*
  1124. Checks whether a client is stopped.
  1125. Return: ~
  1126. (`boolean`) true if client is stopped or in the process of being
  1127. stopped; false otherwise
  1128. Client:notify({method}, {params}) *Client:notify()*
  1129. Sends a notification to an LSP server.
  1130. Parameters: ~
  1131. • {method} (`string`) LSP method name.
  1132. • {params} (`table?`) LSP request params.
  1133. Return: ~
  1134. (`boolean`) status indicating if the notification was successful. If
  1135. it is false, then the client has shutdown.
  1136. Client:on_attach({bufnr}) *Client:on_attach()*
  1137. Runs the on_attach function from the client's config if it was defined.
  1138. Useful for buffer-local setup.
  1139. Parameters: ~
  1140. • {bufnr} (`integer`) Buffer number
  1141. *Client:request()*
  1142. Client:request({method}, {params}, {handler}, {bufnr})
  1143. Sends a request to the server.
  1144. This is a thin wrapper around {client.rpc.request} with some additional
  1145. checks for capabilities and handler availability.
  1146. Parameters: ~
  1147. • {method} (`string`) LSP method name.
  1148. • {params} (`table?`) LSP request params.
  1149. • {handler} (`lsp.Handler?`) Response |lsp-handler| for this method.
  1150. • {bufnr} (`integer?`) (default: 0) Buffer handle, or 0 for current.
  1151. Return (multiple): ~
  1152. (`boolean`) status indicates whether the request was successful. If it
  1153. is `false`, then it will always be `false` (the client has shutdown).
  1154. (`integer?`) request_id Can be used with |Client:cancel_request()|.
  1155. `nil` is request failed.
  1156. See also: ~
  1157. • |vim.lsp.buf_request_all()|
  1158. *Client:request_sync()*
  1159. Client:request_sync({method}, {params}, {timeout_ms}, {bufnr})
  1160. Sends a request to the server and synchronously waits for the response.
  1161. This is a wrapper around |Client:request()|
  1162. Parameters: ~
  1163. • {method} (`string`) LSP method name.
  1164. • {params} (`table`) LSP request params.
  1165. • {timeout_ms} (`integer?`) Maximum time in milliseconds to wait for a
  1166. result. Defaults to 1000
  1167. • {bufnr} (`integer?`) (default: 0) Buffer handle, or 0 for
  1168. current.
  1169. Return (multiple): ~
  1170. (`{err: lsp.ResponseError?, result:any}?`) `result` and `err` from the
  1171. |lsp-handler|. `nil` is the request was unsuccessful
  1172. (`string?`) err On timeout, cancel or error, where `err` is a string
  1173. describing the failure reason.
  1174. See also: ~
  1175. • |vim.lsp.buf_request_sync()|
  1176. Client:stop({force}) *Client:stop()*
  1177. Stops a client, optionally with force.
  1178. By default, it will just request the server to shutdown without force. If
  1179. you request to stop a client which has previously been requested to
  1180. shutdown, it will automatically escalate and force shutdown.
  1181. Parameters: ~
  1182. • {force} (`boolean?`)
  1183. Client:supports_method({method}, {bufnr}) *Client:supports_method()*
  1184. Checks if a client supports a given method. Always returns true for
  1185. unknown off-spec methods.
  1186. Note: Some language server capabilities can be file specific.
  1187. Parameters: ~
  1188. • {method} (`string`)
  1189. • {bufnr} (`integer?`)
  1190. ==============================================================================
  1191. Lua module: vim.lsp.buf *lsp-buf*
  1192. *vim.lsp.ListOpts*
  1193. Fields: ~
  1194. • {on_list}? (`fun(t: vim.lsp.LocationOpts.OnList)`) list-handler
  1195. replacing the default handler. Called for any non-empty
  1196. result. This table can be used with |setqflist()| or
  1197. |setloclist()|. E.g.: >lua
  1198. local function on_list(options)
  1199. vim.fn.setqflist({}, ' ', options)
  1200. vim.cmd.cfirst()
  1201. end
  1202. vim.lsp.buf.definition({ on_list = on_list })
  1203. vim.lsp.buf.references(nil, { on_list = on_list })
  1204. <
  1205. • {loclist}? (`boolean`) Whether to use the |location-list| or the
  1206. |quickfix| list in the default handler. >lua
  1207. vim.lsp.buf.definition({ loclist = true })
  1208. vim.lsp.buf.references(nil, { loclist = false })
  1209. <
  1210. *vim.lsp.LocationOpts*
  1211. Extends: |vim.lsp.ListOpts|
  1212. Fields: ~
  1213. • {reuse_win}? (`boolean`) Jump to existing window if buffer is already
  1214. open.
  1215. *vim.lsp.LocationOpts.OnList*
  1216. Fields: ~
  1217. • {items} (`table[]`) Structured like |setqflist-what|
  1218. • {title}? (`string`) Title for the list.
  1219. • {context}? (`table`) `ctx` from |lsp-handler|
  1220. *vim.lsp.buf.hover.Opts*
  1221. Extends: |vim.lsp.util.open_floating_preview.Opts|
  1222. Fields: ~
  1223. • {silent}? (`boolean`)
  1224. *vim.lsp.buf.signature_help.Opts*
  1225. Extends: |vim.lsp.util.open_floating_preview.Opts|
  1226. Fields: ~
  1227. • {silent}? (`boolean`)
  1228. *vim.lsp.buf.add_workspace_folder()*
  1229. add_workspace_folder({workspace_folder})
  1230. Add the folder at path to the workspace folders. If {path} is not
  1231. provided, the user will be prompted for a path using |input()|.
  1232. Parameters: ~
  1233. • {workspace_folder} (`string?`)
  1234. clear_references() *vim.lsp.buf.clear_references()*
  1235. Removes document highlights from current buffer.
  1236. code_action({opts}) *vim.lsp.buf.code_action()*
  1237. Selects a code action available at the current cursor position.
  1238. Parameters: ~
  1239. • {opts} (`table?`) A table with the following fields:
  1240. • {context}? (`lsp.CodeActionContext`) Corresponds to
  1241. `CodeActionContext` of the LSP specification:
  1242. • {diagnostics}? (`table`) LSP `Diagnostic[]`. Inferred from
  1243. the current position if not provided.
  1244. • {only}? (`table`) List of LSP `CodeActionKind`s used to
  1245. filter the code actions. Most language servers support
  1246. values like `refactor` or `quickfix`.
  1247. • {triggerKind}? (`integer`) The reason why code actions
  1248. were requested.
  1249. • {filter}? (`fun(x: lsp.CodeAction|lsp.Command):boolean`)
  1250. Predicate taking an `CodeAction` and returning a boolean.
  1251. • {apply}? (`boolean`) When set to `true`, and there is just
  1252. one remaining action (after filtering), the action is
  1253. applied without user query.
  1254. • {range}? (`{start: integer[], end: integer[]}`) Range for
  1255. which code actions should be requested. If in visual mode
  1256. this defaults to the active selection. Table must contain
  1257. `start` and `end` keys with {row,col} tuples using mark-like
  1258. indexing. See |api-indexing|
  1259. See also: ~
  1260. • https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_codeAction
  1261. • vim.lsp.protocol.CodeActionTriggerKind
  1262. declaration({opts}) *vim.lsp.buf.declaration()*
  1263. Jumps to the declaration of the symbol under the cursor.
  1264. Note: ~
  1265. • Many servers do not implement this method. Generally, see
  1266. |vim.lsp.buf.definition()| instead.
  1267. Parameters: ~
  1268. • {opts} (`vim.lsp.LocationOpts?`) See |vim.lsp.LocationOpts|.
  1269. definition({opts}) *vim.lsp.buf.definition()*
  1270. Jumps to the definition of the symbol under the cursor.
  1271. Parameters: ~
  1272. • {opts} (`vim.lsp.LocationOpts?`) See |vim.lsp.LocationOpts|.
  1273. document_highlight() *vim.lsp.buf.document_highlight()*
  1274. Send request to the server to resolve document highlights for the current
  1275. text document position. This request can be triggered by a key mapping or
  1276. by events such as `CursorHold`, e.g.: >vim
  1277. autocmd CursorHold <buffer> lua vim.lsp.buf.document_highlight()
  1278. autocmd CursorHoldI <buffer> lua vim.lsp.buf.document_highlight()
  1279. autocmd CursorMoved <buffer> lua vim.lsp.buf.clear_references()
  1280. <
  1281. Note: Usage of |vim.lsp.buf.document_highlight()| requires the following
  1282. highlight groups to be defined or you won't be able to see the actual
  1283. highlights. |hl-LspReferenceText| |hl-LspReferenceRead|
  1284. |hl-LspReferenceWrite|
  1285. document_symbol({opts}) *vim.lsp.buf.document_symbol()*
  1286. Lists all symbols in the current buffer in the |location-list|.
  1287. Parameters: ~
  1288. • {opts} (`vim.lsp.ListOpts?`) See |vim.lsp.ListOpts|.
  1289. format({opts}) *vim.lsp.buf.format()*
  1290. Formats a buffer using the attached (and optionally filtered) language
  1291. server clients.
  1292. Parameters: ~
  1293. • {opts} (`table?`) A table with the following fields:
  1294. • {formatting_options}? (`table`) Can be used to specify
  1295. FormattingOptions. Some unspecified options will be
  1296. automatically derived from the current Nvim options. See
  1297. https://microsoft.github.io/language-server-protocol/specification/#formattingOptions
  1298. • {timeout_ms}? (`integer`, default: `1000`) Time in
  1299. milliseconds to block for formatting requests. No effect if
  1300. async=true.
  1301. • {bufnr}? (`integer`, default: current buffer) Restrict
  1302. formatting to the clients attached to the given buffer.
  1303. • {filter}? (`fun(client: vim.lsp.Client): boolean?`)
  1304. Predicate used to filter clients. Receives a client as
  1305. argument and must return a boolean. Clients matching the
  1306. predicate are included. Example: >lua
  1307. -- Never request typescript-language-server for formatting
  1308. vim.lsp.buf.format {
  1309. filter = function(client) return client.name ~= "ts_ls" end
  1310. }
  1311. <
  1312. • {async}? (`boolean`, default: false) If true the method
  1313. won't block. Editing the buffer while formatting
  1314. asynchronous can lead to unexpected changes.
  1315. • {id}? (`integer`) Restrict formatting to the client with ID
  1316. (client.id) matching this field.
  1317. • {name}? (`string`) Restrict formatting to the client with
  1318. name (client.name) matching this field.
  1319. • {range}?
  1320. (`{start:[integer,integer],end:[integer, integer]}|{start:[integer,integer],end:[integer,integer]}[]`,
  1321. default: current selection in visual mode, `nil` in other
  1322. modes, formatting the full buffer) Range to format. Table
  1323. must contain `start` and `end` keys with {row,col} tuples
  1324. using (1,0) indexing. Can also be a list of tables that
  1325. contain `start` and `end` keys as described above, in which
  1326. case `textDocument/rangesFormatting` support is required.
  1327. hover({config}) *vim.lsp.buf.hover()*
  1328. Displays hover information about the symbol under the cursor in a floating
  1329. window. The window will be dismissed on cursor move. Calling the function
  1330. twice will jump into the floating window (thus by default, "KK" will open
  1331. the hover window and focus it). In the floating window, all commands and
  1332. mappings are available as usual, except that "q" dismisses the window. You
  1333. can scroll the contents the same as you would any other buffer.
  1334. Note: to disable hover highlights, add the following to your config: >lua
  1335. vim.api.nvim_create_autocmd('ColorScheme', {
  1336. callback = function()
  1337. vim.api.nvim_set_hl(0, 'LspReferenceTarget', {})
  1338. end,
  1339. })
  1340. <
  1341. Parameters: ~
  1342. • {config} (`vim.lsp.buf.hover.Opts?`) See |vim.lsp.buf.hover.Opts|.
  1343. implementation({opts}) *vim.lsp.buf.implementation()*
  1344. Lists all the implementations for the symbol under the cursor in the
  1345. quickfix window.
  1346. Parameters: ~
  1347. • {opts} (`vim.lsp.LocationOpts?`) See |vim.lsp.LocationOpts|.
  1348. incoming_calls() *vim.lsp.buf.incoming_calls()*
  1349. Lists all the call sites of the symbol under the cursor in the |quickfix|
  1350. window. If the symbol can resolve to multiple items, the user can pick one
  1351. in the |inputlist()|.
  1352. list_workspace_folders() *vim.lsp.buf.list_workspace_folders()*
  1353. List workspace folders.
  1354. outgoing_calls() *vim.lsp.buf.outgoing_calls()*
  1355. Lists all the items that are called by the symbol under the cursor in the
  1356. |quickfix| window. If the symbol can resolve to multiple items, the user
  1357. can pick one in the |inputlist()|.
  1358. references({context}, {opts}) *vim.lsp.buf.references()*
  1359. Lists all the references to the symbol under the cursor in the quickfix
  1360. window.
  1361. Parameters: ~
  1362. • {context} (`lsp.ReferenceContext?`) Context for the request
  1363. • {opts} (`vim.lsp.ListOpts?`) See |vim.lsp.ListOpts|.
  1364. See also: ~
  1365. • https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_references
  1366. *vim.lsp.buf.remove_workspace_folder()*
  1367. remove_workspace_folder({workspace_folder})
  1368. Remove the folder at path from the workspace folders. If {path} is not
  1369. provided, the user will be prompted for a path using |input()|.
  1370. Parameters: ~
  1371. • {workspace_folder} (`string?`)
  1372. rename({new_name}, {opts}) *vim.lsp.buf.rename()*
  1373. Renames all references to the symbol under the cursor.
  1374. Parameters: ~
  1375. • {new_name} (`string?`) If not provided, the user will be prompted for
  1376. a new name using |vim.ui.input()|.
  1377. • {opts} (`table?`) Additional options:
  1378. • {filter}? (`fun(client: vim.lsp.Client): boolean?`)
  1379. Predicate used to filter clients. Receives a client as
  1380. argument and must return a boolean. Clients matching the
  1381. predicate are included.
  1382. • {name}? (`string`) Restrict clients used for rename to
  1383. ones where client.name matches this field.
  1384. • {bufnr}? (`integer`) (default: current buffer)
  1385. signature_help({config}) *vim.lsp.buf.signature_help()*
  1386. Displays signature information about the symbol under the cursor in a
  1387. floating window.
  1388. Parameters: ~
  1389. • {config} (`vim.lsp.buf.signature_help.Opts?`) See
  1390. |vim.lsp.buf.signature_help.Opts|.
  1391. type_definition({opts}) *vim.lsp.buf.type_definition()*
  1392. Jumps to the definition of the type of the symbol under the cursor.
  1393. Parameters: ~
  1394. • {opts} (`vim.lsp.LocationOpts?`) See |vim.lsp.LocationOpts|.
  1395. typehierarchy({kind}) *vim.lsp.buf.typehierarchy()*
  1396. Lists all the subtypes or supertypes of the symbol under the cursor in the
  1397. |quickfix| window. If the symbol can resolve to multiple items, the user
  1398. can pick one using |vim.ui.select()|.
  1399. Parameters: ~
  1400. • {kind} (`"subtypes"|"supertypes"`)
  1401. workspace_symbol({query}, {opts}) *vim.lsp.buf.workspace_symbol()*
  1402. Lists all symbols in the current workspace in the quickfix window.
  1403. The list is filtered against {query}; if the argument is omitted from the
  1404. call, the user is prompted to enter a string on the command line. An empty
  1405. string means no filtering is done.
  1406. Parameters: ~
  1407. • {query} (`string?`) optional
  1408. • {opts} (`vim.lsp.ListOpts?`) See |vim.lsp.ListOpts|.
  1409. ==============================================================================
  1410. Lua module: vim.lsp.diagnostic *lsp-diagnostic*
  1411. from({diagnostics}) *vim.lsp.diagnostic.from()*
  1412. Converts the input `vim.Diagnostic`s to LSP diagnostics.
  1413. Parameters: ~
  1414. • {diagnostics} (`vim.Diagnostic[]`)
  1415. Return: ~
  1416. (`lsp.Diagnostic[]`)
  1417. *vim.lsp.diagnostic.get_namespace()*
  1418. get_namespace({client_id}, {is_pull})
  1419. Get the diagnostic namespace associated with an LSP client
  1420. |vim.diagnostic| for diagnostics
  1421. Parameters: ~
  1422. • {client_id} (`integer`) The id of the LSP client
  1423. • {is_pull} (`boolean?`) Whether the namespace is for a pull or push
  1424. client. Defaults to push
  1425. *vim.lsp.diagnostic.on_diagnostic()*
  1426. on_diagnostic({error}, {result}, {ctx})
  1427. |lsp-handler| for the method "textDocument/diagnostic"
  1428. See |vim.diagnostic.config()| for configuration options.
  1429. Parameters: ~
  1430. • {error} (`lsp.ResponseError?`)
  1431. • {result} (`lsp.DocumentDiagnosticReport`)
  1432. • {ctx} (`lsp.HandlerContext`)
  1433. *vim.lsp.diagnostic.on_publish_diagnostics()*
  1434. on_publish_diagnostics({_}, {result}, {ctx})
  1435. |lsp-handler| for the method "textDocument/publishDiagnostics"
  1436. See |vim.diagnostic.config()| for configuration options.
  1437. Parameters: ~
  1438. • {result} (`lsp.PublishDiagnosticsParams`)
  1439. • {ctx} (`lsp.HandlerContext`)
  1440. ==============================================================================
  1441. Lua module: vim.lsp.codelens *lsp-codelens*
  1442. clear({client_id}, {bufnr}) *vim.lsp.codelens.clear()*
  1443. Clear the lenses
  1444. Parameters: ~
  1445. • {client_id} (`integer?`) filter by client_id. All clients if nil
  1446. • {bufnr} (`integer?`) filter by buffer. All buffers if nil, 0 for
  1447. current buffer
  1448. display({lenses}, {bufnr}, {client_id}) *vim.lsp.codelens.display()*
  1449. Display the lenses using virtual text
  1450. Parameters: ~
  1451. • {lenses} (`lsp.CodeLens[]?`) lenses to display
  1452. • {bufnr} (`integer`)
  1453. • {client_id} (`integer`)
  1454. get({bufnr}) *vim.lsp.codelens.get()*
  1455. Return all lenses for the given buffer
  1456. Parameters: ~
  1457. • {bufnr} (`integer`) Buffer number. 0 can be used for the current
  1458. buffer.
  1459. Return: ~
  1460. (`lsp.CodeLens[]`)
  1461. on_codelens({err}, {result}, {ctx}) *vim.lsp.codelens.on_codelens()*
  1462. |lsp-handler| for the method `textDocument/codeLens`
  1463. Parameters: ~
  1464. • {err} (`lsp.ResponseError?`)
  1465. • {result} (`lsp.CodeLens[]`)
  1466. • {ctx} (`lsp.HandlerContext`)
  1467. refresh({opts}) *vim.lsp.codelens.refresh()*
  1468. Refresh the lenses.
  1469. It is recommended to trigger this using an autocmd or via keymap.
  1470. Example: >vim
  1471. autocmd BufEnter,CursorHold,InsertLeave <buffer> lua vim.lsp.codelens.refresh({ bufnr = 0 })
  1472. <
  1473. Parameters: ~
  1474. • {opts} (`table?`) Optional fields
  1475. • {bufnr} (`integer?`) filter by buffer. All buffers if nil, 0
  1476. for current buffer
  1477. run() *vim.lsp.codelens.run()*
  1478. Run the code lens in the current line
  1479. save({lenses}, {bufnr}, {client_id}) *vim.lsp.codelens.save()*
  1480. Store lenses for a specific buffer and client
  1481. Parameters: ~
  1482. • {lenses} (`lsp.CodeLens[]?`) lenses to store
  1483. • {bufnr} (`integer`)
  1484. • {client_id} (`integer`)
  1485. ==============================================================================
  1486. Lua module: vim.lsp.completion *lsp-completion*
  1487. *vim.lsp.completion.BufferOpts*
  1488. Fields: ~
  1489. • {autotrigger}? (`boolean`) Default: false When true, completion
  1490. triggers automatically based on the server's
  1491. `triggerCharacters`.
  1492. • {convert}? (`fun(item: lsp.CompletionItem): table`) Transforms an
  1493. LSP CompletionItem to |complete-items|.
  1494. *vim.lsp.completion.enable()*
  1495. enable({enable}, {client_id}, {bufnr}, {opts})
  1496. Enables or disables completions from the given language client in the
  1497. given buffer.
  1498. Parameters: ~
  1499. • {enable} (`boolean`) True to enable, false to disable
  1500. • {client_id} (`integer`) Client ID
  1501. • {bufnr} (`integer`) Buffer handle, or 0 for the current buffer
  1502. • {opts} (`vim.lsp.completion.BufferOpts?`) See
  1503. |vim.lsp.completion.BufferOpts|.
  1504. trigger() *vim.lsp.completion.trigger()*
  1505. Trigger LSP completion in the current buffer.
  1506. ==============================================================================
  1507. Lua module: vim.lsp.inlay_hint *lsp-inlay_hint*
  1508. enable({enable}, {filter}) *vim.lsp.inlay_hint.enable()*
  1509. Enables or disables inlay hints for the {filter}ed scope.
  1510. To "toggle", pass the inverse of `is_enabled()`: >lua
  1511. vim.lsp.inlay_hint.enable(not vim.lsp.inlay_hint.is_enabled())
  1512. <
  1513. Attributes: ~
  1514. Since: 0.10.0
  1515. Parameters: ~
  1516. • {enable} (`boolean?`) true/nil to enable, false to disable
  1517. • {filter} (`table?`) Optional filters |kwargs|, or `nil` for all.
  1518. • {bufnr} (`integer?`) Buffer number, or 0 for current
  1519. buffer, or nil for all.
  1520. get({filter}) *vim.lsp.inlay_hint.get()*
  1521. Get the list of inlay hints, (optionally) restricted by buffer or range.
  1522. Example usage: >lua
  1523. local hint = vim.lsp.inlay_hint.get({ bufnr = 0 })[1] -- 0 for current buffer
  1524. local client = vim.lsp.get_client_by_id(hint.client_id)
  1525. local resp = client:request_sync('inlayHint/resolve', hint.inlay_hint, 100, 0)
  1526. local resolved_hint = assert(resp and resp.result, resp.err)
  1527. vim.lsp.util.apply_text_edits(resolved_hint.textEdits, 0, client.encoding)
  1528. location = resolved_hint.label[1].location
  1529. client:request('textDocument/hover', {
  1530. textDocument = { uri = location.uri },
  1531. position = location.range.start,
  1532. })
  1533. <
  1534. Attributes: ~
  1535. Since: 0.10.0
  1536. Parameters: ~
  1537. • {filter} (`table?`) Optional filters |kwargs|:
  1538. • {bufnr} (`integer?`)
  1539. • {range} (`lsp.Range?`)
  1540. Return: ~
  1541. (`table[]`) A list of objects with the following fields:
  1542. • {bufnr} (`integer`)
  1543. • {client_id} (`integer`)
  1544. • {inlay_hint} (`lsp.InlayHint`)
  1545. is_enabled({filter}) *vim.lsp.inlay_hint.is_enabled()*
  1546. Query whether inlay hint is enabled in the {filter}ed scope
  1547. Attributes: ~
  1548. Since: 0.10.0
  1549. Parameters: ~
  1550. • {filter} (`table?`) Optional filters |kwargs|, or `nil` for all.
  1551. • {bufnr} (`integer?`) Buffer number, or 0 for current
  1552. buffer, or nil for all.
  1553. Return: ~
  1554. (`boolean`)
  1555. ==============================================================================
  1556. Lua module: vim.lsp.semantic_tokens *lsp-semantic_tokens*
  1557. force_refresh({bufnr}) *vim.lsp.semantic_tokens.force_refresh()*
  1558. Force a refresh of all semantic tokens
  1559. Only has an effect if the buffer is currently active for semantic token
  1560. highlighting (|vim.lsp.semantic_tokens.start()| has been called for it)
  1561. Parameters: ~
  1562. • {bufnr} (`integer?`) filter by buffer. All buffers if nil, current
  1563. buffer if 0
  1564. *vim.lsp.semantic_tokens.get_at_pos()*
  1565. get_at_pos({bufnr}, {row}, {col})
  1566. Return the semantic token(s) at the given position. If called without
  1567. arguments, returns the token under the cursor.
  1568. Parameters: ~
  1569. • {bufnr} (`integer?`) Buffer number (0 for current buffer, default)
  1570. • {row} (`integer?`) Position row (default cursor position)
  1571. • {col} (`integer?`) Position column (default cursor position)
  1572. Return: ~
  1573. (`table?`) List of tokens at position. Each token has the following
  1574. fields:
  1575. • line (integer) line number, 0-based
  1576. • start_col (integer) start column, 0-based
  1577. • end_col (integer) end column, 0-based
  1578. • type (string) token type as string, e.g. "variable"
  1579. • modifiers (table) token modifiers as a set. E.g., { static = true,
  1580. readonly = true }
  1581. • client_id (integer)
  1582. *vim.lsp.semantic_tokens.highlight_token()*
  1583. highlight_token({token}, {bufnr}, {client_id}, {hl_group}, {opts})
  1584. Highlight a semantic token.
  1585. Apply an extmark with a given highlight group for a semantic token. The
  1586. mark will be deleted by the semantic token engine when appropriate; for
  1587. example, when the LSP sends updated tokens. This function is intended for
  1588. use inside |LspTokenUpdate| callbacks.
  1589. Parameters: ~
  1590. • {token} (`table`) A semantic token, found as `args.data.token` in
  1591. |LspTokenUpdate|
  1592. • {bufnr} (`integer`) The buffer to highlight, or `0` for current
  1593. buffer
  1594. • {client_id} (`integer`) The ID of the |vim.lsp.Client|
  1595. • {hl_group} (`string`) Highlight group name
  1596. • {opts} (`table?`) Optional parameters:
  1597. • {priority}? (`integer`, default:
  1598. `vim.hl.priorities.semantic_tokens + 3`) Priority for
  1599. the applied extmark.
  1600. start({bufnr}, {client_id}, {opts}) *vim.lsp.semantic_tokens.start()*
  1601. Start the semantic token highlighting engine for the given buffer with the
  1602. given client. The client must already be attached to the buffer.
  1603. NOTE: This is currently called automatically by
  1604. |vim.lsp.buf_attach_client()|. To opt-out of semantic highlighting with a
  1605. server that supports it, you can delete the semanticTokensProvider table
  1606. from the {server_capabilities} of your client in your |LspAttach| callback
  1607. or your configuration's `on_attach` callback: >lua
  1608. client.server_capabilities.semanticTokensProvider = nil
  1609. <
  1610. Parameters: ~
  1611. • {bufnr} (`integer`) Buffer number, or `0` for current buffer
  1612. • {client_id} (`integer`) The ID of the |vim.lsp.Client|
  1613. • {opts} (`table?`) Optional keyword arguments
  1614. • debounce (integer, default: 200): Debounce token
  1615. requests to the server by the given number in
  1616. milliseconds
  1617. stop({bufnr}, {client_id}) *vim.lsp.semantic_tokens.stop()*
  1618. Stop the semantic token highlighting engine for the given buffer with the
  1619. given client.
  1620. NOTE: This is automatically called by a |LspDetach| autocmd that is set up
  1621. as part of `start()`, so you should only need this function to manually
  1622. disengage the semantic token engine without fully detaching the LSP client
  1623. from the buffer.
  1624. Parameters: ~
  1625. • {bufnr} (`integer`) Buffer number, or `0` for current buffer
  1626. • {client_id} (`integer`) The ID of the |vim.lsp.Client|
  1627. ==============================================================================
  1628. Lua module: vim.lsp.util *lsp-util*
  1629. *vim.lsp.util.open_floating_preview.Opts*
  1630. Fields: ~
  1631. • {height}? (`integer`) Height of floating window
  1632. • {width}? (`integer`) Width of floating window
  1633. • {wrap}? (`boolean`, default: `true`) Wrap long lines
  1634. • {wrap_at}? (`integer`) Character to wrap at for computing height
  1635. when wrap is enabled
  1636. • {max_width}? (`integer`) Maximal width of floating window
  1637. • {max_height}? (`integer`) Maximal height of floating window
  1638. • {focus_id}? (`string`) If a popup with this id is opened, then
  1639. focus it
  1640. • {close_events}? (`table`) List of events that closes the floating
  1641. window
  1642. • {focusable}? (`boolean`, default: `true`) Make float focusable.
  1643. • {focus}? (`boolean`, default: `true`) If `true`, and if
  1644. {focusable} is also `true`, focus an existing
  1645. floating window with the same {focus_id}
  1646. • {offset_x}? (`integer`) offset to add to `col`
  1647. • {offset_y}? (`integer`) offset to add to `row`
  1648. • {border}? (`string|(string|[string,string])[]`) override
  1649. `border`
  1650. • {zindex}? (`integer`) override `zindex`, defaults to 50
  1651. • {title}? (`string`)
  1652. • {title_pos}? (`'left'|'center'|'right'`)
  1653. • {relative}? (`'mouse'|'cursor'|'editor'`) (default: `'cursor'`)
  1654. • {anchor_bias}? (`'auto'|'above'|'below'`, default: `'auto'`) -
  1655. "auto": place window based on which side of the
  1656. cursor has more lines
  1657. • "above": place the window above the cursor unless
  1658. there are not enough lines to display the full
  1659. window height.
  1660. • "below": place the window below the cursor unless
  1661. there are not enough lines to display the full
  1662. window height.
  1663. *vim.lsp.util.apply_text_document_edit()*
  1664. apply_text_document_edit({text_document_edit}, {index}, {position_encoding})
  1665. Applies a `TextDocumentEdit`, which is a list of changes to a single
  1666. document.
  1667. Parameters: ~
  1668. • {text_document_edit} (`lsp.TextDocumentEdit`)
  1669. • {index} (`integer?`) Optional index of the edit, if from
  1670. a list of edits (or nil, if not from a list)
  1671. • {position_encoding} (`'utf-8'|'utf-16'|'utf-32'?`)
  1672. See also: ~
  1673. • https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocumentEdit
  1674. *vim.lsp.util.apply_text_edits()*
  1675. apply_text_edits({text_edits}, {bufnr}, {position_encoding})
  1676. Applies a list of text edits to a buffer.
  1677. Parameters: ~
  1678. • {text_edits} (`lsp.TextEdit[]`)
  1679. • {bufnr} (`integer`) Buffer id
  1680. • {position_encoding} (`'utf-8'|'utf-16'|'utf-32'`)
  1681. See also: ~
  1682. • https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textEdit
  1683. *vim.lsp.util.apply_workspace_edit()*
  1684. apply_workspace_edit({workspace_edit}, {position_encoding})
  1685. Applies a `WorkspaceEdit`.
  1686. Parameters: ~
  1687. • {workspace_edit} (`lsp.WorkspaceEdit`)
  1688. • {position_encoding} (`'utf-8'|'utf-16'|'utf-32'`) (required)
  1689. See also: ~
  1690. • https://microsoft.github.io/language-server-protocol/specifications/specification-current/#workspace_applyEdit
  1691. buf_clear_references({bufnr}) *vim.lsp.util.buf_clear_references()*
  1692. Removes document highlights from a buffer.
  1693. Parameters: ~
  1694. • {bufnr} (`integer?`) Buffer id
  1695. *vim.lsp.util.buf_highlight_references()*
  1696. buf_highlight_references({bufnr}, {references}, {position_encoding})
  1697. Shows a list of document highlights for a certain buffer.
  1698. Parameters: ~
  1699. • {bufnr} (`integer`) Buffer id
  1700. • {references} (`lsp.DocumentHighlight[]`) objects to highlight
  1701. • {position_encoding} (`'utf-8'|'utf-16'|'utf-32'`)
  1702. See also: ~
  1703. • https://microsoft.github.io/language-server-protocol/specification/#textDocumentContentChangeEvent
  1704. *vim.lsp.util.character_offset()*
  1705. character_offset({buf}, {row}, {col}, {offset_encoding})
  1706. Returns the UTF-32 and UTF-16 offsets for a position in a certain buffer.
  1707. Parameters: ~
  1708. • {buf} (`integer`) buffer number (0 for current)
  1709. • {row} (`integer`) 0-indexed line
  1710. • {col} (`integer`) 0-indexed byte offset in line
  1711. • {offset_encoding} (`'utf-8'|'utf-16'|'utf-32'?`) defaults to
  1712. `offset_encoding` of first client of `buf`
  1713. Return: ~
  1714. (`integer`) `offset_encoding` index of the character in line {row}
  1715. column {col} in buffer {buf}
  1716. *vim.lsp.util.convert_input_to_markdown_lines()*
  1717. convert_input_to_markdown_lines({input}, {contents})
  1718. Converts any of `MarkedString` | `MarkedString[]` | `MarkupContent` into a
  1719. list of lines containing valid markdown. Useful to populate the hover
  1720. window for `textDocument/hover`, for parsing the result of
  1721. `textDocument/signatureHelp`, and potentially others.
  1722. Note that if the input is of type `MarkupContent` and its kind is
  1723. `plaintext`, then the corresponding value is returned without further
  1724. modifications.
  1725. Parameters: ~
  1726. • {input} (`lsp.MarkedString|lsp.MarkedString[]|lsp.MarkupContent`)
  1727. • {contents} (`string[]?`) List of strings to extend with converted
  1728. lines. Defaults to {}.
  1729. Return: ~
  1730. (`string[]`) extended with lines of converted markdown.
  1731. See also: ~
  1732. • https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_hover
  1733. *vim.lsp.util.convert_signature_help_to_markdown_lines()*
  1734. convert_signature_help_to_markdown_lines({signature_help}, {ft}, {triggers})
  1735. Converts `textDocument/signatureHelp` response to markdown lines.
  1736. Parameters: ~
  1737. • {signature_help} (`lsp.SignatureHelp`) Response of
  1738. `textDocument/SignatureHelp`
  1739. • {ft} (`string?`) filetype that will be use as the `lang`
  1740. for the label markdown code block
  1741. • {triggers} (`string[]?`) list of trigger characters from the
  1742. lsp server. used to better determine parameter
  1743. offsets
  1744. Return (multiple): ~
  1745. (`string[]?`) lines of converted markdown.
  1746. (`Range4?`) highlight range for the active parameter
  1747. See also: ~
  1748. • https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_signatureHelp
  1749. get_effective_tabstop({bufnr}) *vim.lsp.util.get_effective_tabstop()*
  1750. Returns indentation size.
  1751. Parameters: ~
  1752. • {bufnr} (`integer?`) Buffer handle, defaults to current
  1753. Return: ~
  1754. (`integer`) indentation size
  1755. See also: ~
  1756. • 'shiftwidth'
  1757. *vim.lsp.util.locations_to_items()*
  1758. locations_to_items({locations}, {position_encoding})
  1759. Returns the items with the byte position calculated correctly and in
  1760. sorted order, for display in quickfix and location lists.
  1761. The `user_data` field of each resulting item will contain the original
  1762. `Location` or `LocationLink` it was computed from.
  1763. The result can be passed to the {list} argument of |setqflist()| or
  1764. |setloclist()|.
  1765. Parameters: ~
  1766. • {locations} (`lsp.Location[]|lsp.LocationLink[]`)
  1767. • {position_encoding} (`'utf-8'|'utf-16'|'utf-32'?`) default to first
  1768. client of buffer
  1769. Return: ~
  1770. (`vim.quickfix.entry[]`) See |setqflist()| for the format
  1771. *vim.lsp.util.make_floating_popup_options()*
  1772. make_floating_popup_options({width}, {height}, {opts})
  1773. Creates a table with sensible default options for a floating window. The
  1774. table can be passed to |nvim_open_win()|.
  1775. Parameters: ~
  1776. • {width} (`integer`) window width (in character cells)
  1777. • {height} (`integer`) window height (in character cells)
  1778. • {opts} (`vim.lsp.util.open_floating_preview.Opts?`) See
  1779. |vim.lsp.util.open_floating_preview.Opts|.
  1780. Return: ~
  1781. (`vim.api.keyset.win_config`)
  1782. *vim.lsp.util.make_formatting_params()*
  1783. make_formatting_params({options})
  1784. Creates a `DocumentFormattingParams` object for the current buffer and
  1785. cursor position.
  1786. Parameters: ~
  1787. • {options} (`lsp.FormattingOptions?`) with valid `FormattingOptions`
  1788. entries
  1789. Return: ~
  1790. (`lsp.DocumentFormattingParams`) object
  1791. See also: ~
  1792. • https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_formatting
  1793. *vim.lsp.util.make_given_range_params()*
  1794. make_given_range_params({start_pos}, {end_pos}, {bufnr}, {position_encoding})
  1795. Using the given range in the current buffer, creates an object that is
  1796. similar to |vim.lsp.util.make_range_params()|.
  1797. Parameters: ~
  1798. • {start_pos} (`[integer,integer]?`) {row,col} mark-indexed
  1799. position. Defaults to the start of the last
  1800. visual selection.
  1801. • {end_pos} (`[integer,integer]?`) {row,col} mark-indexed
  1802. position. Defaults to the end of the last visual
  1803. selection.
  1804. • {bufnr} (`integer?`) buffer handle or 0 for current,
  1805. defaults to current
  1806. • {position_encoding} (`'utf-8'|'utf-16'|'utf-32'`)
  1807. Return: ~
  1808. (`{ textDocument: { uri: lsp.DocumentUri }, range: lsp.Range }`)
  1809. *vim.lsp.util.make_position_params()*
  1810. make_position_params({window}, {position_encoding})
  1811. Creates a `TextDocumentPositionParams` object for the current buffer and
  1812. cursor position.
  1813. Parameters: ~
  1814. • {window} (`integer?`) window handle or 0 for current,
  1815. defaults to current
  1816. • {position_encoding} (`'utf-8'|'utf-16'|'utf-32'`)
  1817. Return: ~
  1818. (`lsp.TextDocumentPositionParams`)
  1819. See also: ~
  1820. • https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocumentPositionParams
  1821. *vim.lsp.util.make_range_params()*
  1822. make_range_params({window}, {position_encoding})
  1823. Using the current position in the current buffer, creates an object that
  1824. can be used as a building block for several LSP requests, such as
  1825. `textDocument/codeAction`, `textDocument/colorPresentation`,
  1826. `textDocument/rangeFormatting`.
  1827. Parameters: ~
  1828. • {window} (`integer?`) window handle or 0 for current,
  1829. defaults to current
  1830. • {position_encoding} (`"utf-8"|"utf-16"|"utf-32"`)
  1831. Return: ~
  1832. (`{ textDocument: { uri: lsp.DocumentUri }, range: lsp.Range }`)
  1833. *vim.lsp.util.make_text_document_params()*
  1834. make_text_document_params({bufnr})
  1835. Creates a `TextDocumentIdentifier` object for the current buffer.
  1836. Parameters: ~
  1837. • {bufnr} (`integer?`) Buffer handle, defaults to current
  1838. Return: ~
  1839. (`lsp.TextDocumentIdentifier`)
  1840. See also: ~
  1841. • https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocumentIdentifier
  1842. *vim.lsp.util.make_workspace_params()*
  1843. make_workspace_params({added}, {removed})
  1844. Create the workspace params
  1845. Parameters: ~
  1846. • {added} (`lsp.WorkspaceFolder[]`)
  1847. • {removed} (`lsp.WorkspaceFolder[]`)
  1848. Return: ~
  1849. (`lsp.WorkspaceFoldersChangeEvent`)
  1850. *vim.lsp.util.open_floating_preview()*
  1851. open_floating_preview({contents}, {syntax}, {opts})
  1852. Shows contents in a floating window.
  1853. Parameters: ~
  1854. • {contents} (`table`) of lines to show in window
  1855. • {syntax} (`string`) of syntax to set for opened buffer
  1856. • {opts} (`vim.lsp.util.open_floating_preview.Opts?`) with optional
  1857. fields (additional keys are filtered with
  1858. |vim.lsp.util.make_floating_popup_options()| before they
  1859. are passed on to |nvim_open_win()|). See
  1860. |vim.lsp.util.open_floating_preview.Opts|.
  1861. Return (multiple): ~
  1862. (`integer`) bufnr of newly created float window
  1863. (`integer`) winid of newly created float window preview window
  1864. preview_location({location}, {opts}) *vim.lsp.util.preview_location()*
  1865. Previews a location in a floating window
  1866. behavior depends on type of location:
  1867. • for Location, range is shown (e.g., function definition)
  1868. • for LocationLink, targetRange is shown (e.g., body of function
  1869. definition)
  1870. Parameters: ~
  1871. • {location} (`lsp.Location|lsp.LocationLink`)
  1872. • {opts} (`vim.lsp.util.open_floating_preview.Opts?`) See
  1873. |vim.lsp.util.open_floating_preview.Opts|.
  1874. Return (multiple): ~
  1875. (`integer?`) buffer id of float window
  1876. (`integer?`) window id of float window
  1877. rename({old_fname}, {new_fname}, {opts}) *vim.lsp.util.rename()*
  1878. Rename old_fname to new_fname
  1879. Existing buffers are renamed as well, while maintaining their bufnr.
  1880. It deletes existing buffers that conflict with the renamed file name only
  1881. when
  1882. • `opts` requests overwriting; or
  1883. • the conflicting buffers are not loaded, so that deleting them does not
  1884. result in data loss.
  1885. Parameters: ~
  1886. • {old_fname} (`string`)
  1887. • {new_fname} (`string`)
  1888. • {opts} (`table?`) Options:
  1889. • {overwrite}? (`boolean`)
  1890. • {ignoreIfExists}? (`boolean`)
  1891. *vim.lsp.util.show_document()*
  1892. show_document({location}, {position_encoding}, {opts})
  1893. Shows document and optionally jumps to the location.
  1894. Parameters: ~
  1895. • {location} (`lsp.Location|lsp.LocationLink`)
  1896. • {position_encoding} (`'utf-8'|'utf-16'|'utf-32'?`)
  1897. • {opts} (`table?`) A table with the following fields:
  1898. • {reuse_win}? (`boolean`) Jump to existing
  1899. window if buffer is already open.
  1900. • {focus}? (`boolean`) Whether to focus/jump to
  1901. location if possible. (defaults: true)
  1902. Return: ~
  1903. (`boolean`) `true` if succeeded
  1904. *vim.lsp.util.stylize_markdown()*
  1905. stylize_markdown({bufnr}, {contents}, {opts})
  1906. Converts markdown into syntax highlighted regions by stripping the code
  1907. blocks and converting them into highlighted code. This will by default
  1908. insert a blank line separator after those code block regions to improve
  1909. readability.
  1910. This method configures the given buffer and returns the lines to set.
  1911. If you want to open a popup with fancy markdown, use
  1912. `open_floating_preview` instead
  1913. Parameters: ~
  1914. • {bufnr} (`integer`)
  1915. • {contents} (`string[]`) of lines to show in window
  1916. • {opts} (`table?`) with optional fields
  1917. • height of floating window
  1918. • width of floating window
  1919. • wrap_at character to wrap at for computing height
  1920. • max_width maximal width of floating window
  1921. • max_height maximal height of floating window
  1922. • separator insert separator after code block
  1923. Return: ~
  1924. (`table`) stripped content
  1925. symbols_to_items({symbols}, {bufnr}) *vim.lsp.util.symbols_to_items()*
  1926. Converts symbols to quickfix list items.
  1927. Parameters: ~
  1928. • {symbols} (`lsp.DocumentSymbol[]|lsp.SymbolInformation[]`)
  1929. • {bufnr} (`integer?`)
  1930. Return: ~
  1931. (`vim.quickfix.entry[]`) See |setqflist()| for the format
  1932. ==============================================================================
  1933. Lua module: vim.lsp.log *lsp-log*
  1934. get_filename() *vim.lsp.log.get_filename()*
  1935. Returns the log filename.
  1936. Return: ~
  1937. (`string`) log filename
  1938. get_level() *vim.lsp.log.get_level()*
  1939. Gets the current log level.
  1940. Return: ~
  1941. (`integer`) current log level
  1942. set_format_func({handle}) *vim.lsp.log.set_format_func()*
  1943. Sets formatting function used to format logs
  1944. Parameters: ~
  1945. • {handle} (`function`) function to apply to logging arguments, pass
  1946. vim.inspect for multi-line formatting
  1947. set_level({level}) *vim.lsp.log.set_level()*
  1948. Sets the current log level.
  1949. Parameters: ~
  1950. • {level} (`string|integer`) One of `vim.lsp.log.levels`
  1951. should_log({level}) *vim.lsp.log.should_log()*
  1952. Checks whether the level is sufficient for logging.
  1953. Parameters: ~
  1954. • {level} (`integer`) log level
  1955. Return: ~
  1956. (`boolean`) true if would log, false if not
  1957. ==============================================================================
  1958. Lua module: vim.lsp.rpc *lsp-rpc*
  1959. *vim.lsp.rpc.PublicClient*
  1960. Client RPC object
  1961. Fields: ~
  1962. • {request} (`fun(method: string, params: table?, callback: fun(err?: lsp.ResponseError, result: any), notify_reply_callback?: fun(message_id: integer)):boolean,integer?`)
  1963. See |vim.lsp.rpc.request()|
  1964. • {notify} (`fun(method: string, params: any): boolean`) See
  1965. |vim.lsp.rpc.notify()|
  1966. • {is_closing} (`fun(): boolean`) Indicates if the RPC is closing.
  1967. • {terminate} (`fun()`) Terminates the RPC client.
  1968. connect({host_or_path}, {port}) *vim.lsp.rpc.connect()*
  1969. Create a LSP RPC client factory that connects to either:
  1970. • a named pipe (windows)
  1971. • a domain socket (unix)
  1972. • a host and port via TCP
  1973. Return a function that can be passed to the `cmd` field for
  1974. |vim.lsp.start()|.
  1975. Parameters: ~
  1976. • {host_or_path} (`string`) host to connect to or path to a pipe/domain
  1977. socket
  1978. • {port} (`integer?`) TCP port to connect to. If absent the
  1979. first argument must be a pipe
  1980. Return: ~
  1981. (`fun(dispatchers: vim.lsp.rpc.Dispatchers): vim.lsp.rpc.PublicClient`)
  1982. format_rpc_error({err}) *vim.lsp.rpc.format_rpc_error()*
  1983. Constructs an error message from an LSP error object.
  1984. Parameters: ~
  1985. • {err} (`table`) The error object
  1986. Return: ~
  1987. (`string`) error_message The formatted error message
  1988. notify({method}, {params}) *vim.lsp.rpc.notify()*
  1989. Sends a notification to the LSP server.
  1990. Parameters: ~
  1991. • {method} (`string`) The invoked LSP method
  1992. • {params} (`table?`) Parameters for the invoked LSP method
  1993. Return: ~
  1994. (`boolean`) `true` if notification could be sent, `false` if not
  1995. *vim.lsp.rpc.request()*
  1996. request({method}, {params}, {callback}, {notify_reply_callback})
  1997. Sends a request to the LSP server and runs {callback} upon response.
  1998. Parameters: ~
  1999. • {method} (`string`) The invoked LSP method
  2000. • {params} (`table?`) Parameters for the invoked LSP
  2001. method
  2002. • {callback} (`fun(err: lsp.ResponseError?, result: any)`)
  2003. Callback to invoke
  2004. • {notify_reply_callback} (`fun(message_id: integer)?`) Callback to
  2005. invoke as soon as a request is no longer
  2006. pending
  2007. Return (multiple): ~
  2008. (`boolean`) success `true` if request could be sent, `false` if not
  2009. (`integer?`) message_id if request could be sent, `nil` if not
  2010. *vim.lsp.rpc.rpc_response_error()*
  2011. rpc_response_error({code}, {message}, {data})
  2012. Creates an RPC response table `error` to be sent to the LSP response.
  2013. Parameters: ~
  2014. • {code} (`integer`) RPC error code defined, see
  2015. `vim.lsp.protocol.ErrorCodes`
  2016. • {message} (`string?`) arbitrary message to send to server
  2017. • {data} (`any?`) arbitrary data to send to server
  2018. Return: ~
  2019. (`lsp.ResponseError`)
  2020. See also: ~
  2021. • lsp.ErrorCodes See `vim.lsp.protocol.ErrorCodes`
  2022. start({cmd}, {dispatchers}, {extra_spawn_params}) *vim.lsp.rpc.start()*
  2023. Starts an LSP server process and create an LSP RPC client object to
  2024. interact with it. Communication with the spawned process happens via
  2025. stdio. For communication via TCP, spawn a process manually and use
  2026. |vim.lsp.rpc.connect()|
  2027. Parameters: ~
  2028. • {cmd} (`string[]`) Command to start the LSP server.
  2029. • {dispatchers} (`table?`) Dispatchers for LSP message types.
  2030. • {notification}
  2031. (`fun(method: string, params: table)`)
  2032. • {server_request}
  2033. (`fun(method: string, params: table): any?, lsp.ResponseError?`)
  2034. • {on_exit}
  2035. (`fun(code: integer, signal: integer)`)
  2036. • {on_error} (`fun(code: integer, err: any)`)
  2037. • {extra_spawn_params} (`table?`) Additional context for the LSP server
  2038. process.
  2039. • {cwd}? (`string`) Working directory for the
  2040. LSP server process
  2041. • {detached}? (`boolean`) Detach the LSP server
  2042. process from the current process
  2043. • {env}? (`table<string,string>`) Additional
  2044. environment variables for LSP server process.
  2045. See |vim.system()|
  2046. Return: ~
  2047. (`vim.lsp.rpc.PublicClient`) See |vim.lsp.rpc.PublicClient|.
  2048. ==============================================================================
  2049. Lua module: vim.lsp.protocol *lsp-protocol*
  2050. *vim.lsp.protocol.make_client_capabilities()*
  2051. make_client_capabilities()
  2052. Gets a new ClientCapabilities object describing the LSP client
  2053. capabilities.
  2054. Return: ~
  2055. (`lsp.ClientCapabilities`)
  2056. Methods *vim.lsp.protocol.Methods*
  2057. LSP method names.
  2058. See also: ~
  2059. • https://microsoft.github.io/language-server-protocol/specification/#metaModel
  2060. *vim.lsp.protocol.resolve_capabilities()*
  2061. resolve_capabilities({server_capabilities})
  2062. Creates a normalized object describing LSP server capabilities.
  2063. Parameters: ~
  2064. • {server_capabilities} (`table`) Table of capabilities supported by
  2065. the server
  2066. Return: ~
  2067. (`lsp.ServerCapabilities?`) Normalized table of capabilities
  2068. vim:tw=78:ts=8:sw=4:sts=4:et:ft=help:norl: