Skip to content

Commit b5b475c

Browse files
2.0.0 (#196)
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.
1 parent f6a5238 commit b5b475c

31 files changed

+1538
-1307
lines changed

.github/CONTRIBUTING.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,10 @@ $ stylua .
4545
$ luacheck --globals vim busted --no-max-line-length -- .
4646
```
4747

48-
4. Make the merge request to the `main` branch of `.gitlab.nvim`
48+
4. Make the merge request to the `develop` branch of `.gitlab.nvim`
4949

5050
Please provide a description of the feature, and links to any relevant issues.
5151

52-
That's it! I'll try to respond to any incoming merge request in a few days. Once we've reviewed it and it's been merged into main, the pipeline will detect whether we're merging in a patch, minor, or major change, and create a new tag (e.g. 1.0.12) and release.
52+
That's it! I'll try to respond to any incoming merge request in a few days. Once we've reviewed it, it will be merged into the develop branch.
53+
54+
After some time, if the develop branch is found to be stable, that branch will be merged into `main` and released. When merged into `main` the pipeline will detect whether we're merging in a patch, minor, or major change, and create a new tag (e.g. 1.0.12) and release.

.github/ISSUE_TEMPLATE/bug_report.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,17 @@ name: Bug report
33
about: Create a report to help improve gitlab.nvim!
44
title: ''
55
labels: ''
6-
assignees: ''
7-
86
---
97

108
## Prerequsities
119

12-
- [ ] The "Troubleshooting" section of the README did not help
13-
- [ ] I've installed the required dependencies
1410
- [ ] I'm on the latest version of the plugin
11+
- [ ] I've installed the required dependencies
12+
- [ ] I've run `:h gitlab.nvim.troubleshooting` and followed the steps there
13+
14+
## Setup Configuration and Environment
15+
16+
Please post here the options you're passing to configure `gitlab.nvim` and specify any environment variables you're relying on.
1517

1618
## Bug Description
1719

@@ -26,5 +28,3 @@ A clear and concise description of what the bug is.
2628
## Screenshots
2729

2830
If applicable, add screenshots to help explain your problem.
29-
30-
## Other Details

.github/workflows/go.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ on:
33
pull_request:
44
branches:
55
- main
6+
- develop
67
jobs:
78
go_lint:
89
name: Lint Go 💅

.github/workflows/lua.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ on:
33
pull_request:
44
branches:
55
- main
6+
- develop
67
jobs:
78
lua_lint:
89
name: Lint Lua 💅

README.md

Lines changed: 11 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ require("gitlab").setup({
150150
resolved = '', -- Symbol to show next to resolved discussions
151151
unresolved = '-', -- Symbol to show next to unresolved discussions
152152
tree_type = "simple", -- Type of discussion tree - "simple" means just list of discussions, "by_file_name" means file tree with discussions under file
153+
toggle_tree_type = "i", -- Toggle type of discussion tree - "simple", or "by_file_name"
153154
winbar = nil -- Custom function to return winbar title, should return a string. Provided with WinbarTable (defined in annotations.lua)
154155
-- If using lualine, please add "gitlab" to disabled file types, otherwise you will not see the winbar.
155156
},
@@ -169,36 +170,17 @@ require("gitlab").setup({
169170
"pipeline",
170171
},
171172
},
172-
discussion_sign_and_diagnostic = {
173-
skip_resolved_discussion = false,
174-
skip_old_revision_discussion = true,
175-
},
176-
discussion_sign = {
177-
-- See :h sign_define for details about sign configuration.
178-
enabled = true,
179-
text = "💬",
180-
linehl = nil,
181-
texthl = nil,
182-
culhl = nil,
183-
numhl = nil,
184-
priority = 20, -- Priority of sign, the lower the number the higher the priority
185-
helper_signs = {
186-
-- For multiline comments the helper signs are used to indicate the whole context
187-
-- Priority of helper signs is lower than the main sign (-1).
188-
enabled = true,
189-
start = "",
190-
mid = "|",
191-
["end"] = "",
173+
discussion_signs = {
174+
enabled = true, -- Show diagnostics for gitlab comments in the reviewer
175+
skip_resolved_discussion = false, -- Show diagnostics for resolved discussions
176+
severity = vim.diagnostic.severity.INFO, -- ERROR, WARN, INFO, or HINT
177+
virtual_text = false, -- Whether to show the comment text inline as floating virtual text
178+
priority = 100, -- Higher will override LSP warnings, etc
179+
icons = {
180+
comment = "→|",
181+
range = " |",
192182
},
193183
},
194-
discussion_diagnostic = {
195-
-- If you want to customize diagnostics for discussions you can make special config
196-
-- for namespace `gitlab_discussion`. See :h vim.diagnostic.config
197-
enabled = true,
198-
severity = vim.diagnostic.severity.INFO,
199-
code = nil, -- see :h diagnostic-structure
200-
display_opts = {}, -- see opts in vim.diagnostic.set
201-
},
202184
pipeline = {
203185
created = "",
204186
pending = "",
@@ -230,7 +212,7 @@ require("gitlab").setup({
230212
directory = "Directory",
231213
directory_icon = "DiffviewFolderSign",
232214
file_name = "Normal",
233-
}
215+
}
234216
}
235217
})
236218
```

doc/gitlab.nvim.txt

Lines changed: 18 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ you call this function with no values the defaults will be used:
182182
resolved = '✓', -- Symbol to show next to resolved discussions
183183
unresolved = '-', -- Symbol to show next to unresolved discussions
184184
tree_type = "simple", -- Type of discussion tree - "simple" means just list of discussions, "by_file_name" means file tree with discussions under file
185+
toggle_tree_type = "i", -- Toggle type of discussion tree - "simple", or "by_file_name"
185186
winbar = nil -- Custom function to return winbar title, should return a string. Provided with WinbarTable (defined in annotations.lua)
186187
-- If using lualine, please add "gitlab" to disabled file types, otherwise you will not see the winbar.
187188
},
@@ -203,35 +204,16 @@ you call this function with no values the defaults will be used:
203204
"labels",
204205
},
205206
},
206-
discussion_sign_and_diagnostic = {
207-
skip_resolved_discussion = false,
208-
skip_old_revision_discussion = true,
209-
},
210-
discussion_sign = {
211-
-- See :h sign_define for details about sign configuration.
212-
enabled = true,
213-
text = "💬",
214-
linehl = nil,
215-
texthl = nil,
216-
culhl = nil,
217-
numhl = nil,
218-
priority = 20, -- Priority of sign, the lower the number the higher the priority
219-
helper_signs = {
220-
-- For multiline comments the helper signs are used to indicate the whole context
221-
-- Priority of helper signs is lower than the main sign (-1).
222-
enabled = true,
223-
start = "↑",
224-
mid = "|",
225-
["end"] = "↓",
226-
},
227-
},
228-
discussion_diagnostic = {
229-
-- If you want to customize diagnostics for discussions you can make special config
230-
-- for namespace `gitlab_discussion`. See :h vim.diagnostic.config
231-
enabled = true,
232-
severity = vim.diagnostic.severity.INFO,
233-
code = nil, -- see :h diagnostic-structure
234-
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+
},
235217
},
236218
pipeline = {
237219
created = "",
@@ -385,46 +367,17 @@ These labels will be visible in the summary panel, as long as you provide the
385367

386368
SIGNS AND DIAGNOSTICS *gitlab.nvim.signs-and-diagnostics*
387369

388-
By default when reviewing files you will see signs and diagnostics (if enabled
389-
in configuration). When cursor is on diagnostic line you can view discussion
390-
thread by using `vim.diagnostic.show`. You can also jump to discussion tree
391-
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`.
392373

374+
You can also jump to discussion tree for the given comment:
393375
>lua
394376
require("gitlab").move_to_discussion_tree_from_diagnostic()
395-
<
396377

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

429382
EMOJIS *gitlab.nvim.emojis*
430383

lua/gitlab/actions/assignees_and_reviewers.lua

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
-- and assignees in Gitlab, those who must review an MR.
33
local u = require("gitlab.utils")
44
local job = require("gitlab.job")
5+
local List = require("gitlab.utils.list")
56
local state = require("gitlab.state")
67
local M = {}
78

@@ -67,13 +68,11 @@ end
6768

6869
M.filter_eligible = function(current, to_remove)
6970
local ids = u.extract(to_remove, "id")
70-
local res = {}
71-
for _, member in ipairs(current) do
71+
return List.new(current):filter(function(member)
7272
if not u.contains(ids, member.id) then
73-
table.insert(res, member)
73+
return true
7474
end
75-
end
76-
return res
75+
end)
7776
end
7877

7978
return M

lua/gitlab/actions/comment.lua

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@ local Popup = require("nui.popup")
55
local state = require("gitlab.state")
66
local job = require("gitlab.job")
77
local u = require("gitlab.utils")
8+
local git = require("gitlab.git")
89
local discussions = require("gitlab.actions.discussions")
910
local miscellaneous = require("gitlab.actions.miscellaneous")
1011
local reviewer = require("gitlab.reviewer")
12+
local Location = require("gitlab.reviewer.location")
1113
local M = {}
1214

1315
-- Popup creation is wrapped in a function so that it is performed *after* user
@@ -20,6 +22,15 @@ end
2022
-- This function will open a comment popup in order to create a comment on the changed/updated
2123
-- line in the current MR
2224
M.create_comment = function()
25+
local has_clean_tree = git.has_clean_tree()
26+
local is_modified = vim.api.nvim_buf_get_option(0, "modified")
27+
if state.settings.reviewer_settings.diffview.imply_local and (is_modified or not has_clean_tree) then
28+
u.notify(
29+
"Cannot leave comments on changed files. \n Please stash all local changes or push them to the feature branch.",
30+
vim.log.levels.WARN
31+
)
32+
return
33+
end
2334
local comment_popup = create_comment_popup()
2435
comment_popup:mount()
2536
state.set_popup_keymaps(comment_popup, function(text)
@@ -95,30 +106,11 @@ M.create_note = function()
95106
end, miscellaneous.attach_file)
96107
end
97108

98-
---@class LineRange
99-
---@field start_line integer
100-
---@field end_line integer
101-
102-
---@class ReviewerLineInfo
103-
---@field old_line integer
104-
---@field new_line integer
105-
---@field type string either "new" or "old"
106-
107-
---@class ReviewerRangeInfo
108-
---@field start ReviewerLineInfo
109-
---@field end ReviewerLineInfo
110-
111-
---@class ReviewerInfo
112-
---@field file_name string
113-
---@field old_line integer | nil
114-
---@field new_line integer | nil
115-
---@field range_info ReviewerRangeInfo|nil
116-
117109
---This function (settings.popup.perform_action) will send the comment to the Go server
118110
---@param text string comment text
119-
---@param range LineRange | nil range of visuel selection or nil
111+
---@param visual_range LineRange | nil range of visual selection or nil
120112
---@param unlinked boolean | nil if true, the comment is not linked to a line
121-
M.confirm_create_comment = function(text, range, unlinked)
113+
M.confirm_create_comment = function(text, visual_range, unlinked)
122114
if text == nil then
123115
u.notify("Reviewer did not provide text of change", vim.log.levels.ERROR)
124116
return
@@ -129,33 +121,42 @@ M.confirm_create_comment = function(text, range, unlinked)
129121
job.run_job("/mr/comment", "POST", body, function(data)
130122
u.notify("Note created!", vim.log.levels.INFO)
131123
discussions.add_discussion({ data = data, unlinked = true })
132-
discussions.refresh_discussion_data()
124+
discussions.refresh()
133125
end)
134126
return
135127
end
136128

137-
local reviewer_info = reviewer.get_location(range)
138-
if not reviewer_info then
129+
local reviewer_data = reviewer.get_reviewer_data()
130+
if reviewer_data == nil then
131+
u.notify("Error getting reviewer data", vim.log.levels.ERROR)
132+
return
133+
end
134+
135+
local location = Location.new(reviewer_data, visual_range)
136+
location:build_location_data()
137+
local location_data = location.location_data
138+
if location_data == nil then
139+
u.notify("Error getting location information", vim.log.levels.ERROR)
139140
return
140141
end
141142

142143
local revision = state.MR_REVISIONS[1]
143144
local body = {
145+
type = "text",
144146
comment = text,
145-
file_name = reviewer_info.file_name,
146-
old_line = reviewer_info.old_line,
147-
new_line = reviewer_info.new_line,
147+
file_name = reviewer_data.file_name,
148148
base_commit_sha = revision.base_commit_sha,
149149
start_commit_sha = revision.start_commit_sha,
150150
head_commit_sha = revision.head_commit_sha,
151-
type = "text",
152-
line_range = reviewer_info.range_info,
151+
old_line = location_data.old_line,
152+
new_line = location_data.new_line,
153+
line_range = location_data.line_range,
153154
}
154155

155156
job.run_job("/mr/comment", "POST", body, function(data)
156157
u.notify("Comment created!", vim.log.levels.INFO)
157158
discussions.add_discussion({ data = data, unlinked = false })
158-
discussions.refresh_discussion_data()
159+
discussions.refresh()
159160
end)
160161
end
161162

lua/gitlab/actions/create_mr.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ local Input = require("nui.input")
55
local Popup = require("nui.popup")
66
local job = require("gitlab.job")
77
local u = require("gitlab.utils")
8+
local git = require("gitlab.git")
89
local state = require("gitlab.state")
910
local miscellaneous = require("gitlab.actions.miscellaneous")
1011

@@ -124,7 +125,7 @@ M.pick_target = function(args)
124125
end
125126

126127
local function make_template_path(t)
127-
local base_dir = vim.fn.trim(vim.fn.system({ "git", "rev-parse", "--show-toplevel" }))
128+
local base_dir = git.base_dir()
128129
return base_dir
129130
.. state.settings.file_separator
130131
.. ".gitlab"

0 commit comments

Comments
 (0)