Feat: Configure discussion tree split width and position
This MR improves the configurability of the plugin by using Nui's split system rather than managing the splits ourselves. This lets the user configure both the positioning of the discussion tree and it's width, and reduces overall maintenance of split management for the plugin.
This commit is contained in:
@@ -96,6 +96,9 @@ require("gitlab").setup({
|
|||||||
delete_comment = "dd",
|
delete_comment = "dd",
|
||||||
reply_to_comment = "r",
|
reply_to_comment = "r",
|
||||||
toggle_node = "t",
|
toggle_node = "t",
|
||||||
|
position = "left", -- "top", "right", "bottom" or "left"
|
||||||
|
size = "20%", -- Size of split
|
||||||
|
relative = "editor" -- Position relative to "editor" or "window"
|
||||||
},
|
},
|
||||||
dialogue = { -- The confirmation dialogue for deleting comments
|
dialogue = { -- The confirmation dialogue for deleting comments
|
||||||
focus_next = { "j", "<Down>", "<Tab>" },
|
focus_next = { "j", "<Down>", "<Tab>" },
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
local u = require("gitlab.utils")
|
local u = require("gitlab.utils")
|
||||||
local NuiTree = require("nui.tree")
|
local NuiTree = require("nui.tree")
|
||||||
|
local NuiSplit = require("nui.split")
|
||||||
local job = require("gitlab.job")
|
local job = require("gitlab.job")
|
||||||
local state = require("gitlab.state")
|
local state = require("gitlab.state")
|
||||||
local Job = require("plenary.job")
|
local Job = require("plenary.job")
|
||||||
@@ -57,11 +58,12 @@ M.list_discussions = function()
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
vim.cmd.tabnew()
|
local splitState = state.DISCUSSION_SPLIT
|
||||||
local buf = vim.api.nvim_create_buf(false, true)
|
splitState.buf_options = { modifiable = false }
|
||||||
vim.api.nvim_command("aboveleft vsplit")
|
local split = NuiSplit(splitState)
|
||||||
vim.api.nvim_buf_set_option(buf, 'filetype', 'markdown')
|
split:mount()
|
||||||
vim.api.nvim_set_current_buf(buf)
|
|
||||||
|
local buf = split.bufnr
|
||||||
local allDiscussions = {}
|
local allDiscussions = {}
|
||||||
for i, discussion in ipairs(data.discussions) do
|
for i, discussion in ipairs(data.discussions) do
|
||||||
local discussionChildren = {}
|
local discussionChildren = {}
|
||||||
@@ -90,7 +92,6 @@ M.list_discussions = function()
|
|||||||
state.tree:render()
|
state.tree:render()
|
||||||
vim.api.nvim_buf_set_option(buf, 'filetype', 'markdown')
|
vim.api.nvim_buf_set_option(buf, 'filetype', 'markdown')
|
||||||
u.darken_metadata(buf, '')
|
u.darken_metadata(buf, '')
|
||||||
M.jump_to_file()
|
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
@@ -105,6 +106,14 @@ M.jump_to_file = function()
|
|||||||
local node = state.tree:get_node()
|
local node = state.tree:get_node()
|
||||||
if node == nil then return end
|
if node == nil then return end
|
||||||
|
|
||||||
|
local wins = vim.api.nvim_list_wins()
|
||||||
|
local discussion_win = vim.api.nvim_get_current_win()
|
||||||
|
for _, winId in ipairs(wins) do
|
||||||
|
if winId ~= discussion_win then
|
||||||
|
vim.api.nvim_set_current_win(winId)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
local childrenIds = node:get_child_ids()
|
local childrenIds = node:get_child_ids()
|
||||||
-- We have selected a note node
|
-- We have selected a note node
|
||||||
if node.file_name ~= nil then
|
if node.file_name ~= nil then
|
||||||
|
|||||||
@@ -134,9 +134,14 @@ M.setPluginConfiguration = function(args)
|
|||||||
error("The .gitlab.nvim project file's 'project_id' must be number")
|
error("The .gitlab.nvim project file's 'project_id' must be number")
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Configuration for the plugin, such as port of server
|
-- Configuration for the plugin, such as port of server, layout, etc
|
||||||
state.PORT = args.port or 21036
|
state.PORT = args.port or 21036
|
||||||
state.LOG_PATH = args.log_path or (vim.fn.stdpath("cache") .. "/gitlab.nvim.log")
|
state.LOG_PATH = args.log_path or (vim.fn.stdpath("cache") .. "/gitlab.nvim.log")
|
||||||
|
state.DISCUSSION_SPLIT = {
|
||||||
|
relative = args.discussion_tree and args.discussion_tree.relative or "editor",
|
||||||
|
position = args.discussion_tree and args.discussion_tree.position or "left",
|
||||||
|
size = args.discussion_tree and args.discussion_tree.size or "20%",
|
||||||
|
}
|
||||||
|
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user