Nvim :help
ページは、ソースからtree-sitter-vimdocパーサーを使用して生成されています。
{namespace}
を必要としますが、コンシューマー用のAPIは通常、名前空間を必要としません(ただし、多くの場合、オプションで指定できます)。良い経験則として、メソッドがバッファの診断を変更することを目的としている場合(例:vim.diagnostic.set())、名前空間が必要です。vim.diagnostic.severity
で定義されている値のいずれかです。vim.diagnostic.get(0, { severity = vim.diagnostic.severity.WARN })
2. 「min」または「max」キー(または両方)を持つテーブルvim.diagnostic.get(0, { severity = { min = vim.diagnostic.severity.WARN } })
vim.diagnostic.get(0, { severity = {
vim.diagnostic.severity.WARN,
vim.diagnostic.severity.INFO,
} })
function(namespace, bufnr, diagnostics, opts)
function(namespace, bufnr)
vim.diagnostic.handlers
に新しいキーを作成することで追加できます(diagnostic-handlers-exampleを参照)。{opts}
テーブルは、設定オプションの完全なセットです(つまり、ハンドラ自体のオプションのみに限定されません)。テーブル内の値はすでに解決されています(つまり、ユーザーが設定オプションに関数を指定した場合、関数はすでに評価されています)。-- It's good practice to namespace custom handlers to avoid collisions
vim.diagnostic.handlers["my/notify"] = {
show = function(namespace, bufnr, diagnostics, opts)
-- In our example, the opts table has a "log_level" option
local level = opts["my/notify"].log_level
local name = vim.diagnostic.get_namespace(namespace).name
local msg = string.format("%d diagnostics in buffer %d from %s",
#diagnostics,
bufnr,
name)
vim.notify(msg, level)
end,
}
-- Users can configure the handler
vim.diagnostic.config({
["my/notify"] = {
log_level = vim.log.levels.INFO
}
})
-- Create a custom namespace. This will aggregate signs from all other
-- namespaces and only show the one with the highest severity on a
-- given line
local ns = vim.api.nvim_create_namespace("my_namespace")
-- Get a reference to the original signs handler
local orig_signs_handler = vim.diagnostic.handlers.signs
-- Override the built-in signs handler
vim.diagnostic.handlers.signs = {
show = function(_, bufnr, _, opts)
-- Get all diagnostics from the whole buffer rather than just the
-- diagnostics passed to the handler
local diagnostics = vim.diagnostic.get(bufnr)
-- Find the "worst" diagnostic per line
local max_severity_per_line = {}
for _, d in pairs(diagnostics) do
local m = max_severity_per_line[d.lnum]
if not m or d.severity < m.severity then
max_severity_per_line[d.lnum] = d
end
end
-- Pass the filtered diagnostics (with our custom namespace) to
-- the original handler
local filtered_diagnostics = vim.tbl_values(max_severity_per_line)
orig_signs_handler.show(ns, bufnr, filtered_diagnostics, opts)
end,
hide = function(_, bufnr)
orig_signs_handler.hide(ns, bufnr)
end,
}
Diagnostic
で始まり、その後にハイライトの種類(例:Sign
、Underline
など)と重大度(例:Error
、Warn
など)が続きます。highlight DiagnosticError guifg="BrightRed"
-- Highlight entire line for errors
-- Highlight the line number for warnings
vim.diagnostic.config({
signs = {
text = {
[vim.diagnostic.severity.ERROR] = '',
[vim.diagnostic.severity.WARN] = '',
},
linehl = {
[vim.diagnostic.severity.ERROR] = 'ErrorMsg',
},
numhl = {
[vim.diagnostic.severity.WARN] = 'WarningMsg',
},
},
})
「severity_sort」オプションが設定されている場合(vim.diagnostic.config()を参照)、各符号の優先度は、関連付けられた診断の重大度に依存します。それ以外の場合、すべての符号は同じ優先度を持ちます(vim.diagnostic.config()の「signs」テーブルの「priority」オプションの値、または設定されていない場合は10)。vim.api.nvim_create_autocmd('DiagnosticChanged', {
callback = function(args)
local diagnostics = args.data.diagnostics
vim.print(diagnostics)
end,
})
{bufnr}
(integer
) バッファ番号{lnum}
(integer
) 診断の開始行(0インデックス){end_lnum}
(integer
) 診断の最終行(0インデックス){col}
(integer
) 診断の開始列(0インデックス){end_col}
(integer
) 診断の最終列(0インデックス){message}
(string
) 診断テキスト{source}
(string
) 診断のソース{code}
(string|integer
) 診断コード{user_data}
(any
) プラグインが追加できる任意のデータ{namespace}
(integer
){namespace}
(integer[]|integer
) 診断を1つ以上の名前空間に制限します。{lnum}
(integer
) 診断を、指定された行番号にまたがるものに制限します。{diagnostic}
(vim.Diagnostic
) ジャンプ先の診断。{count}
、{namespace}
、および{severity}
と相互排他です。vim.Diagnosticを参照してください。{count}
(integer
) {pos}
から始まる、移動する診断の数。正の整数は{count}
診断だけ前方に移動し、負の整数は{count}
診断だけ後方に移動します。{diagnostic}
と相互排他です。{pos}
([integer,integer]
) (row, col)
タプルとしてのカーソル位置。nvim_win_get_cursor()を参照してください。{count}
が使用されている場合に、最も近い診断を見つけるために使用されます。{count}
がnilでない場合にのみ使用されます。デフォルトは現在のカーソル位置です。{float}
(boolean|vim.diagnostic.Opts.Float
, デフォルト: false
) true
の場合、移動後にvim.diagnostic.open_float()を呼び出します。テーブルの場合、テーブルをvim.diagnostic.open_float()の{opts}
パラメーターとして渡します。オーバーライドされない限り、フロートは新しいカーソル位置に診断を表示します(「cursor」が「scope」オプションに渡された場合と同様)。{winid}
(integer
, デフォルト: 0
) ウィンドウID{name}
(string
){user_data}
(table
){disabled}
(boolean
)false
: この機能を無効にします。true
: この機能を有効にし、デフォルト設定を使用します。table
: この機能を有効にし、上書きを行います。デフォルト値を使用するには、空のテーブルを使用します。function
: 上記のいずれかを返すシグネチャ (namespace, bufnr) を持つ関数。{underline}
(boolean|vim.diagnostic.Opts.Underline|fun(namespace: integer, bufnr:integer): vim.diagnostic.Opts.Underline
, デフォルト: true
) 診断に下線を使用します。{virtual_text}
(boolean|vim.diagnostic.Opts.VirtualText|fun(namespace: integer, bufnr:integer): vim.diagnostic.Opts.VirtualText
, デフォルト: true
) 診断に仮想テキストを使用します。 1つの名前空間に複数の診断が設定されている場合、診断ごとに1つのプレフィックスと最後の診断メッセージが表示されます。{signs}
(boolean|vim.diagnostic.Opts.Signs|fun(namespace: integer, bufnr:integer): vim.diagnostic.Opts.Signs
, デフォルト: true
) 診断に signos を使用します diagnostic-signs。{float}
(boolean|vim.diagnostic.Opts.Float|fun(namespace: integer, bufnr:integer): vim.diagnostic.Opts.Float
) 浮動ウィンドウのオプション。 vim.diagnostic.Opts.Floatを参照してください。{severity_sort}
(boolean|{reverse?:boolean}
, デフォルト: false
) 診断を重大度でソートします。これは、 signos 、仮想テキスト、およびハイライトが表示される順序に影響します。 trueの場合、重大度の高い診断が重大度の低い診断の前に表示されます(例:ERRORがWARNの前に表示されます)。オプション{reverse}
(boolean) ソート順を反転します。{bufnr}
(integer
, デフォルト: 現在のバッファ) 診断を表示するバッファ番号。{namespace}
(integer
) 診断を指定された名前空間に制限します。{scope}
('line'|'buffer'|'cursor'|'c'|'l'|'b'
, デフォルト: line
) バッファ全体(buffer
)、現在のカーソル行(line
)、または現在のカーソル位置(cursor
)から診断を表示します。短縮バージョンも使用できます (c
は cursor
、l
は line
、b
は buffer
)。{pos}
(integer|[integer,integer]
) {scope}
が "line" または "cursor" の場合、カーソル位置ではなくこの位置を使用します。数値の場合、行番号として解釈されます。それ以外の場合は、(行、列)のタプルです。{severity_sort}
(boolean|{reverse?:boolean}
, デフォルト: false
) 診断を重大度でソートします。 vim.diagnostic.config()の設定を上書きします。{severity}
(vim.diagnostic.SeverityFilter
) diagnostic-severityを参照してください。 vim.diagnostic.config()の設定を上書きします。{header}
(string|[string,any]
) 浮動ウィンドウのヘッダーとして使用する文字列。テーブルの場合、[text, hl_group]
タプルとして解釈されます。 vim.diagnostic.config()の設定を上書きします。{source}
(boolean|'if_many'
) 診断ソースをメッセージに含めます。バッファに複数の診断ソースがある場合にのみソースを表示するには、"if_many" を使用します。それ以外の場合、truthy な値は常に診断ソースを表示することを意味します。 vim.diagnostic.config()の設定を上書きします。{format}
(fun(diagnostic:vim.Diagnostic): string
) 診断を入力として受け取り、文字列を返す関数。戻り値は、診断を表示するために使用されるテキストです。 vim.diagnostic.config()の設定を上書きします。{prefix}
(string|table|(fun(diagnostic:vim.Diagnostic,i:integer,total:integer): string, string)
) 浮動ウィンドウの各診断にプレフィックスを付けます。function
の場合、{i}
は評価中の診断のインデックス、{total}
はウィンドウに表示される診断の総数です。関数は、ウィンドウの各診断の先頭に付加される string
と、プレフィックスの強調表示に使用される(オプションの)強調表示グループを返す必要があります。string
の場合、強調表示なしでウィンドウの各診断の先頭に付加されます。 vim.diagnostic.config()の設定を上書きします。{suffix}
(string|table|(fun(diagnostic:vim.Diagnostic,i:integer,total:integer): string, string)
) {prefix}
と同じですが、テキストを診断の先頭ではなく末尾に追加します。 vim.diagnostic.config()の設定を上書きします。{focus_id}
(string
){float}
(boolean|vim.diagnostic.Opts.Float
, デフォルト: false) vim.diagnostic.jump()の{float}
パラメータのデフォルト値。{priority}
(integer
, デフォルト: 10
) signos に使用する基本優先度。 {severity_sort}
が使用されている場合、signo の優先度はその重大度に基づいて調整されます。それ以外の場合、すべての signo は同じ優先度を使用します。{text}
(table<vim.diagnostic.Severity,string>
) diagnostic-severity を signo カラムに表示する signo テキストにマッピングするテーブル。デフォルトでは、エラー、警告、情報、ヒントにそれぞれ "E"
、"W"
、"I"
、"H"
が使用されます。例vim.diagnostic.config({
signs = { text = { [vim.diagnostic.severity.ERROR] = 'E', ... } }
})
{numhl}
(table<vim.diagnostic.Severity,string>
) diagnostic-severity を signo が配置されている行番号に使用されるハイライトグループにマッピングするテーブル。{linehl}
(table<vim.diagnostic.Severity,string>
) diagnostic-severity を signo が配置されている行全体に使用されるハイライトグループにマッピングするテーブル。{source}
(boolean|"if_many"
) 診断ソースを仮想テキストに含めます。バッファに複数の診断ソースがある場合にのみソースを表示するには、'if_many'
を使用します。それ以外の場合、truthy な値は常に診断ソースを表示することを意味します。{spacing}
(integer
) 仮想テキストの先頭に追加される空白の数。{prefix}
(string|(fun(diagnostic:vim.Diagnostic,i:integer,total:integer): string)
) 診断メッセージにプレフィックスを付けます。 function
の場合、{i}
は評価中の診断のインデックス、{total}
はその行の診断の総数です。これは、診断記号またはエラーコードをレンダリングするために使用できます。{suffix}
(string|(fun(diagnostic:vim.Diagnostic): string)
) 診断メッセージにサフィックスを付けます。これは、LSP診断エラーコードをレンダリングするために使用できます。{format}
(fun(diagnostic:vim.Diagnostic): string
) 戻り値は、診断を表示するために使用されるテキストです。例function(diagnostic)
if diagnostic.severity == vim.diagnostic.severity.ERROR then
return string.format("E: %s", diagnostic.message)
end
return diagnostic.message
end
vim.diagnostic.config({ virtual_text = true })
vim.diagnostic.set(ns, 0, diagnostics, { virtual_text = false })
{namespace}
(integer?
) 指定された名前空間のオプションを更新します。省略した場合、グローバル診断オプションを更新します。{bufnr}
(integer?
) 診断を取得するバッファ番号。現在のバッファの場合は0を、すべてバッファの場合はnilを使用します。is_enabled()
の逆を渡します。vim.diagnostic.enable(not vim.diagnostic.is_enabled())
{enable}
(boolean?
) 有効にする場合はtrue/nil、無効にする場合はfalse。{ns_id}
(integer
) 診断名前空間、またはすべてにnil
。{bufnr}
(integer
) バッファ番号、現在のバッファの場合は0、すべてバッファの場合はnil
。{bufnr}
(integer?
) 診断を取得するバッファ番号。現在のバッファの場合は0を、すべてバッファの場合はnilを使用します。{namespace}
(integer
) 診断名前空間{namespace}
(integer?
) 診断の名前空間。省略した場合、すべての名前空間の診断が非表示になります。{bufnr}
(integer?
) バッファ番号、または現在のバッファの場合は0。省略した場合、すべてのバッファの診断が非表示になります。{ns_id}
(integer
) 診断名前空間、またはすべてにnil
。{bufnr}
(integer
) バッファ番号、現在のバッファの場合は0、すべてバッファの場合はnil
。boolean
)WARNING filename:27:3: Variable 'foo' does not exist
local s = "WARNING filename:27:3: Variable 'foo' does not exist"
local pattern = "^(%w+) %w+:(%d+):(%d+): (.+)$"
local groups = { "severity", "lnum", "col", "message" }
vim.diagnostic.match(s, pattern, groups, { WARNING = vim.diagnostic.WARN })
{str}
(string
) 診断を解析する文字列。{pat}
(string
) キャプチャグループを持つLuaパターン。{defaults}
(table?
) {groups}
にリストされていないフィールドのデフォルト値のテーブル。省略した場合、数値はデフォルトで0になり、「severity」はデフォルトでERRORになります。integer?
) float_bufnr (integer?
) winid{namespace}
(integer?
) 診断の名前空間。省略した場合、すべての名前空間の診断が削除されます。{bufnr}
(integer?
) 指定されたバッファの診断を削除します。省略した場合、すべてのバッファの診断が削除されます。{namespace}
(integer
) 診断の名前空間{bufnr}
(integer
) バッファ番号{bufnr}
(integer
) バッファ番号、または現在のバッファの場合は0{opts}
(vim.diagnostic.Opts?
) vim.diagnostic.show()に渡す表示オプション。 vim.diagnostic.Optsを参照してください。{opts}
) vim.diagnostic.setloclist(){opts}
(table?
) 次のキーを持つ設定テーブル{namespace}
(integer
) 指定された名前空間からの診断のみを追加します。{winnr}
(integer
, デフォルト: 0
) ロケーションリストを設定するウィンドウ番号。{open}
(boolean
, デフォルト: true
) 設定後にロケーションリストを開きます。{opts}
(table?
) 次のキーを持つ設定テーブル{open}
(boolean
, デフォルト: true
) 設定後にクイックフィックスリストを開きます。{title}
(string
) クイックフィックスリストのタイトル。デフォルトは「Diagnostics」です。{namespace}
, {bufnr}
, {diagnostics}
, {opts}
) 指定された名前空間とバッファの診断を表示します。{namespace}
(integer?
) 診断の名前空間。省略した場合、すべての名前空間の診断が表示されます。{bufnr}
(integer?
) バッファ番号、または現在のバッファの場合は0。省略した場合、すべてのバッファの診断が表示されます。{diagnostics}
(vim.Diagnostic[]?
) 表示する診断。省略した場合、指定された名前空間とバッファの保存された診断が使用されます。これは、診断を保存せずに診断のリストを表示したり、診断のサブセットのみを表示したりするために使用できます。 {namespace}
または{bufnr}
がnilの場合は使用できません。 vim.Diagnosticを参照してください。{diagnostics}
) vim.diagnostic.toqflist(){bufnr}
(integer
) バッファ番号、または現在のバッファの場合は0