Skip to content

Commit 1ec7b56

Browse files
committed
feat: support disable_diagnostics for all contexts (resolves #503)
1 parent 0bae1a3 commit 1ec7b56

File tree

6 files changed

+57
-33
lines changed

6 files changed

+57
-33
lines changed

README.md

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ local actions = require("diffview.actions")
183183

184184
require("diffview").setup({
185185
diff_binaries = false, -- Show diffs for binaries
186-
enhanced_diff_hl = false, -- See ':h diffview-config-enhanced_diff_hl'
186+
enhanced_diff_hl = false, -- See |diffview-config-enhanced_diff_hl|
187187
git_cmd = { "git" }, -- The git executable followed by default args.
188188
hg_cmd = { "hg" }, -- The hg executable followed by default args.
189189
use_icons = true, -- Requires nvim-web-devicons
@@ -208,22 +208,24 @@ require("diffview").setup({
208208
-- |'diff3_vertical'
209209
-- |'diff3_mixed'
210210
-- |'diff4_mixed'
211-
-- For more info, see ':h diffview-config-view.x.layout'.
211+
-- For more info, see |diffview-config-view.x.layout|.
212212
default = {
213213
-- Config for changed files, and staged files in diff views.
214214
layout = "diff2_horizontal",
215-
winbar_info = false, -- See ':h diffview-config-view.x.winbar_info'
215+
disable_diagnostics = false, -- Temporarily disable diagnostics for diff buffers while in the view.
216+
winbar_info = false, -- See |diffview-config-view.x.winbar_info|
216217
},
217218
merge_tool = {
218219
-- Config for conflicted files in diff views during a merge or rebase.
219220
layout = "diff3_horizontal",
220-
disable_diagnostics = true, -- Temporarily disable diagnostics for conflict buffers while in the view.
221-
winbar_info = true, -- See ':h diffview-config-view.x.winbar_info'
221+
disable_diagnostics = true, -- Temporarily disable diagnostics for diff buffers while in the view.
222+
winbar_info = true, -- See |diffview-config-view.x.winbar_info|
222223
},
223224
file_history = {
224225
-- Config for changed files in file history views.
225226
layout = "diff2_horizontal",
226-
winbar_info = false, -- See ':h diffview-config-view.x.winbar_info'
227+
disable_diagnostics = false, -- Temporarily disable diagnostics for diff buffers while in the view.
228+
winbar_info = false, -- See |diffview-config-view.x.winbar_info|
227229
},
228230
},
229231
file_panel = {
@@ -232,14 +234,14 @@ require("diffview").setup({
232234
flatten_dirs = true, -- Flatten dirs that only contain one single dir
233235
folder_statuses = "only_folded", -- One of 'never', 'only_folded' or 'always'.
234236
},
235-
win_config = { -- See ':h diffview-config-win_config'
237+
win_config = { -- See |diffview-config-win_config|
236238
position = "left",
237239
width = 35,
238-
win_opts = {}
240+
win_opts = {},
239241
},
240242
},
241243
file_history_panel = {
242-
log_options = { -- See ':h diffview-config-log_options'
244+
log_options = { -- See |diffview-config-log_options|
243245
git = {
244246
single_file = {
245247
diff_merges = "combined",
@@ -253,22 +255,20 @@ require("diffview").setup({
253255
multi_file = {},
254256
},
255257
},
256-
win_config = { -- See ':h diffview-config-win_config'
258+
win_config = { -- See |diffview-config-win_config|
257259
position = "bottom",
258260
height = 16,
259-
win_opts = {}
261+
win_opts = {},
260262
},
261263
},
262264
commit_log_panel = {
263-
win_config = { -- See ':h diffview-config-win_config'
264-
win_opts = {},
265-
}
265+
win_config = {}, -- See |diffview-config-win_config|
266266
},
267267
default_args = { -- Default args prepended to the arg-list for the listed commands
268268
DiffviewOpen = {},
269269
DiffviewFileHistory = {},
270270
},
271-
hooks = {}, -- See ':h diffview-config-hooks'
271+
hooks = {}, -- See |diffview-config-hooks|
272272
keymaps = {
273273
disable_defaults = false, -- Disable the default keymaps
274274
view = {
@@ -364,15 +364,23 @@ require("diffview").setup({
364364
{ "n", "<C-A-d>", actions.open_in_diffview, { desc = "Open the entry under the cursor in a diffview" } },
365365
{ "n", "y", actions.copy_hash, { desc = "Copy the commit hash of the entry under the cursor" } },
366366
{ "n", "L", actions.open_commit_log, { desc = "Show commit details" } },
367+
{ "n", "X", actions.restore_entry, { desc = "Restore file to the state from the selected entry" } },
368+
{ "n", "zr", actions.open_fold, { desc = "Expand fold" } },
369+
{ "n", "zo", actions.open_fold, { desc = "Expand fold" } },
370+
{ "n", "zm", actions.close_fold, { desc = "Collapse fold" } },
371+
{ "n", "zc", actions.close_fold, { desc = "Collapse fold" } },
372+
{ "n", "h", actions.close_fold, { desc = "Collapse fold" } },
373+
{ "n", "za", actions.toggle_fold, { desc = "Toggle fold" } },
367374
{ "n", "zR", actions.open_all_folds, { desc = "Expand all folds" } },
368375
{ "n", "zM", actions.close_all_folds, { desc = "Collapse all folds" } },
369376
{ "n", "j", actions.next_entry, { desc = "Bring the cursor to the next file entry" } },
370377
{ "n", "<down>", actions.next_entry, { desc = "Bring the cursor to the next file entry" } },
371-
{ "n", "k", actions.prev_entry, { desc = "Bring the cursor to the previous file entry." } },
372-
{ "n", "<up>", actions.prev_entry, { desc = "Bring the cursor to the previous file entry." } },
373-
{ "n", "<cr>", actions.select_entry, { desc = "Open the diff for the selected entry." } },
374-
{ "n", "o", actions.select_entry, { desc = "Open the diff for the selected entry." } },
375-
{ "n", "<2-LeftMouse>", actions.select_entry, { desc = "Open the diff for the selected entry." } },
378+
{ "n", "k", actions.prev_entry, { desc = "Bring the cursor to the previous file entry" } },
379+
{ "n", "<up>", actions.prev_entry, { desc = "Bring the cursor to the previous file entry" } },
380+
{ "n", "<cr>", actions.select_entry, { desc = "Open the diff for the selected entry" } },
381+
{ "n", "o", actions.select_entry, { desc = "Open the diff for the selected entry" } },
382+
{ "n", "l", actions.select_entry, { desc = "Open the diff for the selected entry" } },
383+
{ "n", "<2-LeftMouse>", actions.select_entry, { desc = "Open the diff for the selected entry" } },
376384
{ "n", "<c-b>", actions.scroll_view(-0.25), { desc = "Scroll the view up" } },
377385
{ "n", "<c-f>", actions.scroll_view(0.25), { desc = "Scroll the view down" } },
378386
{ "n", "<tab>", actions.select_next_entry, { desc = "Open the diff for the next file" } },

doc/diffview.txt

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ view.x.layout *diffview-config-view.x.layout*
442442
| "diff4_mixed"
443443
| -1
444444
<
445-
Default: (see example config above)
445+
Default: (see defaults)
446446

447447
This determines the layout used for diffs in the various different
448448
views. Some of the layouts are only applicable to certain types of
@@ -550,17 +550,17 @@ view.x.layout *diffview-config-view.x.layout*
550550
└──────────────┘
551551

552552
view.x.winbar_info *diffview-config-view.x.winbar_info*
553-
Type: `boolean`, Default: (see example config above)
553+
Type: `boolean`, Default: (see defaults)
554554

555555
Use the 'winbar' to show contextual info about the different versions
556556
of a file in a diff.
557557

558-
*diffview-config-view.merge_tool.disable_diagnostics*
559-
view.merge_tool.disable_diagnostics
560-
Type: `boolean`, Default: `true`
558+
*diffview-config-view.x.disable_diagnostics*
559+
view.x.disable_diagnostics
560+
Type: `boolean`, Default: (see defaults)
561561

562-
Temporarily disable diagnostics for conflict buffers while in a
563-
diff_view. The diagnostics are enabled again when leaving or closing
562+
Temporarily disable diagnostics for diff buffers while in a view. The
563+
diagnostics are automatically enabled again when leaving or closing
564564
the view's tab page.
565565

566566
win_config *diffview-config-win_config*
@@ -652,7 +652,7 @@ win_config *diffview-config-win_config*
652652

653653

654654
log_options *diffview-config-log_options*
655-
Type: `table`, Default: (see example config above)
655+
Type: `table`, Default: (see defaults)
656656

657657
This table allows you to control the default options that are passed
658658
to git-log in order to produce the file history. The table is divided
@@ -789,7 +789,7 @@ hooks *diffview-config-hooks*
789789
<
790790

791791
keymaps *diffview-config-keymaps*
792-
Type: `table`, Default: (see example config above)
792+
Type: `table`, Default: (see defaults)
793793

794794
The keymaps config is structured as a table with sub-tables for
795795
various different contexts where mappings can be declared. In these

doc/diffview_defaults.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ DEFAULT CONFIG *diffview.defaults*
2121
},
2222
view = {
2323
-- Configure the layout and behavior of different types of views.
24-
-- Available layouts:
24+
-- Available layouts:
2525
-- 'diff1_plain'
2626
-- |'diff2_horizontal'
2727
-- |'diff2_vertical'
@@ -33,17 +33,19 @@ DEFAULT CONFIG *diffview.defaults*
3333
default = {
3434
-- Config for changed files, and staged files in diff views.
3535
layout = "diff2_horizontal",
36+
disable_diagnostics = false, -- Temporarily disable diagnostics for diff buffers while in the view.
3637
winbar_info = false, -- See |diffview-config-view.x.winbar_info|
3738
},
3839
merge_tool = {
3940
-- Config for conflicted files in diff views during a merge or rebase.
4041
layout = "diff3_horizontal",
41-
disable_diagnostics = true, -- Temporarily disable diagnostics for conflict buffers while in the view.
42+
disable_diagnostics = true, -- Temporarily disable diagnostics for diff buffers while in the view.
4243
winbar_info = true, -- See |diffview-config-view.x.winbar_info|
4344
},
4445
file_history = {
4546
-- Config for changed files in file history views.
4647
layout = "diff2_horizontal",
48+
disable_diagnostics = false, -- Temporarily disable diagnostics for diff buffers while in the view.
4749
winbar_info = false, -- See |diffview-config-view.x.winbar_info|
4850
},
4951
},

lua/diffview/config.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ M.defaults = {
5656
view = {
5757
default = {
5858
layout = "diff2_horizontal",
59+
disable_diagnostics = false,
5960
winbar_info = false,
6061
},
6162
merge_tool = {
@@ -65,6 +66,7 @@ M.defaults = {
6566
},
6667
file_history = {
6768
layout = "diff2_horizontal",
69+
disable_diagnostics = false,
6870
winbar_info = false,
6971
},
7072
},

lua/diffview/scene/window.lua

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,10 +159,20 @@ Window.open_file = async.void(function(self)
159159
self:apply_file_winopts()
160160
end
161161

162+
local view = lib.get_current_view()
163+
local disable_diagnostics = false
164+
165+
if self.file.kind == "conflicting" then
166+
disable_diagnostics = conf.view.merge_tool.disable_diagnostics
167+
elseif view and FileHistoryView.__get():ancestorof(view) then
168+
disable_diagnostics = conf.view.file_history.disable_diagnostics
169+
else
170+
disable_diagnostics = conf.view.default.disable_diagnostics
171+
end
172+
162173
self.file:attach_buffer(false, {
163174
keymaps = config.get_layout_keymaps(self.parent),
164-
disable_diagnostics = self.file.kind == "conflicting"
165-
and conf.view.merge_tool.disable_diagnostics,
175+
disable_diagnostics = disable_diagnostics,
166176
})
167177

168178
if self:show_winbar_info() then

lua/diffview/vcs/file.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,7 @@ function File:attach_buffer(force, opt)
360360
if HAS_NVIM_0_10 then
361361
vim.diagnostic.enable(false, { bufnr = self.bufnr })
362362
else
363+
---@diagnostic disable-next-line: deprecated
363364
vim.diagnostic.disable(self.bufnr)
364365
end
365366
end
@@ -391,6 +392,7 @@ function File:detach_buffer()
391392
if HAS_NVIM_0_10 then
392393
vim.diagnostic.enable(true, { bufnr = self.bufnr })
393394
else
395+
---@diagnostic disable-next-line: param-type-mismatch
394396
vim.diagnostic.enable(self.bufnr)
395397
end
396398
end

0 commit comments

Comments
 (0)