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.
This commit is contained in:
committed by
GitHub
parent
dc70c97810
commit
95dcc41885
@@ -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.
|
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
|
## Keybindings
|
||||||
|
|
||||||
@@ -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`
|
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.
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ local List = require("gitlab.utils.list")
|
|||||||
local u = require("gitlab.utils")
|
local u = require("gitlab.utils")
|
||||||
local reviewer = require("gitlab.reviewer")
|
local reviewer = require("gitlab.reviewer")
|
||||||
local indicators_common = require("gitlab.indicators.common")
|
local indicators_common = require("gitlab.indicators.common")
|
||||||
local common_indicators = require("gitlab.indicators.common")
|
|
||||||
local state = require("gitlab.state")
|
local state = require("gitlab.state")
|
||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
@@ -183,8 +182,8 @@ local function get_new_line(node)
|
|||||||
return node.new_line
|
return node.new_line
|
||||||
end
|
end
|
||||||
|
|
||||||
local _, start_new_line = common_indicators.parse_line_code(range.start.line_code)
|
local _, new_start_line = indicators_common.parse_line_code(range.start.line_code)
|
||||||
return start_new_line
|
return new_start_line
|
||||||
end
|
end
|
||||||
|
|
||||||
---Takes a node and returns the line where the note is positioned in the old SHA. If
|
---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)
|
|||||||
return node.old_line
|
return node.old_line
|
||||||
end
|
end
|
||||||
|
|
||||||
local start_old_line, _ = common_indicators.parse_line_code(range.start.line_code)
|
local old_start_line, _ = indicators_common.parse_line_code(range.start.line_code)
|
||||||
return start_old_line
|
return old_start_line
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param id string|integer
|
---@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)
|
M.get_line_number = function(id)
|
||||||
---@type Discussion|DraftNote|nil
|
---@type Discussion|DraftNote|nil
|
||||||
local d_or_n
|
local d_or_n
|
||||||
@@ -214,19 +214,50 @@ M.get_line_number = function(id)
|
|||||||
end)
|
end)
|
||||||
|
|
||||||
if d_or_n == nil then
|
if d_or_n == nil then
|
||||||
return
|
return nil, true
|
||||||
end
|
end
|
||||||
|
|
||||||
local first_note = indicators_common.get_first_note(d_or_n)
|
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
|
end
|
||||||
|
|
||||||
---@param root_node NuiTree.Node
|
---@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)
|
M.get_line_number_from_node = function(root_node)
|
||||||
if root_node.range then
|
if root_node.range then
|
||||||
local start_old_line, start_new_line = common_indicators.parse_line_code(root_node.range.start.line_code)
|
local line_number, _, is_new_sha = M.get_line_numbers_for_range(
|
||||||
return root_node.old_line and start_old_line or start_new_line
|
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
|
else
|
||||||
return M.get_line_number(root_node.id)
|
return M.get_line_number(root_node.id)
|
||||||
end
|
end
|
||||||
@@ -240,12 +271,12 @@ M.jump_to_reviewer = function(tree, callback)
|
|||||||
u.notify("Could not get discussion node", vim.log.levels.ERROR)
|
u.notify("Could not get discussion node", vim.log.levels.ERROR)
|
||||||
return
|
return
|
||||||
end
|
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
|
if line_number == nil then
|
||||||
u.notify("Could not get line number", vim.log.levels.ERROR)
|
u.notify("Could not get line number", vim.log.levels.ERROR)
|
||||||
return
|
return
|
||||||
end
|
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()
|
callback()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -111,12 +111,7 @@ end
|
|||||||
---Opens the discussion tree, sets the keybindings. It also
|
---Opens the discussion tree, sets the keybindings. It also
|
||||||
---creates the tree for notes (which are not linked to specific lines of code)
|
---creates the tree for notes (which are not linked to specific lines of code)
|
||||||
---@param callback function?
|
---@param callback function?
|
||||||
M.toggle = function(callback)
|
M.open = function(callback)
|
||||||
if M.split_visible then
|
|
||||||
M.close()
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
state.DISCUSSION_DATA.discussions = u.ensure_table(state.DISCUSSION_DATA.discussions)
|
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.DISCUSSION_DATA.unlinked_discussions = u.ensure_table(state.DISCUSSION_DATA.unlinked_discussions)
|
||||||
state.DRAFT_NOTES = u.ensure_table(state.DRAFT_NOTES)
|
state.DRAFT_NOTES = u.ensure_table(state.DRAFT_NOTES)
|
||||||
|
|||||||
@@ -191,7 +191,7 @@ local function get_modification_type_from_new_sha(new_line, hunks, all_diff_outp
|
|||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
return List.new(hunks):find(function(hunk)
|
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 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
|
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))
|
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
|
|||||||
end
|
end
|
||||||
|
|
||||||
return List.new(hunks):find(function(hunk)
|
return List.new(hunks):find(function(hunk)
|
||||||
local old_line_end = hunk.old_line + hunk.old_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
|
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_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)
|
return (in_old_range or in_new_range) and line_was_removed(old_line, hunk, all_diff_output)
|
||||||
end) and "deleted" or "unmodified"
|
end) and "deleted" or "unmodified"
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -67,8 +67,9 @@ end
|
|||||||
---@param d_or_n Discussion|DraftNote
|
---@param d_or_n Discussion|DraftNote
|
||||||
---@return boolean
|
---@return boolean
|
||||||
M.is_old_sha = function(d_or_n)
|
M.is_old_sha = function(d_or_n)
|
||||||
local first_note = M.get_first_note(d_or_n)
|
local position = M.get_first_note(d_or_n).position
|
||||||
return first_note.position.old_line ~= nil
|
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
|
end
|
||||||
|
|
||||||
---@param discussion Discussion|DraftNote
|
---@param discussion Discussion|DraftNote
|
||||||
|
|||||||
@@ -72,19 +72,17 @@ local create_multiline_diagnostic = function(d_or_n)
|
|||||||
error("Parsing multi-line comment but note does not contain line range")
|
error("Parsing multi-line comment but note does not contain line range")
|
||||||
end
|
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({
|
return create_diagnostic({
|
||||||
lnum = start_new_line - 1,
|
lnum = start_line - 1,
|
||||||
end_lnum = first_note.position.new_line - 1,
|
end_lnum = end_line - 1,
|
||||||
}, d_or_n)
|
}, d_or_n)
|
||||||
else
|
|
||||||
return create_diagnostic({
|
|
||||||
lnum = start_old_line - 1,
|
|
||||||
end_lnum = first_note.position.old_line - 1,
|
|
||||||
}, d_or_n)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
---Set diagnostics in currently new SHA.
|
---Set diagnostics in currently new SHA.
|
||||||
|
|||||||
@@ -68,12 +68,18 @@ return {
|
|||||||
pipeline = async.sequence({ latest_pipeline }, pipeline.open),
|
pipeline = async.sequence({ latest_pipeline }, pipeline.open),
|
||||||
merge = async.sequence({ u.merge(info, { refresh = true }) }, merge.merge),
|
merge = async.sequence({ u.merge(info, { refresh = true }) }, merge.merge),
|
||||||
-- Discussion Tree Actions 🌴
|
-- Discussion Tree Actions 🌴
|
||||||
toggle_discussions = async.sequence({
|
toggle_discussions = function()
|
||||||
|
if discussions.split_visible then
|
||||||
|
discussions.close()
|
||||||
|
else
|
||||||
|
async.sequence({
|
||||||
info,
|
info,
|
||||||
user,
|
user,
|
||||||
u.merge(draft_notes_dep, { refresh = true }),
|
u.merge(draft_notes_dep, { refresh = true }),
|
||||||
u.merge(discussion_data, { refresh = true }),
|
u.merge(discussion_data, { refresh = true }),
|
||||||
}, discussions.toggle),
|
}, discussions.open)()
|
||||||
|
end
|
||||||
|
end,
|
||||||
toggle_draft_mode = discussions.toggle_draft_mode,
|
toggle_draft_mode = discussions.toggle_draft_mode,
|
||||||
publish_all_drafts = draft_notes.publish_all_drafts,
|
publish_all_drafts = draft_notes.publish_all_drafts,
|
||||||
refresh_data = function()
|
refresh_data = function()
|
||||||
|
|||||||
@@ -524,6 +524,7 @@ M.create_box_popup_state = function(title, enter)
|
|||||||
top = title,
|
top = title,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
opacity = settings.opacity,
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user