Skip to content

Commit

Permalink
Release (#330)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
harrisoncramer authored Jul 6, 2024
1 parent dc70c97 commit 95dcc41
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 44 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ For more settings, please see `:h gitlab.nvim.connecting-to-gitlab`

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.

For a list of all these settings please run `:h gitlab.nvim` which is stored in `doc/gitlab.nvim.txt`
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).

## Keybindings

Expand Down Expand Up @@ -155,3 +155,7 @@ vim.keymap.set("n", "glD", gitlab.toggle_draft_mode)
```

For more information about each of these commands, and about the APIs in general, run `:h gitlab.nvim.api`

## Contributing

Contributions to the plugin are welcome. Please read [.github/CONTRIBUTING.md](.github/CONTRIBUTING.md) before you start working on a pull request.
57 changes: 44 additions & 13 deletions lua/gitlab/actions/common.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ local List = require("gitlab.utils.list")
local u = require("gitlab.utils")
local reviewer = require("gitlab.reviewer")
local indicators_common = require("gitlab.indicators.common")
local common_indicators = require("gitlab.indicators.common")
local state = require("gitlab.state")
local M = {}

Expand Down Expand Up @@ -183,8 +182,8 @@ local function get_new_line(node)
return node.new_line
end

local _, start_new_line = common_indicators.parse_line_code(range.start.line_code)
return start_new_line
local _, new_start_line = indicators_common.parse_line_code(range.start.line_code)
return new_start_line
end

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

local start_old_line, _ = common_indicators.parse_line_code(range.start.line_code)
return start_old_line
local old_start_line, _ = indicators_common.parse_line_code(range.start.line_code)
return old_start_line
end

---@param id string|integer
---@return integer|nil
---@return integer|nil line_number
---@return boolean is_new_sha True if line number refers to NEW SHA
M.get_line_number = function(id)
---@type Discussion|DraftNote|nil
local d_or_n
Expand All @@ -214,19 +214,50 @@ M.get_line_number = function(id)
end)

if d_or_n == nil then
return
return nil, true
end

local first_note = indicators_common.get_first_note(d_or_n)
return (indicators_common.is_new_sha(d_or_n) and first_note.position.new_line or first_note.position.old_line) or 1
local is_new_sha = indicators_common.is_new_sha(d_or_n)
return ((is_new_sha and first_note.position.new_line or first_note.position.old_line) or 1), is_new_sha
end

---Return the start and end line numbers for the note range. The range is calculated from the line
---codes but the position itself is based on either the `new_line` or `old_line`.
---@param old_line integer|nil The line number in the OLD version
---@param new_line integer|nil The line number in the NEW version
---@param start_line_code string The line code for the start of the range
---@param end_line_code string The line code for the end of the range
---@return integer start_line
---@return integer end_line
---@return boolean is_new_sha True if line range refers to NEW SHA
M.get_line_numbers_for_range = function(old_line, new_line, start_line_code, end_line_code)
local old_start_line, new_start_line = indicators_common.parse_line_code(start_line_code)
local old_end_line, new_end_line = indicators_common.parse_line_code(end_line_code)
if old_line ~= nil and old_start_line ~= 0 then
local range = old_end_line - old_start_line
return (old_line - range), old_line, false
elseif new_line ~= nil then
local range = new_end_line - new_start_line
return (new_line - range), new_line, true
else
u.notify("Error getting new or old line for range", vim.log.levels.ERROR)
return 1, 1, false
end
end

---@param root_node NuiTree.Node
---@return integer|nil
---@return integer|nil line_number
---@return boolean is_new_sha True if line number refers to NEW SHA
M.get_line_number_from_node = function(root_node)
if root_node.range then
local start_old_line, start_new_line = common_indicators.parse_line_code(root_node.range.start.line_code)
return root_node.old_line and start_old_line or start_new_line
local line_number, _, is_new_sha = M.get_line_numbers_for_range(
root_node.old_line,
root_node.new_line,
root_node.range.start.line_code,
root_node.range["end"].line_code
)
return line_number, is_new_sha
else
return M.get_line_number(root_node.id)
end
Expand All @@ -240,12 +271,12 @@ M.jump_to_reviewer = function(tree, callback)
u.notify("Could not get discussion node", vim.log.levels.ERROR)
return
end
local line_number = M.get_line_number_from_node(root_node)
local line_number, is_new_sha = M.get_line_number_from_node(root_node)
if line_number == nil then
u.notify("Could not get line number", vim.log.levels.ERROR)
return
end
reviewer.jump(root_node.file_name, line_number, root_node.old_line == nil)
reviewer.jump(root_node.file_name, line_number, is_new_sha)
callback()
end

Expand Down
7 changes: 1 addition & 6 deletions lua/gitlab/actions/discussions/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,7 @@ end
---Opens the discussion tree, sets the keybindings. It also
---creates the tree for notes (which are not linked to specific lines of code)
---@param callback function?
M.toggle = function(callback)
if M.split_visible then
M.close()
return
end

M.open = function(callback)
state.DISCUSSION_DATA.discussions = u.ensure_table(state.DISCUSSION_DATA.discussions)
state.DISCUSSION_DATA.unlinked_discussions = u.ensure_table(state.DISCUSSION_DATA.unlinked_discussions)
state.DRAFT_NOTES = u.ensure_table(state.DRAFT_NOTES)
Expand Down
8 changes: 4 additions & 4 deletions lua/gitlab/hunks.lua
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ local function get_modification_type_from_new_sha(new_line, hunks, all_diff_outp
return nil
end
return List.new(hunks):find(function(hunk)
local new_line_end = hunk.new_line + hunk.new_range
local new_line_end = hunk.new_line + hunk.new_range - (hunk.new_range > 0 and 1 or 0)
local in_new_range = new_line >= hunk.new_line and new_line <= new_line_end
local is_range_zero = hunk.new_range == 0 and hunk.old_range == 0
return in_new_range and (is_range_zero or line_was_added(new_line, hunk, all_diff_output))
Expand All @@ -209,10 +209,10 @@ local function get_modification_type_from_old_sha(old_line, new_line, hunks, all
end

return List.new(hunks):find(function(hunk)
local old_line_end = hunk.old_line + hunk.old_range
local new_line_end = hunk.new_line + hunk.new_range
local old_line_end = hunk.old_line + hunk.old_range - (hunk.old_range > 0 and 1 or 0)
local new_line_end = hunk.new_line + hunk.new_range - (hunk.new_range > 0 and 1 or 0)
local in_old_range = old_line >= hunk.old_line and old_line <= old_line_end
local in_new_range = old_line >= hunk.new_line and new_line <= new_line_end
local in_new_range = new_line >= hunk.new_line and new_line <= new_line_end
return (in_old_range or in_new_range) and line_was_removed(old_line, hunk, all_diff_output)
end) and "deleted" or "unmodified"
end
Expand Down
5 changes: 3 additions & 2 deletions lua/gitlab/indicators/common.lua
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,9 @@ end
---@param d_or_n Discussion|DraftNote
---@return boolean
M.is_old_sha = function(d_or_n)
local first_note = M.get_first_note(d_or_n)
return first_note.position.old_line ~= nil
local position = M.get_first_note(d_or_n).position
local old_start_line = position.line_range ~= nil and M.parse_line_code(position.line_range.start.line_code) or nil
return position.old_line ~= nil and old_start_line ~= 0
end

---@param discussion Discussion|DraftNote
Expand Down
22 changes: 10 additions & 12 deletions lua/gitlab/indicators/diagnostics.lua
Original file line number Diff line number Diff line change
Expand Up @@ -72,19 +72,17 @@ local create_multiline_diagnostic = function(d_or_n)
error("Parsing multi-line comment but note does not contain line range")
end

local start_old_line, start_new_line = indicators_common.parse_line_code(line_range.start.line_code)
local start_line, end_line, _ = actions_common.get_line_numbers_for_range(
first_note.position.old_line,
first_note.position.new_line,
line_range.start.line_code,
line_range["end"].line_code
)

if indicators_common.is_new_sha(d_or_n) then
return create_diagnostic({
lnum = start_new_line - 1,
end_lnum = first_note.position.new_line - 1,
}, d_or_n)
else
return create_diagnostic({
lnum = start_old_line - 1,
end_lnum = first_note.position.old_line - 1,
}, d_or_n)
end
return create_diagnostic({
lnum = start_line - 1,
end_lnum = end_line - 1,
}, d_or_n)
end

---Set diagnostics in currently new SHA.
Expand Down
18 changes: 12 additions & 6 deletions lua/gitlab/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,18 @@ return {
pipeline = async.sequence({ latest_pipeline }, pipeline.open),
merge = async.sequence({ u.merge(info, { refresh = true }) }, merge.merge),
-- Discussion Tree Actions 🌴
toggle_discussions = async.sequence({
info,
user,
u.merge(draft_notes_dep, { refresh = true }),
u.merge(discussion_data, { refresh = true }),
}, discussions.toggle),
toggle_discussions = function()
if discussions.split_visible then
discussions.close()
else
async.sequence({
info,
user,
u.merge(draft_notes_dep, { refresh = true }),
u.merge(discussion_data, { refresh = true }),
}, discussions.open)()
end
end,
toggle_draft_mode = discussions.toggle_draft_mode,
publish_all_drafts = draft_notes.publish_all_drafts,
refresh_data = function()
Expand Down
1 change: 1 addition & 0 deletions lua/gitlab/utils/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,7 @@ M.create_box_popup_state = function(title, enter)
top = title,
},
},
opacity = settings.opacity,
}
end

Expand Down

0 comments on commit 95dcc41

Please sign in to comment.