diagnostic.txt 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912
  1. *diagnostic.txt* Diagnostics
  2. NVIM REFERENCE MANUAL
  3. Diagnostic framework *vim.diagnostic*
  4. Nvim provides a framework for displaying errors or warnings from external
  5. tools, otherwise known as "diagnostics". These diagnostics can come from a
  6. variety of sources, such as linters or LSP servers. The diagnostic framework
  7. is an extension to existing error handling functionality such as the
  8. |quickfix| list.
  9. Type |gO| to see the table of contents.
  10. ==============================================================================
  11. QUICKSTART *diagnostic-quickstart*
  12. Anything that reports diagnostics is referred to below as a "diagnostic
  13. producer". Diagnostic producers need only follow a few simple steps to
  14. report diagnostics:
  15. 1. Create a namespace |nvim_create_namespace()|. Note that the namespace must
  16. have a name. Anonymous namespaces WILL NOT WORK.
  17. 2. (Optional) Configure options for the diagnostic namespace
  18. |vim.diagnostic.config()|.
  19. 3. Generate diagnostics.
  20. 4. Set the diagnostics for the buffer |vim.diagnostic.set()|.
  21. 5. Repeat from step 3.
  22. Generally speaking, the API is split between functions meant to be used by
  23. diagnostic producers and those meant for diagnostic consumers (i.e. end users
  24. who want to read and view the diagnostics for a buffer). The APIs for
  25. producers require a {namespace} as their first argument, while those for
  26. consumers generally do not require a namespace (though often one may be
  27. optionally supplied). A good rule of thumb is that if a method is meant to
  28. modify the diagnostics for a buffer (e.g. |vim.diagnostic.set()|) then it
  29. requires a namespace.
  30. *vim.diagnostic.severity* *diagnostic-severity*
  31. The "severity" key in a diagnostic is one of the values defined in
  32. `vim.diagnostic.severity`:
  33. vim.diagnostic.severity.ERROR
  34. vim.diagnostic.severity.WARN
  35. vim.diagnostic.severity.INFO
  36. vim.diagnostic.severity.HINT
  37. Functions that take a severity as an optional parameter (e.g.
  38. |vim.diagnostic.get()|) accept one of three forms:
  39. 1. A single |vim.diagnostic.severity| value: >lua
  40. vim.diagnostic.get(0, { severity = vim.diagnostic.severity.WARN })
  41. 2. A table with a "min" or "max" key (or both): >lua
  42. vim.diagnostic.get(0, { severity = { min = vim.diagnostic.severity.WARN } })
  43. <
  44. This form allows users to specify a range of severities.
  45. 3. A list-like table: >lua
  46. vim.diagnostic.get(0, { severity = {
  47. vim.diagnostic.severity.WARN,
  48. vim.diagnostic.severity.INFO,
  49. } })
  50. <
  51. This form allows users to filter for specific severities
  52. ==============================================================================
  53. HANDLERS *diagnostic-handlers*
  54. Diagnostics are shown to the user with |vim.diagnostic.show()|. The display of
  55. diagnostics is managed through handlers. A handler is a table with a "show"
  56. and (optionally) a "hide" function. The "show" function has the signature
  57. >
  58. function(namespace, bufnr, diagnostics, opts)
  59. <
  60. and is responsible for displaying or otherwise handling the given
  61. diagnostics. The "hide" function takes care of "cleaning up" any actions taken
  62. by the "show" function and has the signature
  63. >
  64. function(namespace, bufnr)
  65. <
  66. Handlers can be configured with |vim.diagnostic.config()| and added by
  67. creating a new key in `vim.diagnostic.handlers` (see
  68. |diagnostic-handlers-example|).
  69. The {opts} table passed to a handler is the full set of configuration options
  70. (that is, it is not limited to just the options for the handler itself). The
  71. values in the table are already resolved (i.e. if a user specifies a
  72. function for a config option, the function has already been evaluated).
  73. Nvim provides these handlers by default: "virtual_text", "signs", and
  74. "underline".
  75. *diagnostic-handlers-example*
  76. The example below creates a new handler that notifies the user of diagnostics
  77. with |vim.notify()|: >lua
  78. -- It's good practice to namespace custom handlers to avoid collisions
  79. vim.diagnostic.handlers["my/notify"] = {
  80. show = function(namespace, bufnr, diagnostics, opts)
  81. -- In our example, the opts table has a "log_level" option
  82. local level = opts["my/notify"].log_level
  83. local name = vim.diagnostic.get_namespace(namespace).name
  84. local msg = string.format("%d diagnostics in buffer %d from %s",
  85. #diagnostics,
  86. bufnr,
  87. name)
  88. vim.notify(msg, level)
  89. end,
  90. }
  91. -- Users can configure the handler
  92. vim.diagnostic.config({
  93. ["my/notify"] = {
  94. log_level = vim.log.levels.INFO
  95. }
  96. })
  97. <
  98. In this example, there is nothing to do when diagnostics are hidden, so we
  99. omit the "hide" function.
  100. Existing handlers can be overridden. For example, use the following to only
  101. show a sign for the highest severity diagnostic on a given line: >lua
  102. -- Create a custom namespace. This will aggregate signs from all other
  103. -- namespaces and only show the one with the highest severity on a
  104. -- given line
  105. local ns = vim.api.nvim_create_namespace("my_namespace")
  106. -- Get a reference to the original signs handler
  107. local orig_signs_handler = vim.diagnostic.handlers.signs
  108. -- Override the built-in signs handler
  109. vim.diagnostic.handlers.signs = {
  110. show = function(_, bufnr, _, opts)
  111. -- Get all diagnostics from the whole buffer rather than just the
  112. -- diagnostics passed to the handler
  113. local diagnostics = vim.diagnostic.get(bufnr)
  114. -- Find the "worst" diagnostic per line
  115. local max_severity_per_line = {}
  116. for _, d in pairs(diagnostics) do
  117. local m = max_severity_per_line[d.lnum]
  118. if not m or d.severity < m.severity then
  119. max_severity_per_line[d.lnum] = d
  120. end
  121. end
  122. -- Pass the filtered diagnostics (with our custom namespace) to
  123. -- the original handler
  124. local filtered_diagnostics = vim.tbl_values(max_severity_per_line)
  125. orig_signs_handler.show(ns, bufnr, filtered_diagnostics, opts)
  126. end,
  127. hide = function(_, bufnr)
  128. orig_signs_handler.hide(ns, bufnr)
  129. end,
  130. }
  131. <
  132. *diagnostic-loclist-example*
  133. Whenever the |location-list| is opened, the following `show` handler will show
  134. the most recent diagnostics: >lua
  135. vim.diagnostic.handlers.loclist = {
  136. show = function(_, _, _, opts)
  137. -- Generally don't want it to open on every update
  138. opts.loclist.open = opts.loclist.open or false
  139. local winid = vim.api.nvim_get_current_win()
  140. vim.diagnostic.setloclist(opts.loclist)
  141. vim.api.nvim_set_current_win(winid)
  142. end
  143. }
  144. <
  145. The handler accepts the same options as |vim.diagnostic.setloclist()| and can be
  146. configured using |vim.diagnostic.config()|: >lua
  147. -- Open the location list on every diagnostic change (warnings/errors only).
  148. vim.diagnostic.config({
  149. loclist = {
  150. open = true,
  151. severity = { min = vim.diagnostic.severity.WARN },
  152. }
  153. })
  154. <
  155. ==============================================================================
  156. HIGHLIGHTS *diagnostic-highlights*
  157. All highlights defined for diagnostics begin with `Diagnostic` followed by
  158. the type of highlight (e.g., `Sign`, `Underline`, etc.) and the severity (e.g.
  159. `Error`, `Warn`, etc.)
  160. By default, highlights for signs, floating windows, and virtual text are linked to the
  161. corresponding default highlight. Underline highlights are not linked and use their
  162. own default highlight groups.
  163. For example, the default highlighting for |hl-DiagnosticSignError| is linked
  164. to |hl-DiagnosticError|. To change the default (and therefore the linked
  165. highlights), use the |:highlight| command: >vim
  166. highlight DiagnosticError guifg="BrightRed"
  167. <
  168. *hl-DiagnosticError*
  169. DiagnosticError
  170. Used as the base highlight group.
  171. Other Diagnostic highlights link to this by default (except Underline)
  172. *hl-DiagnosticWarn*
  173. DiagnosticWarn
  174. Used as the base highlight group.
  175. Other Diagnostic highlights link to this by default (except Underline)
  176. *hl-DiagnosticInfo*
  177. DiagnosticInfo
  178. Used as the base highlight group.
  179. Other Diagnostic highlights link to this by default (except Underline)
  180. *hl-DiagnosticHint*
  181. DiagnosticHint
  182. Used as the base highlight group.
  183. Other Diagnostic highlights link to this by default (except Underline)
  184. *hl-DiagnosticOk*
  185. DiagnosticOk
  186. Used as the base highlight group.
  187. Other Diagnostic highlights link to this by default (except Underline)
  188. *hl-DiagnosticVirtualTextError*
  189. DiagnosticVirtualTextError
  190. Used for "Error" diagnostic virtual text.
  191. *hl-DiagnosticVirtualTextWarn*
  192. DiagnosticVirtualTextWarn
  193. Used for "Warn" diagnostic virtual text.
  194. *hl-DiagnosticVirtualTextInfo*
  195. DiagnosticVirtualTextInfo
  196. Used for "Info" diagnostic virtual text.
  197. *hl-DiagnosticVirtualTextHint*
  198. DiagnosticVirtualTextHint
  199. Used for "Hint" diagnostic virtual text.
  200. *hl-DiagnosticVirtualTextOk*
  201. DiagnosticVirtualTextOk
  202. Used for "Ok" diagnostic virtual text.
  203. *hl-DiagnosticUnderlineError*
  204. DiagnosticUnderlineError
  205. Used to underline "Error" diagnostics.
  206. *hl-DiagnosticUnderlineWarn*
  207. DiagnosticUnderlineWarn
  208. Used to underline "Warn" diagnostics.
  209. *hl-DiagnosticUnderlineInfo*
  210. DiagnosticUnderlineInfo
  211. Used to underline "Info" diagnostics.
  212. *hl-DiagnosticUnderlineHint*
  213. DiagnosticUnderlineHint
  214. Used to underline "Hint" diagnostics.
  215. *hl-DiagnosticUnderlineOk*
  216. DiagnosticUnderlineOk
  217. Used to underline "Ok" diagnostics.
  218. *hl-DiagnosticFloatingError*
  219. DiagnosticFloatingError
  220. Used to color "Error" diagnostic messages in diagnostics float.
  221. See |vim.diagnostic.open_float()|
  222. *hl-DiagnosticFloatingWarn*
  223. DiagnosticFloatingWarn
  224. Used to color "Warn" diagnostic messages in diagnostics float.
  225. *hl-DiagnosticFloatingInfo*
  226. DiagnosticFloatingInfo
  227. Used to color "Info" diagnostic messages in diagnostics float.
  228. *hl-DiagnosticFloatingHint*
  229. DiagnosticFloatingHint
  230. Used to color "Hint" diagnostic messages in diagnostics float.
  231. *hl-DiagnosticFloatingOk*
  232. DiagnosticFloatingOk
  233. Used to color "Ok" diagnostic messages in diagnostics float.
  234. *hl-DiagnosticSignError*
  235. DiagnosticSignError
  236. Used for "Error" signs in sign column.
  237. *hl-DiagnosticSignWarn*
  238. DiagnosticSignWarn
  239. Used for "Warn" signs in sign column.
  240. *hl-DiagnosticSignInfo*
  241. DiagnosticSignInfo
  242. Used for "Info" signs in sign column.
  243. *hl-DiagnosticSignHint*
  244. DiagnosticSignHint
  245. Used for "Hint" signs in sign column.
  246. *hl-DiagnosticSignOk*
  247. DiagnosticSignOk
  248. Used for "Ok" signs in sign column.
  249. *hl-DiagnosticDeprecated*
  250. DiagnosticDeprecated
  251. Used for deprecated or obsolete code.
  252. *hl-DiagnosticUnnecessary*
  253. DiagnosticUnnecessary
  254. Used for unnecessary or unused code.
  255. ==============================================================================
  256. SIGNS *diagnostic-signs*
  257. Signs are defined for each diagnostic severity. The default text for each sign
  258. is the first letter of the severity name (for example, "E" for ERROR). Signs
  259. can be customized with |vim.diagnostic.config()|. Example: >lua
  260. -- Highlight entire line for errors
  261. -- Highlight the line number for warnings
  262. vim.diagnostic.config({
  263. signs = {
  264. text = {
  265. [vim.diagnostic.severity.ERROR] = '',
  266. [vim.diagnostic.severity.WARN] = '',
  267. },
  268. linehl = {
  269. [vim.diagnostic.severity.ERROR] = 'ErrorMsg',
  270. },
  271. numhl = {
  272. [vim.diagnostic.severity.WARN] = 'WarningMsg',
  273. },
  274. },
  275. })
  276. When the "severity_sort" option is set (see |vim.diagnostic.config()|) the
  277. priority of each sign depends on the severity of the associated diagnostic.
  278. Otherwise, all signs have the same priority (the value of the "priority"
  279. option in the "signs" table of |vim.diagnostic.config()| or 10 if unset).
  280. ==============================================================================
  281. EVENTS *diagnostic-events*
  282. *DiagnosticChanged*
  283. DiagnosticChanged After diagnostics have changed. When used from Lua,
  284. the new diagnostics are passed to the autocmd
  285. callback in the "data" table.
  286. Example: >lua
  287. vim.api.nvim_create_autocmd('DiagnosticChanged', {
  288. callback = function(args)
  289. local diagnostics = args.data.diagnostics
  290. vim.print(diagnostics)
  291. end,
  292. })
  293. <
  294. ==============================================================================
  295. Lua module: vim.diagnostic *diagnostic-api*
  296. *vim.Diagnostic*
  297. *diagnostic-structure*
  298. Diagnostics use the same indexing as the rest of the Nvim API (i.e.
  299. 0-based rows and columns). |api-indexing|
  300. Fields: ~
  301. • {bufnr}? (`integer`) Buffer number
  302. • {lnum} (`integer`) The starting line of the diagnostic
  303. (0-indexed)
  304. • {end_lnum}? (`integer`) The final line of the diagnostic (0-indexed)
  305. • {col} (`integer`) The starting column of the diagnostic
  306. (0-indexed)
  307. • {end_col}? (`integer`) The final column of the diagnostic
  308. (0-indexed)
  309. • {severity}? (`vim.diagnostic.Severity`) The severity of the
  310. diagnostic |vim.diagnostic.severity|
  311. • {message} (`string`) The diagnostic text
  312. • {source}? (`string`) The source of the diagnostic
  313. • {code}? (`string|integer`) The diagnostic code
  314. • {user_data}? (`any`) arbitrary data plugins can add
  315. • {namespace}? (`integer`)
  316. *vim.diagnostic.GetOpts*
  317. A table with the following keys:
  318. Fields: ~
  319. • {namespace}? (`integer[]|integer`) Limit diagnostics to one or more
  320. namespaces.
  321. • {lnum}? (`integer`) Limit diagnostics to those spanning the
  322. specified line number.
  323. • {severity}? (`vim.diagnostic.SeverityFilter`) See
  324. |diagnostic-severity|.
  325. *vim.diagnostic.JumpOpts*
  326. Extends: |vim.diagnostic.GetOpts|
  327. Configuration table with the keys listed below. Some parameters can have
  328. their default values changed with |vim.diagnostic.config()|.
  329. Fields: ~
  330. • {diagnostic}? (`vim.Diagnostic`) The diagnostic to jump to. Mutually
  331. exclusive with {count}, {namespace}, and {severity}.
  332. See |vim.Diagnostic|.
  333. • {count}? (`integer`) The number of diagnostics to move by,
  334. starting from {pos}. A positive integer moves forward
  335. by {count} diagnostics, while a negative integer moves
  336. backward by {count} diagnostics. Mutually exclusive
  337. with {diagnostic}.
  338. • {pos}? (`[integer,integer]`) Cursor position as a `(row, col)`
  339. tuple. See |nvim_win_get_cursor()|. Used to find the
  340. nearest diagnostic when {count} is used. Only used when
  341. {count} is non-nil. Default is the current cursor
  342. position.
  343. • {wrap}? (`boolean`, default: `true`) Whether to loop around
  344. file or not. Similar to 'wrapscan'.
  345. • {severity}? (`vim.diagnostic.SeverityFilter`) See
  346. |diagnostic-severity|.
  347. • {float}? (`boolean|vim.diagnostic.Opts.Float`, default: `false`)
  348. If `true`, call |vim.diagnostic.open_float()| after
  349. moving. If a table, pass the table as the {opts}
  350. parameter to |vim.diagnostic.open_float()|. Unless
  351. overridden, the float will show diagnostics at the new
  352. cursor position (as if "cursor" were passed to the
  353. "scope" option).
  354. • {winid}? (`integer`, default: `0`) Window ID
  355. *vim.diagnostic.NS*
  356. Fields: ~
  357. • {name} (`string`)
  358. • {opts} (`vim.diagnostic.Opts`) See |vim.diagnostic.Opts|.
  359. • {user_data} (`table`)
  360. • {disabled}? (`boolean`)
  361. *vim.diagnostic.Opts*
  362. Many of the configuration options below accept one of the following:
  363. • `false`: Disable this feature
  364. • `true`: Enable this feature, use default settings.
  365. • `table`: Enable this feature with overrides. Use an empty table to use
  366. default values.
  367. • `function`: Function with signature (namespace, bufnr) that returns any
  368. of the above.
  369. Fields: ~
  370. • {underline}? (`boolean|vim.diagnostic.Opts.Underline|fun(namespace: integer, bufnr:integer): vim.diagnostic.Opts.Underline`, default: `true`)
  371. Use underline for diagnostics.
  372. • {virtual_text}? (`boolean|vim.diagnostic.Opts.VirtualText|fun(namespace: integer, bufnr:integer): vim.diagnostic.Opts.VirtualText`, default: `true`)
  373. Use virtual text for diagnostics. If multiple
  374. diagnostics are set for a namespace, one prefix
  375. per diagnostic + the last diagnostic message are
  376. shown.
  377. • {signs}? (`boolean|vim.diagnostic.Opts.Signs|fun(namespace: integer, bufnr:integer): vim.diagnostic.Opts.Signs`, default: `true`)
  378. Use signs for diagnostics |diagnostic-signs|.
  379. • {float}? (`boolean|vim.diagnostic.Opts.Float|fun(namespace: integer, bufnr:integer): vim.diagnostic.Opts.Float`)
  380. Options for floating windows. See
  381. |vim.diagnostic.Opts.Float|.
  382. • {update_in_insert}? (`boolean`, default: `false`) Update diagnostics
  383. in Insert mode (if `false`, diagnostics are
  384. updated on |InsertLeave|)
  385. • {severity_sort}? (`boolean|{reverse?:boolean}`, default: `false`)
  386. Sort diagnostics by severity. This affects the
  387. order in which signs, virtual text, and
  388. highlights are displayed. When true, higher
  389. severities are displayed before lower severities
  390. (e.g. ERROR is displayed before WARN). Options:
  391. • {reverse}? (boolean) Reverse sort order
  392. • {jump}? (`vim.diagnostic.Opts.Jump`) Default values for
  393. |vim.diagnostic.jump()|. See
  394. |vim.diagnostic.Opts.Jump|.
  395. *vim.diagnostic.Opts.Float*
  396. Fields: ~
  397. • {bufnr}? (`integer`, default: current buffer) Buffer number
  398. to show diagnostics from.
  399. • {namespace}? (`integer`) Limit diagnostics to the given namespace
  400. • {scope}? (`'line'|'buffer'|'cursor'|'c'|'l'|'b'`, default:
  401. `line`) Show diagnostics from the whole buffer
  402. (`buffer"`, the current cursor line (`line`), or the
  403. current cursor position (`cursor`). Shorthand
  404. versions are also accepted (`c` for `cursor`, `l`
  405. for `line`, `b` for `buffer`).
  406. • {pos}? (`integer|[integer,integer]`) If {scope} is "line"
  407. or "cursor", use this position rather than the
  408. cursor position. If a number, interpreted as a line
  409. number; otherwise, a (row, col) tuple.
  410. • {severity_sort}? (`boolean|{reverse?:boolean}`, default: `false`)
  411. Sort diagnostics by severity. Overrides the setting
  412. from |vim.diagnostic.config()|.
  413. • {severity}? (`vim.diagnostic.SeverityFilter`) See
  414. |diagnostic-severity|. Overrides the setting from
  415. |vim.diagnostic.config()|.
  416. • {header}? (`string|[string,any]`) String to use as the header
  417. for the floating window. If a table, it is
  418. interpreted as a `[text, hl_group]` tuple. Overrides
  419. the setting from |vim.diagnostic.config()|.
  420. • {source}? (`boolean|'if_many'`) Include the diagnostic source
  421. in the message. Use "if_many" to only show sources
  422. if there is more than one source of diagnostics in
  423. the buffer. Otherwise, any truthy value means to
  424. always show the diagnostic source. Overrides the
  425. setting from |vim.diagnostic.config()|.
  426. • {format}? (`fun(diagnostic:vim.Diagnostic): string`) A
  427. function that takes a diagnostic as input and
  428. returns a string. The return value is the text used
  429. to display the diagnostic. Overrides the setting
  430. from |vim.diagnostic.config()|.
  431. • {prefix}? (`string|table|(fun(diagnostic:vim.Diagnostic,i:integer,total:integer): string, string)`)
  432. Prefix each diagnostic in the floating window:
  433. • If a `function`, {i} is the index of the
  434. diagnostic being evaluated and {total} is the
  435. total number of diagnostics displayed in the
  436. window. The function should return a `string`
  437. which is prepended to each diagnostic in the
  438. window as well as an (optional) highlight group
  439. which will be used to highlight the prefix.
  440. • If a `table`, it is interpreted as a
  441. `[text, hl_group]` tuple as in |nvim_echo()|
  442. • If a `string`, it is prepended to each diagnostic
  443. in the window with no highlight. Overrides the
  444. setting from |vim.diagnostic.config()|.
  445. • {suffix}? (`string|table|(fun(diagnostic:vim.Diagnostic,i:integer,total:integer): string, string)`)
  446. Same as {prefix}, but appends the text to the
  447. diagnostic instead of prepending it. Overrides the
  448. setting from |vim.diagnostic.config()|.
  449. • {focus_id}? (`string`)
  450. • {border}? (`string`) see |nvim_open_win()|.
  451. *vim.diagnostic.Opts.Jump*
  452. Fields: ~
  453. • {float}? (`boolean|vim.diagnostic.Opts.Float`, default: false)
  454. Default value of the {float} parameter of
  455. |vim.diagnostic.jump()|.
  456. • {wrap}? (`boolean`, default: true) Default value of the {wrap}
  457. parameter of |vim.diagnostic.jump()|.
  458. • {severity}? (`vim.diagnostic.SeverityFilter`) Default value of the
  459. {severity} parameter of |vim.diagnostic.jump()|.
  460. *vim.diagnostic.Opts.Signs*
  461. Fields: ~
  462. • {severity}? (`vim.diagnostic.SeverityFilter`) Only show virtual text
  463. for diagnostics matching the given severity
  464. |diagnostic-severity|
  465. • {priority}? (`integer`, default: `10`) Base priority to use for
  466. signs. When {severity_sort} is used, the priority of a
  467. sign is adjusted based on its severity. Otherwise, all
  468. signs use the same priority.
  469. • {text}? (`table<vim.diagnostic.Severity,string>`) A table mapping
  470. |diagnostic-severity| to the sign text to display in the
  471. sign column. The default is to use `"E"`, `"W"`, `"I"`,
  472. and `"H"` for errors, warnings, information, and hints,
  473. respectively. Example: >lua
  474. vim.diagnostic.config({
  475. signs = { text = { [vim.diagnostic.severity.ERROR] = 'E', ... } }
  476. })
  477. <
  478. • {numhl}? (`table<vim.diagnostic.Severity,string>`) A table mapping
  479. |diagnostic-severity| to the highlight group used for the
  480. line number where the sign is placed.
  481. • {linehl}? (`table<vim.diagnostic.Severity,string>`) A table mapping
  482. |diagnostic-severity| to the highlight group used for the
  483. whole line the sign is placed in.
  484. *vim.diagnostic.Opts.Underline*
  485. Fields: ~
  486. • {severity}? (`vim.diagnostic.SeverityFilter`) Only underline
  487. diagnostics matching the given severity
  488. |diagnostic-severity|.
  489. *vim.diagnostic.Opts.VirtualText*
  490. Fields: ~
  491. • {severity}? (`vim.diagnostic.SeverityFilter`) Only show
  492. virtual text for diagnostics matching the given
  493. severity |diagnostic-severity|
  494. • {source}? (`boolean|"if_many"`) Include the diagnostic
  495. source in virtual text. Use `'if_many'` to only
  496. show sources if there is more than one
  497. diagnostic source in the buffer. Otherwise, any
  498. truthy value means to always show the diagnostic
  499. source.
  500. • {spacing}? (`integer`) Amount of empty spaces inserted at
  501. the beginning of the virtual text.
  502. • {prefix}? (`string|(fun(diagnostic:vim.Diagnostic,i:integer,total:integer): string)`)
  503. Prepend diagnostic message with prefix. If a
  504. `function`, {i} is the index of the diagnostic
  505. being evaluated, and {total} is the total number
  506. of diagnostics for the line. This can be used to
  507. render diagnostic symbols or error codes.
  508. • {suffix}? (`string|(fun(diagnostic:vim.Diagnostic): string)`)
  509. Append diagnostic message with suffix. This can
  510. be used to render an LSP diagnostic error code.
  511. • {format}? (`fun(diagnostic:vim.Diagnostic): string`) The
  512. return value is the text used to display the
  513. diagnostic. Example: >lua
  514. function(diagnostic)
  515. if diagnostic.severity == vim.diagnostic.severity.ERROR then
  516. return string.format("E: %s", diagnostic.message)
  517. end
  518. return diagnostic.message
  519. end
  520. <
  521. • {hl_mode}? (`'replace'|'combine'|'blend'`) See
  522. |nvim_buf_set_extmark()|.
  523. • {virt_text}? (`[string,any][]`) See |nvim_buf_set_extmark()|.
  524. • {virt_text_pos}? (`'eol'|'overlay'|'right_align'|'inline'`) See
  525. |nvim_buf_set_extmark()|.
  526. • {virt_text_win_col}? (`integer`) See |nvim_buf_set_extmark()|.
  527. • {virt_text_hide}? (`boolean`) See |nvim_buf_set_extmark()|.
  528. config({opts}, {namespace}) *vim.diagnostic.config()*
  529. Configure diagnostic options globally or for a specific diagnostic
  530. namespace.
  531. Configuration can be specified globally, per-namespace, or ephemerally
  532. (i.e. only for a single call to |vim.diagnostic.set()| or
  533. |vim.diagnostic.show()|). Ephemeral configuration has highest priority,
  534. followed by namespace configuration, and finally global configuration.
  535. For example, if a user enables virtual text globally with >lua
  536. vim.diagnostic.config({ virtual_text = true })
  537. <
  538. and a diagnostic producer sets diagnostics with >lua
  539. vim.diagnostic.set(ns, 0, diagnostics, { virtual_text = false })
  540. <
  541. then virtual text will not be enabled for those diagnostics.
  542. Parameters: ~
  543. • {opts} (`vim.diagnostic.Opts?`) When omitted or `nil`, retrieve
  544. the current configuration. Otherwise, a configuration
  545. table (see |vim.diagnostic.Opts|).
  546. • {namespace} (`integer?`) Update the options for the given namespace.
  547. When omitted, update the global diagnostic options.
  548. Return: ~
  549. (`vim.diagnostic.Opts?`) Current diagnostic config if {opts} is
  550. omitted. See |vim.diagnostic.Opts|.
  551. count({bufnr}, {opts}) *vim.diagnostic.count()*
  552. Get current diagnostics count.
  553. Parameters: ~
  554. • {bufnr} (`integer?`) Buffer number to get diagnostics from. Use 0 for
  555. current buffer or nil for all buffers.
  556. • {opts} (`vim.diagnostic.GetOpts?`) See |vim.diagnostic.GetOpts|.
  557. Return: ~
  558. (`table`) Table with actually present severity values as keys (see
  559. |diagnostic-severity|) and integer counts as values.
  560. enable({enable}, {filter}) *vim.diagnostic.enable()*
  561. Enables or disables diagnostics.
  562. To "toggle", pass the inverse of `is_enabled()`: >lua
  563. vim.diagnostic.enable(not vim.diagnostic.is_enabled())
  564. <
  565. Parameters: ~
  566. • {enable} (`boolean?`) true/nil to enable, false to disable
  567. • {filter} (`table?`) Optional filters |kwargs|, or `nil` for all.
  568. • {ns_id}? (`integer`) Diagnostic namespace, or `nil` for
  569. all.
  570. • {bufnr}? (`integer`) Buffer number, or 0 for current
  571. buffer, or `nil` for all buffers.
  572. fromqflist({list}) *vim.diagnostic.fromqflist()*
  573. Convert a list of quickfix items to a list of diagnostics.
  574. Parameters: ~
  575. • {list} (`table[]`) List of quickfix items from |getqflist()| or
  576. |getloclist()|.
  577. Return: ~
  578. (`vim.Diagnostic[]`) See |vim.Diagnostic|.
  579. get({bufnr}, {opts}) *vim.diagnostic.get()*
  580. Get current diagnostics.
  581. Modifying diagnostics in the returned table has no effect. To set
  582. diagnostics in a buffer, use |vim.diagnostic.set()|.
  583. Parameters: ~
  584. • {bufnr} (`integer?`) Buffer number to get diagnostics from. Use 0 for
  585. current buffer or nil for all buffers.
  586. • {opts} (`vim.diagnostic.GetOpts?`) See |vim.diagnostic.GetOpts|.
  587. Return: ~
  588. (`vim.Diagnostic[]`) Fields `bufnr`, `end_lnum`, `end_col`, and
  589. `severity` are guaranteed to be present. See |vim.Diagnostic|.
  590. get_namespace({namespace}) *vim.diagnostic.get_namespace()*
  591. Get namespace metadata.
  592. Parameters: ~
  593. • {namespace} (`integer`) Diagnostic namespace
  594. Return: ~
  595. (`vim.diagnostic.NS`) Namespace metadata. See |vim.diagnostic.NS|.
  596. get_namespaces() *vim.diagnostic.get_namespaces()*
  597. Get current diagnostic namespaces.
  598. Return: ~
  599. (`table<integer,vim.diagnostic.NS>`) List of active diagnostic
  600. namespaces |vim.diagnostic|.
  601. get_next({opts}) *vim.diagnostic.get_next()*
  602. Get the next diagnostic closest to the cursor position.
  603. Parameters: ~
  604. • {opts} (`vim.diagnostic.JumpOpts?`) See |vim.diagnostic.JumpOpts|.
  605. Return: ~
  606. (`vim.Diagnostic?`) Next diagnostic. See |vim.Diagnostic|.
  607. get_prev({opts}) *vim.diagnostic.get_prev()*
  608. Get the previous diagnostic closest to the cursor position.
  609. Parameters: ~
  610. • {opts} (`vim.diagnostic.JumpOpts?`) See |vim.diagnostic.JumpOpts|.
  611. Return: ~
  612. (`vim.Diagnostic?`) Previous diagnostic. See |vim.Diagnostic|.
  613. hide({namespace}, {bufnr}) *vim.diagnostic.hide()*
  614. Hide currently displayed diagnostics.
  615. This only clears the decorations displayed in the buffer. Diagnostics can
  616. be redisplayed with |vim.diagnostic.show()|. To completely remove
  617. diagnostics, use |vim.diagnostic.reset()|.
  618. To hide diagnostics and prevent them from re-displaying, use
  619. |vim.diagnostic.enable()|.
  620. Parameters: ~
  621. • {namespace} (`integer?`) Diagnostic namespace. When omitted, hide
  622. diagnostics from all namespaces.
  623. • {bufnr} (`integer?`) Buffer number, or 0 for current buffer. When
  624. omitted, hide diagnostics in all buffers.
  625. is_enabled({filter}) *vim.diagnostic.is_enabled()*
  626. Check whether diagnostics are enabled.
  627. Attributes: ~
  628. Since: 0.10.0
  629. Parameters: ~
  630. • {filter} (`table?`) Optional filters |kwargs|, or `nil` for all.
  631. • {ns_id}? (`integer`) Diagnostic namespace, or `nil` for
  632. all.
  633. • {bufnr}? (`integer`) Buffer number, or 0 for current
  634. buffer, or `nil` for all buffers.
  635. Return: ~
  636. (`boolean`)
  637. jump({opts}) *vim.diagnostic.jump()*
  638. Move to a diagnostic.
  639. Parameters: ~
  640. • {opts} (`vim.diagnostic.JumpOpts`) See |vim.diagnostic.JumpOpts|.
  641. Return: ~
  642. (`vim.Diagnostic?`) The diagnostic that was moved to. See
  643. |vim.Diagnostic|.
  644. *vim.diagnostic.match()*
  645. match({str}, {pat}, {groups}, {severity_map}, {defaults})
  646. Parse a diagnostic from a string.
  647. For example, consider a line of output from a linter: >
  648. WARNING filename:27:3: Variable 'foo' does not exist
  649. <
  650. This can be parsed into |vim.Diagnostic| structure with: >lua
  651. local s = "WARNING filename:27:3: Variable 'foo' does not exist"
  652. local pattern = "^(%w+) %w+:(%d+):(%d+): (.+)$"
  653. local groups = { "severity", "lnum", "col", "message" }
  654. vim.diagnostic.match(s, pattern, groups, { WARNING = vim.diagnostic.WARN })
  655. <
  656. Parameters: ~
  657. • {str} (`string`) String to parse diagnostics from.
  658. • {pat} (`string`) Lua pattern with capture groups.
  659. • {groups} (`string[]`) List of fields in a |vim.Diagnostic|
  660. structure to associate with captures from {pat}.
  661. • {severity_map} (`table`) A table mapping the severity field from
  662. {groups} with an item from |vim.diagnostic.severity|.
  663. • {defaults} (`table?`) Table of default values for any fields not
  664. listed in {groups}. When omitted, numeric values
  665. default to 0 and "severity" defaults to ERROR.
  666. Return: ~
  667. (`vim.Diagnostic?`) |vim.Diagnostic| structure or `nil` if {pat} fails
  668. to match {str}.
  669. open_float({opts}) *vim.diagnostic.open_float()*
  670. Show diagnostics in a floating window.
  671. Parameters: ~
  672. • {opts} (`vim.diagnostic.Opts.Float?`) See
  673. |vim.diagnostic.Opts.Float|.
  674. Return (multiple): ~
  675. (`integer?`) float_bufnr
  676. (`integer?`) winid
  677. reset({namespace}, {bufnr}) *vim.diagnostic.reset()*
  678. Remove all diagnostics from the given namespace.
  679. Unlike |vim.diagnostic.hide()|, this function removes all saved
  680. diagnostics. They cannot be redisplayed using |vim.diagnostic.show()|. To
  681. simply remove diagnostic decorations in a way that they can be
  682. re-displayed, use |vim.diagnostic.hide()|.
  683. Parameters: ~
  684. • {namespace} (`integer?`) Diagnostic namespace. When omitted, remove
  685. diagnostics from all namespaces.
  686. • {bufnr} (`integer?`) Remove diagnostics for the given buffer.
  687. When omitted, diagnostics are removed for all buffers.
  688. set({namespace}, {bufnr}, {diagnostics}, {opts}) *vim.diagnostic.set()*
  689. Set diagnostics for the given namespace and buffer.
  690. Parameters: ~
  691. • {namespace} (`integer`) The diagnostic namespace
  692. • {bufnr} (`integer`) Buffer number
  693. • {diagnostics} (`vim.Diagnostic[]`) See |vim.Diagnostic|.
  694. • {opts} (`vim.diagnostic.Opts?`) Display options to pass to
  695. |vim.diagnostic.show()|. See |vim.diagnostic.Opts|.
  696. setloclist({opts}) *vim.diagnostic.setloclist()*
  697. Add buffer diagnostics to the location list.
  698. Parameters: ~
  699. • {opts} (`table?`) Configuration table with the following keys:
  700. • {namespace}? (`integer`) Only add diagnostics from the given
  701. namespace.
  702. • {winnr}? (`integer`, default: `0`) Window number to set
  703. location list for.
  704. • {open}? (`boolean`, default: `true`) Open the location list
  705. after setting.
  706. • {title}? (`string`) Title of the location list. Defaults to
  707. "Diagnostics".
  708. • {severity}? (`vim.diagnostic.SeverityFilter`) See
  709. |diagnostic-severity|.
  710. setqflist({opts}) *vim.diagnostic.setqflist()*
  711. Add all diagnostics to the quickfix list.
  712. Parameters: ~
  713. • {opts} (`table?`) Configuration table with the following keys:
  714. • {namespace}? (`integer`) Only add diagnostics from the given
  715. namespace.
  716. • {open}? (`boolean`, default: `true`) Open quickfix list
  717. after setting.
  718. • {title}? (`string`) Title of quickfix list. Defaults to
  719. "Diagnostics". If there's already a quickfix list with this
  720. title, it's updated. If not, a new quickfix list is created.
  721. • {severity}? (`vim.diagnostic.SeverityFilter`) See
  722. |diagnostic-severity|.
  723. *vim.diagnostic.show()*
  724. show({namespace}, {bufnr}, {diagnostics}, {opts})
  725. Display diagnostics for the given namespace and buffer.
  726. Parameters: ~
  727. • {namespace} (`integer?`) Diagnostic namespace. When omitted, show
  728. diagnostics from all namespaces.
  729. • {bufnr} (`integer?`) Buffer number, or 0 for current buffer.
  730. When omitted, show diagnostics in all buffers.
  731. • {diagnostics} (`vim.Diagnostic[]?`) The diagnostics to display. When
  732. omitted, use the saved diagnostics for the given
  733. namespace and buffer. This can be used to display a
  734. list of diagnostics without saving them or to display
  735. only a subset of diagnostics. May not be used when
  736. {namespace} or {bufnr} is nil. See |vim.Diagnostic|.
  737. • {opts} (`vim.diagnostic.Opts?`) Display options. See
  738. |vim.diagnostic.Opts|.
  739. toqflist({diagnostics}) *vim.diagnostic.toqflist()*
  740. Convert a list of diagnostics to a list of quickfix items that can be
  741. passed to |setqflist()| or |setloclist()|.
  742. Parameters: ~
  743. • {diagnostics} (`vim.Diagnostic[]`) See |vim.Diagnostic|.
  744. Return: ~
  745. (`table[]`) Quickfix list items |setqflist-what|
  746. vim:tw=78:ts=8:sw=4:sts=4:et:ft=help:norl: