wookayin / semshi

šŸŒˆ Semantic Highlighting for Python in Neovim
79 stars 5 forks source link

semshiLocal highlight group not applied #14

Closed freohr closed 11 months ago

freohr commented 12 months ago

After defining custom colors for the various Semshi highlights groups, I noticed that local variables were not highlighted in the expected color, instead remaining the default color for non-highlighted tokens.

Here's a screenshot with colors hint to show the color I expect

image

You can see that semshiLocal is expected to be a pale blue, but in the various functions, local variables (like args and random_table_roller in the main() function) remain the default white, whereas function names are highlighted as semshiGlobal, parameters are highlighted as semshiParameter, etc.

wookayin commented 12 months ago

What does :hi semshiLocal give you? Probably colorscheme setting was done AFTER the config is executed, so the highlight would have been lost. Note that :colorscheme ... resets all the existing highlights.

You can also have the cursor on local variables and try :Inspect (requires nvim 0.9.0+) to see which highlight groups/extmarks are currently applied.

Here is one way you can do:

{
  'wookayin/semshi',
  build = ':UpdateRemotePlugins',
  config = function()
    -- Defines custom user highlight for semshi.
    local function setup_highlight()
      vim.api.nvim_set_hl(0, "semshiLocal", { ctermfg=209, fg="#80aa9e" } )
      vim.api.nvim_set_hl(0, "semshiGlobal", { ctermfg=214, fg="#d3869b" } )
    end
    -- Apply the highlight setting whenever colorscheme changes.
    vim.api.nvim_create_autocmd('Colorscheme', {
      pattern = '*',
      group = vim.api.nvim_create_augroup('semshi_colorscheme', { clear = true }),
      callback = setup_highlight,
    })
    setup_highlight()
  end,
}
freohr commented 11 months ago

The first command gives me this

:hi semshiLocal
semshiLocal    xxx ctermfg=209 guifg=#80aa9e
Press ENTER or type command to continue

which match the values I've put in my config

And for the :Inspect calls

Extmarks

I've wrapped my semshi colors in a function like you suggested, triggered on colorscheme changes, but to no avail as local variables are still not hl'ed.

wookayin commented 11 months ago

Please provide sample source code (minimal reproduction example) and python version you're using for the python3 remote host.

freohr commented 11 months ago

minimalist example, put it in empty python file

def one_function(param):
    local = param
    print(local)

one_function("anything")

using extra/python-pynvim 0.4.3-3 from the Arch package repo, system python version is 3.11.5 (I don't know if pynvim would use another version)

installed semshi info from lazy.nvim

    ā—‹ semshi ļ€–  python
        dir    $HOME/.local/share/nvim/lazy/semshi
        url    https://github.com/wookayin/semshi
        branch master
        commit dbb0861
        readme README.md
        ft     ļ€–  python 
wookayin commented 11 months ago

Did you set g:semshi#excluded_hl_groups = []? Print its value, and local is excluded by default.

README: https://github.com/wookayin/semshi/blob/master/README.md#options

g:semshi#excluded_hl_groups | ['local'] | List of highlight groups not to highlight. Choose fromĀ local,Ā unresolved,Ā attribute,Ā builtin,Ā free,Ā global,Ā parameter,Ā parameterUnused,Ā self,Ā imported. (It's recommended to keepĀ localĀ in the list because highlighting all locals in a large file can cause performance issues.)

freohr commented 11 months ago

g:semshi#excluded_hl_groups = []

Yep that was it, I should have read the doc more closely >.>

Thank you for your support, I'll close this now.