Skip to content

fix(#2415): nvim 0.8 highlight overhaul support, limited to only show highest highlight precedence #2642

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

Merged
merged 3 commits into from
Jan 29, 2024

Conversation

Confidenceman02
Copy link
Contributor

nvim-tree is using nvim_get_hl which was introduced in nvim 0.9 to replace the unstable get_hl_defs in the following commit.

Unfortunately this raises an error in 0.8 nvim versions due to the function not existing.

Failed to run `config` for nvim-tree.lua
...are/nvim/lazy/nvim-tree.lua/lua/nvim-tree/appearance.lua:199: attempt to call field 'nvim_get_hl' (a nil value)
stacktrace:
  - ~/.config/nvim/lua/confidenceman02/plugins/nvim-tree.lua:14 _in_ **config**
  - ~/.config/nvim/lua/confidenceman02/lazy.lua:14
  • Fall back to get_hl_defs when detecting 0.8
  • Set the 'link' property to nil to emulate link = false in builder.lua

nvim-tree is using `nvim_get_hl` which was introduced in nvim 0.9 to
replace the unstable `get_hl_defs` in the following [commit](https://github.com/neovim/neovim/pull/22693/files).

Unfortunately this raises an error in 0.8 nvim versions due to the
function not existing.

```
Failed to run `config` for nvim-tree.lua
...are/nvim/lazy/nvim-tree.lua/lua/nvim-tree/appearance.lua:199: attempt to call field 'nvim_get_hl' (a nil value)
stacktrace:
  - ~/.config/nvim/lua/confidenceman02/plugins/nvim-tree.lua:14 _in_ **config**
  - ~/.config/nvim/lua/confidenceman02/lazy.lua:14
```

- Fall back to get_hl_defs when detecting 0.8
- Set the 'link' property to nil to emulate `link = false` in
  `builder.lua`
local hl
if vim.fn.has "nvim-0.8" == 1 then
hl = vim.api.nvim__get_hl_defs(0)[group] or {}
if hl["link"] then
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check feels a little overkill considering we default to a table. I'm too much of a lua noob to know for sure.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's fine; safety first.

Copy link
Member

@alex-courtis alex-courtis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Many thanks for your work!

Let's invert those conditions, you test on 0.8, I test on 0.9 and we're ready to go.

local hl
if vim.fn.has "nvim-0.8" == 1 then
hl = vim.api.nvim__get_hl_defs(0)[group] or {}
if hl["link"] then
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's fine; safety first.

local hl_to = vim.api.nvim_get_hl(0, { name = to })
local hl_from
local hl_to
if vim.fn.has "nvim-0.8" == 1 then
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately we'll have to invert this condition: nvim-0.8 is true when using 0.9

I discovered this as nvim__get_hl_defs has been completely removed from 0.9. So much for non-breaking changes...

if vim.fn.has "nvim-0.9" == 1 then
name_hl_group = self:create_combined_group(name_groups)
else
name_hl_group = name_groups[#name_groups]
Copy link
Member

@alex-courtis alex-courtis Jan 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no practical API to follow links all the way to the actual definitions, so we don't try.

nvim_get_hl_by_name and nvim__get_hl_defs can't follow the links nor give the right data for the setter. vim.fn.synIDtrans is a very tedious and time consuming method to get the real data and not worth the time.

@alex-courtis alex-courtis changed the title Add support for get_hl_defs in nvim 0.8 fix(#2415): nvim 0.8 highlight overhaul support, limited to only show highest highlight precedence Jan 29, 2024
@alex-courtis
Copy link
Member

alex-courtis commented Jan 29, 2024

Apologies for clobbering your changes; this is on the urgent side.

Many thanks for raising and fixing this!

@alex-courtis alex-courtis merged commit f39f7b6 into nvim-tree:master Jan 29, 2024
juefeiyan pushed a commit to juefeiyan/nvim-tree.lua that referenced this pull request Jan 30, 2024
…only show highest highlight precedence (nvim-tree#2642)

* fix: Add support for get_hl_defs in nvim 0.8

nvim-tree is using `nvim_get_hl` which was introduced in nvim 0.9 to
replace the unstable `get_hl_defs` in the following [commit](https://github.com/neovim/neovim/pull/22693/files).

Unfortunately this raises an error in 0.8 nvim versions due to the
function not existing.

```
Failed to run `config` for nvim-tree.lua
...are/nvim/lazy/nvim-tree.lua/lua/nvim-tree/appearance.lua:199: attempt to call field 'nvim_get_hl' (a nil value)
stacktrace:
  - ~/.config/nvim/lua/confidenceman02/plugins/nvim-tree.lua:14 _in_ **config**
  - ~/.config/nvim/lua/confidenceman02/lazy.lua:14
```

- Fall back to get_hl_defs when detecting 0.8
- Set the 'link' property to nil to emulate `link = false` in
  `builder.lua`

* fix(nvim-tree#2415): nvim 0.8 highlight overhaul support, limited to only show highest highlight precedence

---------

Co-authored-by: Jaime Terreu <[email protected]>
Co-authored-by: Alexander Courtis <[email protected]>
@Confidenceman02
Copy link
Contributor Author

Apologies for clobbering your changes; this is on the urgent side.

Many thanks for raising and fixing this!

Ah nice one!

Yea sorry I was on an extended long, long weekend!

Thanks again.

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 this pull request may close these issues.

2 participants