supermaven-inc / supermaven-nvim

The official Neovim plugin for Supermaven
https://supermaven.com/
MIT License
279 stars 16 forks source link

FR: Customize highlight group #49

Open chrisgrieser opened 4 weeks ago

chrisgrieser commented 4 weeks ago

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 commented 4 weeks ago

Is this the expected behaviour @chrisgrieser?

[!WARNING] Flashbang start 👍🏼

https://github.com/supermaven-inc/supermaven-nvim/assets/71392160/133fad02-58a1-4458-b31e-e5efe7e8a915

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 commented 4 weeks ago

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 commented 4 weeks ago

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.

chrisgrieser commented 4 weeks ago

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

AlejandroSuero commented 4 weeks ago

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

chrisgrieser commented 4 weeks ago

@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 commented 4 weeks ago

@chrisgrieser I logged out the callback with:

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

Here are the results:

https://github.com/supermaven-inc/supermaven-nvim/assets/71392160/fc88870f-ad99-4bfc-b84e-d21d9a8783b0

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 commented 4 weeks ago

@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.