rktjmp / lush.nvim

Create Neovim themes with real-time feedback, export anywhere.
MIT License
1.44k stars 47 forks source link

Suggestions for handling of linting of the "globals" for each of the highlight groups? #61

Closed megalithic closed 3 years ago

megalithic commented 3 years ago

I love this project with lush.nvim. Thank you!

My question/issue is mostly around how we might handle all of the "globals" that end up being "undefined" for each of the highlight groups that are defined.

I realize this question is out of scope of this project, I'm more just curious how you, and/or contributors/users of this project and lush.nvim might be handling this.

Thanks!

rktjmp commented 3 years ago

I am not sure we really can do much.

Packer does some similar stuff to Lush, in terms of setting up a DSL environment, they let you inject a use function so the linter/lsp can see something.

Note that if you get linter complaints about use being an undefined global, these errors are spurious - packer injects use into the scope of the function passed to startup. If these errors bother you, the easiest fix is to simply specify use as an argument to the function you pass to startup, e.g.

packer.startup(function(use)
...your config...
end)

Not sure how appropriate that would be in Lush, you would end up with something like spec.Normal { ... }, but I already have some vague ideas for injection for other things #36 which are theoretically more useful than just avoiding linter errors.

It would be great if you could just hint sumneko/etc to ignore certain things via a comment, like how you can tell it that vim is a global but I've never gotten around to looking into it.

rktjmp commented 3 years ago

Personally I just ignore the warnings or disable the LSP/Linter which isn't a great solution...

rktjmp commented 3 years ago

https://github.com/sumneko/lua-language-server/wiki/EmmyLua-Annotations#diagnostic

This is listed on the sumneko wiki, but also listed under EmmyLua, so probably works in both, at least theoretically. When I try them they don't work.

It does make me wonder if :Lushify can maybe inject known globals into the LSP somehow when it runs.

rktjmp commented 3 years ago

Actually seems that I just had to update sumneko, so this should work:

---@diagnostic disable: undefined-global
local theme = lush(function() ...
rktjmp commented 3 years ago

Fixed https://github.com/rktjmp/lush.nvim/commit/71adf072e8c55dfbf010045b34ae0b761a2200e7 https://github.com/rktjmp/lush-template/commit/d0aded25861cebcc0c93eedc7a039254eeb03157 if you're using the latest sumneko server and probably emmylua.