Skip to content

Commit 2010c24

Browse files
Fix: Rebuild Diagnostics + Signs (#203)
* Updated lua/gitlab/actions/discussions/signs.lua * Initial commit of changes * Updated lua/gitlab/actions/discussions/signs.lua * Updated lua/gitlab/actions/discussions/signs.lua * Updated lua/gitlab/actions/discussions/init.lua * Updated lua/gitlab/actions/discussions/signs.lua * Split up signs and diagnostics * Moved common to common file * Continued modularization * added formatting * Moved signs/diagnostic lines into appropriate files * Updated lua/gitlab/reviewer/init.lua * Renamed is_current_sha => is_current_sha_focused * Updated lua/gitlab/reviewer/init.lua * Moved actions.indicators => indicators * Split discussions/signs apart into separate modules * Fixed filter function, fixed discussions * Updated lua/gitlab/indicators/diagnostics.lua * Setting diagnostics, handling and catching errors * Greatly simplified diagnostics setup * Re-split multi-line * Updated lua/gitlab/indicators/diagnostics.lua * Setting up signs * Updated lua/gitlab/indicators/signs.lua * Updated signs + display options * Updated lua/gitlab/state.lua * Updated doc/gitlab.nvim.txt * Updated readme * Added deprecation warning * formatting
1 parent 4c4f4b5 commit 2010c24

File tree

15 files changed

+455
-579
lines changed

15 files changed

+455
-579
lines changed

README.md

Lines changed: 9 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -170,35 +170,16 @@ require("gitlab").setup({
170170
"pipeline",
171171
},
172172
},
173-
discussion_sign_and_diagnostic = {
173+
discussion_signs = {
174+
enabled = true, -- Show diagnostics for gitlab comments in the reviewer
174175
skip_resolved_discussion = false,
175-
skip_old_revision_discussion = true,
176-
},
177-
discussion_sign = {
178-
-- See :h sign_define for details about sign configuration.
179-
enabled = true,
180-
text = "💬",
181-
linehl = nil,
182-
texthl = nil,
183-
culhl = nil,
184-
numhl = nil,
185-
priority = 20, -- Priority of sign, the lower the number the higher the priority
186-
helper_signs = {
187-
-- For multiline comments the helper signs are used to indicate the whole context
188-
-- Priority of helper signs is lower than the main sign (-1).
189-
enabled = true,
190-
start = "",
191-
mid = "|",
192-
["end"] = "",
193-
},
194-
},
195-
discussion_diagnostic = {
196-
-- If you want to customize diagnostics for discussions you can make special config
197-
-- for namespace `gitlab_discussion`. See :h vim.diagnostic.config
198-
enabled = true,
199176
severity = vim.diagnostic.severity.INFO,
200-
code = nil, -- see :h diagnostic-structure
201-
display_opts = {}, -- see opts in vim.diagnostic.set
177+
virtual_text = false,
178+
icons = {
179+
comment = "→|",
180+
range = " |",
181+
},
182+
skip_old_revision_discussion = false,
202183
},
203184
pipeline = {
204185
created = "",
@@ -231,7 +212,7 @@ require("gitlab").setup({
231212
directory = "Directory",
232213
directory_icon = "DiffviewFolderSign",
233214
file_name = "Normal",
234-
}
215+
}
235216
}
236217
})
237218
```

doc/gitlab.nvim.txt

Lines changed: 17 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -204,35 +204,16 @@ you call this function with no values the defaults will be used:
204204
"labels",
205205
},
206206
},
207-
discussion_sign_and_diagnostic = {
208-
skip_resolved_discussion = false,
209-
skip_old_revision_discussion = true,
210-
},
211-
discussion_sign = {
212-
-- See :h sign_define for details about sign configuration.
213-
enabled = true,
214-
text = "💬",
215-
linehl = nil,
216-
texthl = nil,
217-
culhl = nil,
218-
numhl = nil,
219-
priority = 20, -- Priority of sign, the lower the number the higher the priority
220-
helper_signs = {
221-
-- For multiline comments the helper signs are used to indicate the whole context
222-
-- Priority of helper signs is lower than the main sign (-1).
223-
enabled = true,
224-
start = "↑",
225-
mid = "|",
226-
["end"] = "↓",
227-
},
228-
},
229-
discussion_diagnostic = {
230-
-- If you want to customize diagnostics for discussions you can make special config
231-
-- for namespace `gitlab_discussion`. See :h vim.diagnostic.config
232-
enabled = true,
233-
severity = vim.diagnostic.severity.INFO,
234-
code = nil, -- see :h diagnostic-structure
235-
display_opts = {}, -- see opts in vim.diagnostic.set
207+
discussion_signs = {
208+
enabled = true,
209+
skip_resolved_discussion = false,
210+
skip_old_revision_discussion = false,
211+
severity = vim.diagnostic.severity.INFO,
212+
virtual_text = false,
213+
icons = {
214+
comment = "→|",
215+
range = " |",
216+
},
236217
},
237218
pipeline = {
238219
created = "",
@@ -386,46 +367,17 @@ These labels will be visible in the summary panel, as long as you provide the
386367

387368
SIGNS AND DIAGNOSTICS *gitlab.nvim.signs-and-diagnostics*
388369

389-
By default when reviewing files you will see signs and diagnostics (if enabled
390-
in configuration). When cursor is on diagnostic line you can view discussion
391-
thread by using `vim.diagnostic.show`. You can also jump to discussion tree
392-
where you can reply, edit or delete discussion.
370+
By default when reviewing files you will see diagnostics in the reviewer
371+
for comments that have been added to a review. When the cursor is on
372+
diagnostic line you can view discussion thread by using `vim.diagnostic.show`.
393373

374+
You can also jump to discussion tree for the given comment:
394375
>lua
395376
require("gitlab").move_to_discussion_tree_from_diagnostic()
396-
<
397377

398-
The `discussion_sign` configuration controls the display of signs for
399-
discussions in the reviewer pane. This allows users to jump to comments in the
400-
current buffer in the reviewer pane directly. Keep in mind that the highlights
401-
provided here can be overridden by other highlights (for example from
402-
`diffview.nvim`).
403-
404-
These diagnostics are configurable in the same way that diagnostics are
405-
typically configurable in Neovim. For instance, the `severity` key sets the
406-
diagnostic severity level and should be set to one of
407-
`vim.diagnostic.severity.ERROR`, `vim.diagnostic.severity.WARN`,
408-
`vim.diagnostic.severity.INFO`, or `vim.diagnostic.severity.HINT`. The
409-
`display_opts` option configures the diagnostic display options (this is
410-
directly used as opts in vim.diagnostic.set). Here you can configure values
411-
like:
412-
413-
- `virtual_text` - Show virtual text for diagnostics.
414-
- `underline` - Underline text for diagnostics.
415-
416-
Diagnostics for discussions use the `gitlab_discussion` namespace. See
417-
|vim.diagnostic.config| and |diagnostic-structure| for more details. Signs and
418-
diagnostics have common settings in `discussion_sign_and_diagnostic`. This
419-
allows customizing if discussions that are resolved or no longer relevant
420-
should still display visual indicators in the editor. The
421-
`skip_resolved_discussion` Boolean will control visibility of resolved
422-
discussions, and `skip_old_revision_discussion` whether to show signs and
423-
diagnostics for discussions on outdated diff revisions.
424-
425-
When interacting with multiline comments, the cursor must be on the "main" line
426-
of diagnostic, where the `discussion_sign.text` is shown, otherwise
427-
`vim.diagnostic.show` and `move_to_discussion_tree_from_diagnostic` will not
428-
work.
378+
You may skip resolved discussions by toggling `discussion_signs.skip_resolved_discussion`
379+
in your setup function to true. By default, discussions from this plugin
380+
are shown at the INFO severity level (see :h vim.diagnostic.severity).
429381

430382
EMOJIS *gitlab.nvim.emojis*
431383

lua/gitlab/actions/discussions/init.lua

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ local List = require("gitlab.utils.list")
1313
local miscellaneous = require("gitlab.actions.miscellaneous")
1414
local discussions_tree = require("gitlab.actions.discussions.tree")
1515
local diffview_lib = require("diffview.lib")
16-
local signs = require("gitlab.actions.discussions.signs")
16+
local signs = require("gitlab.indicators.signs")
17+
local diagnostics = require("gitlab.indicators.diagnostics")
1718
local winbar = require("gitlab.actions.discussions.winbar")
1819
local help = require("gitlab.actions.help")
1920
local emoji = require("gitlab.emoji")
@@ -63,7 +64,8 @@ M.initialize_discussions = function()
6364
M.modifiable(false)
6465
end)
6566
reviewer.set_callback_for_reviewer_leave(function()
66-
signs.clear_signs_and_diagnostics()
67+
signs.clear_signs()
68+
diagnostics.clear_diagnostics()
6769
M.modifiable(true)
6870
end)
6971
end
@@ -92,11 +94,8 @@ end
9294

9395
--- Take existing data and refresh the diagnostics, the winbar, and the signs
9496
M.refresh_view = function()
95-
if state.settings.discussion_sign.enabled then
96-
signs.refresh_signs(M.discussions)
97-
end
98-
if state.settings.discussion_diagnostic.enabled then
99-
signs.refresh_diagnostics(M.discussions)
97+
if state.settings.discussion_signs.enabled then
98+
diagnostics.refresh_diagnostics(M.discussions)
10099
end
101100
if M.split_visible then
102101
local linked_is_focused = M.linked_bufnr == M.focused_bufnr
@@ -168,7 +167,7 @@ M.toggle = function(callback)
168167
M.focused_bufnr = default_buffer
169168

170169
M.switch_can_edit_bufs(false)
171-
winbar.update_winbar(M.discussions, M.unlinked_discussions, default_discussions and "Discussions" or "Notes")
170+
M.refresh_view()
172171

173172
vim.api.nvim_set_current_win(current_window)
174173
if type(callback) == "function" then
@@ -198,7 +197,7 @@ end
198197
---Move to the discussion tree at the discussion from diagnostic on current line.
199198
M.move_to_discussion_tree = function()
200199
local current_line = vim.api.nvim_win_get_cursor(0)[1]
201-
local diagnostics = vim.diagnostic.get(0, { namespace = signs.diagnostics_namespace, lnum = current_line - 1 })
200+
local d = vim.diagnostic.get(0, { namespace = diagnostics.diagnostics_namespace, lnum = current_line - 1 })
202201

203202
---Function used to jump to the discussion tree after the menu selection.
204203
local jump_after_menu_selection = function(diagnostic)
@@ -229,11 +228,11 @@ M.move_to_discussion_tree = function()
229228
end
230229
end
231230

232-
if #diagnostics == 0 then
231+
if #d == 0 then
233232
u.notify("No diagnostics for this line", vim.log.levels.WARN)
234233
return
235-
elseif #diagnostics > 1 then
236-
vim.ui.select(diagnostics, {
234+
elseif #d > 1 then
235+
vim.ui.select(d, {
237236
prompt = "Choose discussion to jump to",
238237
format_item = function(diagnostic)
239238
return diagnostic.message
@@ -245,7 +244,7 @@ M.move_to_discussion_tree = function()
245244
jump_after_menu_selection(diagnostic)
246245
end)
247246
else
248-
jump_after_menu_selection(diagnostics[1])
247+
jump_after_menu_selection(d[1])
249248
end
250249
end
251250

@@ -389,7 +388,7 @@ end
389388

390389
-- This function (settings.discussion_tree.jump_to_reviewer) will jump the cursor to the reviewer's location associated with the note. The implementation depends on the reviewer
391390
M.jump_to_reviewer = function(tree)
392-
local file_name, new_line, old_line, is_undefined_type, error = M.get_note_location(tree)
391+
local file_name, new_line, old_line, error = M.get_note_location(tree)
393392
if error ~= nil then
394393
u.notify(error, vim.log.levels.ERROR)
395394
return
@@ -403,13 +402,13 @@ M.jump_to_reviewer = function(tree)
403402
return
404403
end
405404

406-
reviewer.jump(file_name, new_line_int, old_line_int, { is_undefined_type = is_undefined_type })
405+
reviewer.jump(file_name, new_line_int, old_line_int)
407406
M.refresh_view()
408407
end
409408

410409
-- This function (settings.discussion_tree.jump_to_file) will jump to the file changed in a new tab
411410
M.jump_to_file = function(tree)
412-
local file_name, new_line, old_line, _, error = M.get_note_location(tree)
411+
local file_name, new_line, old_line, error = M.get_note_location(tree)
413412
if error ~= nil then
414413
u.notify(error, vim.log.levels.ERROR)
415414
return
@@ -911,21 +910,17 @@ end
911910

912911
---Get note location
913912
---@param tree NuiTree
914-
---@return string, string, string, boolean, string?
913+
---@return string, string, string, string?
915914
M.get_note_location = function(tree)
916915
local node = tree:get_node()
917916
if node == nil then
918-
return "", "", "", false, "Could not get node"
917+
return "", "", "", "Could not get node"
919918
end
920919
local discussion_node = M.get_root_node(tree, node)
921920
if discussion_node == nil then
922-
return "", "", "", false, "Could not get discussion node"
921+
return "", "", "", "Could not get discussion node"
923922
end
924-
return discussion_node.file_name,
925-
discussion_node.new_line,
926-
discussion_node.old_line,
927-
discussion_node.undefined_type or false,
928-
nil
923+
return discussion_node.file_name, discussion_node.new_line, discussion_node.old_line, nil
929924
end
930925

931926
---@param tree NuiTree

0 commit comments

Comments
 (0)