Skip to content

Commit a9de870

Browse files
committed
refactor: rename tabnr to tabid
The `vim.api.nvim_get_current_tabpage()` function returns a tab ID, not a tab number, as exemplified by the usage: `vim.cmd.tabclose(vim.api.nvim_tabpage_get_number(M.tabid))`
1 parent 49d2495 commit a9de870

3 files changed

Lines changed: 17 additions & 17 deletions

File tree

lua/gitlab/actions/comment.lua

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -300,14 +300,14 @@ end
300300
---@return boolean
301301
M.can_create_comment = function(must_be_visual)
302302
-- Check that diffview is initialized
303-
if reviewer.tabnr == nil then
303+
if reviewer.tabid == nil then
304304
u.notify("Reviewer must be initialized first", vim.log.levels.ERROR)
305305
return false
306306
end
307307

308308
-- Check that we are in the Diffview tab
309-
local tabnr = vim.api.nvim_get_current_tabpage()
310-
if tabnr ~= reviewer.tabnr then
309+
local tabid = vim.api.nvim_get_current_tabpage()
310+
if tabid ~= reviewer.tabid then
311311
u.notify("Comments can only be left in the reviewer pane", vim.log.levels.ERROR)
312312
return false
313313
end

lua/gitlab/actions/rebase.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ end
4747
local on_pull_exit = function(result, err)
4848
if result ~= nil then
4949
local reviewer = require("gitlab.reviewer")
50-
if reviewer.tabnr ~= nil then
50+
if reviewer.tabid ~= nil then
5151
reviewer.reload()
5252
end
5353
elseif err ~= nil then

lua/gitlab/reviewer/init.lua

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ local async = require("diffview.async")
1212
local M = {
1313
is_open = false,
1414
bufnr = nil,
15-
tabnr = nil,
15+
tabid = nil,
1616
stored_win = nil,
1717
buf_winids = {},
1818
}
@@ -67,7 +67,7 @@ M.open = function()
6767
return
6868
end
6969
M.diffview_layout = M.diffview.cur_layout
70-
M.tabnr = vim.api.nvim_get_current_tabpage()
70+
M.tabid = vim.api.nvim_get_current_tabpage()
7171

7272
if state.settings.discussion_diagnostic ~= nil or state.settings.discussion_sign ~= nil then
7373
u.notify(
@@ -78,13 +78,13 @@ M.open = function()
7878

7979
-- Register Diffview hook for close event to set tab page # to nil
8080
local on_diffview_closed = function(view)
81-
if view.tabpage == M.tabnr then
82-
M.tabnr = nil
81+
if view.tabpage == M.tabid then
82+
M.tabid = nil
8383
require("gitlab.actions.discussions.winbar").cleanup_timer()
8484
end
8585
end
8686
require("diffview.config").user_emitter:on("view_closed", function(_, args)
87-
if M.tabnr == args.tabpage then
87+
if M.tabid == args.tabpage then
8888
M.is_open = false
8989
on_diffview_closed(args)
9090
end
@@ -101,8 +101,8 @@ end
101101

102102
-- Closes the reviewer and cleans up
103103
M.close = function()
104-
if M.tabnr ~= nil and vim.api.nvim_tabpage_is_valid(M.tabnr) then
105-
vim.cmd.tabclose(vim.api.nvim_tabpage_get_number(M.tabnr))
104+
if M.tabid ~= nil and vim.api.nvim_tabpage_is_valid(M.tabid) then
105+
vim.cmd.tabclose(vim.api.nvim_tabpage_get_number(M.tabid))
106106
end
107107
local discussions = require("gitlab.actions.discussions")
108108
discussions.close()
@@ -136,11 +136,11 @@ M.jump = function(file_name, old_file_name, line_number, new_buffer)
136136
-- Draft comments don't have `old_file_name` set
137137
old_file_name = old_file_name or file_name
138138

139-
if M.tabnr == nil then
139+
if M.tabid == nil then
140140
u.notify("Can't jump to Diffvew. Is it open?", vim.log.levels.ERROR)
141141
return
142142
end
143-
vim.api.nvim_set_current_tabpage(M.tabnr)
143+
vim.api.nvim_set_current_tabpage(M.tabid)
144144

145145
if M.diffview == nil then
146146
u.notify("Could not find Diffview view", vim.log.levels.ERROR)
@@ -288,7 +288,7 @@ M.set_callback_for_file_changed = function(callback)
288288
pattern = { "DiffviewDiffBufWinEnter" },
289289
group = group,
290290
callback = function(...)
291-
if M.tabnr == vim.api.nvim_get_current_tabpage() then
291+
if M.tabid == vim.api.nvim_get_current_tabpage() then
292292
callback(...)
293293
end
294294
end,
@@ -303,7 +303,7 @@ M.set_callback_for_buf_read = function(callback)
303303
pattern = { "DiffviewDiffBufRead" },
304304
group = group,
305305
callback = function(...)
306-
if vim.api.nvim_get_current_tabpage() == M.tabnr then
306+
if vim.api.nvim_get_current_tabpage() == M.tabid then
307307
callback(...)
308308
end
309309
end,
@@ -318,7 +318,7 @@ M.set_callback_for_reviewer_leave = function(callback)
318318
pattern = { "DiffviewViewLeave", "DiffviewViewClosed" },
319319
group = group,
320320
callback = function(...)
321-
if vim.api.nvim_get_current_tabpage() == M.tabnr then
321+
if vim.api.nvim_get_current_tabpage() == M.tabid then
322322
callback(...)
323323
end
324324
end,
@@ -334,7 +334,7 @@ M.set_callback_for_reviewer_enter = function(callback)
334334
pattern = { "DiffviewViewEnter", "DiffviewViewOpened" },
335335
group = group,
336336
callback = function(...)
337-
if vim.api.nvim_get_current_tabpage() == M.tabnr then
337+
if vim.api.nvim_get_current_tabpage() == M.tabid then
338338
callback(...)
339339
end
340340
end,

0 commit comments

Comments
 (0)