Skip to content

Commit 3d76b8d

Browse files
authored
Fix: Syntax in discussion tree (#433)
1 parent 508a394 commit 3d76b8d

File tree

7 files changed

+42
-37
lines changed

7 files changed

+42
-37
lines changed

after/syntax/gitlab.vim

Lines changed: 21 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,26 @@ if filereadable($VIMRUNTIME . '/syntax/markdown.vim')
22
source $VIMRUNTIME/syntax/markdown.vim
33
endif
44

5-
syntax match Date "\v\d+\s+\w+\s+ago"
6-
highlight link Date GitlabDate
7-
8-
execute 'syntax match Unresolved /\s' . g:gitlab_discussion_tree_unresolved . '\s\?/'
9-
highlight link Unresolved GitlabUnresolved
10-
11-
execute 'syntax match Unlinked /\s' . g:gitlab_discussion_tree_unlinked . '\s\?/'
12-
highlight link Unlinked GitlabUnlinked
13-
14-
execute 'syntax match Resolved /\s' . g:gitlab_discussion_tree_resolved . '\s\?/'
15-
highlight link Resolved GitlabResolved
16-
17-
execute 'syntax match GitlabDiscussionOpen /^\s*' . g:gitlab_discussion_tree_expander_open . '/'
18-
highlight link GitlabDiscussionOpen GitlabExpander
19-
20-
execute 'syntax match GitlabDiscussionClosed /^\s*' . g:gitlab_discussion_tree_expander_closed . '/'
21-
highlight link GitlabDiscussionClosed GitlabExpander
22-
23-
execute 'syntax match Draft /' . g:gitlab_discussion_tree_draft . '/'
24-
highlight link Draft GitlabDraft
25-
26-
execute 'syntax match Username "@[a-zA-Z0-9.]\+"'
27-
highlight link Username GitlabUsername
28-
29-
execute 'syntax match Mention "\%(' . g:gitlab_discussion_tree_expander_open . '\|'
30-
\ . g:gitlab_discussion_tree_expander_closed . '\)\@<!@[a-zA-Z0-9.]*"'
31-
highlight link Mention GitlabMention
5+
let expanders = '^\s*\%(' . g:gitlab_discussion_tree_expander_open . '\|' . g:gitlab_discussion_tree_expander_closed . '\)'
6+
let username = '@[a-zA-Z0-9.]\+'
7+
8+
" Covers times like '14 days ago', 'just now', as well as 'October 3, 2024'
9+
let time_ago = '\d\+ \w\+ ago'
10+
let formatted_date = '\w\+ \{1,2}\d\{1,2}, \d\{4}'
11+
let date = '\%(' . time_ago . '\|' . formatted_date . '\|just now\)'
12+
13+
let published = date . ' \%(' . g:gitlab_discussion_tree_resolved . '\|' . g:gitlab_discussion_tree_unresolved . '\|' . g:gitlab_discussion_tree_unlinked . '\)\?'
14+
let state = ' \%(' . published . '\|' . g:gitlab_discussion_tree_draft . '\)'
15+
16+
execute 'syntax match GitlabNoteHeader "' . expanders . username . state . '" contains=GitlabDate,GitlabUnresolved,GitlabUnlinked,GitlabResolved,GitlabExpander,GitlabDraft,GitlabUsername'
17+
18+
execute 'syntax match GitlabDate "' . date . '" contained'
19+
execute 'syntax match GitlabUnresolved "' . g:gitlab_discussion_tree_unresolved . '" contained'
20+
execute 'syntax match GitlabUnlinked "' . g:gitlab_discussion_tree_unlinked . '" contained'
21+
execute 'syntax match GitlabResolved "' . g:gitlab_discussion_tree_resolved . '" contained'
22+
execute 'syntax match GitlabExpander "' . expanders . '" contained'
23+
execute 'syntax match GitlabDraft "' . g:gitlab_discussion_tree_draft . '" contained'
24+
execute 'syntax match GitlabUsername "' . username . '" contained'
25+
execute 'syntax match GitlabMention "' . username . '"'
3226

3327
let b:current_syntax = 'gitlab'

doc/gitlab.nvim.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,8 @@ you call this function with no values the defaults will be used:
268268
relative = "editor", -- Position of tree split relative to "editor" or "window"
269269
resolved = '✓', -- Symbol to show next to resolved discussions
270270
unresolved = '-', -- Symbol to show next to unresolved discussions
271+
unlinked = "󰌸", -- Symbol to show next to unliked comments (i.e., not threads)
272+
draft = "✎", -- Symbol to show next to draft comments/notes
271273
tree_type = "simple", -- Type of discussion tree - "simple" means just list of discussions, "by_file_name" means file tree with discussions under file
272274
draft_mode = false, -- Whether comments are posted as drafts as part of a review
273275
winbar = nil -- Custom function to return winbar title, should return a string. Provided with WinbarTable (defined in annotations.lua)

lua/gitlab/actions/common.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ local M = {}
1313
---@return string
1414
M.build_note_header = function(note)
1515
if note.note then
16-
return "@" .. state.USER.username .. " " .. ""
16+
return "@" .. state.USER.username .. " " .. state.settings.discussion_tree.draft
1717
end
1818
return "@" .. note.author.username .. " " .. u.time_since(note.created_at)
1919
end

lua/gitlab/actions/discussions/winbar.lua

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,14 @@ end
222222

223223
M.get_drafts_text = function(base_title, drafts_count, focused)
224224
return get_connector(base_title)
225-
.. string.format("%d%s", drafts_count, (focused and ("%#GitlabDraft#" .. "" .. "%#Text#") or ""))
225+
.. string.format(
226+
"%d%s",
227+
drafts_count,
228+
(
229+
focused and ("%#GitlabDraft#" .. state.settings.discussion_tree.draft .. "%#Text#")
230+
or state.settings.discussion_tree.draft
231+
)
232+
)
226233
end
227234

228235
M.get_nonresolveable_text = function(base_title, non_resolvable_count, focused)

lua/gitlab/actions/help.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ M.open = function()
2121
table.insert(
2222
help_content_lines,
2323
string.format(
24-
"✎ = draft; %s = unlinked comment; %s = resolved",
24+
"%s = draft; %s = unlinked comment; %s = resolved",
25+
state.settings.discussion_tree.draft,
2526
state.settings.discussion_tree.unlinked,
2627
state.settings.discussion_tree.resolved
2728
)

lua/gitlab/colors.lua

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ local state = require("gitlab.state")
33
local colors = state.settings.colors
44

55
-- Set icons into global vim variables for syntax matching
6-
local expanders = state.settings.discussion_tree.expanders
7-
vim.g.gitlab_discussion_tree_expander_open = expanders.expanded
8-
vim.g.gitlab_discussion_tree_expander_closed = expanders.collapsed
9-
vim.g.gitlab_discussion_tree_draft = ""
10-
vim.g.gitlab_discussion_tree_resolved = ""
11-
vim.g.gitlab_discussion_tree_unresolved = "-"
12-
vim.g.gitlab_discussion_tree_unlinked = "󰌸"
6+
local discussion_tree = state.settings.discussion_tree
7+
vim.g.gitlab_discussion_tree_expander_open = discussion_tree.expanders.expanded
8+
vim.g.gitlab_discussion_tree_expander_closed = discussion_tree.expanders.collapsed
9+
vim.g.gitlab_discussion_tree_draft = discussion_tree.draft
10+
vim.g.gitlab_discussion_tree_resolved = discussion_tree.resolved
11+
vim.g.gitlab_discussion_tree_unresolved = discussion_tree.unresolved
12+
vim.g.gitlab_discussion_tree_unlinked = discussion_tree.unlinked
1313

1414
local discussion = colors.discussion_tree
1515

lua/gitlab/state.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ M.settings = {
166166
resolved = "",
167167
unresolved = "-",
168168
unlinked = "󰌸",
169+
draft = "",
169170
tree_type = "simple",
170171
draft_mode = false,
171172
},

0 commit comments

Comments
 (0)