-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: further customise highlight colors #31
Conversation
lua/precognition/init.lua
Outdated
@@ -355,6 +355,13 @@ function M.setup(opts) | |||
|
|||
ns = vim.api.nvim_create_namespace("precognition") | |||
au = vim.api.nvim_create_augroup("precognition", { clear = true }) | |||
|
|||
if type(config.highlightColor) == "table" then | |||
vim.api.nvim_set_hl(ns, "precognition", config.highlightColor) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you're right, this should probably use the global namespace.
Also, mind capitalizing the hlgroup name? I don't think it actually matters, but pascal-case is generally used for hlgroups.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I use the global namespace, it doesn't seem to apply the colors provided. I can see the lightlight is defined, :filter precog highlight
but just with a grey color instead of my defined yellow. However, if I reload the plugin via :Lazy reload precog
(where precog
is the name I gave to the Lazy spec for this plugin), it then uses the correct colors. I can't find anything further on the correct way to do this, after a bit of searching. Any ideas or pointers?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you test the latest refactors i've done. It seems to work for me good now
Thanks for the PR! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR!
lua/precognition/init.lua
Outdated
@@ -355,6 +355,13 @@ function M.setup(opts) | |||
|
|||
ns = vim.api.nvim_create_namespace("precognition") | |||
au = vim.api.nvim_create_augroup("precognition", { clear = true }) | |||
|
|||
if type(config.highlightColor) == "table" then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we drop the if here, and create the highlight group anyways and use it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Possibly. I was trying to support your original implementation of just a highlight string as well as a custom highlight. Really what I wanted was a way to configure some basic colours or styles, and not have to try and find an existing highlight that could change when I changed my colorscheme. Perhaps we could drop support for the string highlight and just take a table and always make a custom highlight group. Internally we can still default to the Comment
styles by just copying them across to the custom highlight.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did some refactoring and dropped the string input
if you want to test it and give any other thoughts i think this is good now!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just some small nits, then looks good to me!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome, lgtm!
Thanks for your help @josh-nz Great idea and only a few tweaks were needed. Brilliant job if you are new |
Is this working for anyone? I'm running into the issue I mentioned here: Not working: Using the global namespace (as per code on
Working: When using the specified namespace, it does apply my config:
I'm running Neovim 0.10.0 if that has any impact. |
Does it not apply any config, eg its plain white text? I can't produce this |
Can you try a hex code. Say #FFFF00 That's what I do in the test which seems to pass Also try foreground as a property. Not fg |
( |
Using some of your config options, like the If you try with my exact config as here: Does it work for you? |
Using Also, when I use the This is a strange intersection of different keys working/not working, and different loading events. I'm not sure I have the time/energy/excitement/whatever to try and debug what appears to be some intersection between Nvim loading lifecycle and Lazy loading lifecycle (even though this doesn't explain why your above config works with You may wish to add a note to the readme that if others are having issues with getting the custom highlight config to work, to refer to this conversation. If I do ever figure it out, I'll comment back here. Otherwise, thanks to you both @tris203 and @willothy for your help and assistance with this PR. |
Interesting. Can you open an issue please @givensuman with neovim version info? |
I got it working, but I'll document the issue here for posterity. $ nvim --version
NVIM v0.10.0
Build type: Release
LuaJIT 2.1.1713484068
Run "nvim -V1 -v" for more info I'm a bit of a Neovim newbie and am using the AstroNvim framework which includes a packaged version of this plugin in it's Astrocommunity repo which was how I was using this plugin when I made the above comment. That addition looks like this in my configuration (specifically, the { import = "astrocommunity.workflow.precognition-nvim" },
{
"tris203/precognition.nvim",
event = "VeryLazy",
config = {
highlightColor = {
foreground = "#FF4499",
},
},
}, I scrubbed that out and manually imported the plugin in a LazySpec file like this (specifically, the {
"tris203/precognition.nvim",
event = "VeryLazy",
opts = {},
config = function()
require("precognition").setup {
highlightColor = {
foreground = "#FF4499",
},
}
end,
}, This seems more likely an AstroNvim issue than a precognition.nvim one, but I'm actually having trouble recreating it to open an issue there. Anyways, thanks for the sweet plugin! |
This adds the ability to define custom colors for the precognition highlight. This allows you to not have to rely in exisiting highlight values. It does this by creating a new highlight if the config for
highlightColor
is a table, otherwise it falls back to using the string specified as the highlight.This is a very quick implementation based on some poking around and the code diff from #28 so it might not be considered good enough as it currently stands. In particular:
@field
type spec for thehighlightColor
now, and as a result the LSP complains that the call tonvim_set_hl
doesn't accept a string, even though we know it is a table.0
instead ofns
as the first argument tonvim_set_hl
and this might be preferable.