FR: Customize highlight group #49

Open
opened 2024-06-06 10:55:21 -04:00 by chrisgrieser · 8 comments
chrisgrieser commented 2024-06-06 10:55:21 -04:00 (Migrated from github.com)

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.

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 2024-06-06 15:29:00 -04:00 (Migrated from github.com)

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,
}
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](https://github.com/folke/lazy.nvim)) ```lua -- 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 2024-06-06 17:30:40 -04:00 (Migrated from github.com)

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.

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: ```lua 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 2024-06-06 17:56:23 -04:00 (Migrated from github.com)

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.
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 commented 2024-06-06 18:36:12 -04:00 (Migrated from github.com)

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

Exposing `suggestion_group` is what I meant to suggest. It's also the method most plugins use when configuring their appearance.
AlejandroSuero commented 2024-06-06 19:25:54 -04:00 (Migrated from github.com)

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

@chrisgrieser I made the changes in #51, tell your thoughts about it and test it if you want.
chrisgrieser commented 2024-06-06 19:41:13 -04:00 (Migrated from github.com)

@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 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](https://github.com/supermaven-inc/supermaven-nvim/pull/51/files#diff-69a952b052fdfa06145a3165f1df6b4ef940b6ae5ef5c5c4c9f4ae35ae12b2f6R47) 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 2024-06-06 20:03:09 -04:00 (Migrated from github.com)

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

@chrisgrieser I logged out the callback with: ```lua 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: ```vim 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 2024-06-06 20:07:16 -04:00 (Migrated from github.com)

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

@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 in to join this conversation.
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
supermaven-inc/supermaven-nvim#49
No description provided.