@@ -37,7 +37,11 @@ function M.at_position(opts, diagnostics, line, col)
3737 return diag .lnum == line and col >= diag .col and col <= diag .end_col
3838 end , diagnostics )
3939
40- return # current_pos_diags > 0 and current_pos_diags or diags_on_line
40+ if opts .options .show_diags_only_under_cursor then
41+ return current_pos_diags
42+ else
43+ return # current_pos_diags > 0 and current_pos_diags or diags_on_line
44+ end
4145end
4246
4347--- @param related_info table
@@ -82,6 +86,28 @@ local function extract_related_diagnostics(diag, max_count)
8286 return related
8387end
8488
89+ --- @param opts table
90+ --- @param diagnostics table
91+ --- @return table
92+ local function add_related_diagnostics (opts , diagnostics )
93+ if not opts .options .show_related or not opts .options .show_related .enabled then
94+ return diagnostics
95+ end
96+
97+ local result = {}
98+ local max_count = opts .options .show_related .max_count or 3
99+
100+ for _ , diag in ipairs (diagnostics ) do
101+ table.insert (result , diag )
102+ if has_related_info (diag ) then
103+ local related = extract_related_diagnostics (diag , max_count )
104+ vim .list_extend (result , related )
105+ end
106+ end
107+
108+ return result
109+ end
110+
85111--- @param opts table
86112--- @param buf number
87113--- @param diagnostics table
@@ -101,22 +127,7 @@ function M.under_cursor(opts, buf, diagnostics)
101127
102128 filtered_diags = M .by_severity (opts , filtered_diags )
103129
104- if not opts .options .show_related or not opts .options .show_related .enabled then
105- return filtered_diags
106- end
107-
108- local result = {}
109- local max_count = opts .options .show_related .max_count or 3
110-
111- for _ , diag in ipairs (filtered_diags ) do
112- table.insert (result , diag )
113- if has_related_info (diag ) then
114- local related = extract_related_diagnostics (diag , max_count )
115- vim .list_extend (result , related )
116- end
117- end
118-
119- return result
130+ return add_related_diagnostics (opts , filtered_diags )
120131end
121132
122133--- @param opts table
@@ -128,6 +139,22 @@ function M.for_display(opts, bufnr, diagnostics)
128139 return M .under_cursor (opts , bufnr , diagnostics )
129140 end
130141
142+ if opts .options .show_diags_only_under_cursor then
143+ local cursor_pos = vim .api .nvim_win_get_cursor (0 )
144+ local current_line = cursor_pos [1 ] - 1
145+
146+ local under_cursor_on_line = M .at_position (opts , diagnostics , current_line , cursor_pos [2 ])
147+
148+ local other_diags = vim .tbl_filter (function (diag )
149+ return diag .lnum ~= current_line
150+ end , diagnostics )
151+
152+ local result = vim .list_extend ({}, under_cursor_on_line )
153+ vim .list_extend (result , other_diags )
154+ result = M .by_severity (opts , result )
155+ return add_related_diagnostics (opts , result )
156+ end
157+
131158 if opts .options .multilines .always_show then
132159 local under_cursor = M .under_cursor (opts , bufnr , diagnostics )
133160 local multiline_diags = diagnostics
0 commit comments