Skip to content

Commit ff6749a

Browse files
committed
feat: force disable diagnostics in certain modes
Ref: #118
1 parent cd40103 commit ff6749a

File tree

2 files changed

+19
-15
lines changed

2 files changed

+19
-15
lines changed

lua/tiny-inline-diagnostic/chunk.lua

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,6 @@ function M.get_chunks(opts, diags_on_line, diag_index, diag_line, cursor_line, b
281281
end
282282
end
283283

284-
285284
if opts.options.format and diag_message then
286285
diag_message = opts.options.format(diag)
287286
end

lua/tiny-inline-diagnostic/diagnostic.lua

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,10 @@ end
7070
---@return table
7171
function M.filter_diags_under_cursor(opts, buf, diagnostics)
7272
if
73-
not vim.api.nvim_buf_is_valid(buf)
74-
or vim.api.nvim_get_current_buf() ~= buf
75-
or not diagnostics
76-
or #diagnostics == 0
73+
not vim.api.nvim_buf_is_valid(buf)
74+
or vim.api.nvim_get_current_buf() ~= buf
75+
or not diagnostics
76+
or #diagnostics == 0
7777
then
7878
return {}
7979
end
@@ -130,8 +130,8 @@ end
130130
---@param diagnostics table
131131
local function update_diagnostics_cache(opts, bufnr, diagnostics)
132132
if vim.tbl_isempty(diagnostics) then
133-
-- The event doesn't contain the associated namespace of the diagnostics,
134-
-- meaning we can't know which namespace was cleared. We thus have to get
133+
-- The event doesn't contain the associated namespace of the diagnostics,
134+
-- meaning we can't know which namespace was cleared. We thus have to get
135135
-- the diagnostics through normal means.
136136
local diags = vim.diagnostic.get(bufnr)
137137
table.sort(diags, function(a, b)
@@ -148,7 +148,7 @@ local function update_diagnostics_cache(opts, bufnr, diagnostics)
148148

149149
-- Find the namespaces of the incoming diagnostics.
150150
-- Use the namespace and not the source because the event is triggered per namespace,
151-
-- while the source field can be unreliable (e.g. Deno LSP seems to switch between
151+
-- while the source field can be unreliable (e.g. Deno LSP seems to switch between
152152
-- deno and deno-ts).
153153
local namespaces = {}
154154
for _, diag in ipairs(diagnostics) do
@@ -184,13 +184,20 @@ local function apply_virtual_texts(opts, bufnr)
184184
end
185185

186186
if
187-
not M.user_toggle_state
188-
or not (M.enabled and vim.diagnostic.is_enabled() and vim.api.nvim_buf_is_valid(bufnr))
187+
not M.user_toggle_state
188+
or not (M.enabled and vim.diagnostic.is_enabled() and vim.api.nvim_buf_is_valid(bufnr))
189189
then
190190
extmarks.clear(bufnr)
191191
return
192192
end
193193

194+
local mode = vim.api.nvim_get_mode().mode
195+
if M.enabled and vim.tbl_contains(DISABLED_MODES, mode) then
196+
disable()
197+
extmarks.clear(event.buf)
198+
return
199+
end
200+
194201
-- Get diagnostics and clear them if needed
195202
local diagnostics = diagnostics_cache[bufnr] or {}
196203
if vim.tbl_isempty(diagnostics) then
@@ -218,13 +225,11 @@ local function apply_virtual_texts(opts, bufnr)
218225

219226
if lnum == cursor_line then
220227
virt_lines, offset, need_to_be_under =
221-
virtual_text_forge.from_diagnostics(opts, diags, diagnostic_pos, bufnr)
228+
virtual_text_forge.from_diagnostics(opts, diags, diagnostic_pos, bufnr)
222229
else
223-
local chunks = chunk_utils.get_chunks(opts, diags, 1, diagnostic_pos[1], cursor_line,
224-
bufnr)
230+
local chunks = chunk_utils.get_chunks(opts, diags, 1, diagnostic_pos[1], cursor_line, bufnr)
225231
local max_width = chunk_utils.get_max_width_from_chunks(chunks.chunks)
226-
virt_lines, offset, need_to_be_under = virtual_text_forge.from_diagnostic(opts, chunks, 1,
227-
max_width, 1)
232+
virt_lines, offset, need_to_be_under = virtual_text_forge.from_diagnostic(opts, chunks, 1, max_width, 1)
228233
end
229234

230235
table.insert(diags_dims, { lnum, #virt_lines })

0 commit comments

Comments
 (0)