gleam
gleam copied to clipboard
Adds import completion when writing imports
Closes #2756
Adds module import completion. Includes the modules from dependencies and root package.
Could we have some tests to check that src
can't import test
too please.
Here's the old implementation which was removed: https://github.com/gleam-lang/gleam/commit/00a41a57
Added some more tests and an extra bit to exclude already imported modules. Not sure if you want to get this in now or if you'd prefer to solve the general issue for https://github.com/gleam-lang/gleam/issues/2766 first
Hmmm ok that's annoying. I'll need to spend more time on this/test the full lsp running locally through vs code. It "feels" like there should be an easy way to swap the existing import with the new one if they accept the suggestion without having to do a separate pass. I'll try to come back to this over the week end
The existing system doesn't have the information on the exact current state of the code so it has to be based off of the source text, or everything has to be changed to be fault tolerant.
Ok I think I get what you mean. Yeah I guess we'd have to run the new/changed source and attempt an incomplete parse. For now it could start with just figuring out if we are stopping the parse at an import but eventually we would use this as a base for general fault tolerant parsing. Does that sound right?
I would just scan across the string once until we hit the desired line and then see if it starts with import
.
Ahh fair enough. Probably getting ahead of myself. Lemme try that and get this going
https://github.com/gleam-lang/gleam/assets/5996838/309576dd-3b4c-41e9-a581-017f6336af57
Ok tried out what you suggested and tested it out a bit on local. Seems to work nicely and take into account the current src well. The only kinda "weird" edge case is that since we filter already imported modules if you are deleting/modifying one of your existing imports it won't recommend that one (which seems like reasonable behavior to me but might be confusing)