Skip to content
48 changes: 21 additions & 27 deletions after/syntax/gitlab.vim
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,26 @@ if filereadable($VIMRUNTIME . '/syntax/markdown.vim')
source $VIMRUNTIME/syntax/markdown.vim
endif

syntax match Date "\v\d+\s+\w+\s+ago"
highlight link Date GitlabDate

execute 'syntax match Unresolved /\s' . g:gitlab_discussion_tree_unresolved . '\s\?/'
highlight link Unresolved GitlabUnresolved

execute 'syntax match Unlinked /\s' . g:gitlab_discussion_tree_unlinked . '\s\?/'
highlight link Unlinked GitlabUnlinked

execute 'syntax match Resolved /\s' . g:gitlab_discussion_tree_resolved . '\s\?/'
highlight link Resolved GitlabResolved

execute 'syntax match GitlabDiscussionOpen /^\s*' . g:gitlab_discussion_tree_expander_open . '/'
highlight link GitlabDiscussionOpen GitlabExpander

execute 'syntax match GitlabDiscussionClosed /^\s*' . g:gitlab_discussion_tree_expander_closed . '/'
highlight link GitlabDiscussionClosed GitlabExpander

execute 'syntax match Draft /' . g:gitlab_discussion_tree_draft . '/'
highlight link Draft GitlabDraft

execute 'syntax match Username "@[a-zA-Z0-9.]\+"'
highlight link Username GitlabUsername

execute 'syntax match Mention "\%(' . g:gitlab_discussion_tree_expander_open . '\|'
\ . g:gitlab_discussion_tree_expander_closed . '\)\@<!@[a-zA-Z0-9.]*"'
highlight link Mention GitlabMention
let expanders = '^\s*\%(' . g:gitlab_discussion_tree_expander_open . '\|' . g:gitlab_discussion_tree_expander_closed . '\)'
let username = '@[a-zA-Z0-9.]\+'

" Covers times like '14 days ago', 'just now', as well as 'October 3, 2024'
let time_ago = '\d\+ \w\+ ago'
let formatted_date = '\w\+ \{1,2}\d\{1,2}, \d\{4}'
let date = '\%(' . time_ago . '\|' . formatted_date . '\|just now\)'

let published = date . ' \%(' . g:gitlab_discussion_tree_resolved . '\|' . g:gitlab_discussion_tree_unresolved . '\|' . g:gitlab_discussion_tree_unlinked . '\)\?'
let state = ' \%(' . published . '\|' . g:gitlab_discussion_tree_draft . '\)'

execute 'syntax match GitlabNoteHeader "' . expanders . username . state . '" contains=GitlabDate,GitlabUnresolved,GitlabUnlinked,GitlabResolved,GitlabExpander,GitlabDraft,GitlabUsername'

execute 'syntax match GitlabDate "' . date . '" contained'
execute 'syntax match GitlabUnresolved "' . g:gitlab_discussion_tree_unresolved . '" contained'
execute 'syntax match GitlabUnlinked "' . g:gitlab_discussion_tree_unlinked . '" contained'
execute 'syntax match GitlabResolved "' . g:gitlab_discussion_tree_resolved . '" contained'
execute 'syntax match GitlabExpander "' . expanders . '" contained'
execute 'syntax match GitlabDraft "' . g:gitlab_discussion_tree_draft . '" contained'
execute 'syntax match GitlabUsername "' . username . '" contained'
execute 'syntax match GitlabMention "' . username . '"'

let b:current_syntax = 'gitlab'
2 changes: 2 additions & 0 deletions doc/gitlab.nvim.txt
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,8 @@ you call this function with no values the defaults will be used:
relative = "editor", -- Position of tree split relative to "editor" or "window"
resolved = '✓', -- Symbol to show next to resolved discussions
unresolved = '-', -- Symbol to show next to unresolved discussions
unlinked = "󰌸", -- Symbol to show next to unliked comments (i.e., not threads)
draft = "✎", -- Symbol to show next to draft comments/notes
tree_type = "simple", -- Type of discussion tree - "simple" means just list of discussions, "by_file_name" means file tree with discussions under file
draft_mode = false, -- Whether comments are posted as drafts as part of a review
winbar = nil -- Custom function to return winbar title, should return a string. Provided with WinbarTable (defined in annotations.lua)
Expand Down
2 changes: 1 addition & 1 deletion lua/gitlab/actions/common.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ local M = {}
---@return string
M.build_note_header = function(note)
if note.note then
return "@" .. state.USER.username .. " " .. "✎"
return "@" .. state.USER.username .. " " .. state.settings.discussion_tree.draft
end
return "@" .. note.author.username .. " " .. u.time_since(note.created_at)
end
Expand Down
9 changes: 8 additions & 1 deletion lua/gitlab/actions/discussions/winbar.lua
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,14 @@ end

M.get_drafts_text = function(base_title, drafts_count, focused)
return get_connector(base_title)
.. string.format("%d%s", drafts_count, (focused and ("%#GitlabDraft#" .. "✎" .. "%#Text#") or "✎"))
.. string.format(
"%d%s",
drafts_count,
(
focused and ("%#GitlabDraft#" .. state.settings.discussion_tree.draft .. "%#Text#")
or state.settings.discussion_tree.draft
)
)
end

M.get_nonresolveable_text = function(base_title, non_resolvable_count, focused)
Expand Down
3 changes: 2 additions & 1 deletion lua/gitlab/actions/help.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ M.open = function()
table.insert(
help_content_lines,
string.format(
"✎ = draft; %s = unlinked comment; %s = resolved",
"%s = draft; %s = unlinked comment; %s = resolved",
state.settings.discussion_tree.draft,
state.settings.discussion_tree.unlinked,
state.settings.discussion_tree.resolved
)
Expand Down
14 changes: 7 additions & 7 deletions lua/gitlab/colors.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ local state = require("gitlab.state")
local colors = state.settings.colors

-- Set icons into global vim variables for syntax matching
local expanders = state.settings.discussion_tree.expanders
vim.g.gitlab_discussion_tree_expander_open = expanders.expanded
vim.g.gitlab_discussion_tree_expander_closed = expanders.collapsed
vim.g.gitlab_discussion_tree_draft = "✎"
vim.g.gitlab_discussion_tree_resolved = "✓"
vim.g.gitlab_discussion_tree_unresolved = "-"
vim.g.gitlab_discussion_tree_unlinked = "󰌸"
local discussion_tree = state.settings.discussion_tree
vim.g.gitlab_discussion_tree_expander_open = discussion_tree.expanders.expanded
vim.g.gitlab_discussion_tree_expander_closed = discussion_tree.expanders.collapsed
vim.g.gitlab_discussion_tree_draft = discussion_tree.draft
vim.g.gitlab_discussion_tree_resolved = discussion_tree.resolved
vim.g.gitlab_discussion_tree_unresolved = discussion_tree.unresolved
vim.g.gitlab_discussion_tree_unlinked = discussion_tree.unlinked

local discussion = colors.discussion_tree

Expand Down
1 change: 1 addition & 0 deletions lua/gitlab/state.lua
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ M.settings = {
resolved = "",
unresolved = "-",
unlinked = "󰌸",
draft = "",
tree_type = "simple",
draft_mode = false,
},
Expand Down
Loading