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:
Harrison (Harry) Cramer
2024-07-06 13:09:56 -04:00
committed by GitHub
parent dc70c97810
commit 95dcc41885
8 changed files with 80 additions and 44 deletions

View File

@@ -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 = {}
@@ -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
@@ -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
@@ -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
@@ -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