This MR is a #MAJOR breaking change to the plugin. While the plugin will continue to work for users with their existing settings, they will be informed of outdated configuration (diagnostics and signs have been simplified) the next time they open the reviewer.

Fix: Trim trailing slash from custom URLs
Update: .github/CONTRIBUTING.md, .github/ISSUE_TEMPLATE/bug_report.md
Feat: Improve discussion tree toggling (#192)
Fix: Toggle modified notes (#188)
Fix: Toggle discussion nodes correctly
Feat: Show Help keymap in discussion tree winbar
Fix: Enable toggling nodes from the note body
Fix: Enable toggling resolved status from child nodes
Fix: Only try to show emoji popup on note nodes
Feat: Add keymap for toggling tree type
Fix: Disable tree type toggling in Notes
Fix Multi Line Issues (Large Refactor) (#197)
Fix: Multi-line discussions. The calculation of a range for a multiline comment has been consolidated and moved into the location.lua file. This does not attempt to fix diagnostics.
Refactor: It refactors the discussions code to split hunk parsing and management into a separate module
Fix: Don't allow comments on modified buffers #194 by preventing comments on the reviewer when using --imply-local and when the working tree is dirty entirely.
Refactor: It introduces a new List class for data aggregation, filtering, etc.
Fix: It removes redundant API calls and refreshes from the discussion pane
Fix: Location provider (#198)
Fix: add nil check for Diffview performance issue (#199)
Fix: Switch Tabs During Comment Creation (#200)
Fix: Check if file is modified (#201)
Fix: Off-By-One Issue in Old SHA (#202)
Fix: Rebuild Diagnostics + Signs (#203)
Fix: Off-By-One Issue in New SHA (#205)
Fix: Reviewer Jumps to wrong location (#206)

BREAKING CHANGE: Changes configuration of diagnostics and signs in the setup call.
This commit is contained in:
Harrison (Harry) Cramer
2024-03-03 11:52:37 -05:00
committed by GitHub
parent f6a5238d4b
commit b5b475ce8b
31 changed files with 1529 additions and 1298 deletions

View File

@@ -0,0 +1,152 @@
local u = require("gitlab.utils")
local diffview_lib = require("diffview.lib")
local discussion_tree = require("gitlab.actions.discussions.tree")
local common = require("gitlab.indicators.common")
local List = require("gitlab.utils.list")
local state = require("gitlab.state")
local discussion_sign_name = "gitlab_discussion"
local M = {}
local diagnostics_namespace = vim.api.nvim_create_namespace(discussion_sign_name)
M.diagnostics_namespace = diagnostics_namespace
M.discussion_sign_name = discussion_sign_name
M.clear_diagnostics = function()
vim.diagnostic.reset(diagnostics_namespace)
end
-- Display options for the diagnostic
local display_opts = {
virtual_text = state.settings.discussion_signs.virtual_text,
severity_sort = true,
underline = false,
}
---Takes some range information and data about a discussion
---and creates a diagnostic to be placed in the reviewer
---@param range_info table
---@param discussion Discussion
---@return Diagnostic
local function create_diagnostic(range_info, discussion)
local message = ""
for _, note in ipairs(discussion.notes) do
message = message .. discussion_tree.build_note_header(note) .. "\n" .. note.body .. "\n"
end
local diagnostic = {
message = message,
col = 0,
severity = state.settings.discussion_signs.severity,
user_data = { discussion_id = discussion.id, header = discussion_tree.build_note_header(discussion.notes[1]) },
source = "gitlab",
code = "gitlab.nvim",
}
return vim.tbl_deep_extend("force", diagnostic, range_info)
end
---Creates a single line diagnostic
---@param discussion Discussion
---@return Diagnostic
local create_single_line_diagnostic = function(discussion)
local first_note = discussion.notes[1]
return create_diagnostic({
lnum = first_note.position.new_line - 1,
}, discussion)
end
---Creates a mutli-line line diagnostic
---@param discussion Discussion
---@return Diagnostic
local create_multiline_diagnostic = function(discussion)
local first_note = discussion.notes[1]
local line_range = first_note.position.line_range
if line_range == nil then
error("Parsing multi-line comment but note does not contain line range")
end
local start_old_line, start_new_line = common.parse_line_code(line_range.start.line_code)
if common.is_new_sha(discussion) then
return create_diagnostic({
lnum = start_new_line - 1,
end_lnum = first_note.position.new_line - 1,
}, discussion)
else
return create_diagnostic({
lnum = start_old_line - 1,
end_lnum = first_note.position.old_line - 1,
}, discussion)
end
end
---Set diagnostics in currently new SHA.
---@param namespace number namespace for diagnostics
---@param diagnostics table see :h vim.diagnostic.set
---@param opts table? see :h vim.diagnostic.set
local set_diagnostics_in_new_sha = function(namespace, diagnostics, opts)
local view = diffview_lib.get_current_view()
if not view then
return
end
vim.diagnostic.set(namespace, view.cur_layout.b.file.bufnr, diagnostics, opts)
require("gitlab.indicators.signs").set_signs(diagnostics, view.cur_layout.b.file.bufnr)
end
---Set diagnostics in old SHA.
---@param namespace number namespace for diagnostics
---@param diagnostics table see :h vim.diagnostic.set
---@param opts table? see :h vim.diagnostic.set
local set_diagnostics_in_old_sha = function(namespace, diagnostics, opts)
local view = diffview_lib.get_current_view()
if not view then
return
end
vim.diagnostic.set(namespace, view.cur_layout.a.file.bufnr, diagnostics, opts)
require("gitlab.indicators.signs").set_signs(diagnostics, view.cur_layout.a.file.bufnr)
end
---Refresh the diagnostics for the currently reviewed file
---@param discussions Discussion[]
M.refresh_diagnostics = function(discussions)
local ok, err = pcall(function()
require("gitlab.indicators.signs").clear_signs()
M.clear_diagnostics()
local filtered_discussions = common.filter_placeable_discussions(discussions)
if filtered_discussions == nil then
return
end
local new_diagnostics = M.parse_new_diagnostics(filtered_discussions)
set_diagnostics_in_new_sha(diagnostics_namespace, new_diagnostics, display_opts)
local old_diagnostics = M.parse_old_diagnostics(filtered_discussions)
set_diagnostics_in_old_sha(diagnostics_namespace, old_diagnostics, display_opts)
end)
if not ok then
u.notify(string.format("Error setting diagnostics: %s", err), vim.log.levels.ERROR)
end
end
---Iterates over each discussion and returns a list of tables with sign
---data, for instance group, priority, line number etc for the new SHA
---@param discussions Discussion[]
---@return DiagnosticTable[]
M.parse_new_diagnostics = function(discussions)
local new_diagnostics = List.new(discussions):filter(common.is_new_sha)
local single_line = new_diagnostics:filter(common.is_single_line):map(create_single_line_diagnostic)
local multi_line = new_diagnostics:filter(common.is_multi_line):map(create_multiline_diagnostic)
return u.combine(single_line, multi_line)
end
---Iterates over each discussion and returns a list of tables with sign
---data, for instance group, priority, line number etc for the old SHA
---@param discussions Discussion[]
---@return DiagnosticTable[]
M.parse_old_diagnostics = function(discussions)
local old_diagnostics = List.new(discussions):filter(common.is_old_sha)
local single_line = old_diagnostics:filter(common.is_single_line):map(create_single_line_diagnostic)
local multi_line = old_diagnostics:filter(common.is_multi_line):map(create_multiline_diagnostic)
return u.combine(single_line, multi_line)
end
return M