From 12c4acb29729afd7d6bf6c615b3fc799f95c4b67 Mon Sep 17 00:00:00 2001
From: Guillaume <guiplum@gmail.com>
Date: Mon, 8 Apr 2024 03:37:55 +0200
Subject: [PATCH] fix: correcting some problem with review mode (#225)

Addresses issues where the new and old lines were not being set correctly
---
 lua/gitlab/actions/discussions/init.lua | 27 +++++++++++--------------
 1 file changed, 12 insertions(+), 15 deletions(-)

diff --git a/lua/gitlab/actions/discussions/init.lua b/lua/gitlab/actions/discussions/init.lua
index eb98661d..11896a92 100644
--- a/lua/gitlab/actions/discussions/init.lua
+++ b/lua/gitlab/actions/discussions/init.lua
@@ -392,20 +392,17 @@ end
 ---@param node any
 ---@return number|nil
 local function get_new_line(node)
-  if node.new_line == nil then
-    return nil
-  end
-
   ---@type GitlabLineRange|nil
   local range = node.range
   if range == nil then
-    if node.new_line == nil then
-      return nil
-    end
     return node.new_line
   end
 
-  local start_new_line, _ = common.parse_line_code(range.start.line_code)
+  if range.start.new_line ~= nil then
+    return range.start.new_line
+  end
+
+  local _, start_new_line = common.parse_line_code(range.start.line_code)
   return start_new_line
 end
 
@@ -414,17 +411,17 @@ end
 ---@param node any
 ---@return number|nil
 local function get_old_line(node)
-  if node.old_line == nil then
-    return nil
-  end
-
   ---@type GitlabLineRange|nil
   local range = node.range
   if range == nil then
     return node.old_line
   end
 
-  local _, start_old_line = common.parse_line_code(range.start.line_code)
+  if range.start.old_line ~= nil then
+    return range.start.old_line
+  end
+
+  local start_old_line, _ = common.parse_line_code(range.start.line_code)
   return start_old_line
 end
 
@@ -453,7 +450,7 @@ M.jump_to_file = function(tree)
   if line_number == nil then
     line_number = 1
   end
-  local bufnr = vim.fn.bufnr(root_node.filename)
+  local bufnr = vim.fn.bufnr(root_node.file_name)
   if bufnr ~= -1 then
     vim.cmd("buffer " .. bufnr)
     vim.api.nvim_win_set_cursor(0, { line_number, 0 })
@@ -461,7 +458,7 @@ M.jump_to_file = function(tree)
   end
 
   -- If buffer is not already open, open it
-  vim.cmd("edit " .. root_node.filename)
+  vim.cmd("edit " .. root_node.file_name)
   vim.api.nvim_win_set_cursor(0, { line_number, 0 })
 end