diagnostic.txt 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707
  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. *diagnostic-structure*
  31. A diagnostic is a Lua table with the following keys. Required keys are
  32. indicated with (*):
  33. bufnr: Buffer number
  34. lnum(*): The starting line of the diagnostic
  35. end_lnum: The final line of the diagnostic
  36. col(*): The starting column of the diagnostic
  37. end_col: The final column of the diagnostic
  38. severity: The severity of the diagnostic |vim.diagnostic.severity|
  39. message(*): The diagnostic text
  40. source: The source of the diagnostic
  41. code: The diagnostic code
  42. user_data: Arbitrary data plugins or users can add
  43. Diagnostics use the same indexing as the rest of the Nvim API (i.e. 0-based
  44. rows and columns). |api-indexing|
  45. *vim.diagnostic.severity* *diagnostic-severity*
  46. The "severity" key in a diagnostic is one of the values defined in
  47. `vim.diagnostic.severity`:
  48. vim.diagnostic.severity.ERROR
  49. vim.diagnostic.severity.WARN
  50. vim.diagnostic.severity.INFO
  51. vim.diagnostic.severity.HINT
  52. Functions that take a severity as an optional parameter (e.g.
  53. |vim.diagnostic.get()|) accept one of two forms:
  54. 1. A single |vim.diagnostic.severity| value: >
  55. vim.diagnostic.get(0, { severity = vim.diagnostic.severity.WARN })
  56. 2. A table with a "min" or "max" key (or both): >
  57. vim.diagnostic.get(0, { severity = { min = vim.diagnostic.severity.WARN } })
  58. The latter form allows users to specify a range of severities.
  59. ==============================================================================
  60. HANDLERS *diagnostic-handlers*
  61. Diagnostics are shown to the user with |vim.diagnostic.show()|. The display of
  62. diagnostics is managed through handlers. A handler is a table with a "show"
  63. and (optionally) a "hide" function. The "show" function has the signature
  64. >
  65. function(namespace, bufnr, diagnostics, opts)
  66. <
  67. and is responsible for displaying or otherwise handling the given
  68. diagnostics. The "hide" function takes care of "cleaning up" any actions taken
  69. by the "show" function and has the signature
  70. >
  71. function(namespace, bufnr)
  72. <
  73. Handlers can be configured with |vim.diagnostic.config()| and added by
  74. creating a new key in `vim.diagnostic.handlers` (see
  75. |diagnostic-handlers-example|).
  76. The {opts} table passed to a handler is the full set of configuration options
  77. (that is, it is not limited to just the options for the handler itself). The
  78. values in the table are already resolved (i.e. if a user specifies a
  79. function for a config option, the function has already been evaluated).
  80. Nvim provides these handlers by default: "virtual_text", "signs", and
  81. "underline".
  82. *diagnostic-handlers-example*
  83. The example below creates a new handler that notifies the user of diagnostics
  84. with |vim.notify()|: >
  85. -- It's good practice to namespace custom handlers to avoid collisions
  86. vim.diagnostic.handlers["my/notify"] = {
  87. show = function(namespace, bufnr, diagnostics, opts)
  88. -- In our example, the opts table has a "log_level" option
  89. local level = opts["my/notify"].log_level
  90. local name = vim.diagnostic.get_namespace(namespace).name
  91. local msg = string.format("%d diagnostics in buffer %d from %s",
  92. #diagnostics,
  93. bufnr,
  94. name)
  95. vim.notify(msg, level)
  96. end,
  97. }
  98. -- Users can configure the handler
  99. vim.diagnostic.config({
  100. ["my/notify"] = {
  101. log_level = vim.log.levels.INFO
  102. }
  103. })
  104. <
  105. In this example, there is nothing to do when diagnostics are hidden, so we
  106. omit the "hide" function.
  107. Existing handlers can be overridden. For example, use the following to only
  108. show a sign for the highest severity diagnostic on a given line: >
  109. -- Create a custom namespace. This will aggregate signs from all other
  110. -- namespaces and only show the one with the highest severity on a
  111. -- given line
  112. local ns = vim.api.nvim_create_namespace("my_namespace")
  113. -- Get a reference to the original signs handler
  114. local orig_signs_handler = vim.diagnostic.handlers.signs
  115. -- Override the built-in signs handler
  116. vim.diagnostic.handlers.signs = {
  117. show = function(_, bufnr, _, opts)
  118. -- Get all diagnostics from the whole buffer rather than just the
  119. -- diagnostics passed to the handler
  120. local diagnostics = vim.diagnostic.get(bufnr)
  121. -- Find the "worst" diagnostic per line
  122. local max_severity_per_line = {}
  123. for _, d in pairs(diagnostics) do
  124. local m = max_severity_per_line[d.lnum]
  125. if not m or d.severity < m.severity then
  126. max_severity_per_line[d.lnum] = d
  127. end
  128. end
  129. -- Pass the filtered diagnostics (with our custom namespace) to
  130. -- the original handler
  131. local filtered_diagnostics = vim.tbl_values(max_severity_per_line)
  132. orig_signs_handler.show(ns, bufnr, filtered_diagnostics, opts)
  133. end,
  134. hide = function(_, bufnr)
  135. orig_signs_handler.hide(ns, bufnr)
  136. end,
  137. }
  138. <
  139. ==============================================================================
  140. HIGHLIGHTS *diagnostic-highlights*
  141. All highlights defined for diagnostics begin with `Diagnostic` followed by
  142. the type of highlight (e.g., `Sign`, `Underline`, etc.) and the severity (e.g.
  143. `Error`, `Warn`, etc.)
  144. By default, highlights for signs, floating windows, and virtual text are linked to the
  145. corresponding default highlight. Underline highlights are not linked and use their
  146. own default highlight groups.
  147. For example, the default highlighting for |hl-DiagnosticSignError| is linked
  148. to |hl-DiagnosticError|. To change the default (and therefore the linked
  149. highlights), use the |:highlight| command: >
  150. highlight DiagnosticError guifg="BrightRed"
  151. <
  152. *hl-DiagnosticError*
  153. DiagnosticError
  154. Used as the base highlight group.
  155. Other Diagnostic highlights link to this by default (except Underline)
  156. *hl-DiagnosticWarn*
  157. DiagnosticWarn
  158. Used as the base highlight group.
  159. Other Diagnostic highlights link to this by default (except Underline)
  160. *hl-DiagnosticInfo*
  161. DiagnosticInfo
  162. Used as the base highlight group.
  163. Other Diagnostic highlights link to this by default (except Underline)
  164. *hl-DiagnosticHint*
  165. DiagnosticHint
  166. Used as the base highlight group.
  167. Other Diagnostic highlights link to this by default (except Underline)
  168. *hl-DiagnosticVirtualTextError*
  169. DiagnosticVirtualTextError
  170. Used for "Error" diagnostic virtual text.
  171. *hl-DiagnosticVirtualTextWarn*
  172. DiagnosticVirtualTextWarn
  173. Used for "Warn" diagnostic virtual text.
  174. *hl-DiagnosticVirtualTextInfo*
  175. DiagnosticVirtualTextInfo
  176. Used for "Info" diagnostic virtual text.
  177. *hl-DiagnosticVirtualTextHint*
  178. DiagnosticVirtualTextHint
  179. Used for "Hint" diagnostic virtual text.
  180. *hl-DiagnosticUnderlineError*
  181. DiagnosticUnderlineError
  182. Used to underline "Error" diagnostics.
  183. *hl-DiagnosticUnderlineWarn*
  184. DiagnosticUnderlineWarn
  185. Used to underline "Warn" diagnostics.
  186. *hl-DiagnosticUnderlineInfo*
  187. DiagnosticUnderlineInfo
  188. Used to underline "Info" diagnostics.
  189. *hl-DiagnosticUnderlineHint*
  190. DiagnosticUnderlineHint
  191. Used to underline "Hint" diagnostics.
  192. *hl-DiagnosticFloatingError*
  193. DiagnosticFloatingError
  194. Used to color "Error" diagnostic messages in diagnostics float.
  195. See |vim.diagnostic.open_float()|
  196. *hl-DiagnosticFloatingWarn*
  197. DiagnosticFloatingWarn
  198. Used to color "Warn" diagnostic messages in diagnostics float.
  199. *hl-DiagnosticFloatingInfo*
  200. DiagnosticFloatingInfo
  201. Used to color "Info" diagnostic messages in diagnostics float.
  202. *hl-DiagnosticFloatingHint*
  203. DiagnosticFloatingHint
  204. Used to color "Hint" diagnostic messages in diagnostics float.
  205. *hl-DiagnosticSignError*
  206. DiagnosticSignError
  207. Used for "Error" signs in sign column.
  208. *hl-DiagnosticSignWarn*
  209. DiagnosticSignWarn
  210. Used for "Warn" signs in sign column.
  211. *hl-DiagnosticSignInfo*
  212. DiagnosticSignInfo
  213. Used for "Info" signs in sign column.
  214. *hl-DiagnosticSignHint*
  215. DiagnosticSignHint
  216. Used for "Hint" signs in sign column.
  217. ==============================================================================
  218. SIGNS *diagnostic-signs*
  219. Signs are defined for each diagnostic severity. The default text for each sign
  220. is the first letter of the severity name (for example, "E" for ERROR). Signs
  221. can be customized using the following: >
  222. sign define DiagnosticSignError text=E texthl=DiagnosticSignError linehl= numhl=
  223. sign define DiagnosticSignWarn text=W texthl=DiagnosticSignWarn linehl= numhl=
  224. sign define DiagnosticSignInfo text=I texthl=DiagnosticSignInfo linehl= numhl=
  225. sign define DiagnosticSignHint text=H texthl=DiagnosticSignHint linehl= numhl=
  226. When the "severity_sort" option is set (see |vim.diagnostic.config()|) the
  227. priority of each sign depends on the severity of the associated diagnostic.
  228. Otherwise, all signs have the same priority (the value of the "priority"
  229. option in the "signs" table of |vim.diagnostic.config()| or 10 if unset).
  230. ==============================================================================
  231. EVENTS *diagnostic-events*
  232. *DiagnosticChanged*
  233. DiagnosticChanged After diagnostics have changed. When used from Lua,
  234. the new diagnostics are passed to the autocmd
  235. callback in the "data" table.
  236. Example: >
  237. vim.api.nvim_create_autocmd('DiagnosticChanged', {
  238. callback = function(args)
  239. local diagnostics = args.data.diagnostics
  240. vim.pretty_print(diagnostics)
  241. end,
  242. })
  243. <
  244. ==============================================================================
  245. Lua module: vim.diagnostic *diagnostic-api*
  246. config({opts}, {namespace}) *vim.diagnostic.config()*
  247. Configure diagnostic options globally or for a specific diagnostic
  248. namespace.
  249. Configuration can be specified globally, per-namespace, or ephemerally
  250. (i.e. only for a single call to |vim.diagnostic.set()| or
  251. |vim.diagnostic.show()|). Ephemeral configuration has highest priority,
  252. followed by namespace configuration, and finally global configuration.
  253. For example, if a user enables virtual text globally with >
  254. vim.diagnostic.config({ virtual_text = true })
  255. <
  256. and a diagnostic producer sets diagnostics with >
  257. vim.diagnostic.set(ns, 0, diagnostics, { virtual_text = false })
  258. <
  259. then virtual text will not be enabled for those diagnostics.
  260. Note:
  261. Each of the configuration options below accepts one of the following:
  262. • `false`: Disable this feature
  263. • `true`: Enable this feature, use default settings.
  264. • `table`: Enable this feature with overrides. Use an empty table to
  265. use default values.
  266. • `function`: Function with signature (namespace, bufnr) that returns
  267. any of the above.
  268. Parameters: ~
  269. • {opts} (table|nil) When omitted or "nil", retrieve the current
  270. configuration. Otherwise, a configuration table with the
  271. following keys:
  272. • underline: (default true) Use underline for
  273. diagnostics. Options:
  274. • severity: Only underline diagnostics matching the
  275. given severity |diagnostic-severity|
  276. • virtual_text: (default true) Use virtual text for
  277. diagnostics. If multiple diagnostics are set for a
  278. namespace, one prefix per diagnostic + the last
  279. diagnostic message are shown. Options:
  280. • severity: Only show virtual text for diagnostics
  281. matching the given severity |diagnostic-severity|
  282. • source: (boolean or string) Include the diagnostic
  283. source in virtual text. Use "if_many" to only show
  284. sources if there is more than one diagnostic source
  285. in the buffer. Otherwise, any truthy value means to
  286. always show the diagnostic source.
  287. • spacing: (number) Amount of empty spaces inserted at
  288. the beginning of the virtual text.
  289. • prefix: (string) Prepend diagnostic message with
  290. prefix.
  291. • format: (function) A function that takes a diagnostic
  292. as input and returns a string. The return value is
  293. the text used to display the diagnostic. Example: >
  294. function(diagnostic)
  295. if diagnostic.severity == vim.diagnostic.severity.ERROR then
  296. return string.format("E: %s", diagnostic.message)
  297. end
  298. return diagnostic.message
  299. end
  300. <
  301. • signs: (default true) Use signs for diagnostics.
  302. Options:
  303. • severity: Only show signs for diagnostics matching
  304. the given severity |diagnostic-severity|
  305. • priority: (number, default 10) Base priority to use
  306. for signs. When {severity_sort} is used, the priority
  307. of a sign is adjusted based on its severity.
  308. Otherwise, all signs use the same priority.
  309. • float: Options for floating windows. See
  310. |vim.diagnostic.open_float()|.
  311. • update_in_insert: (default false) Update diagnostics in
  312. Insert mode (if false, diagnostics are updated on
  313. InsertLeave)
  314. • severity_sort: (default false) Sort diagnostics by
  315. severity. This affects the order in which signs and
  316. virtual text are displayed. When true, higher
  317. severities are displayed before lower severities (e.g.
  318. ERROR is displayed before WARN). Options:
  319. • reverse: (boolean) Reverse sort order
  320. • {namespace} (number|nil) Update the options for the given namespace.
  321. When omitted, update the global diagnostic options.
  322. disable({bufnr}, {namespace}) *vim.diagnostic.disable()*
  323. Disable diagnostics in the given buffer.
  324. Parameters: ~
  325. • {bufnr} (number|nil) Buffer number, or 0 for current buffer. When
  326. omitted, disable diagnostics in all buffers.
  327. • {namespace} (number|nil) Only disable diagnostics for the given
  328. namespace.
  329. enable({bufnr}, {namespace}) *vim.diagnostic.enable()*
  330. Enable diagnostics in the given buffer.
  331. Parameters: ~
  332. • {bufnr} (number|nil) Buffer number, or 0 for current buffer. When
  333. omitted, enable diagnostics in all buffers.
  334. • {namespace} (number|nil) Only enable diagnostics for the given
  335. namespace.
  336. fromqflist({list}) *vim.diagnostic.fromqflist()*
  337. Convert a list of quickfix items to a list of diagnostics.
  338. Parameters: ~
  339. • {list} (table) A list of quickfix items from |getqflist()| or
  340. |getloclist()|.
  341. Return: ~
  342. array of diagnostics |diagnostic-structure|
  343. get({bufnr}, {opts}) *vim.diagnostic.get()*
  344. Get current diagnostics.
  345. Parameters: ~
  346. • {bufnr} (number|nil) Buffer number to get diagnostics from. Use 0 for
  347. current buffer or nil for all buffers.
  348. • {opts} (table|nil) A table with the following keys:
  349. • namespace: (number) Limit diagnostics to the given
  350. namespace.
  351. • lnum: (number) Limit diagnostics to the given line number.
  352. • severity: See |diagnostic-severity|.
  353. Return: ~
  354. (table) A list of diagnostic items |diagnostic-structure|.
  355. get_namespace({namespace}) *vim.diagnostic.get_namespace()*
  356. Get namespace metadata.
  357. Parameters: ~
  358. • {namespace} (number) Diagnostic namespace
  359. Return: ~
  360. (table) Namespace metadata
  361. get_namespaces() *vim.diagnostic.get_namespaces()*
  362. Get current diagnostic namespaces.
  363. Return: ~
  364. (table) A list of active diagnostic namespaces |vim.diagnostic|.
  365. get_next({opts}) *vim.diagnostic.get_next()*
  366. Get the next diagnostic closest to the cursor position.
  367. Parameters: ~
  368. • {opts} (table) See |vim.diagnostic.goto_next()|
  369. Return: ~
  370. (table) Next diagnostic
  371. get_next_pos({opts}) *vim.diagnostic.get_next_pos()*
  372. Return the position of the next diagnostic in the current buffer.
  373. Parameters: ~
  374. • {opts} (table) See |vim.diagnostic.goto_next()|
  375. Return: ~
  376. (table) Next diagnostic position as a (row, col) tuple.
  377. get_prev({opts}) *vim.diagnostic.get_prev()*
  378. Get the previous diagnostic closest to the cursor position.
  379. Parameters: ~
  380. • {opts} (table) See |vim.diagnostic.goto_next()|
  381. Return: ~
  382. (table) Previous diagnostic
  383. get_prev_pos({opts}) *vim.diagnostic.get_prev_pos()*
  384. Return the position of the previous diagnostic in the current buffer.
  385. Parameters: ~
  386. • {opts} (table) See |vim.diagnostic.goto_next()|
  387. Return: ~
  388. (table) Previous diagnostic position as a (row, col) tuple.
  389. goto_next({opts}) *vim.diagnostic.goto_next()*
  390. Move to the next diagnostic.
  391. Parameters: ~
  392. • {opts} (table|nil) Configuration table with the following keys:
  393. • namespace: (number) Only consider diagnostics from the given
  394. namespace.
  395. • cursor_position: (cursor position) Cursor position as a
  396. (row, col) tuple. See |nvim_win_get_cursor()|. Defaults to
  397. the current cursor position.
  398. • wrap: (boolean, default true) Whether to loop around file or
  399. not. Similar to 'wrapscan'.
  400. • severity: See |diagnostic-severity|.
  401. • float: (boolean or table, default true) If "true", call
  402. |vim.diagnostic.open_float()| after moving. If a table, pass
  403. the table as the {opts} parameter to
  404. |vim.diagnostic.open_float()|. Unless overridden, the float
  405. will show diagnostics at the new cursor position (as if
  406. "cursor" were passed to the "scope" option).
  407. • win_id: (number, default 0) Window ID
  408. goto_prev({opts}) *vim.diagnostic.goto_prev()*
  409. Move to the previous diagnostic in the current buffer.
  410. Parameters: ~
  411. • {opts} (table) See |vim.diagnostic.goto_next()|
  412. hide({namespace}, {bufnr}) *vim.diagnostic.hide()*
  413. Hide currently displayed diagnostics.
  414. This only clears the decorations displayed in the buffer. Diagnostics can
  415. be redisplayed with |vim.diagnostic.show()|. To completely remove
  416. diagnostics, use |vim.diagnostic.reset()|.
  417. To hide diagnostics and prevent them from re-displaying, use
  418. |vim.diagnostic.disable()|.
  419. Parameters: ~
  420. • {namespace} (number|nil) Diagnostic namespace. When omitted, hide
  421. diagnostics from all namespaces.
  422. • {bufnr} (number|nil) Buffer number, or 0 for current buffer. When
  423. omitted, hide diagnostics in all buffers.
  424. *vim.diagnostic.match()*
  425. match({str}, {pat}, {groups}, {severity_map}, {defaults})
  426. Parse a diagnostic from a string.
  427. For example, consider a line of output from a linter: >
  428. WARNING filename:27:3: Variable 'foo' does not exist
  429. <
  430. This can be parsed into a diagnostic |diagnostic-structure| with: >
  431. local s = "WARNING filename:27:3: Variable 'foo' does not exist"
  432. local pattern = "^(%w+) %w+:(%d+):(%d+): (.+)$"
  433. local groups = { "severity", "lnum", "col", "message" }
  434. vim.diagnostic.match(s, pattern, groups, { WARNING = vim.diagnostic.WARN })
  435. <
  436. Parameters: ~
  437. • {str} (string) String to parse diagnostics from.
  438. • {pat} (string) Lua pattern with capture groups.
  439. • {groups} (table) List of fields in a |diagnostic-structure| to
  440. associate with captures from {pat}.
  441. • {severity_map} (table) A table mapping the severity field from
  442. {groups} with an item from |vim.diagnostic.severity|.
  443. • {defaults} (table|nil) Table of default values for any fields not
  444. listed in {groups}. When omitted, numeric values
  445. default to 0 and "severity" defaults to ERROR.
  446. Return: ~
  447. diagnostic |diagnostic-structure| or `nil` if {pat} fails to match
  448. {str}.
  449. open_float({opts}, {...}) *vim.diagnostic.open_float()*
  450. Show diagnostics in a floating window.
  451. Parameters: ~
  452. • {opts} (table|nil) Configuration table with the same keys as
  453. |vim.lsp.util.open_floating_preview()| in addition to the
  454. following:
  455. • bufnr: (number) Buffer number to show diagnostics from.
  456. Defaults to the current buffer.
  457. • namespace: (number) Limit diagnostics to the given namespace
  458. • scope: (string, default "line") Show diagnostics from the
  459. whole buffer ("buffer"), the current cursor line ("line"),
  460. or the current cursor position ("cursor"). Shorthand
  461. versions are also accepted ("c" for "cursor", "l" for
  462. "line", "b" for "buffer").
  463. • pos: (number or table) If {scope} is "line" or "cursor", use
  464. this position rather than the cursor position. If a number,
  465. interpreted as a line number; otherwise, a (row, col) tuple.
  466. • severity_sort: (default false) Sort diagnostics by severity.
  467. Overrides the setting from |vim.diagnostic.config()|.
  468. • severity: See |diagnostic-severity|. Overrides the setting
  469. from |vim.diagnostic.config()|.
  470. • header: (string or table) String to use as the header for
  471. the floating window. If a table, it is interpreted as a
  472. [text, hl_group] tuple. Overrides the setting from
  473. |vim.diagnostic.config()|.
  474. • source: (boolean or string) Include the diagnostic source in
  475. the message. Use "if_many" to only show sources if there is
  476. more than one source of diagnostics in the buffer.
  477. Otherwise, any truthy value means to always show the
  478. diagnostic source. Overrides the setting from
  479. |vim.diagnostic.config()|.
  480. • format: (function) A function that takes a diagnostic as
  481. input and returns a string. The return value is the text
  482. used to display the diagnostic. Overrides the setting from
  483. |vim.diagnostic.config()|.
  484. • prefix: (function, string, or table) Prefix each diagnostic
  485. in the floating window. If a function, it must have the
  486. signature (diagnostic, i, total) -> (string, string), where
  487. {i} is the index of the diagnostic being evaluated and
  488. {total} is the total number of diagnostics displayed in the
  489. window. The function should return a string which is
  490. prepended to each diagnostic in the window as well as an
  491. (optional) highlight group which will be used to highlight
  492. the prefix. If {prefix} is a table, it is interpreted as a
  493. [text, hl_group] tuple as in |nvim_echo()|; otherwise, if
  494. {prefix} is a string, it is prepended to each diagnostic in
  495. the window with no highlight. Overrides the setting from
  496. |vim.diagnostic.config()|.
  497. Return: ~
  498. tuple ({float_bufnr}, {win_id})
  499. reset({namespace}, {bufnr}) *vim.diagnostic.reset()*
  500. Remove all diagnostics from the given namespace.
  501. Unlike |vim.diagnostic.hide()|, this function removes all saved
  502. diagnostics. They cannot be redisplayed using |vim.diagnostic.show()|. To
  503. simply remove diagnostic decorations in a way that they can be
  504. re-displayed, use |vim.diagnostic.hide()|.
  505. Parameters: ~
  506. • {namespace} (number|nil) Diagnostic namespace. When omitted, remove
  507. diagnostics from all namespaces.
  508. • {bufnr} (number|nil) Remove diagnostics for the given buffer.
  509. When omitted, diagnostics are removed for all buffers.
  510. set({namespace}, {bufnr}, {diagnostics}, {opts}) *vim.diagnostic.set()*
  511. Set diagnostics for the given namespace and buffer.
  512. Parameters: ~
  513. • {namespace} (number) The diagnostic namespace
  514. • {bufnr} (number) Buffer number
  515. • {diagnostics} (table) A list of diagnostic items
  516. |diagnostic-structure|
  517. • {opts} (table|nil) Display options to pass to
  518. |vim.diagnostic.show()|
  519. setloclist({opts}) *vim.diagnostic.setloclist()*
  520. Add buffer diagnostics to the location list.
  521. Parameters: ~
  522. • {opts} (table|nil) Configuration table with the following keys:
  523. • namespace: (number) Only add diagnostics from the given
  524. namespace.
  525. • winnr: (number, default 0) Window number to set location
  526. list for.
  527. • open: (boolean, default true) Open the location list after
  528. setting.
  529. • title: (string) Title of the location list. Defaults to
  530. "Diagnostics".
  531. • severity: See |diagnostic-severity|.
  532. setqflist({opts}) *vim.diagnostic.setqflist()*
  533. Add all diagnostics to the quickfix list.
  534. Parameters: ~
  535. • {opts} (table|nil) Configuration table with the following keys:
  536. • namespace: (number) Only add diagnostics from the given
  537. namespace.
  538. • open: (boolean, default true) Open quickfix list after
  539. setting.
  540. • title: (string) Title of quickfix list. Defaults to
  541. "Diagnostics".
  542. • severity: See |diagnostic-severity|.
  543. *vim.diagnostic.show()*
  544. show({namespace}, {bufnr}, {diagnostics}, {opts})
  545. Display diagnostics for the given namespace and buffer.
  546. Parameters: ~
  547. • {namespace} (number|nil) Diagnostic namespace. When omitted, show
  548. diagnostics from all namespaces.
  549. • {bufnr} (number|nil) Buffer number, or 0 for current buffer.
  550. When omitted, show diagnostics in all buffers.
  551. • {diagnostics} (table|nil) The diagnostics to display. When omitted,
  552. use the saved diagnostics for the given namespace and
  553. buffer. This can be used to display a list of
  554. diagnostics without saving them or to display only a
  555. subset of diagnostics. May not be used when {namespace}
  556. or {bufnr} is nil.
  557. • {opts} (table|nil) Display options. See
  558. |vim.diagnostic.config()|.
  559. toqflist({diagnostics}) *vim.diagnostic.toqflist()*
  560. Convert a list of diagnostics to a list of quickfix items that can be
  561. passed to |setqflist()| or |setloclist()|.
  562. Parameters: ~
  563. • {diagnostics} (table) List of diagnostics |diagnostic-structure|.
  564. Return: ~
  565. array of quickfix list items |setqflist-what|
  566. vim:tw=78:ts=8:sw=4:sts=4:et:ft=help:norl: