Skip to content

Commit cc68476

Browse files
authored
Make Popups Configurable (#129)
This makes the popups in the plugin (those for editing and creating comments, replies, the pipeline, etc) configurable. Users can change the default width, height, transparency, and border properties, and set overrides per popup.
1 parent 02db3e4 commit cc68476

File tree

8 files changed

+75
-37
lines changed

8 files changed

+75
-37
lines changed

.github/CONTRIBUTING.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ If you are using Lazy as a plugin manager, the easiest way to work on changes is
2020
build = function()
2121
require("gitlab.server").build()
2222
end,
23-
dir = "~/.path/to/your-closed-version", -- Pass in the path to your cloned repository
23+
dir = "~/.path/to/your-cloned-version", -- Pass in the path to your cloned repository
2424
config = function()
2525
require("gitlab").setup({})
2626
end,
@@ -31,18 +31,18 @@ If you are making changes to the Go codebase, don't forget to run `make compile`
3131

3232
3. Apply formatters and linters to your changes
3333

34-
For changes to the Go codbase: We use <a href="https://pkg.go.dev/cmd/gofmt">gofmt</a> to check formatting and <a href="https://github.com/golangci/golangci-lint">golangci-lint</a> to check linting. Run these commands in the root of the repository:
34+
For changes to the Go codebase: We use <a href="https://pkg.go.dev/cmd/gofmt">gofmt</a> to check formatting and <a href="https://github.com/golangci/golangci-lint">golangci-lint</a> to check linting. Run these commands in the root of the repository:
3535

3636
```bash
37-
$ stylua .
38-
$ luacheck --globals vim busted --no-max-line-length -- .
37+
$ go fmt ./...
38+
$ golangci-lint run
3939
```
4040

4141
For changes to the Lua codebase: We use <a href="https://github.com/JohnnyMorganz/StyLua">stylua</a> for formatting and <a href="https://github.com/mpeterv/luacheck">luacheck</a> for linting. Run these commands in the root of the repository:
4242

4343
```bash
44-
$ go fmt ./...
45-
$ golangci-lint run
44+
$ stylua .
45+
$ luacheck --globals vim busted --no-max-line-length -- .
4646
```
4747

4848
4. Make the merge request to the `main` branch of `.gitlab.nvim`

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ bin
77
tests/plugins
88
!tests/plugins/.placeholder
99
luacov.*
10+
tags

README.md

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ use {
7676
"MunifTanjim/nui.nvim",
7777
"nvim-lua/plenary.nvim",
7878
"sindrets/diffview.nvim",
79-
"stevearc/dressing.nvim",
79+
"stevearc/dressing.nvim", -- Recommended but not required. Better UI for pickers.
80+
"nvim-tree/nvim-web-devicons", -- Recommended but not required. Icons in discussion tree.
8081
},
8182
run = function() require("gitlab.server").build(true) end,
8283
config = function()
@@ -120,6 +121,15 @@ require("gitlab").setup({
120121
exit = "<Esc>",
121122
perform_action = "<leader>s", -- Once in normal mode, does action (like saving comment or editing description, etc)
122123
perform_linewise_action = "<leader>l", -- Once in normal mode, does the linewise action (see logs for this job, etc)
124+
width = "40%",
125+
height = "60%",
126+
border = "rounded", -- One of "rounded", "single", "double", "solid"
127+
opacity = 1.0, -- From 0.0 (fully transparent) to 1.0 (fully opaque)
128+
comment = nil, -- Individual popup overrides, e.g. { width = "60%", height = "80%", border = "single", opacity = 0.85 },
129+
edit = nil,
130+
note = nil,
131+
pipeline = nil,
132+
reply = nil,
123133
},
124134
discussion_tree = { -- The discussion tree that holds all comments
125135
blacklist = {}, -- List of usernames to remove from tree (bots, CI, etc)
@@ -252,7 +262,7 @@ To display all discussions for the current MR, use the `toggle_discussions` acti
252262
require("gitlab").toggle_discussions()
253263
```
254264

255-
You can jump to the comment's location in the reviewer window by using the `state.settings.discussion_tree.jump_to_reviewer` key, or the actual file with the 'state.settings.discussion_tree.jump_to_file' key.
265+
You can jump to the comment's location in the reviewer window by using the `state.settings.discussion_tree.jump_to_reviewer` key, or to the actual file with the `state.settings.discussion_tree.jump_to_file` key.
256266

257267
Within the discussion tree, you can delete/edit/reply to comments with the `state.settings.discussion_tree.SOME_ACTION` keybindings.
258268

@@ -264,26 +274,26 @@ require("gitlab").create_note()
264274

265275
### Discussion signs and diagnostics
266276

267-
By default when reviewing files you will see signs and diagnostics ( if enabled in configuration ). When cursor is on diagnostic line you can view discussion thread by using `vim.diagnostic.show`. You can also jump to discussion tree where you can reply, edit or delete discussion.
277+
By default when reviewing files you will see signs and diagnostics (if enabled in configuration). When cursor is on diagnostic line you can view discussion thread by using `vim.diagnostic.show`. You can also jump to discussion tree where you can reply, edit or delete discussion.
268278

269279
```lua
270280
require("gitlab").move_to_discussion_tree_from_diagnostic()
271281
```
272282

273-
The `discussion_sign` configuration controls the display of signs for discussions in the reviewer pane. Keep in mind that the highlights provided here can be overridden by other highlights (for example from diffview.nvim). This allows users to jump to comments in the current buffer in the reviewer pane directly.
283+
The `discussion_sign` configuration controls the display of signs for discussions in the reviewer pane. This allows users to jump to comments in the current buffer in the reviewer pane directly. Keep in mind that the highlights provided here can be overridden by other highlights (for example from `diffview.nvim`).
274284

275-
These diagnostics are configurable in the same way that diagnostics are typically configurable in Neovim. For instance, the `severity` key sets the diagnostic severity level and should be set to one of `vim.diagnostic.severity.ERROR`, `vim.diagnostic.severity.WARN`, `vim.diagnostic.severity.INFO`, or `vim.diagnostic.severity.HINT`. The `display_opts` option configures the diagnostic display options where you can configure values like (this is directly used as opts in vim.diagnostic.set):
285+
These diagnostics are configurable in the same way that diagnostics are typically configurable in Neovim. For instance, the `severity` key sets the diagnostic severity level and should be set to one of `vim.diagnostic.severity.ERROR`, `vim.diagnostic.severity.WARN`, `vim.diagnostic.severity.INFO`, or `vim.diagnostic.severity.HINT`. The `display_opts` option configures the diagnostic display options (this is directly used as opts in vim.diagnostic.set). Here you can configure values like:
276286

277287
- `virtual_text` - Show virtual text for diagnostics.
278288
- `underline` - Underline text for diagnostics.
279289

280-
Diagnostics for discussions use the `gitlab_discussion` namespace. See `:h vim.diagnostic.config` and `:h diagnostic-structure` for more details. Signs and diagnostics have common settings in `discussion_sign_and_diagnostics`. This allows customizing if discussions that are resolved or no longer relevant should still display visual indicators in the editor. The `skip_resolved_discussion` Boolean will control visibility of resolved discussions, and `skip_old_revision_discussion` whether to show signs and diagnostics for discussions on outdated diff revisions.
290+
Diagnostics for discussions use the `gitlab_discussion` namespace. See `:h vim.diagnostic.config` and `:h diagnostic-structure` for more details. Signs and diagnostics have common settings in `discussion_sign_and_diagnostic`. This allows customizing if discussions that are resolved or no longer relevant should still display visual indicators in the editor. The `skip_resolved_discussion` Boolean will control visibility of resolved discussions, and `skip_old_revision_discussion` whether to show signs and diagnostics for discussions on outdated diff revisions.
281291

282292
When interacting with multiline comments, the cursor must be on the "main" line of diagnostic, where the `discussion_sign.text` is shown, otherwise `vim.diagnostic.show` and `jump_to_discussion_tree_from_diagnostic` will not work.
283293

284294
### Uploading Files
285295

286-
To attach a file to an MR description, reply, comment, and so forth use the `settings.popup.perform_linewise_action` keybinding when the popup is open. This will open a picker that will look in the directory you specify in the `settings.attachment_dir` folder (this must be an absolute path) for files.
296+
To attach a file to an MR description, reply, comment, and so forth use the `settings.popup.perform_linewise_action` keybinding when the popup is open. This will open a picker that will look for files in the directory you specify in the `settings.attachment_dir` folder (this must be an absolute path).
287297

288298
When you have picked the file, it will be added to the current buffer at the current line.
289299

@@ -331,8 +341,7 @@ require("dressing").setup({
331341

332342
### Restarting or Shutting Down
333343

334-
The `gitlab.nvim` server will shut down automatically when you exit Neovim. However, if you would like to manage this yourself (for instance, restart the server when you check out a new branch) you may do so via the `restart` command, or `shutdown` commands, which
335-
both accept callbacks.
344+
The `gitlab.nvim` server will shut down automatically when you exit Neovim. However, if you would like to manage this yourself (for instance, restart the server when you check out a new branch) you may do so via the `restart` command, or `shutdown` commands, which both accept callbacks.
336345

337346
```lua
338347
require("gitlab.server").restart()
@@ -382,7 +391,7 @@ vim.keymap.set("n", "glo", gitlab.open_in_browser)
382391

383392
**To check that the current settings of the plugin are configured correctly, please run: `:lua require("gitlab").print_settings()`**
384393

385-
This plugin uses a Golang server to reach out to Gitlab. It's possible that something is going wrong when starting that server or connecting with Gitlab. The Golang server runs outside of Neovim, and can be interacted with directly in order to troubleshoot. To start the server, check out your feature branch and run these commands:
394+
This plugin uses a Go server to reach out to Gitlab. It's possible that something is going wrong when starting that server or connecting with Gitlab. The Go server runs outside of Neovim, and can be interacted with directly in order to troubleshoot. To start the server, check out your feature branch and run these commands:
386395

387396
```lua
388397
:lua require("gitlab.server").build(true)

lua/gitlab/actions/comment.lua

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,17 @@ local miscellaneous = require("gitlab.actions.miscellaneous")
1010
local reviewer = require("gitlab.reviewer")
1111
local M = {}
1212

13-
local comment_popup = Popup(u.create_popup_state("Comment", "40%", "60%"))
14-
local note_popup = Popup(u.create_popup_state("Note", "40%", "60%"))
13+
-- Popup creation is wrapped in a function so that it is performed *after* user
14+
-- configuration has been merged with default configuration, not when this file is being
15+
-- required.
16+
local function create_comment_popup()
17+
return Popup(u.create_popup_state("Comment", state.settings.popup.comment))
18+
end
1519

1620
-- This function will open a comment popup in order to create a comment on the changed/updated
1721
-- line in the current MR
1822
M.create_comment = function()
23+
local comment_popup = create_comment_popup()
1924
comment_popup:mount()
2025
state.set_popup_keymaps(comment_popup, function(text)
2126
M.confirm_create_comment(text)
@@ -27,6 +32,7 @@ M.create_multiline_comment = function()
2732
if not u.check_visual_mode() then
2833
return
2934
end
35+
local comment_popup = create_comment_popup()
3036
local start_line, end_line = u.get_visual_selection_boundaries()
3137
comment_popup:mount()
3238
state.set_popup_keymaps(comment_popup, function(text)
@@ -40,6 +46,7 @@ M.create_comment_suggestion = function()
4046
if not u.check_visual_mode() then
4147
return
4248
end
49+
local comment_popup = create_comment_popup()
4350
local start_line, end_line = u.get_visual_selection_boundaries()
4451
local current_line = vim.api.nvim_win_get_cursor(0)[1]
4552
local range = end_line - start_line
@@ -81,6 +88,7 @@ M.create_comment_suggestion = function()
8188
end
8289

8390
M.create_note = function()
91+
local note_popup = Popup(u.create_popup_state("Note", state.settings.popup.note))
8492
note_popup:mount()
8593
state.set_popup_keymaps(note_popup, function(text)
8694
M.confirm_create_comment(text, nil, true)

lua/gitlab/actions/discussions/init.lua

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ local reviewer = require("gitlab.reviewer")
1313
local miscellaneous = require("gitlab.actions.miscellaneous")
1414
local discussions_tree = require("gitlab.actions.discussions.tree")
1515

16-
local edit_popup = Popup(u.create_popup_state("Edit Comment", "80%", "80%"))
17-
local reply_popup = Popup(u.create_popup_state("Reply", "80%", "80%"))
1816
local discussion_sign_name = "gitlab_discussion"
1917
local discussion_helper_sign_start = "gitlab_discussion_helper_start"
2018
local discussion_helper_sign_mid = "gitlab_discussion_helper_mid"
@@ -470,6 +468,7 @@ end
470468

471469
-- The reply popup will mount in a window when you trigger it (settings.discussion_tree.reply) when hovering over a node in the discussion tree.
472470
M.reply = function(tree)
471+
local reply_popup = Popup(u.create_popup_state("Reply", state.settings.popup.reply))
473472
local node = tree:get_node()
474473
local discussion_node = M.get_root_node(tree, node)
475474
local id = tostring(discussion_node.id)
@@ -536,6 +535,7 @@ end
536535

537536
-- This function (settings.discussion_tree.edit_comment) will open the edit popup for the current comment in the discussion tree
538537
M.edit_comment = function(tree, unlinked)
538+
local edit_popup = Popup(u.create_popup_state("Edit Comment", state.settings.popup.edit))
539539
local current_node = tree:get_node()
540540
local note_node = M.get_note_node(tree, current_node)
541541
local root_node = M.get_root_node(tree, current_node)
@@ -811,37 +811,37 @@ M.set_tree_keymaps = function(tree, bufnr, unlinked)
811811
if M.is_current_node_note(tree) then
812812
M.edit_comment(tree, unlinked)
813813
end
814-
end, { buffer = bufnr })
814+
end, { buffer = bufnr, desc = "Edit comment" })
815815
vim.keymap.set("n", state.settings.discussion_tree.delete_comment, function()
816816
if M.is_current_node_note(tree) then
817817
M.delete_comment(tree, unlinked)
818818
end
819-
end, { buffer = bufnr })
819+
end, { buffer = bufnr, desc = "Delete comment" })
820820
vim.keymap.set("n", state.settings.discussion_tree.toggle_resolved, function()
821821
if M.is_current_node_note(tree) then
822822
M.toggle_discussion_resolved(tree)
823823
end
824-
end, { buffer = bufnr })
824+
end, { buffer = bufnr, desc = "Toggle resolved" })
825825
vim.keymap.set("n", state.settings.discussion_tree.toggle_node, function()
826826
M.toggle_node(tree)
827-
end, { buffer = bufnr })
827+
end, { buffer = bufnr, desc = "Toggle node" })
828828
vim.keymap.set("n", state.settings.discussion_tree.reply, function()
829829
if M.is_current_node_note(tree) then
830830
M.reply(tree)
831831
end
832-
end, { buffer = bufnr })
832+
end, { buffer = bufnr, desc = "Reply" })
833833

834834
if not unlinked then
835835
vim.keymap.set("n", state.settings.discussion_tree.jump_to_file, function()
836836
if M.is_current_node_note(tree) then
837837
M.jump_to_file(tree)
838838
end
839-
end, { buffer = bufnr })
839+
end, { buffer = bufnr, desc = "Jump to file" })
840840
vim.keymap.set("n", state.settings.discussion_tree.jump_to_reviewer, function()
841841
if M.is_current_node_note(tree) then
842842
M.jump_to_reviewer(tree)
843843
end
844-
end, { buffer = bufnr })
844+
end, { buffer = bufnr, desc = "Jump to reviewer" })
845845
end
846846
end
847847

lua/gitlab/actions/pipeline.lua

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
-- This module is responsible for the MR pipline
1+
-- This module is responsible for the MR pipeline
22
-- This lets the user see the current status of the pipeline
33
-- and retrigger the pipeline from within the editor
44
local Popup = require("nui.popup")
@@ -42,7 +42,8 @@ M.open = function()
4242
local width = string.len(pipeline.web_url) + 10
4343
local height = 6 + #pipeline_jobs + 3
4444

45-
local pipeline_popup = Popup(u.create_popup_state("Loading Pipeline...", width, height))
45+
local pipeline_popup =
46+
Popup(u.create_popup_state("Loading Pipeline...", state.settings.popup.pipeline, width, height))
4647
M.pipeline_popup = pipeline_popup
4748
pipeline_popup:mount()
4849

lua/gitlab/state.lua

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,15 @@ M.settings = {
1818
exit = "<Esc>",
1919
perform_action = "<leader>s",
2020
perform_linewise_action = "<leader>l",
21+
width = "40%",
22+
height = "60%",
23+
border = "rounded",
24+
opacity = 1.0,
25+
edit = nil,
26+
reply = nil,
27+
comment = nil,
28+
note = nil,
29+
pipeline = nil,
2130
},
2231
discussion_tree = {
2332
blacklist = {},
@@ -207,7 +216,7 @@ M.set_popup_keymaps = function(popup, action, linewise_action, opts)
207216
end
208217
vim.keymap.set("n", M.settings.popup.exit, function()
209218
exit(popup, opts.cb)
210-
end, { buffer = popup.bufnr })
219+
end, { buffer = popup.bufnr, desc = "Exit popup" })
211220
if action ~= nil then
212221
vim.keymap.set("n", M.settings.popup.perform_action, function()
213222
local text = u.get_buffer_text(popup.bufnr)
@@ -218,7 +227,7 @@ M.set_popup_keymaps = function(popup, action, linewise_action, opts)
218227
exit(popup)
219228
action(text, popup.bufnr)
220229
end
221-
end, { buffer = popup.bufnr })
230+
end, { buffer = popup.bufnr, desc = "Perform action" })
222231
end
223232

224233
if linewise_action ~= nil then
@@ -227,7 +236,7 @@ M.set_popup_keymaps = function(popup, action, linewise_action, opts)
227236
local linnr = vim.api.nvim_win_get_cursor(0)[1]
228237
local text = u.get_line_content(bufnr, linnr)
229238
linewise_action(text)
230-
end, { buffer = popup.bufnr })
239+
end, { buffer = popup.bufnr, desc = "Perform linewise action" })
231240
end
232241
end
233242

lua/gitlab/utils/init.lua

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -344,26 +344,36 @@ M.jump_to_buffer = function(bufnr, line_number)
344344
vim.api.nvim_win_set_cursor(0, { line_number, 0 })
345345
end
346346

347-
M.create_popup_state = function(title, width, height)
348-
return {
347+
---Get the popup view_opts
348+
---@param title string The string to appear on top of the popup
349+
---@param settings table User defined popup settings
350+
---@param width string Override default width
351+
---@param height string Override default height
352+
---@return table
353+
M.create_popup_state = function(title, settings, width, height)
354+
local default_settings = require("gitlab.state").settings.popup
355+
local user_settings = settings or {}
356+
local view_opts = {
349357
buf_options = {
350358
filetype = "markdown",
351359
},
352360
relative = "editor",
353361
enter = true,
354362
focusable = true,
355363
border = {
356-
style = "rounded",
364+
style = user_settings.border or default_settings.border,
357365
text = {
358366
top = title,
359367
},
360368
},
361369
position = "50%",
362370
size = {
363-
width = width,
364-
height = height,
371+
width = user_settings.width or width or default_settings.width,
372+
height = user_settings.height or height or default_settings.height,
365373
},
374+
opacity = user_settings.opacity or default_settings.opacity,
366375
}
376+
return view_opts
367377
end
368378

369379
M.read_file = function(file_path)

0 commit comments

Comments
 (0)