1+ local config = require (" nvim-tree.config" )
12local core = require (" nvim-tree.core" )
23local utils = require (" nvim-tree.utils" )
34local view = require (" nvim-tree.view" )
@@ -38,11 +39,16 @@ local function uniformize_path(path)
3839end
3940
4041--- Severity is within diagnostics.severity.min, diagnostics.severity.max
41- --- @param severity lsp.DiagnosticSeverity
42- --- @param config table
42+ --- Alway in range when using vim.diagnostic.Opts:
43+ --- @see nvim_tree.config.diagnostics.diagnostic_opts
44+ --- @param severity vim.diagnostic.Severity
4345--- @return boolean
44- local function is_severity_in_range (severity , config )
45- return config .max <= severity and severity <= config .min
46+ local function is_severity_in_range (severity )
47+ if config .g .diagnostics .diagnostic_opts then
48+ return true
49+ else
50+ return severity >= config .g .diagnostics .severity .max and severity <= config .g .diagnostics .severity .min
51+ end
4652end
4753
4854--- Handle any COC exceptions, preventing any propagation
@@ -86,7 +92,7 @@ local function from_coc()
8692 local bufname = uniformize_path (diagnostic .file )
8793 local coc_severity = COC_SEVERITY_LEVELS [diagnostic .severity ]
8894 local highest_severity = buffer_severity [bufname ] or coc_severity
89- if is_severity_in_range (highest_severity , M . severity ) then
95+ if is_severity_in_range (highest_severity ) then
9096 buffer_severity [bufname ] = math.min (highest_severity , coc_severity )
9197 end
9298 end
122128--- On disabling LSP, a reset event will be sent for all buffers.
123129--- @param ev table standard event with data.diagnostics populated
124130function M .update_lsp (ev )
125- if not M .enable or not ev or not ev .data or not ev .data .diagnostics then
131+ if not config . g . diagnostics .enable or not ev or not ev .data or not ev .data .diagnostics then
126132 return
127133 end
128134
@@ -138,7 +144,7 @@ function M.update_lsp(ev)
138144
139145 -- most severe (lowest) severity in user range
140146 for _ , diagnostic in ipairs (diagnostics ) do
141- if diagnostic .severity >= M . severity . max and diagnostic . severity <= M . severity . min then
147+ if is_severity_in_range ( diagnostic .severity ) then
142148 if not new_severity or diagnostic .severity < new_severity then
143149 new_severity = diagnostic .severity
144150 end
@@ -150,7 +156,7 @@ function M.update_lsp(ev)
150156 NODE_SEVERITIES [bufname ] = new_severity
151157 NODE_SEVERITIES_VERSION = NODE_SEVERITIES_VERSION + 1
152158
153- utils .debounce (" DiagnosticChanged redraw" , M .debounce_delay , function ()
159+ utils .debounce (" DiagnosticChanged redraw" , config . g . diagnostics .debounce_delay , function ()
154160 local profile_redraw = log .profile_start (" DiagnosticChanged redraw" )
155161
156162 local explorer = core .get_explorer ()
@@ -168,10 +174,10 @@ end
168174--- Fired on CocDiagnosticChanged events:
169175--- debounced retrieval, cache update, version increment and draw
170176function M .update_coc ()
171- if not M .enable then
177+ if not config . g . diagnostics .enable then
172178 return
173179 end
174- utils .debounce (" CocDiagnosticChanged update" , M .debounce_delay , function ()
180+ utils .debounce (" CocDiagnosticChanged update" , config . g . diagnostics .debounce_delay , function ()
175181 local profile = log .profile_start (" CocDiagnosticChanged update" )
176182 NODE_SEVERITIES = from_coc ()
177183 NODE_SEVERITIES_VERSION = NODE_SEVERITIES_VERSION + 1
@@ -198,12 +204,12 @@ end
198204--- @param node Node
199205--- @return DiagStatus | nil
200206function M .get_diag_status (node )
201- if not M .enable then
207+ if not config . g . diagnostics .enable then
202208 return nil
203209 end
204210
205211 -- dir but we shouldn't show on dirs at all
206- if node :is (DirectoryNode ) and not M .show_on_dirs then
212+ if node :is (DirectoryNode ) and not config . g . diagnostics .show_on_dirs then
207213 return nil
208214 end
209215
@@ -222,26 +228,10 @@ function M.get_diag_status(node)
222228 end
223229
224230 -- dir is closed or we should show on open_dirs
225- if not dir .open or M .show_on_open_dirs then
231+ if not dir .open or config . g . diagnostics .show_on_open_dirs then
226232 return node .diag_status
227233 end
228234 return nil
229235end
230236
231- function M .setup (opts )
232- M .enable = opts .diagnostics .enable
233- M .debounce_delay = opts .diagnostics .debounce_delay
234- M .severity = opts .diagnostics .diagnostic_opts and {
235- min = vim .diagnostic .severity .HINT ,
236- max = vim .diagnostic .severity .ERROR
237- } or opts .diagnostics .severity
238-
239- if M .enable then
240- log .line (" diagnostics" , " setup" )
241- end
242-
243- M .show_on_dirs = opts .diagnostics .show_on_dirs
244- M .show_on_open_dirs = opts .diagnostics .show_on_open_dirs
245- end
246-
247237return M
0 commit comments