lsp.txt 85 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036
  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
  17. following the upstream installation instruction.
  18. A list of language servers is available at:
  19. https://microsoft.github.io/language-server-protocol/implementors/servers/
  20. 2. Configure the LSP client per language server.
  21. A minimal example:
  22. >
  23. vim.lsp.start({
  24. name = 'my-server-name',
  25. cmd = {'name-of-language-server-executable'},
  26. root_dir = vim.fs.dirname(vim.fs.find({'setup.py', 'pyproject.toml'}, { upward = true })[1]),
  27. })
  28. <
  29. See |vim.lsp.start()| for details.
  30. 3. Configure keymaps and autocmds to utilize LSP features.
  31. See |lsp-config|.
  32. <
  33. *lsp-config*
  34. Starting a LSP client will automatically report diagnostics via
  35. |vim.diagnostic|. Read |vim.diagnostic.config()| to learn how to customize the
  36. display.
  37. It also sets some buffer options if the options are otherwise empty and if the
  38. language server supports the functionality.
  39. - 'omnifunc' is set to |vim.lsp.omnifunc()|. This allows to trigger completion
  40. using |i_CTRL-X_CTRL-O|
  41. - 'tagfunc' is set to |vim.lsp.tagfunc()|. This enables features like
  42. go-to-definition, |:tjump|, and keymaps like |CTRL-]|, |CTRL-W_]|,
  43. |CTRL-W_}| to utilize the language server.
  44. - 'formatexpr' is set to |vim.lsp.formatexpr()| if both 'formatprg' and
  45. 'formatexpr' are empty. This allows to format lines via |gq| if the language
  46. server supports it.
  47. To use other LSP features like hover, rename, etc. you can setup some
  48. additional keymaps. It's recommended to setup them in a |LspAttach| autocmd to
  49. ensure they're only active if there is a LSP client running. An example:
  50. >
  51. vim.api.nvim_create_autocmd('LspAttach', {
  52. callback = function(args)
  53. vim.keymap.set('n', 'K', vim.lsp.buf.hover, { buffer = args.buf })
  54. end,
  55. })
  56. <
  57. The most used functions are:
  58. - |vim.lsp.buf.hover()|
  59. - |vim.lsp.buf.format()|
  60. - |vim.lsp.buf.references()|
  61. - |vim.lsp.buf.implementation()|
  62. - |vim.lsp.buf.code_action()|
  63. Not all language servers provide the same capabilities. To ensure you only set
  64. keymaps if the language server supports a feature, you can guard the keymap
  65. calls behind capability checks:
  66. >
  67. vim.api.nvim_create_autocmd('LspAttach', {
  68. callback = function(args)
  69. local client = vim.lsp.get_client_by_id(args.data.client_id)
  70. if client.server_capabilities.hoverProvider then
  71. vim.keymap.set('n', 'K', vim.lsp.buf.hover, { buffer = args.buf })
  72. end
  73. end,
  74. })
  75. <
  76. To learn what capabilities are available you can run the following command in
  77. a buffer with a started LSP client:
  78. >
  79. :lua =vim.lsp.get_active_clients()[1].server_capabilities
  80. <
  81. Full list of features provided by default can be found in |lsp-buf|.
  82. ================================================================================
  83. FAQ *lsp-faq*
  84. - Q: How to force-reload LSP?
  85. A: Stop all clients, then reload the buffer. >
  86. :lua vim.lsp.stop_client(vim.lsp.get_active_clients())
  87. :edit
  88. - Q: Why isn't completion working?
  89. A: In the buffer where you want to use LSP, check that 'omnifunc' is set to
  90. "v:lua.vim.lsp.omnifunc": >
  91. :verbose set omnifunc?
  92. < Some other plugin may be overriding the option. To avoid that, you could
  93. set the option in an |after-directory| ftplugin, e.g.
  94. "after/ftplugin/python.vim".
  95. - Q: How do I run a request synchronously (e.g. for formatting on file save)?
  96. A: Check if the function has an `async` parameter and set the value to
  97. false.
  98. E.g. code formatting: >
  99. " Auto-format *.rs (rust) files prior to saving them
  100. " (async = false is the default for format)
  101. autocmd BufWritePre *.rs lua vim.lsp.buf.format({ async = false })
  102. <
  103. *lsp-vs-treesitter*
  104. - Q: How do LSP and Treesitter compare?
  105. A: LSP requires a client and language server. The language server uses
  106. semantic analysis to understand code at a project level. This provides
  107. language servers with the ability to rename across files, find
  108. definitions in external libraries and more.
  109. Treesitter is a language parsing library that provides excellent tools
  110. for incrementally parsing text and handling errors. This makes it a great
  111. fit for editors to understand the contents of the current file for things
  112. like syntax highlighting, simple goto-definitions, scope analysis and
  113. more.
  114. LSP and Treesitter are both great tools for editing and inspecting code.
  115. ================================================================================
  116. LSP API *lsp-api*
  117. LSP core API is described at |lsp-core|. Those are the core functions for
  118. creating and managing clients.
  119. The `vim.lsp.buf_…` functions perform operations for all LSP clients attached
  120. to the given buffer. |lsp-buf|
  121. LSP request/response handlers are implemented as Lua functions (see
  122. |lsp-handler|). The |vim.lsp.handlers| table defines default handlers used
  123. when creating a new client. Keys are LSP method names: >
  124. :lua print(vim.inspect(vim.tbl_keys(vim.lsp.handlers)))
  125. <
  126. *lsp-method*
  127. Methods are the names of requests and notifications as defined by the LSP
  128. specification. These LSP requests/notifications are defined by default:
  129. callHierarchy/incomingCalls
  130. callHierarchy/outgoingCalls
  131. textDocument/codeAction
  132. textDocument/completion
  133. textDocument/declaration*
  134. textDocument/definition
  135. textDocument/documentHighlight
  136. textDocument/documentSymbol
  137. textDocument/formatting
  138. textDocument/hover
  139. textDocument/implementation*
  140. textDocument/publishDiagnostics
  141. textDocument/rangeFormatting
  142. textDocument/references
  143. textDocument/rename
  144. textDocument/signatureHelp
  145. textDocument/typeDefinition*
  146. window/logMessage
  147. window/showMessage
  148. window/showMessageRequest
  149. workspace/applyEdit
  150. workspace/symbol
  151. * NOTE: These are sometimes not implemented by servers.
  152. *lsp-handler*
  153. lsp-handlers are functions with special signatures that are designed to handle
  154. responses and notifications from LSP servers.
  155. For |lsp-request|, each |lsp-handler| has this signature: >
  156. function(err, result, ctx, config)
  157. <
  158. Parameters: ~
  159. {err} (table|nil)
  160. When the language server is unable to complete a
  161. request, a table with information about the error is
  162. sent. Otherwise, it is `nil`. See |lsp-response|.
  163. {result} (Result | Params | nil)
  164. When the language server is able to successfully
  165. complete a request, this contains the `result` key of
  166. the response. See |lsp-response|.
  167. {ctx} (table)
  168. Context describes additional calling state associated
  169. with the handler. It consists of the following key,
  170. value pairs:
  171. {method} (string)
  172. The |lsp-method| name.
  173. {client_id} (number)
  174. The ID of the |vim.lsp.client|.
  175. {bufnr} (Buffer)
  176. Buffer handle, or 0 for current.
  177. {params} (table|nil)
  178. The parameters used in the original
  179. request which resulted in this handler
  180. call.
  181. {config} (table)
  182. Configuration for the handler.
  183. Each handler can define its own configuration table
  184. that allows users to customize the behavior of a
  185. particular handler.
  186. To configure a particular |lsp-handler|, see:
  187. |lsp-handler-configuration|
  188. Returns: ~
  189. The |lsp-handler| can respond by returning two values: `result, err`
  190. Where `err` must be shaped like an RPC error:
  191. `{ code, message, data? }`
  192. You can use |vim.lsp.rpc.rpc_response_error()| to create this object.
  193. For |lsp-notification|, each |lsp-handler| has this signature: >
  194. function(err, result, ctx, config)
  195. <
  196. Parameters: ~
  197. {err} (nil)
  198. This is always `nil`.
  199. See |lsp-notification|
  200. {result} (Result)
  201. This contains the `params` key of the notification.
  202. See |lsp-notification|
  203. {ctx} (table)
  204. Context describes additional calling state associated
  205. with the handler. It consists of the following key,
  206. value pairs:
  207. {method} (string)
  208. The |lsp-method| name.
  209. {client_id} (number)
  210. The ID of the |vim.lsp.client|.
  211. {config} (table)
  212. Configuration for the handler.
  213. Each handler can define its own configuration table
  214. that allows users to customize the behavior of a
  215. particular handler.
  216. For an example, see:
  217. |vim.lsp.diagnostic.on_publish_diagnostics()|
  218. To configure a particular |lsp-handler|, see:
  219. |lsp-handler-configuration|
  220. Returns: ~
  221. The |lsp-handler|'s return value will be ignored.
  222. *lsp-handler-configuration*
  223. To configure the behavior of a builtin |lsp-handler|, the convenient method
  224. |vim.lsp.with()| is provided for users.
  225. To configure the behavior of |vim.lsp.diagnostic.on_publish_diagnostics()|,
  226. consider the following example, where a new |lsp-handler| is created using
  227. |vim.lsp.with()| that no longer generates signs for the diagnostics: >
  228. vim.lsp.handlers["textDocument/publishDiagnostics"] = vim.lsp.with(
  229. vim.lsp.diagnostic.on_publish_diagnostics, {
  230. -- Disable signs
  231. signs = false,
  232. }
  233. )
  234. <
  235. To enable signs, use |vim.lsp.with()| again to create and assign a new
  236. |lsp-handler| to |vim.lsp.handlers| for the associated method: >
  237. vim.lsp.handlers["textDocument/publishDiagnostics"] = vim.lsp.with(
  238. vim.lsp.diagnostic.on_publish_diagnostics, {
  239. -- Enable signs
  240. signs = true,
  241. }
  242. )
  243. <
  244. To configure a handler on a per-server basis, you can use the {handlers} key
  245. for |vim.lsp.start_client()| >
  246. vim.lsp.start_client {
  247. ..., -- Other configuration omitted.
  248. handlers = {
  249. ["textDocument/publishDiagnostics"] = vim.lsp.with(
  250. vim.lsp.diagnostic.on_publish_diagnostics, {
  251. -- Disable virtual_text
  252. virtual_text = false,
  253. }
  254. ),
  255. },
  256. }
  257. <
  258. or if using 'nvim-lspconfig', you can use the {handlers} key of `setup()`: >
  259. require('lspconfig').rust_analyzer.setup {
  260. handlers = {
  261. ["textDocument/publishDiagnostics"] = vim.lsp.with(
  262. vim.lsp.diagnostic.on_publish_diagnostics, {
  263. -- Disable virtual_text
  264. virtual_text = false
  265. }
  266. ),
  267. }
  268. }
  269. <
  270. Some handlers do not have an explicitly named handler function (such as
  271. ||vim.lsp.diagnostic.on_publish_diagnostics()|). To override these, first
  272. create a reference to the existing handler: >
  273. local on_references = vim.lsp.handlers["textDocument/references"]
  274. vim.lsp.handlers["textDocument/references"] = vim.lsp.with(
  275. on_references, {
  276. -- Use location list instead of quickfix list
  277. loclist = true,
  278. }
  279. )
  280. <
  281. *lsp-handler-resolution*
  282. Handlers can be set by:
  283. - Setting a field in vim.lsp.handlers. *vim.lsp.handlers*
  284. vim.lsp.handlers is a global table that contains the default mapping of
  285. |lsp-method| names to |lsp-handlers|.
  286. To override the handler for the `"textDocument/definition"` method: >
  287. vim.lsp.handlers["textDocument/definition"] = my_custom_default_definition
  288. <
  289. - The {handlers} parameter for |vim.lsp.start_client()|.
  290. This will set the |lsp-handler| as the default handler for this server.
  291. For example: >
  292. vim.lsp.start_client {
  293. ..., -- Other configuration omitted.
  294. handlers = {
  295. ["textDocument/definition"] = my_custom_server_definition
  296. },
  297. }
  298. - The {handler} parameter for |vim.lsp.buf_request()|.
  299. This will set the |lsp-handler| ONLY for the current request.
  300. For example: >
  301. vim.lsp.buf_request(
  302. 0,
  303. "textDocument/definition",
  304. definition_params,
  305. my_request_custom_definition
  306. )
  307. <
  308. In summary, the |lsp-handler| will be chosen based on the current |lsp-method|
  309. in the following order:
  310. 1. Handler passed to |vim.lsp.buf_request()|, if any.
  311. 2. Handler defined in |vim.lsp.start_client()|, if any.
  312. 3. Handler defined in |vim.lsp.handlers|, if any.
  313. *vim.lsp.log_levels*
  314. Log levels are defined in |vim.log.levels|
  315. VIM.LSP.PROTOCOL *vim.lsp.protocol*
  316. Module `vim.lsp.protocol` defines constants dictated by the LSP specification,
  317. and helper functions for creating protocol-related objects.
  318. https://github.com/microsoft/language-server-protocol/raw/gh-pages/_specifications/specification-3-14.md
  319. For example `vim.lsp.protocol.ErrorCodes` allows reverse lookup by number or
  320. name: >
  321. vim.lsp.protocol.TextDocumentSyncKind.Full == 1
  322. vim.lsp.protocol.TextDocumentSyncKind[1] == "Full"
  323. <
  324. *lsp-response*
  325. For the format of the response message, see:
  326. https://microsoft.github.io/language-server-protocol/specifications/specification-current/#responseMessage
  327. *lsp-notification*
  328. For the format of the notification message, see:
  329. https://microsoft.github.io/language-server-protocol/specifications/specification-current/#notificationMessage
  330. *lsp-on-list-handler*
  331. `on_list` receives a table with:
  332. - `items` table[], structured like |setqflist-what|
  333. - `title` string, title for the list.
  334. - `context` table|nil. `ctx` from |lsp-handler|
  335. This table can be used with vim.fn.setqflist or vim.fn.setloclist. E.g.:
  336. >
  337. local function on_list(options)
  338. vim.fn.setqflist({}, ' ', options)
  339. vim.api.nvim_command('cfirst')
  340. end
  341. vim.lsp.buf.definition{on_list=on_list}
  342. vim.lsp.buf.references(nil, {on_list=on_list})
  343. <
  344. If you prefer loclist do something like this:
  345. >
  346. local function on_list(options)
  347. vim.fn.setloclist(0, {}, ' ', options)
  348. vim.api.nvim_command('lopen')
  349. end
  350. <
  351. ================================================================================
  352. LSP HIGHLIGHT *lsp-highlight*
  353. Reference Highlights:
  354. Highlight groups that are meant to be used by |vim.lsp.buf.document_highlight()|.
  355. You can see more about the differences in types here:
  356. https://microsoft.github.io/language-server-protocol/specification#textDocument_documentHighlight
  357. *hl-LspReferenceText*
  358. LspReferenceText used for highlighting "text" references
  359. *hl-LspReferenceRead*
  360. LspReferenceRead used for highlighting "read" references
  361. *hl-LspReferenceWrite*
  362. LspReferenceWrite used for highlighting "write" references
  363. *lsp-highlight-codelens*
  364. Highlight groups related to |lsp-codelens| functionality.
  365. *hl-LspCodeLens*
  366. LspCodeLens
  367. Used to color the virtual text of the codelens. See
  368. |nvim_buf_set_extmark()|.
  369. LspCodeLensSeparator *hl-LspCodeLensSeparator*
  370. Used to color the separator between two or more code lenses.
  371. *lsp-highlight-signature*
  372. Highlight groups related to |vim.lsp.handlers.signature_help()|.
  373. *hl-LspSignatureActiveParameter*
  374. LspSignatureActiveParameter
  375. Used to highlight the active parameter in the signature help. See
  376. |vim.lsp.handlers.signature_help()|.
  377. ==============================================================================
  378. EVENTS *lsp-events*
  379. *LspAttach*
  380. After an LSP client attaches to a buffer. The |autocmd-pattern| is the
  381. name of the buffer. When used from Lua, the client ID is passed to the
  382. callback in the "data" table. Example: >
  383. vim.api.nvim_create_autocmd("LspAttach", {
  384. callback = function(args)
  385. local bufnr = args.buf
  386. local client = vim.lsp.get_client_by_id(args.data.client_id)
  387. if client.server_capabilities.completionProvider then
  388. vim.bo[bufnr].omnifunc = "v:lua.vim.lsp.omnifunc"
  389. end
  390. if client.server_capabilities.definitionProvider then
  391. vim.bo[bufnr].tagfunc = "v:lua.vim.lsp.tagfunc"
  392. end
  393. end,
  394. })
  395. <
  396. *LspDetach*
  397. Just before an LSP client detaches from a buffer. The |autocmd-pattern| is the
  398. name of the buffer. When used from Lua, the client ID is passed to the
  399. callback in the "data" table. Example: >
  400. vim.api.nvim_create_autocmd("LspDetach", {
  401. callback = function(args)
  402. local client = vim.lsp.get_client_by_id(args.data.client_id)
  403. -- Do something with the client
  404. vim.cmd("setlocal tagfunc< omnifunc<")
  405. end,
  406. })
  407. <
  408. Also the following |User| |autocommand|s are provided:
  409. LspProgressUpdate *LspProgressUpdate*
  410. Upon receipt of a progress notification from the server. See
  411. |vim.lsp.util.get_progress_messages()|.
  412. LspRequest *LspRequest*
  413. After a change to the active set of pending LSP requests. See {requests}
  414. in |vim.lsp.client|.
  415. Example: >
  416. autocmd User LspProgressUpdate redrawstatus
  417. autocmd User LspRequest redrawstatus
  418. <
  419. ==============================================================================
  420. Lua module: vim.lsp *lsp-core*
  421. buf_attach_client({bufnr}, {client_id}) *vim.lsp.buf_attach_client()*
  422. Implements the `textDocument/did…` notifications required to track a
  423. buffer for any language server.
  424. Without calling this, the server won't be notified of changes to a buffer.
  425. Parameters: ~
  426. • {bufnr} (number) Buffer handle, or 0 for current
  427. • {client_id} (number) Client id
  428. buf_detach_client({bufnr}, {client_id}) *vim.lsp.buf_detach_client()*
  429. Detaches client from the specified buffer. Note: While the server is
  430. notified that the text document (buffer) was closed, it is still able to
  431. send notifications should it ignore this notification.
  432. Parameters: ~
  433. • {bufnr} (number) Buffer handle, or 0 for current
  434. • {client_id} (number) Client id
  435. buf_is_attached({bufnr}, {client_id}) *vim.lsp.buf_is_attached()*
  436. Checks if a buffer is attached for a particular client.
  437. Parameters: ~
  438. • {bufnr} (number) Buffer handle, or 0 for current
  439. • {client_id} (number) the client id
  440. buf_notify({bufnr}, {method}, {params}) *vim.lsp.buf_notify()*
  441. Send a notification to a server
  442. Parameters: ~
  443. • {bufnr} [number] (optional): The number of the buffer
  444. • {method} [string]: Name of the request method
  445. • {params} [string]: Arguments to send to the server
  446. Return: ~
  447. true if any client returns true; false otherwise
  448. *vim.lsp.buf_request_all()*
  449. buf_request_all({bufnr}, {method}, {params}, {callback})
  450. Sends an async request for all active clients attached to the buffer.
  451. Executes the callback on the combined result. Parameters are the same as
  452. |vim.lsp.buf_request()| but the return result and callback are different.
  453. Parameters: ~
  454. • {bufnr} (number) Buffer handle, or 0 for current.
  455. • {method} (string) LSP method name
  456. • {params} (optional, table) Parameters to send to the server
  457. • {callback} (function) The callback to call when all requests are
  458. finished.
  459. Return: ~
  460. (function) A function that will cancel all requests which is the same
  461. as the one returned from `buf_request`.
  462. *vim.lsp.buf_request_sync()*
  463. buf_request_sync({bufnr}, {method}, {params}, {timeout_ms})
  464. Sends a request to all server and waits for the response of all of them.
  465. Calls |vim.lsp.buf_request_all()| but blocks Nvim while awaiting the
  466. result. Parameters are the same as |vim.lsp.buf_request()| but the return
  467. result is different. Wait maximum of {timeout_ms} (default 1000) ms.
  468. Parameters: ~
  469. • {bufnr} (number) Buffer handle, or 0 for current.
  470. • {method} (string) LSP method name
  471. • {params} (optional, table) Parameters to send to the server
  472. • {timeout_ms} (optional, number, default=1000) Maximum time in
  473. milliseconds to wait for a result.
  474. Return: ~
  475. Map of client_id:request_result. On timeout, cancel or error, returns
  476. `(nil, err)` where `err` is a string describing the failure reason.
  477. client() *vim.lsp.client*
  478. LSP client object. You can get an active client object via
  479. |vim.lsp.get_client_by_id()| or |vim.lsp.get_active_clients()|.
  480. • Methods:
  481. • request(method, params, [handler], bufnr) Sends a request to the
  482. server. This is a thin wrapper around {client.rpc.request} with some
  483. additional checking. If {handler} is not specified, If one is not
  484. found there, then an error will occur. Returns: {status},
  485. {[client_id]}. {status} is a boolean indicating if the notification
  486. was successful. If it is `false`, then it will always be `false` (the
  487. client has shutdown). If {status} is `true`, the function returns
  488. {request_id} as the second result. You can use this with
  489. `client.cancel_request(request_id)` to cancel the request.
  490. • request_sync(method, params, timeout_ms, bufnr) Sends a request to the
  491. server and synchronously waits for the response. This is a wrapper
  492. around {client.request} Returns: { err=err, result=result }, a
  493. dictionary, where `err` and `result` come from the |lsp-handler|. On
  494. timeout, cancel or error, returns `(nil, err)` where `err` is a string
  495. describing the failure reason. If the request was unsuccessful returns
  496. `nil`.
  497. • notify(method, params) Sends a notification to an LSP server. Returns:
  498. a boolean to indicate if the notification was successful. If it is
  499. false, then it will always be false (the client has shutdown).
  500. • cancel_request(id) Cancels a request with a given request id. Returns:
  501. same as `notify()`.
  502. • stop([force]) Stops a client, optionally with force. By default, it
  503. will just ask the server to shutdown without force. If you request to
  504. stop a client which has previously been requested to shutdown, it will
  505. automatically escalate and force shutdown.
  506. • is_stopped() Checks whether a client is stopped. Returns: true if the
  507. client is fully stopped.
  508. • on_attach(client, bufnr) Runs the on_attach function from the client's
  509. config if it was defined. Useful for buffer-local setup.
  510. • Members
  511. • {id} (number): The id allocated to the client.
  512. • {name} (string): If a name is specified on creation, that will be
  513. used. Otherwise it is just the client id. This is used for logs and
  514. messages.
  515. • {rpc} (table): RPC client object, for low level interaction with the
  516. client. See |vim.lsp.rpc.start()|.
  517. • {offset_encoding} (string): The encoding used for communicating with
  518. the server. You can modify this in the `config`'s `on_init` method
  519. before text is sent to the server.
  520. • {handlers} (table): The handlers used by the client as described in
  521. |lsp-handler|.
  522. • {requests} (table): The current pending requests in flight to the
  523. server. Entries are key-value pairs with the key being the request ID
  524. while the value is a table with `type`, `bufnr`, and `method`
  525. key-value pairs. `type` is either "pending" for an active request, or
  526. "cancel" for a cancel request.
  527. • {config} (table): copy of the table that was passed by the user to
  528. |vim.lsp.start_client()|.
  529. • {server_capabilities} (table): Response from the server sent on
  530. `initialize` describing the server's capabilities.
  531. client_is_stopped({client_id}) *vim.lsp.client_is_stopped()*
  532. Checks whether a client is stopped.
  533. Parameters: ~
  534. • {client_id} (Number)
  535. Return: ~
  536. true if client is stopped, false otherwise.
  537. *vim.lsp.for_each_buffer_client()*
  538. for_each_buffer_client({bufnr}, {fn})
  539. Invokes a function for each LSP client attached to a buffer.
  540. Parameters: ~
  541. • {bufnr} (number) Buffer number
  542. • {fn} (function) Function to run on each client attached to buffer
  543. {bufnr}. The function takes the client, client ID, and buffer
  544. number as arguments. Example: >
  545. vim.lsp.for_each_buffer_client(0, function(client, client_id, bufnr)
  546. print(vim.inspect(client))
  547. end)
  548. <
  549. formatexpr({opts}) *vim.lsp.formatexpr()*
  550. Provides an interface between the built-in client and a `formatexpr`
  551. function.
  552. Currently only supports a single client. This can be set via `setlocal
  553. formatexpr=v:lua.vim.lsp.formatexpr()` but will typically or in
  554. `on_attach` via `vim.api.nvim_buf_set_option(bufnr, 'formatexpr',
  555. 'v:lua.vim.lsp.formatexpr(#{timeout_ms:250})')`.
  556. Parameters: ~
  557. • {opts} (table) options for customizing the formatting expression
  558. which takes the following optional keys:
  559. • timeout_ms (default 500ms). The timeout period for the
  560. formatting request.
  561. get_active_clients({filter}) *vim.lsp.get_active_clients()*
  562. Get active clients.
  563. Parameters: ~
  564. • {filter} (table|nil) A table with key-value pairs used to filter the
  565. returned clients. The available keys are:
  566. • id (number): Only return clients with the given id
  567. • bufnr (number): Only return clients attached to this
  568. buffer
  569. • name (string): Only return clients with the given name
  570. Return: ~
  571. (table) List of |vim.lsp.client| objects
  572. *vim.lsp.get_buffers_by_client_id()*
  573. get_buffers_by_client_id({client_id})
  574. Returns list of buffers attached to client_id.
  575. Parameters: ~
  576. • {client_id} (number) client id
  577. Return: ~
  578. list of buffer ids
  579. get_client_by_id({client_id}) *vim.lsp.get_client_by_id()*
  580. Gets a client by id, or nil if the id is invalid. The returned client may
  581. not yet be fully initialized.
  582. Parameters: ~
  583. • {client_id} (number) client id
  584. Return: ~
  585. |vim.lsp.client| object, or nil
  586. get_log_path() *vim.lsp.get_log_path()*
  587. Gets the path of the logfile used by the LSP client.
  588. Return: ~
  589. (String) Path to logfile.
  590. omnifunc({findstart}, {base}) *vim.lsp.omnifunc()*
  591. Implements 'omnifunc' compatible LSP completion.
  592. Parameters: ~
  593. • {findstart} 0 or 1, decides behavior
  594. • {base} If findstart=0, text to match against
  595. Return: ~
  596. (number) Decided by {findstart}:
  597. • findstart=0: column where the completion starts, or -2 or -3
  598. • findstart=1: list of matches (actually just calls |complete()|)
  599. See also: ~
  600. |complete-functions|
  601. |complete-items|
  602. |CompleteDone|
  603. set_log_level({level}) *vim.lsp.set_log_level()*
  604. Sets the global log level for LSP logging.
  605. Levels by name: "TRACE", "DEBUG", "INFO", "WARN", "ERROR", "OFF"
  606. Level numbers begin with "TRACE" at 0
  607. Use `lsp.log_levels` for reverse lookup.
  608. Parameters: ~
  609. • {level} [number|string] the case insensitive level name or number
  610. See also: ~
  611. |vim.lsp.log_levels|
  612. start({config}, {opts}) *vim.lsp.start()*
  613. Create a new LSP client and start a language server or reuses an already
  614. running client if one is found matching `name` and `root_dir`. Attaches
  615. the current buffer to the client.
  616. Example:
  617. >
  618. vim.lsp.start({
  619. name = 'my-server-name',
  620. cmd = {'name-of-language-server-executable'},
  621. root_dir = vim.fs.dirname(vim.fs.find({'pyproject.toml', 'setup.py'}, { upward = true })[1]),
  622. })
  623. <
  624. See |vim.lsp.start_client()| for all available options. The most important
  625. are:
  626. • `name` arbitrary name for the LSP client. Should be unique per language
  627. server.
  628. • `cmd` command (in list form) used to start the language server. Must be
  629. absolute, or found on `$PATH`. Shell constructs like `~` are not
  630. expanded.
  631. • `root_dir` path to the project root. By default this is used to decide
  632. if an existing client should be re-used. The example above uses
  633. |vim.fs.find()| and |vim.fs.dirname()| to detect the root by traversing
  634. the file system upwards starting from the current directory until either
  635. a `pyproject.toml` or `setup.py` file is found.
  636. • `workspace_folders` list of `{ uri:string, name: string }` tables
  637. specifying the project root folders used by the language server. If
  638. `nil` the property is derived from `root_dir` for convenience.
  639. Language servers use this information to discover metadata like the
  640. dependencies of your project and they tend to index the contents within
  641. the project folder.
  642. To ensure a language server is only started for languages it can handle,
  643. make sure to call |vim.lsp.start()| within a |FileType| autocmd. Either
  644. use |:au|, |nvim_create_autocmd()| or put the call in a
  645. `ftplugin/<filetype_name>.lua` (See |ftplugin-name|)
  646. Parameters: ~
  647. • {config} (table) Same configuration as documented in
  648. |vim.lsp.start_client()|
  649. • {opts} nil|table Optional keyword arguments:
  650. • reuse_client (fun(client: client, config: table): boolean)
  651. Predicate used to decide if a client should be re-used.
  652. Used on all running clients. The default implementation
  653. re-uses a client if name and root_dir matches.
  654. Return: ~
  655. (number|nil) client_id
  656. start_client({config}) *vim.lsp.start_client()*
  657. Starts and initializes a client with the given configuration.
  658. Parameter `cmd` is required.
  659. The following parameters describe fields in the {config} table.
  660. Parameters: ~
  661. • {cmd} (table|string|fun(dispatchers: table):table)
  662. command string or list treated like |jobstart()|.
  663. The command must launch the language server
  664. process. `cmd` can also be a function that
  665. creates an RPC client. The function receives a
  666. dispatchers table and must return a table with
  667. the functions `request`, `notify`, `is_closing`
  668. and `terminate` See |vim.lsp.rpc.request()| and
  669. |vim.lsp.rpc.notify()| For TCP there is a
  670. built-in rpc client factory:
  671. |vim.lsp.rpc.connect()|
  672. • {cmd_cwd} (string, default=|getcwd()|) Directory to launch
  673. the `cmd` process. Not related to `root_dir`.
  674. • {cmd_env} (table) Environment flags to pass to the LSP on
  675. spawn. Can be specified using keys like a map or
  676. as a list with `k=v` pairs or both. Non-string values are coerced to
  677. string. Example: >
  678. { "PRODUCTION=true"; "TEST=123"; PORT = 8080; HOST = "0.0.0.0"; }
  679. <
  680. • {detached} (boolean, default true) Daemonize the server
  681. process so that it runs in a separate process
  682. group from Nvim. Nvim will shutdown the process
  683. on exit, but if Nvim fails to exit cleanly this
  684. could leave behind orphaned server processes.
  685. • {workspace_folders} (table) List of workspace folders passed to the
  686. language server. For backwards compatibility
  687. rootUri and rootPath will be derived from the
  688. first workspace folder in this list. See
  689. `workspaceFolders` in the LSP spec.
  690. • {capabilities} Map overriding the default capabilities defined
  691. by |vim.lsp.protocol.make_client_capabilities()|,
  692. passed to the language server on initialization.
  693. Hint: use make_client_capabilities() and modify
  694. its result.
  695. • Note: To send an empty dictionary use
  696. `{[vim.type_idx]=vim.types.dictionary}`, else
  697. it will be encoded as an array.
  698. • {handlers} Map of language server method names to
  699. |lsp-handler|
  700. • {settings} Map with language server specific settings. These
  701. are returned to the language server if requested
  702. via `workspace/configuration`. Keys are
  703. case-sensitive.
  704. • {commands} (table) Table that maps string of clientside
  705. commands to user-defined functions. Commands
  706. passed to start_client take precedence over the
  707. global command registry. Each key must be a
  708. unique command name, and the value is a function
  709. which is called if any LSP action (code action,
  710. code lenses, ...) triggers the command.
  711. • {init_options} Values to pass in the initialization request as
  712. `initializationOptions`. See `initialize` in the
  713. LSP spec.
  714. • {name} (string, default=client-id) Name in log messages.
  715. • {get_language_id} function(bufnr, filetype) -> language ID as
  716. string. Defaults to the filetype.
  717. • {offset_encoding} (default="utf-16") One of "utf-8", "utf-16", or
  718. "utf-32" which is the encoding that the LSP
  719. server expects. Client does not verify this is
  720. correct.
  721. • {on_error} Callback with parameters (code, ...), invoked
  722. when the client operation throws an error. `code`
  723. is a number describing the error. Other arguments
  724. may be passed depending on the error kind. See
  725. `vim.lsp.rpc.client_errors` for possible errors.
  726. Use `vim.lsp.rpc.client_errors[code]` to get
  727. human-friendly name.
  728. • {before_init} Callback with parameters (initialize_params,
  729. config) invoked before the LSP "initialize"
  730. phase, where `params` contains the parameters
  731. being sent to the server and `config` is the
  732. config that was passed to
  733. |vim.lsp.start_client()|. You can use this to
  734. modify parameters before they are sent.
  735. • {on_init} Callback (client, initialize_result) invoked
  736. after LSP "initialize", where `result` is a table
  737. of `capabilities` and anything else the server
  738. may send. For example, clangd sends
  739. `initialize_result.offsetEncoding` if
  740. `capabilities.offsetEncoding` was sent to it. You
  741. can only modify the `client.offset_encoding` here
  742. before any notifications are sent. Most language
  743. servers expect to be sent client specified
  744. settings after initialization. Neovim does not
  745. make this assumption. A
  746. `workspace/didChangeConfiguration` notification
  747. should be sent to the server during on_init.
  748. • {on_exit} Callback (code, signal, client_id) invoked on
  749. client exit.
  750. • code: exit code of the process
  751. • signal: number describing the signal used to
  752. terminate (if any)
  753. • client_id: client handle
  754. • {on_attach} Callback (client, bufnr) invoked when client
  755. attaches to a buffer.
  756. • {trace} "off" | "messages" | "verbose" | nil passed
  757. directly to the language server in the initialize
  758. request. Invalid/empty values will default to
  759. "off"
  760. • {flags} A table with flags for the client. The current
  761. (experimental) flags are:
  762. • allow_incremental_sync (bool, default true):
  763. Allow using incremental sync for buffer edits
  764. • debounce_text_changes (number, default 150):
  765. Debounce didChange notifications to the server
  766. by the given number in milliseconds. No
  767. debounce occurs if nil
  768. • exit_timeout (number|boolean, default false):
  769. Milliseconds to wait for server to exit cleanly
  770. after sending the "shutdown" request before
  771. sending kill -15. If set to false, nvim exits
  772. immediately after sending the "shutdown"
  773. request to the server.
  774. • {root_dir} (string) Directory where the LSP server will base
  775. its workspaceFolders, rootUri, and rootPath on
  776. initialization.
  777. Return: ~
  778. Client id. |vim.lsp.get_client_by_id()| Note: client may not be fully
  779. initialized. Use `on_init` to do any actions once the client has been
  780. initialized.
  781. stop_client({client_id}, {force}) *vim.lsp.stop_client()*
  782. Stops a client(s).
  783. You can also use the `stop()` function on a |vim.lsp.client| object. To
  784. stop all clients:
  785. >
  786. vim.lsp.stop_client(vim.lsp.get_active_clients())
  787. <
  788. By default asks the server to shutdown, unless stop was requested already
  789. for this client, then force-shutdown is attempted.
  790. Parameters: ~
  791. • {client_id} client id or |vim.lsp.client| object, or list thereof
  792. • {force} (boolean) (optional) shutdown forcefully
  793. tagfunc({...}) *vim.lsp.tagfunc()*
  794. Provides an interface between the built-in client and 'tagfunc'.
  795. When used with normal mode commands (e.g. |CTRL-]|) this will invoke the
  796. "textDocument/definition" LSP method to find the tag under the cursor.
  797. Otherwise, uses "workspace/symbol". If no results are returned from any
  798. LSP servers, falls back to using built-in tags.
  799. Parameters: ~
  800. • {pattern} Pattern used to find a workspace symbol
  801. • {flags} See |tag-function|
  802. Return: ~
  803. A list of matching tags
  804. with({handler}, {override_config}) *vim.lsp.with()*
  805. Function to manage overriding defaults for LSP handlers.
  806. Parameters: ~
  807. • {handler} (function) See |lsp-handler|
  808. • {override_config} (table) Table containing the keys to override
  809. behavior of the {handler}
  810. ==============================================================================
  811. Lua module: vim.lsp.buf *lsp-buf*
  812. *vim.lsp.buf.add_workspace_folder()*
  813. add_workspace_folder({workspace_folder})
  814. Add the folder at path to the workspace folders. If {path} is not
  815. provided, the user will be prompted for a path using |input()|.
  816. clear_references() *vim.lsp.buf.clear_references()*
  817. Removes document highlights from current buffer.
  818. code_action({options}) *vim.lsp.buf.code_action()*
  819. Selects a code action available at the current cursor position.
  820. Parameters: ~
  821. • {options} (table|nil) Optional table which holds the following
  822. optional fields:
  823. • context: (table|nil) Corresponds to `CodeActionContext` of the LSP specification:
  824. • diagnostics (table|nil): LSP`Diagnostic[]` . Inferred from the current position if not provided.
  825. • only (table|nil): List of LSP `CodeActionKind`s used to
  826. filter the code actions. Most language servers support
  827. values like `refactor` or `quickfix`.
  828. • filter: (function|nil) Predicate taking an `CodeAction`
  829. and returning a boolean.
  830. • apply: (boolean|nil) When set to `true`, and there is
  831. just one remaining action (after filtering), the action
  832. is applied without user query.
  833. • range: (table|nil) Range for which code actions should be
  834. requested. If in visual mode this defaults to the active
  835. selection. Table must contain `start` and `end` keys with
  836. {row, col} tuples using mark-like indexing. See
  837. |api-indexing|
  838. See also: ~
  839. https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_codeAction
  840. completion({context}) *vim.lsp.buf.completion()*
  841. Retrieves the completion items at the current cursor position. Can only be
  842. called in Insert mode.
  843. Parameters: ~
  844. • {context} (context support not yet implemented) Additional
  845. information about the context in which a completion was
  846. triggered (how it was triggered, and by which trigger
  847. character, if applicable)
  848. See also: ~
  849. vim.lsp.protocol.constants.CompletionTriggerKind
  850. declaration({options}) *vim.lsp.buf.declaration()*
  851. Jumps to the declaration of the symbol under the cursor.
  852. Note:
  853. Many servers do not implement this method. Generally, see
  854. |vim.lsp.buf.definition()| instead.
  855. Parameters: ~
  856. • {options} (table|nil) additional options
  857. • reuse_win: (boolean) Jump to existing window if buffer is
  858. already open.
  859. • on_list: (function) handler for list results. See
  860. |lsp-on-list-handler|
  861. definition({options}) *vim.lsp.buf.definition()*
  862. Jumps to the definition of the symbol under the cursor.
  863. Parameters: ~
  864. • {options} (table|nil) additional options
  865. • reuse_win: (boolean) Jump to existing window if buffer is
  866. already open.
  867. • on_list: (function) handler for list results. See
  868. |lsp-on-list-handler|
  869. document_highlight() *vim.lsp.buf.document_highlight()*
  870. Send request to the server to resolve document highlights for the current
  871. text document position. This request can be triggered by a key mapping or
  872. by events such as `CursorHold`, e.g.:
  873. >
  874. autocmd CursorHold <buffer> lua vim.lsp.buf.document_highlight()
  875. autocmd CursorHoldI <buffer> lua vim.lsp.buf.document_highlight()
  876. autocmd CursorMoved <buffer> lua vim.lsp.buf.clear_references()
  877. <
  878. Note: Usage of |vim.lsp.buf.document_highlight()| requires the following
  879. highlight groups to be defined or you won't be able to see the actual
  880. highlights. |hl-LspReferenceText| |hl-LspReferenceRead|
  881. |hl-LspReferenceWrite|
  882. document_symbol({options}) *vim.lsp.buf.document_symbol()*
  883. Lists all symbols in the current buffer in the quickfix window.
  884. Parameters: ~
  885. • {options} (table|nil) additional options
  886. • on_list: (function) handler for list results. See
  887. |lsp-on-list-handler|
  888. execute_command({command_params}) *vim.lsp.buf.execute_command()*
  889. Executes an LSP server command.
  890. Parameters: ~
  891. • {command_params} (table) A valid `ExecuteCommandParams` object
  892. See also: ~
  893. https://microsoft.github.io/language-server-protocol/specifications/specification-current/#workspace_executeCommand
  894. format({options}) *vim.lsp.buf.format()*
  895. Formats a buffer using the attached (and optionally filtered) language
  896. server clients.
  897. Parameters: ~
  898. • {options} table|nil Optional table which holds the following optional
  899. fields:
  900. • formatting_options (table|nil): Can be used to specify
  901. FormattingOptions. Some unspecified options will be
  902. automatically derived from the current Neovim options.
  903. See https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#formattingOptions
  904. • timeout_ms (integer|nil, default 1000): Time in
  905. milliseconds to block for formatting requests. No effect
  906. if async=true
  907. • bufnr (number|nil): Restrict formatting to the clients
  908. attached to the given buffer, defaults to the current
  909. buffer (0).
  910. • filter (function|nil): Predicate used to filter clients.
  911. Receives a client as argument and must return a boolean.
  912. Clients matching the predicate are included. Example: • >
  913. -- Never request typescript-language-server for formatting
  914. vim.lsp.buf.format {
  915. filter = function(client) return client.name ~= "tsserver" end
  916. }
  917. <
  918. • async boolean|nil If true the method won't block.
  919. Defaults to false. Editing the buffer while formatting
  920. asynchronous can lead to unexpected changes.
  921. • id (number|nil): Restrict formatting to the client with
  922. ID (client.id) matching this field.
  923. • name (string|nil): Restrict formatting to the client with
  924. name (client.name) matching this field.
  925. • range (table|nil) Range to format. Table must contain
  926. `start` and `end` keys with {row, col} tuples using (1,0)
  927. indexing. Defaults to current selection in visual mode
  928. Defaults to `nil` in other modes, formatting the full
  929. buffer
  930. formatting({options}) *vim.lsp.buf.formatting()*
  931. Formats the current buffer.
  932. Parameters: ~
  933. • {options} (table|nil) Can be used to specify FormattingOptions. Some
  934. unspecified options will be automatically derived from the
  935. current Neovim options.
  936. See also: ~
  937. https://microsoft.github.io/language-server-protocol/specification#textDocument_formatting
  938. *vim.lsp.buf.formatting_seq_sync()*
  939. formatting_seq_sync({options}, {timeout_ms}, {order})
  940. Formats the current buffer by sequentially requesting formatting from
  941. attached clients.
  942. Useful when multiple clients with formatting capability are attached.
  943. Since it's synchronous, can be used for running on save, to make sure
  944. buffer is formatted prior to being saved. {timeout_ms} is passed on to the
  945. |vim.lsp.client| `request_sync` method. Example: >
  946. vim.api.nvim_command[[autocmd BufWritePre <buffer> lua vim.lsp.buf.formatting_seq_sync()]]
  947. <
  948. Parameters: ~
  949. • {options} (table|nil) `FormattingOptions` entries
  950. • {timeout_ms} (number|nil) Request timeout
  951. • {order} (table|nil) List of client names. Formatting is
  952. requested from clients in the following order: first all
  953. clients that are not in the `order` list, then the
  954. remaining clients in the order as they occur in the
  955. `order` list.
  956. *vim.lsp.buf.formatting_sync()*
  957. formatting_sync({options}, {timeout_ms})
  958. Performs |vim.lsp.buf.formatting()| synchronously.
  959. Useful for running on save, to make sure buffer is formatted prior to
  960. being saved. {timeout_ms} is passed on to |vim.lsp.buf_request_sync()|.
  961. Example:
  962. >
  963. autocmd BufWritePre <buffer> lua vim.lsp.buf.formatting_sync()
  964. <
  965. Parameters: ~
  966. • {options} (table|nil) with valid `FormattingOptions` entries
  967. • {timeout_ms} (number) Request timeout
  968. See also: ~
  969. |vim.lsp.buf.format()|
  970. hover() *vim.lsp.buf.hover()*
  971. Displays hover information about the symbol under the cursor in a floating
  972. window. Calling the function twice will jump into the floating window.
  973. implementation({options}) *vim.lsp.buf.implementation()*
  974. Lists all the implementations for the symbol under the cursor in the
  975. quickfix window.
  976. Parameters: ~
  977. • {options} (table|nil) additional options
  978. • on_list: (function) handler for list results. See
  979. |lsp-on-list-handler|
  980. incoming_calls() *vim.lsp.buf.incoming_calls()*
  981. Lists all the call sites of the symbol under the cursor in the |quickfix|
  982. window. If the symbol can resolve to multiple items, the user can pick one
  983. in the |inputlist()|.
  984. list_workspace_folders() *vim.lsp.buf.list_workspace_folders()*
  985. List workspace folders.
  986. outgoing_calls() *vim.lsp.buf.outgoing_calls()*
  987. Lists all the items that are called by the symbol under the cursor in the
  988. |quickfix| window. If the symbol can resolve to multiple items, the user
  989. can pick one in the |inputlist()|.
  990. *vim.lsp.buf.range_code_action()*
  991. range_code_action({context}, {start_pos}, {end_pos})
  992. Performs |vim.lsp.buf.code_action()| for a given range.
  993. Parameters: ~
  994. • {context} (table|nil) `CodeActionContext` of the LSP specification:
  995. • diagnostics: (table|nil) LSP`Diagnostic[]` . Inferred from the current position if not provided.
  996. • only: (table|nil) List of LSP `CodeActionKind`s used to
  997. filter the code actions. Most language servers support
  998. values like `refactor` or `quickfix`.
  999. • {start_pos} ({number, number}, optional) mark-indexed position.
  1000. Defaults to the start of the last visual selection.
  1001. • {end_pos} ({number, number}, optional) mark-indexed position.
  1002. Defaults to the end of the last visual selection.
  1003. *vim.lsp.buf.range_formatting()*
  1004. range_formatting({options}, {start_pos}, {end_pos})
  1005. Formats a given range.
  1006. Parameters: ~
  1007. • {options} Table with valid `FormattingOptions` entries.
  1008. • {start_pos} ({number, number}, optional) mark-indexed position.
  1009. Defaults to the start of the last visual selection.
  1010. • {end_pos} ({number, number}, optional) mark-indexed position.
  1011. Defaults to the end of the last visual selection.
  1012. references({context}, {options}) *vim.lsp.buf.references()*
  1013. Lists all the references to the symbol under the cursor in the quickfix
  1014. window.
  1015. Parameters: ~
  1016. • {context} (table) Context for the request
  1017. • {options} (table|nil) additional options
  1018. • on_list: (function) handler for list results. See
  1019. |lsp-on-list-handler|
  1020. See also: ~
  1021. https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_references
  1022. *vim.lsp.buf.remove_workspace_folder()*
  1023. remove_workspace_folder({workspace_folder})
  1024. Remove the folder at path from the workspace folders. If {path} is not
  1025. provided, the user will be prompted for a path using |input()|.
  1026. rename({new_name}, {options}) *vim.lsp.buf.rename()*
  1027. Renames all references to the symbol under the cursor.
  1028. Parameters: ~
  1029. • {new_name} (string|nil) If not provided, the user will be prompted
  1030. for a new name using |vim.ui.input()|.
  1031. • {options} (table|nil) additional options
  1032. • filter (function|nil): Predicate used to filter clients.
  1033. Receives a client as argument and must return a boolean.
  1034. Clients matching the predicate are included.
  1035. • name (string|nil): Restrict clients used for rename to
  1036. ones where client.name matches this field.
  1037. server_ready() *vim.lsp.buf.server_ready()*
  1038. Checks whether the language servers attached to the current buffer are
  1039. ready.
  1040. Return: ~
  1041. `true` if server responds.
  1042. signature_help() *vim.lsp.buf.signature_help()*
  1043. Displays signature information about the symbol under the cursor in a
  1044. floating window.
  1045. type_definition({options}) *vim.lsp.buf.type_definition()*
  1046. Jumps to the definition of the type of the symbol under the cursor.
  1047. Parameters: ~
  1048. • {options} (table|nil) additional options
  1049. • reuse_win: (boolean) Jump to existing window if buffer is
  1050. already open.
  1051. • on_list: (function) handler for list results. See
  1052. |lsp-on-list-handler|
  1053. workspace_symbol({query}, {options}) *vim.lsp.buf.workspace_symbol()*
  1054. Lists all symbols in the current workspace in the quickfix window.
  1055. The list is filtered against {query}; if the argument is omitted from the
  1056. call, the user is prompted to enter a string on the command line. An empty
  1057. string means no filtering is done.
  1058. Parameters: ~
  1059. • {query} (string, optional)
  1060. • {options} (table|nil) additional options
  1061. • on_list: (function) handler for list results. See
  1062. |lsp-on-list-handler|
  1063. ==============================================================================
  1064. Lua module: vim.lsp.diagnostic *lsp-diagnostic*
  1065. get_namespace({client_id}) *vim.lsp.diagnostic.get_namespace()*
  1066. Get the diagnostic namespace associated with an LSP client
  1067. |vim.diagnostic|.
  1068. Parameters: ~
  1069. • {client_id} (number) The id of the LSP client
  1070. *vim.lsp.diagnostic.on_publish_diagnostics()*
  1071. on_publish_diagnostics({_}, {result}, {ctx}, {config})
  1072. |lsp-handler| for the method "textDocument/publishDiagnostics"
  1073. See |vim.diagnostic.config()| for configuration options. Handler-specific
  1074. configuration can be set using |vim.lsp.with()|: >
  1075. vim.lsp.handlers["textDocument/publishDiagnostics"] = vim.lsp.with(
  1076. vim.lsp.diagnostic.on_publish_diagnostics, {
  1077. -- Enable underline, use default values
  1078. underline = true,
  1079. -- Enable virtual text, override spacing to 4
  1080. virtual_text = {
  1081. spacing = 4,
  1082. },
  1083. -- Use a function to dynamically turn signs off
  1084. -- and on, using buffer local variables
  1085. signs = function(namespace, bufnr)
  1086. return vim.b[bufnr].show_signs == true
  1087. end,
  1088. -- Disable a feature
  1089. update_in_insert = false,
  1090. }
  1091. )
  1092. <
  1093. Parameters: ~
  1094. • {config} (table) Configuration table (see |vim.diagnostic.config()|).
  1095. ==============================================================================
  1096. Lua module: vim.lsp.codelens *lsp-codelens*
  1097. display({lenses}, {bufnr}, {client_id}) *vim.lsp.codelens.display()*
  1098. Display the lenses using virtual text
  1099. Parameters: ~
  1100. • {lenses} (table) of lenses to display (`CodeLens[] | null`)
  1101. • {bufnr} (number)
  1102. • {client_id} (number)
  1103. get({bufnr}) *vim.lsp.codelens.get()*
  1104. Return all lenses for the given buffer
  1105. Parameters: ~
  1106. • {bufnr} (number) Buffer number. 0 can be used for the current buffer.
  1107. Return: ~
  1108. (table) (`CodeLens[]`)
  1109. *vim.lsp.codelens.on_codelens()*
  1110. on_codelens({err}, {result}, {ctx}, {_})
  1111. |lsp-handler| for the method `textDocument/codeLens`
  1112. refresh() *vim.lsp.codelens.refresh()*
  1113. Refresh the codelens for the current buffer
  1114. It is recommended to trigger this using an autocmd or via keymap.
  1115. >
  1116. autocmd BufEnter,CursorHold,InsertLeave <buffer> lua vim.lsp.codelens.refresh()
  1117. <
  1118. run() *vim.lsp.codelens.run()*
  1119. Run the code lens in the current line
  1120. save({lenses}, {bufnr}, {client_id}) *vim.lsp.codelens.save()*
  1121. Store lenses for a specific buffer and client
  1122. Parameters: ~
  1123. • {lenses} (table) of lenses to store (`CodeLens[] | null`)
  1124. • {bufnr} (number)
  1125. • {client_id} (number)
  1126. ==============================================================================
  1127. Lua module: vim.lsp.handlers *lsp-handlers*
  1128. hover({_}, {result}, {ctx}, {config}) *vim.lsp.handlers.hover()*
  1129. |lsp-handler| for the method "textDocument/hover" >
  1130. vim.lsp.handlers["textDocument/hover"] = vim.lsp.with(
  1131. vim.lsp.handlers.hover, {
  1132. -- Use a sharp border with `FloatBorder` highlights
  1133. border = "single"
  1134. }
  1135. )
  1136. <
  1137. Parameters: ~
  1138. • {config} (table) Configuration table.
  1139. • border: (default=nil)
  1140. • Add borders to the floating window
  1141. • See |nvim_open_win()|
  1142. *vim.lsp.handlers.signature_help()*
  1143. signature_help({_}, {result}, {ctx}, {config})
  1144. |lsp-handler| for the method "textDocument/signatureHelp". The active
  1145. parameter is highlighted with |hl-LspSignatureActiveParameter|. >
  1146. vim.lsp.handlers["textDocument/signatureHelp"] = vim.lsp.with(
  1147. vim.lsp.handlers.signature_help, {
  1148. -- Use a sharp border with `FloatBorder` highlights
  1149. border = "single"
  1150. }
  1151. )
  1152. <
  1153. Parameters: ~
  1154. • {config} (table) Configuration table.
  1155. • border: (default=nil)
  1156. • Add borders to the floating window
  1157. • See |nvim_open_win()|
  1158. ==============================================================================
  1159. Lua module: vim.lsp.util *lsp-util*
  1160. *vim.lsp.util.apply_text_document_edit()*
  1161. apply_text_document_edit({text_document_edit}, {index}, {offset_encoding})
  1162. Applies a `TextDocumentEdit`, which is a list of changes to a single
  1163. document.
  1164. Parameters: ~
  1165. • {text_document_edit} table: a `TextDocumentEdit` object
  1166. • {index} number: Optional index of the edit, if from a
  1167. list of edits (or nil, if not from a list)
  1168. See also: ~
  1169. https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocumentEdit
  1170. *vim.lsp.util.apply_text_edits()*
  1171. apply_text_edits({text_edits}, {bufnr}, {offset_encoding})
  1172. Applies a list of text edits to a buffer.
  1173. Parameters: ~
  1174. • {text_edits} (table) list of `TextEdit` objects
  1175. • {bufnr} (number) Buffer id
  1176. • {offset_encoding} (string) utf-8|utf-16|utf-32
  1177. See also: ~
  1178. https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textEdit
  1179. *vim.lsp.util.apply_workspace_edit()*
  1180. apply_workspace_edit({workspace_edit}, {offset_encoding})
  1181. Applies a `WorkspaceEdit`.
  1182. Parameters: ~
  1183. • {workspace_edit} (table) `WorkspaceEdit`
  1184. • {offset_encoding} (string) utf-8|utf-16|utf-32 (required)
  1185. buf_clear_references({bufnr}) *vim.lsp.util.buf_clear_references()*
  1186. Removes document highlights from a buffer.
  1187. Parameters: ~
  1188. • {bufnr} (number) Buffer id
  1189. *vim.lsp.util.buf_highlight_references()*
  1190. buf_highlight_references({bufnr}, {references}, {offset_encoding})
  1191. Shows a list of document highlights for a certain buffer.
  1192. Parameters: ~
  1193. • {bufnr} (number) Buffer id
  1194. • {references} (table) List of `DocumentHighlight` objects to
  1195. highlight
  1196. • {offset_encoding} (string) One of "utf-8", "utf-16", "utf-32".
  1197. See also: ~
  1198. https://microsoft.github.io/language-server-protocol/specifications/specification-3-17/#documentHighlight
  1199. *vim.lsp.util.character_offset()*
  1200. character_offset({buf}, {row}, {col}, {offset_encoding})
  1201. Returns the UTF-32 and UTF-16 offsets for a position in a certain buffer.
  1202. Parameters: ~
  1203. • {buf} (number) buffer number (0 for current)
  1204. • {row} 0-indexed line
  1205. • {col} 0-indexed byte offset in line
  1206. • {offset_encoding} (string) utf-8|utf-16|utf-32|nil defaults to
  1207. `offset_encoding` of first client of `buf`
  1208. Return: ~
  1209. (number, number) `offset_encoding` index of the character in line
  1210. {row} column {col} in buffer {buf}
  1211. *vim.lsp.util.convert_input_to_markdown_lines()*
  1212. convert_input_to_markdown_lines({input}, {contents})
  1213. Converts any of `MarkedString` | `MarkedString[]` | `MarkupContent` into a
  1214. list of lines containing valid markdown. Useful to populate the hover
  1215. window for `textDocument/hover`, for parsing the result of
  1216. `textDocument/signatureHelp`, and potentially others.
  1217. Parameters: ~
  1218. • {input} (`MarkedString` | `MarkedString[]` | `MarkupContent`)
  1219. • {contents} (table, optional, default `{}`) List of strings to extend
  1220. with converted lines
  1221. Return: ~
  1222. {contents}, extended with lines of converted markdown.
  1223. See also: ~
  1224. https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_hover
  1225. *vim.lsp.util.convert_signature_help_to_markdown_lines()*
  1226. convert_signature_help_to_markdown_lines({signature_help}, {ft}, {triggers})
  1227. Converts `textDocument/SignatureHelp` response to markdown lines.
  1228. Parameters: ~
  1229. • {signature_help} Response of `textDocument/SignatureHelp`
  1230. • {ft} optional filetype that will be use as the `lang` for
  1231. the label markdown code block
  1232. • {triggers} optional list of trigger characters from the lsp
  1233. server. used to better determine parameter offsets
  1234. Return: ~
  1235. list of lines of converted markdown.
  1236. See also: ~
  1237. https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_signatureHelp
  1238. *vim.lsp.util.extract_completion_items()*
  1239. extract_completion_items({result})
  1240. Can be used to extract the completion items from a `textDocument/completion` request, which may return one of `CompletionItem[]` , `CompletionList` or null.
  1241. Parameters: ~
  1242. • {result} (table) The result of a `textDocument/completion` request
  1243. Return: ~
  1244. (table) List of completion items
  1245. See also: ~
  1246. https://microsoft.github.io/language-server-protocol/specification#textDocument_completion
  1247. get_effective_tabstop({bufnr}) *vim.lsp.util.get_effective_tabstop()*
  1248. Returns indentation size.
  1249. Parameters: ~
  1250. • {bufnr} (number|nil): Buffer handle, defaults to current
  1251. Return: ~
  1252. (number) indentation size
  1253. See also: ~
  1254. 'shiftwidth'
  1255. *vim.lsp.util.jump_to_location()*
  1256. jump_to_location({location}, {offset_encoding}, {reuse_win})
  1257. Jumps to a location.
  1258. Parameters: ~
  1259. • {location} (table) (`Location`|`LocationLink`)
  1260. • {offset_encoding} (string) utf-8|utf-16|utf-32 (required)
  1261. • {reuse_win} (boolean) Jump to existing window if buffer is
  1262. already opened.
  1263. Return: ~
  1264. `true` if the jump succeeded
  1265. *vim.lsp.util.locations_to_items()*
  1266. locations_to_items({locations}, {offset_encoding})
  1267. Returns the items with the byte position calculated correctly and in
  1268. sorted order, for display in quickfix and location lists.
  1269. The result can be passed to the {list} argument of |setqflist()| or
  1270. |setloclist()|.
  1271. Parameters: ~
  1272. • {locations} (table) list of `Location`s or `LocationLink`s
  1273. • {offset_encoding} (string) offset_encoding for locations
  1274. utf-8|utf-16|utf-32
  1275. Return: ~
  1276. (table) list of items
  1277. lookup_section({settings}, {section}) *vim.lsp.util.lookup_section()*
  1278. Helper function to return nested values in language server settings
  1279. Parameters: ~
  1280. • {settings} a table of language server settings
  1281. • {section} a string indicating the field of the settings table
  1282. Return: ~
  1283. (table or string) The value of settings accessed via section
  1284. *vim.lsp.util.make_floating_popup_options()*
  1285. make_floating_popup_options({width}, {height}, {opts})
  1286. Creates a table with sensible default options for a floating window. The
  1287. table can be passed to |nvim_open_win()|.
  1288. Parameters: ~
  1289. • {width} (number) window width (in character cells)
  1290. • {height} (number) window height (in character cells)
  1291. • {opts} (table, optional)
  1292. • offset_x (number) offset to add to `col`
  1293. • offset_y (number) offset to add to `row`
  1294. • border (string or table) override `border`
  1295. • focusable (string or table) override `focusable`
  1296. • zindex (string or table) override `zindex`, defaults to 50
  1297. Return: ~
  1298. (table) Options
  1299. *vim.lsp.util.make_formatting_params()*
  1300. make_formatting_params({options})
  1301. Creates a `DocumentFormattingParams` object for the current buffer and
  1302. cursor position.
  1303. Parameters: ~
  1304. • {options} (table|nil) with valid `FormattingOptions` entries
  1305. Return: ~
  1306. `DocumentFormattingParams` object
  1307. See also: ~
  1308. https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_formatting
  1309. *vim.lsp.util.make_given_range_params()*
  1310. make_given_range_params({start_pos}, {end_pos}, {bufnr}, {offset_encoding})
  1311. Using the given range in the current buffer, creates an object that is
  1312. similar to |vim.lsp.util.make_range_params()|.
  1313. Parameters: ~
  1314. • {start_pos} number[]|nil {row, col} mark-indexed position.
  1315. Defaults to the start of the last visual selection.
  1316. • {end_pos} number[]|nil {row, col} mark-indexed position.
  1317. Defaults to the end of the last visual selection.
  1318. • {bufnr} (number|nil) buffer handle or 0 for current,
  1319. defaults to current
  1320. • {offset_encoding} "utf-8"|"utf-16"|"utf-32"|nil defaults to
  1321. `offset_encoding` of first client of `bufnr`
  1322. Return: ~
  1323. { textDocument = { uri = `current_file_uri` }, range = { start =
  1324. `start_position`, end = `end_position` } }
  1325. *vim.lsp.util.make_position_params()*
  1326. make_position_params({window}, {offset_encoding})
  1327. Creates a `TextDocumentPositionParams` object for the current buffer and
  1328. cursor position.
  1329. Parameters: ~
  1330. • {window} number|nil: window handle or 0 for current,
  1331. defaults to current
  1332. • {offset_encoding} (string) utf-8|utf-16|utf-32|nil defaults to
  1333. `offset_encoding` of first client of buffer of
  1334. `window`
  1335. Return: ~
  1336. `TextDocumentPositionParams` object
  1337. See also: ~
  1338. https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocumentPositionParams
  1339. *vim.lsp.util.make_range_params()*
  1340. make_range_params({window}, {offset_encoding})
  1341. Using the current position in the current buffer, creates an object that
  1342. can be used as a building block for several LSP requests, such as
  1343. `textDocument/codeAction`, `textDocument/colorPresentation`,
  1344. `textDocument/rangeFormatting`.
  1345. Parameters: ~
  1346. • {window} number|nil: window handle or 0 for current,
  1347. defaults to current
  1348. • {offset_encoding} "utf-8"|"utf-16"|"utf-32"|nil defaults to
  1349. `offset_encoding` of first client of buffer of
  1350. `window`
  1351. Return: ~
  1352. { textDocument = { uri = `current_file_uri` }, range = { start =
  1353. `current_position`, end = `current_position` } }
  1354. *vim.lsp.util.make_text_document_params()*
  1355. make_text_document_params({bufnr})
  1356. Creates a `TextDocumentIdentifier` object for the current buffer.
  1357. Parameters: ~
  1358. • {bufnr} number|nil: Buffer handle, defaults to current
  1359. Return: ~
  1360. `TextDocumentIdentifier`
  1361. See also: ~
  1362. https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocumentIdentifier
  1363. *vim.lsp.util.make_workspace_params()*
  1364. make_workspace_params({added}, {removed})
  1365. Create the workspace params
  1366. Parameters: ~
  1367. • {added}
  1368. • {removed}
  1369. *vim.lsp.util.open_floating_preview()*
  1370. open_floating_preview({contents}, {syntax}, {opts})
  1371. Shows contents in a floating window.
  1372. Parameters: ~
  1373. • {contents} (table) of lines to show in window
  1374. • {syntax} (string) of syntax to set for opened buffer
  1375. • {opts} (table) with optional fields (additional keys are passed
  1376. on to |nvim_open_win()|)
  1377. • height: (number) height of floating window
  1378. • width: (number) width of floating window
  1379. • wrap: (boolean, default true) wrap long lines
  1380. • wrap_at: (number) character to wrap at for computing
  1381. height when wrap is enabled
  1382. • max_width: (number) maximal width of floating window
  1383. • max_height: (number) maximal height of floating window
  1384. • pad_top: (number) number of lines to pad contents at top
  1385. • pad_bottom: (number) number of lines to pad contents at
  1386. bottom
  1387. • focus_id: (string) if a popup with this id is opened,
  1388. then focus it
  1389. • close_events: (table) list of events that closes the
  1390. floating window
  1391. • focusable: (boolean, default true) Make float focusable
  1392. • focus: (boolean, default true) If `true`, and if
  1393. {focusable} is also `true`, focus an existing floating
  1394. window with the same {focus_id}
  1395. Return: ~
  1396. bufnr,winnr buffer and window number of the newly created floating
  1397. preview window
  1398. parse_snippet({input}) *vim.lsp.util.parse_snippet()*
  1399. Parses snippets in a completion entry.
  1400. Parameters: ~
  1401. • {input} (string) unparsed snippet
  1402. Return: ~
  1403. (string) parsed snippet
  1404. preview_location({location}, {opts}) *vim.lsp.util.preview_location()*
  1405. Previews a location in a floating window
  1406. behavior depends on type of location:
  1407. • for Location, range is shown (e.g., function definition)
  1408. • for LocationLink, targetRange is shown (e.g., body of function
  1409. definition)
  1410. Parameters: ~
  1411. • {location} a single `Location` or `LocationLink`
  1412. Return: ~
  1413. (bufnr,winnr) buffer and window number of floating window or nil
  1414. rename({old_fname}, {new_fname}, {opts}) *vim.lsp.util.rename()*
  1415. Rename old_fname to new_fname
  1416. Parameters: ~
  1417. • {opts} (table)
  1418. set_lines({lines}, {A}, {B}, {new_lines}) *vim.lsp.util.set_lines()*
  1419. Replaces text in a range with new text.
  1420. CAUTION: Changes in-place!
  1421. Parameters: ~
  1422. • {lines} (table) Original list of strings
  1423. • {A} (table) Start position; a 2-tuple of {line, col} numbers
  1424. • {B} (table) End position; a 2-tuple of {line, col} numbers
  1425. • {new_lines} A list of strings to replace the original
  1426. Return: ~
  1427. (table) The modified {lines} object
  1428. *vim.lsp.util.stylize_markdown()*
  1429. stylize_markdown({bufnr}, {contents}, {opts})
  1430. Converts markdown into syntax highlighted regions by stripping the code
  1431. blocks and converting them into highlighted code. This will by default
  1432. insert a blank line separator after those code block regions to improve
  1433. readability.
  1434. This method configures the given buffer and returns the lines to set.
  1435. If you want to open a popup with fancy markdown, use
  1436. `open_floating_preview` instead
  1437. Parameters: ~
  1438. • {contents} (table) of lines to show in window
  1439. • {opts} dictionary with optional fields
  1440. • height of floating window
  1441. • width of floating window
  1442. • wrap_at character to wrap at for computing height
  1443. • max_width maximal width of floating window
  1444. • max_height maximal height of floating window
  1445. • pad_top number of lines to pad contents at top
  1446. • pad_bottom number of lines to pad contents at bottom
  1447. • separator insert separator after code block
  1448. Return: ~
  1449. width,height size of float
  1450. symbols_to_items({symbols}, {bufnr}) *vim.lsp.util.symbols_to_items()*
  1451. Converts symbols to quickfix list items.
  1452. Parameters: ~
  1453. • {symbols} DocumentSymbol[] or SymbolInformation[]
  1454. *vim.lsp.util.text_document_completion_list_to_complete_items()*
  1455. text_document_completion_list_to_complete_items({result}, {prefix})
  1456. Turns the result of a `textDocument/completion` request into
  1457. vim-compatible |complete-items|.
  1458. Parameters: ~
  1459. • {result} The result of a `textDocument/completion` call, e.g. from
  1460. |vim.lsp.buf.completion()|, which may be one of
  1461. `CompletionItem[]`, `CompletionList` or `null`
  1462. • {prefix} (string) the prefix to filter the completion items
  1463. Return: ~
  1464. { matches = complete-items table, incomplete = bool }
  1465. See also: ~
  1466. |complete-items|
  1467. trim_empty_lines({lines}) *vim.lsp.util.trim_empty_lines()*
  1468. Removes empty lines from the beginning and end.
  1469. Parameters: ~
  1470. • {lines} (table) list of lines to trim
  1471. Return: ~
  1472. (table) trimmed list of lines
  1473. *vim.lsp.util.try_trim_markdown_code_blocks()*
  1474. try_trim_markdown_code_blocks({lines})
  1475. Accepts markdown lines and tries to reduce them to a filetype if they
  1476. comprise just a single code block.
  1477. CAUTION: Modifies the input in-place!
  1478. Parameters: ~
  1479. • {lines} (table) list of lines
  1480. Return: ~
  1481. (string) filetype or "markdown" if it was unchanged.
  1482. ==============================================================================
  1483. Lua module: vim.lsp.log *lsp-log*
  1484. get_filename() *vim.lsp.log.get_filename()*
  1485. Returns the log filename.
  1486. Return: ~
  1487. (string) log filename
  1488. get_level() *vim.lsp.log.get_level()*
  1489. Gets the current log level.
  1490. Return: ~
  1491. (string) current log level
  1492. set_format_func({handle}) *vim.lsp.log.set_format_func()*
  1493. Sets formatting function used to format logs
  1494. Parameters: ~
  1495. • {handle} (function) function to apply to logging arguments, pass
  1496. vim.inspect for multi-line formatting
  1497. set_level({level}) *vim.lsp.log.set_level()*
  1498. Sets the current log level.
  1499. Parameters: ~
  1500. • {level} (string or number) One of `vim.lsp.log.levels`
  1501. should_log({level}) *vim.lsp.log.should_log()*
  1502. Checks whether the level is sufficient for logging.
  1503. Parameters: ~
  1504. • {level} (number) log level
  1505. Return: ~
  1506. (bool) true if would log, false if not
  1507. ==============================================================================
  1508. Lua module: vim.lsp.rpc *lsp-rpc*
  1509. connect({host}, {port}) *vim.lsp.rpc.connect()*
  1510. Create a LSP RPC client factory that connects via TCP to the given host
  1511. and port
  1512. Parameters: ~
  1513. • {host} (string)
  1514. • {port} (number)
  1515. Return: ~
  1516. (function)
  1517. format_rpc_error({err}) *vim.lsp.rpc.format_rpc_error()*
  1518. Constructs an error message from an LSP error object.
  1519. Parameters: ~
  1520. • {err} (table) The error object
  1521. Return: ~
  1522. (string) The formatted error message
  1523. notify({method}, {params}) *vim.lsp.rpc.notify()*
  1524. Sends a notification to the LSP server.
  1525. Parameters: ~
  1526. • {method} (string) The invoked LSP method
  1527. • {params} (table|nil): Parameters for the invoked LSP method
  1528. Return: ~
  1529. (bool) `true` if notification could be sent, `false` if not
  1530. *vim.lsp.rpc.request()*
  1531. request({method}, {params}, {callback}, {notify_reply_callback})
  1532. Sends a request to the LSP server and runs {callback} upon response.
  1533. Parameters: ~
  1534. • {method} (string) The invoked LSP method
  1535. • {params} (table|nil) Parameters for the invoked LSP
  1536. method
  1537. • {callback} (function) Callback to invoke
  1538. • {notify_reply_callback} (function|nil) Callback to invoke as soon as
  1539. a request is no longer pending
  1540. Return: ~
  1541. (bool, number) `(true, message_id)` if request could be sent, `false`
  1542. if not
  1543. *vim.lsp.rpc.rpc_response_error()*
  1544. rpc_response_error({code}, {message}, {data})
  1545. Creates an RPC response object/table.
  1546. Parameters: ~
  1547. • {code} (number) RPC error code defined in
  1548. `vim.lsp.protocol.ErrorCodes`
  1549. • {message} (string|nil) arbitrary message to send to server
  1550. • {data} any|nil arbitrary data to send to server
  1551. *vim.lsp.rpc.start()*
  1552. start({cmd}, {cmd_args}, {dispatchers}, {extra_spawn_params})
  1553. Starts an LSP server process and create an LSP RPC client object to
  1554. interact with it. Communication with the spawned process happens via
  1555. stdio. For communication via TCP, spawn a process manually and use
  1556. |vim.lsp.rpc.connect()|
  1557. Parameters: ~
  1558. • {cmd} (string) Command to start the LSP server.
  1559. • {cmd_args} (table) List of additional string arguments to
  1560. pass to {cmd}.
  1561. • {dispatchers} (table|nil) Dispatchers for LSP message types.
  1562. Valid dispatcher names are:
  1563. • `"notification"`
  1564. • `"server_request"`
  1565. • `"on_error"`
  1566. • `"on_exit"`
  1567. • {extra_spawn_params} (table|nil) Additional context for the LSP
  1568. server process. May contain:
  1569. • {cwd} (string) Working directory for the LSP
  1570. server process
  1571. • {env} (table) Additional environment variables
  1572. for LSP server process
  1573. Return: ~
  1574. Client RPC object.
  1575. Methods:
  1576. • `notify()` |vim.lsp.rpc.notify()|
  1577. • `request()` |vim.lsp.rpc.request()|
  1578. • `is_closing()` returns a boolean indicating if the RPC is closing.
  1579. • `terminate()` terminates the RPC client.
  1580. ==============================================================================
  1581. Lua module: vim.lsp.sync *lsp-sync*
  1582. *vim.lsp.sync.compute_diff()*
  1583. compute_diff({___MissingCloseParenHere___})
  1584. Returns the range table for the difference between prev and curr lines
  1585. Parameters: ~
  1586. • {prev_lines} (table) list of lines
  1587. • {curr_lines} (table) list of lines
  1588. • {firstline} (number) line to begin search for first difference
  1589. • {lastline} (number) line to begin search in old_lines for last
  1590. difference
  1591. • {new_lastline} (number) line to begin search in new_lines for last
  1592. difference
  1593. • {offset_encoding} (string) encoding requested by language server
  1594. Return: ~
  1595. (table) TextDocumentContentChangeEvent see https://microsoft.github.io/language-server-protocol/specifications/specification-3-17/#textDocumentContentChangeEvent
  1596. ==============================================================================
  1597. Lua module: vim.lsp.protocol *lsp-protocol*
  1598. *vim.lsp.protocol.make_client_capabilities()*
  1599. make_client_capabilities()
  1600. Gets a new ClientCapabilities object describing the LSP client
  1601. capabilities.
  1602. *vim.lsp.protocol.resolve_capabilities()*
  1603. resolve_capabilities({server_capabilities})
  1604. Creates a normalized object describing LSP server capabilities.
  1605. Parameters: ~
  1606. • {server_capabilities} (table) Table of capabilities supported by the
  1607. server
  1608. Return: ~
  1609. (table) Normalized table of capabilities
  1610. vim:tw=78:ts=8:sw=4:sts=4:et:ft=help:norl: