Skip to content

Commit 95dcc41

Browse files
Release (#330)
Fix diagnostic position when sha changes (#299) Fix: Remove API calls on Discussion Close (#328) Chore: Remove root node type (#329) This is a PATCH release.
1 parent dc70c97 commit 95dcc41

File tree

8 files changed

+80
-44
lines changed

8 files changed

+80
-44
lines changed

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ For more settings, please see `:h gitlab.nvim.connecting-to-gitlab`
118118

119119
The plugin expects you to call `setup()` and pass in a table of options. All of these values are optional, and if you call this function with no values the defaults will be used.
120120

121-
For a list of all these settings please run `:h gitlab.nvim` which is stored in `doc/gitlab.nvim.txt`
121+
For a list of all these settings please run `:h gitlab.nvim.configuring-the-plugin` which will show you the help stored in [doc/gitlab.nvim.txt](doc/gitlab.nvim.txt).
122122

123123
## Keybindings
124124

@@ -155,3 +155,7 @@ vim.keymap.set("n", "glD", gitlab.toggle_draft_mode)
155155
```
156156

157157
For more information about each of these commands, and about the APIs in general, run `:h gitlab.nvim.api`
158+
159+
## Contributing
160+
161+
Contributions to the plugin are welcome. Please read [.github/CONTRIBUTING.md](.github/CONTRIBUTING.md) before you start working on a pull request.

lua/gitlab/actions/common.lua

Lines changed: 44 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ local List = require("gitlab.utils.list")
55
local u = require("gitlab.utils")
66
local reviewer = require("gitlab.reviewer")
77
local indicators_common = require("gitlab.indicators.common")
8-
local common_indicators = require("gitlab.indicators.common")
98
local state = require("gitlab.state")
109
local M = {}
1110

@@ -183,8 +182,8 @@ local function get_new_line(node)
183182
return node.new_line
184183
end
185184

186-
local _, start_new_line = common_indicators.parse_line_code(range.start.line_code)
187-
return start_new_line
185+
local _, new_start_line = indicators_common.parse_line_code(range.start.line_code)
186+
return new_start_line
188187
end
189188

190189
---Takes a node and returns the line where the note is positioned in the old SHA. If
@@ -198,12 +197,13 @@ local function get_old_line(node)
198197
return node.old_line
199198
end
200199

201-
local start_old_line, _ = common_indicators.parse_line_code(range.start.line_code)
202-
return start_old_line
200+
local old_start_line, _ = indicators_common.parse_line_code(range.start.line_code)
201+
return old_start_line
203202
end
204203

205204
---@param id string|integer
206-
---@return integer|nil
205+
---@return integer|nil line_number
206+
---@return boolean is_new_sha True if line number refers to NEW SHA
207207
M.get_line_number = function(id)
208208
---@type Discussion|DraftNote|nil
209209
local d_or_n
@@ -214,19 +214,50 @@ M.get_line_number = function(id)
214214
end)
215215

216216
if d_or_n == nil then
217-
return
217+
return nil, true
218218
end
219219

220220
local first_note = indicators_common.get_first_note(d_or_n)
221-
return (indicators_common.is_new_sha(d_or_n) and first_note.position.new_line or first_note.position.old_line) or 1
221+
local is_new_sha = indicators_common.is_new_sha(d_or_n)
222+
return ((is_new_sha and first_note.position.new_line or first_note.position.old_line) or 1), is_new_sha
223+
end
224+
225+
---Return the start and end line numbers for the note range. The range is calculated from the line
226+
---codes but the position itself is based on either the `new_line` or `old_line`.
227+
---@param old_line integer|nil The line number in the OLD version
228+
---@param new_line integer|nil The line number in the NEW version
229+
---@param start_line_code string The line code for the start of the range
230+
---@param end_line_code string The line code for the end of the range
231+
---@return integer start_line
232+
---@return integer end_line
233+
---@return boolean is_new_sha True if line range refers to NEW SHA
234+
M.get_line_numbers_for_range = function(old_line, new_line, start_line_code, end_line_code)
235+
local old_start_line, new_start_line = indicators_common.parse_line_code(start_line_code)
236+
local old_end_line, new_end_line = indicators_common.parse_line_code(end_line_code)
237+
if old_line ~= nil and old_start_line ~= 0 then
238+
local range = old_end_line - old_start_line
239+
return (old_line - range), old_line, false
240+
elseif new_line ~= nil then
241+
local range = new_end_line - new_start_line
242+
return (new_line - range), new_line, true
243+
else
244+
u.notify("Error getting new or old line for range", vim.log.levels.ERROR)
245+
return 1, 1, false
246+
end
222247
end
223248

224249
---@param root_node NuiTree.Node
225-
---@return integer|nil
250+
---@return integer|nil line_number
251+
---@return boolean is_new_sha True if line number refers to NEW SHA
226252
M.get_line_number_from_node = function(root_node)
227253
if root_node.range then
228-
local start_old_line, start_new_line = common_indicators.parse_line_code(root_node.range.start.line_code)
229-
return root_node.old_line and start_old_line or start_new_line
254+
local line_number, _, is_new_sha = M.get_line_numbers_for_range(
255+
root_node.old_line,
256+
root_node.new_line,
257+
root_node.range.start.line_code,
258+
root_node.range["end"].line_code
259+
)
260+
return line_number, is_new_sha
230261
else
231262
return M.get_line_number(root_node.id)
232263
end
@@ -240,12 +271,12 @@ M.jump_to_reviewer = function(tree, callback)
240271
u.notify("Could not get discussion node", vim.log.levels.ERROR)
241272
return
242273
end
243-
local line_number = M.get_line_number_from_node(root_node)
274+
local line_number, is_new_sha = M.get_line_number_from_node(root_node)
244275
if line_number == nil then
245276
u.notify("Could not get line number", vim.log.levels.ERROR)
246277
return
247278
end
248-
reviewer.jump(root_node.file_name, line_number, root_node.old_line == nil)
279+
reviewer.jump(root_node.file_name, line_number, is_new_sha)
249280
callback()
250281
end
251282

lua/gitlab/actions/discussions/init.lua

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -111,12 +111,7 @@ end
111111
---Opens the discussion tree, sets the keybindings. It also
112112
---creates the tree for notes (which are not linked to specific lines of code)
113113
---@param callback function?
114-
M.toggle = function(callback)
115-
if M.split_visible then
116-
M.close()
117-
return
118-
end
119-
114+
M.open = function(callback)
120115
state.DISCUSSION_DATA.discussions = u.ensure_table(state.DISCUSSION_DATA.discussions)
121116
state.DISCUSSION_DATA.unlinked_discussions = u.ensure_table(state.DISCUSSION_DATA.unlinked_discussions)
122117
state.DRAFT_NOTES = u.ensure_table(state.DRAFT_NOTES)

lua/gitlab/hunks.lua

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ local function get_modification_type_from_new_sha(new_line, hunks, all_diff_outp
191191
return nil
192192
end
193193
return List.new(hunks):find(function(hunk)
194-
local new_line_end = hunk.new_line + hunk.new_range
194+
local new_line_end = hunk.new_line + hunk.new_range - (hunk.new_range > 0 and 1 or 0)
195195
local in_new_range = new_line >= hunk.new_line and new_line <= new_line_end
196196
local is_range_zero = hunk.new_range == 0 and hunk.old_range == 0
197197
return in_new_range and (is_range_zero or line_was_added(new_line, hunk, all_diff_output))
@@ -209,10 +209,10 @@ local function get_modification_type_from_old_sha(old_line, new_line, hunks, all
209209
end
210210

211211
return List.new(hunks):find(function(hunk)
212-
local old_line_end = hunk.old_line + hunk.old_range
213-
local new_line_end = hunk.new_line + hunk.new_range
212+
local old_line_end = hunk.old_line + hunk.old_range - (hunk.old_range > 0 and 1 or 0)
213+
local new_line_end = hunk.new_line + hunk.new_range - (hunk.new_range > 0 and 1 or 0)
214214
local in_old_range = old_line >= hunk.old_line and old_line <= old_line_end
215-
local in_new_range = old_line >= hunk.new_line and new_line <= new_line_end
215+
local in_new_range = new_line >= hunk.new_line and new_line <= new_line_end
216216
return (in_old_range or in_new_range) and line_was_removed(old_line, hunk, all_diff_output)
217217
end) and "deleted" or "unmodified"
218218
end

lua/gitlab/indicators/common.lua

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,9 @@ end
6767
---@param d_or_n Discussion|DraftNote
6868
---@return boolean
6969
M.is_old_sha = function(d_or_n)
70-
local first_note = M.get_first_note(d_or_n)
71-
return first_note.position.old_line ~= nil
70+
local position = M.get_first_note(d_or_n).position
71+
local old_start_line = position.line_range ~= nil and M.parse_line_code(position.line_range.start.line_code) or nil
72+
return position.old_line ~= nil and old_start_line ~= 0
7273
end
7374

7475
---@param discussion Discussion|DraftNote

lua/gitlab/indicators/diagnostics.lua

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -72,19 +72,17 @@ local create_multiline_diagnostic = function(d_or_n)
7272
error("Parsing multi-line comment but note does not contain line range")
7373
end
7474

75-
local start_old_line, start_new_line = indicators_common.parse_line_code(line_range.start.line_code)
75+
local start_line, end_line, _ = actions_common.get_line_numbers_for_range(
76+
first_note.position.old_line,
77+
first_note.position.new_line,
78+
line_range.start.line_code,
79+
line_range["end"].line_code
80+
)
7681

77-
if indicators_common.is_new_sha(d_or_n) then
78-
return create_diagnostic({
79-
lnum = start_new_line - 1,
80-
end_lnum = first_note.position.new_line - 1,
81-
}, d_or_n)
82-
else
83-
return create_diagnostic({
84-
lnum = start_old_line - 1,
85-
end_lnum = first_note.position.old_line - 1,
86-
}, d_or_n)
87-
end
82+
return create_diagnostic({
83+
lnum = start_line - 1,
84+
end_lnum = end_line - 1,
85+
}, d_or_n)
8886
end
8987

9088
---Set diagnostics in currently new SHA.

lua/gitlab/init.lua

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,18 @@ return {
6868
pipeline = async.sequence({ latest_pipeline }, pipeline.open),
6969
merge = async.sequence({ u.merge(info, { refresh = true }) }, merge.merge),
7070
-- Discussion Tree Actions 🌴
71-
toggle_discussions = async.sequence({
72-
info,
73-
user,
74-
u.merge(draft_notes_dep, { refresh = true }),
75-
u.merge(discussion_data, { refresh = true }),
76-
}, discussions.toggle),
71+
toggle_discussions = function()
72+
if discussions.split_visible then
73+
discussions.close()
74+
else
75+
async.sequence({
76+
info,
77+
user,
78+
u.merge(draft_notes_dep, { refresh = true }),
79+
u.merge(discussion_data, { refresh = true }),
80+
}, discussions.open)()
81+
end
82+
end,
7783
toggle_draft_mode = discussions.toggle_draft_mode,
7884
publish_all_drafts = draft_notes.publish_all_drafts,
7985
refresh_data = function()

lua/gitlab/utils/init.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,7 @@ M.create_box_popup_state = function(title, enter)
524524
top = title,
525525
},
526526
},
527+
opacity = settings.opacity,
527528
}
528529
end
529530

0 commit comments

Comments
 (0)