From 9742b5b2292ee951ed1e4d1d297c5adb2e3ddfcc Mon Sep 17 00:00:00 2001 From: "Harrison (Harry) Cramer" <32515581+harrisoncramer@users.noreply.github.com> Date: Tue, 7 Nov 2023 22:58:03 -0500 Subject: [PATCH] Feat: Add Color Configuration (#82) This MR adds the ability to customize colors for the discussion tree --- README.md | 7 +++++++ after/syntax/gitlab.vim | 15 +++++++++++++++ lua/gitlab/actions/discussions.lua | 3 +++ lua/gitlab/colors.lua | 9 +++++++++ lua/gitlab/init.lua | 1 + lua/gitlab/state.lua | 7 +++++++ lua/gitlab/utils/init.lua | 6 ++++++ 7 files changed, 48 insertions(+) create mode 100644 after/syntax/gitlab.vim create mode 100644 lua/gitlab/colors.lua diff --git a/README.md b/README.md index b6ca227e..3ead4cbc 100644 --- a/README.md +++ b/README.md @@ -133,6 +133,13 @@ require("gitlab").setup({ success = "✓", failed = "", }, + colors = { + discussion_tree = { + username = 'Keyword', -- The highlight group used, for instance 'DiagnosticSignWarn' + date = 'Comment', + chevron = 'Comment', + } + } }) ``` diff --git a/after/syntax/gitlab.vim b/after/syntax/gitlab.vim new file mode 100644 index 00000000..2a693022 --- /dev/null +++ b/after/syntax/gitlab.vim @@ -0,0 +1,15 @@ +if filereadable($VIMRUNTIME . '/syntax/markdown.vim') + source $VIMRUNTIME/syntax/markdown.vim +endif + +syntax match Username "@\w\+" +syntax match Date "\v\d+\s+\w+\s+ago" +syntax match ChevronDown "" +syntax match ChevronRight "" + +highlight link Username GitlabUsername +highlight link Date GitlabDate +highlight link ChevronDown GitlabChevron +highlight link ChevronRight GitlabChevron + +let b:current_syntax = "gitlab" diff --git a/lua/gitlab/actions/discussions.lua b/lua/gitlab/actions/discussions.lua index 94446304..f1245e95 100644 --- a/lua/gitlab/actions/discussions.lua +++ b/lua/gitlab/actions/discussions.lua @@ -67,6 +67,7 @@ M.toggle = function() { linked_section.bufnr, data.discussions, "No Discussions for this MR" }, { unlinked_section.bufnr, data.unlinked_discussions, "No Notes (Unlinked Discussions) for this MR" }, }) + M.switch_can_edit_bufs(false) end) end @@ -288,6 +289,7 @@ M.rebuild_discussion_tree = function() M.set_tree_keymaps(discussion_tree, M.linked_section_bufnr, false) M.discussion_tree = discussion_tree M.switch_can_edit_bufs(false) + vim.api.nvim_buf_set_option(M.linked_section_bufnr, "filetype", "gitlab") end M.rebuild_unlinked_discussion_tree = function() @@ -299,6 +301,7 @@ M.rebuild_unlinked_discussion_tree = function() M.set_tree_keymaps(unlinked_discussion_tree, M.unlinked_section_bufnr, true) M.unlinked_discussion_tree = unlinked_discussion_tree M.switch_can_edit_bufs(false) + vim.api.nvim_buf_set_option(M.unlinked_section_bufnr, "filetype", "gitlab") end M.switch_can_edit_bufs = function(bool) diff --git a/lua/gitlab/colors.lua b/lua/gitlab/colors.lua new file mode 100644 index 00000000..27a7769f --- /dev/null +++ b/lua/gitlab/colors.lua @@ -0,0 +1,9 @@ +local state = require("gitlab.state") +local u = require("gitlab.utils") + +local colors = state.settings.colors +local discussion = colors.discussion_tree + +vim.api.nvim_set_hl(0, "GitlabUsername", u.get_colors_for_group(discussion.username)) +vim.api.nvim_set_hl(0, "GitlabDate", u.get_colors_for_group(discussion.date)) +vim.api.nvim_set_hl(0, "GitlabChevron", u.get_colors_for_group(discussion.chevron)) diff --git a/lua/gitlab/init.lua b/lua/gitlab/init.lua index c6b5995b..e76f0fdc 100644 --- a/lua/gitlab/init.lua +++ b/lua/gitlab/init.lua @@ -23,6 +23,7 @@ return { server.build() -- Builds the Go binary if it doesn't exist state.setPluginConfiguration() -- Sets configuration from `.gitlab.nvim` file state.merge_settings(args) -- Sets keymaps and other settings from setup function + require("gitlab.colors") -- Sets colors reviewer.init() -- Picks and initializes reviewer (default is Delta) u.has_reviewer(args.reviewer or "delta") end, diff --git a/lua/gitlab/state.lua b/lua/gitlab/state.lua index 7cbf5217..c4d98bab 100644 --- a/lua/gitlab/state.lua +++ b/lua/gitlab/state.lua @@ -59,6 +59,13 @@ M.settings = { }, go_server_running = false, is_gitlab_project = false, + colors = { + discussion_tree = { + username = "Keyword", + date = "Comment", + chevron = "Comment", + }, + }, } -- Merges user settings into the default settings, overriding them diff --git a/lua/gitlab/utils/init.lua b/lua/gitlab/utils/init.lua index 8fbc4dfe..7778502b 100644 --- a/lua/gitlab/utils/init.lua +++ b/lua/gitlab/utils/init.lua @@ -1,6 +1,12 @@ local Job = require("plenary.job") local M = {} +M.get_colors_for_group = function(group) + local normal_fg = vim.fn.synIDattr(vim.fn.hlID(group), "fg") + local normal_bg = vim.fn.synIDattr(vim.fn.hlID(group), "bg") + return { fg = normal_fg, bg = normal_bg } +end + M.get_current_line_number = function() return vim.api.nvim_call_function("line", { "." }) end