-
-
Notifications
You must be signed in to change notification settings - Fork 45
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
Add more LuaLS types for better LSP info #54
Conversation
I am all in favour of more type hints, but I think you went a bit too far in typing out everything.
I don't think we need to type-check arbitrary strings. This is already handled by
How would your suggestion handle language names we don't have registered in the plugin?
This is a whole can of worms I have been kicking down the road. If the user calls a I will have to look into this issue deeper because my code still does
Can the language server handle
I would rather know why
Please, no more rewrites :( Yeah, |
This is really more of a draft where I played around with the types a bit. I plan to clean up everything a bit more soon. The main focus is what I did in
I am not really including the types for the strings in e.g. Do you not think it is worth it to include a list of the language strings to give you completions?
Ok, for now I will remove this code from this pull request then. It sounds like we should think about that more.
LuaLS can handle
I will remove
I don't plan on doing work towards a rewrite either. :/ It was more of a general comment. I will add some of the updates later tonight. |
I have cleaned up this draft a bit now (removed superfluous type annotations and removed the Please let me know if there is anything in the types you would want me to simplify or remove. I think the current setup in |
d7802fa
to
7c62fe2
Compare
I have reviewed all changes except for |
I thought it was mostly minor things that might as well be included here, but if you prefer I can quickly move the small cleanup stuff to another pull request. Update: Since I saw the error in #59 affected some people, I made a separate pull request with the small cleanup stuff. That pull request should fix that issue too. |
How does the file |
neodev should ensure that everything is set up correctly for all plugins by default. Without neodev I think you need to set your runtime path correctly in a |
Sorry the sync on this branch got messed up. I will fix it soon. Update: It should be fixed now. |
I'm done with |
Two notes:
|
In that case I guess |
Also, should we maybe add a note in the docs and/or README about making sure to set up the LSP correctly (e.g. via Neodev)? |
I don't think so. People either already know how to set up the Lua language server correctly, in which case that's just noise, or they don't, in which case that's just useless and confusing bloat. I feel the same about plugin installation instructions that list standard code snippets for five different plugin managers, when it should be just one sentence that says "install it like any other plugin". Unless the plugin has special requirements (compiled binary, dependencies, extra configuration steps) of course. Maybe my brain is wired differently, but when I keep seeing the same text over and over again by brain starts to block out that boilerplate, and that's when mistakes are made because there was one time where it was actually useful, but I did not see it. |
I have removed the class definition for the plugin library. The language server can derive the type of all fields from their values, and we never pass the table to any other function. Is there something that would work better if we had a separate class for the table? |
I don't really like that we have to list all supported languages three times. I tried this annotations:
In my mind this should work, the key type is |
I have removed the type for highlight groups. People will either use the default list, in which case they don't need auto-completion, or they will use custom highlight groups from some theme, in which case the auto-completion is actually counter-productive. |
From what I can tell this doesn't make anything worse than before, so it makes sense to remove it, yes. Update: Actually the completions don't seem to work as well for me with this setup when choosing e.g. global via the enter key inside |
I have nothing else to add, so if you are done as well let's squash and merge everything.
Yes, I noticed it as well, but it should be handled by the language server. |
It is hard to avoid multiple "duplicate" types like the current setup, because LuaLS doesn't really allow us to construct the types programatically. I don't know any good way than the current definitions that gives us proper completions. Something like ---@class rainbow_delimiters.config.strategies
---@field [''] (rainbow_delimiters.strategy | fun(): rainbow_delimiters.strategy?)?
---@field [rainbow_delimiters.language] (rainbow_delimiters.strategy | fun(): rainbow_delimiters.strategy?)? should give the correct type checks, but not the correct completions, which I think is a big part of the help from the LSP, and I think it is probably the same for what you wrote; you will get the type checks but not completions. |
I have squashed it now. |
One note before you commit it: If we write Update: The Cleanup commit shows what I mean. I can squash it again if you are fine with that change? |
Either way is fine by me. I like |
Okay, I have made it |
I added a note on types to |
Co-authored-by: Alejandro Sanchez <[email protected]>
I added the luadoc types mentioned above now. |
I have merged it now, thank you. |
I added a lot of type information, so we can get proper LSP information when setting up the plugin:
I also made a few other small edits that might be worth discussing. Here is a list of things to think about before this is ready to be committed:
vim
misspelled asvin
is still a string. We could change this or see if there is some good workaround. (Spelling mistakes will be caught by:checkhealth
, so we should be good with the current code.)setup
inrainbow-delimiters.lua
, I have added an__index
meta method for now. This is a temporary solution, that I think should make lazy work as expected, but I am not sure if that is a good solution. I assume you would still like to avoid puttingsetup
inrainbow-delimiters.lua
? (Think about this later.)integer
instead ofnumber
for stuff likebufnr
(or anything else that you know is an integer). Do you want to changenumber
tointeger
or leave it as it is now? (Yes, useinteger
.)'comment'
to the blacklist, since that seems like a good idea based on [Bug]: Some comments cause neovim to slow down and freeze when present with this plugin #53. I can remove it again, if you prefer? (Remove it for now and instead investigate whycomment
causes problems.)Other notes:
['<name>']
in a Lua table (like['local']
or['']
).vim.g.rainbow_delimiters
should be of typerainbow_delimiters.config
. So for now a user of the plugin will have to add---@type rainbow_delimiters.config
beforevim.g.rainbow_delimiters
to get the LSP to work as expected. I have added this to the docs for now, but we can remove it if we figure out how to avoid this step. If you use the setup function the type is already correct now without the user adding anything.