diagnostic.txt 41 KB

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