Skip to content
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

FR: Customize highlight group #49

Open
chrisgrieser opened this issue Jun 6, 2024 · 8 comments · May be fixed by #51
Open

FR: Customize highlight group #49

chrisgrieser opened this issue Jun 6, 2024 · 8 comments · May be fixed by #51

Comments

@chrisgrieser
Copy link

chrisgrieser commented Jun 6, 2024

Currently, we can customize the color of the ghost text suggestions via color in the setup call. (which, btw, is not working for me.) However, that is quite inflexible. For instance, I switch between two themes (light/dark mode), and one color that works in light mode does not work well in dark mode.

A solution for this would be to simply let users link a Highlight group that the suggestions should use. That way, the appearance of the suggestions should follow whatever theme the user switches to. It's also what other plugins commonly do to solve that problem.

@AlejandroSuero
Copy link
Contributor

Is this the expected behaviour @chrisgrieser?

Warning

Flashbang start 👍🏼

switching-from-light-to-dark.mp4

My current config (using lazy.nvim)

-- path/to/plugins/supermaven.lua
return {
  "supermaven-inc/supermaven-nvim",
  lazy = false,
  config = function()
    require("supermaven-nvim").setup({
      keymaps = {
        accept_suggestion = "<S-Tab>",
      },
      color = {
        suggestion_color = "#DC8CE2",
        cterm = 117,
      },
    })
  end,
}

@chrisgrieser
Copy link
Author

Not sure what you mean, but from the config in your video, I actually figured out that the respective highlight group is exported and can therefore be configured via this:

require("supermaven-nvim.completion_preview").suggestion_group

So for me personally, this solves it, though nonetheless it would be more user-friendly, if the highlight group could be customizable directly in the settings.

@AlejandroSuero
Copy link
Contributor

What I meant is that with the config I am using it detects the color I changed it to be even when changing from a dark colorscheme to a light one.

My question would be, if what you want is to persist the same color for both dark and light or change them depending on the colorscheme.

From what I am understanding is that you want for example the ghost text to be link to for example the group Comment and take the coloscheme's color for Comment.

If that is the case I think of 2 simple solutions.

  • Expose the suggestion_group in the config settings.
  • Create an override function like colorschemes usually do to change the highlight groups.

@chrisgrieser
Copy link
Author

Exposing suggestion_group is what I meant to suggest. It's also the method most plugins use when configuring their appearance.

AlejandroSuero added a commit to AlejandroSuero/supermaven-nvim that referenced this issue Jun 6, 2024
@AlejandroSuero
Copy link
Contributor

@chrisgrieser I made the changes in #51, tell your thoughts about it and test it if you want.

@chrisgrieser
Copy link
Author

chrisgrieser commented Jun 6, 2024

@AlejandroSuero thanks for the implementation!

There seems to be an issue that initially, supermaven uses the wrong color, a problem that does not occur when I use require("supermaven-nvim.completion_preview").suggestion_group = "NonText".

I think when supermaven is loaded after the colorscheme is set, the callback here is never called. However, when loading the colorscheme after supermaven has been loaded, the correct color is displayed. I think running the callback function once on manually on initialization might solve this already.

@AlejandroSuero
Copy link
Contributor

@chrisgrieser I logged out the callback with:

print("setting suggestion group")
print(config.color.suggestion_group)

Here are the results:

suggestion_group-log.mp4

Is getting called in every VimEnter event or ColorScheme event.

When logging out the event I get the following:

setting suggestion group NonText
event {
  buf = 1,
  event = "ColorScheme",
  file = "",
  group = 18,
  id = 46,
  match = "astrodark"
}
setting suggestion group NonText
event {
  buf = 1,
  event = "VimEnter",
  file = "",
  group = 18,
  id = 46,
  match = ""
}

Every time the colorscheme is change it will call the callback function with the event.event = "ColorScheme".

@AlejandroSuero
Copy link
Contributor

@chrisgrieser if I change my plugin to load on event = "VeryLazy" it won't be called unless I change the colorscheme. Maybe this is what you are experiencing.

I am going to ask in the PR itself if I should change it so it can be load with that behaviour in mind or create another PR with those changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants