gleam icon indicating copy to clipboard operation
gleam copied to clipboard

Adds import completion when writing imports

Open Acepie opened this issue 11 months ago • 2 comments

Closes #2756

Adds module import completion. Includes the modules from dependencies and root package.

Acepie avatar Mar 19 '24 02:03 Acepie

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

lpil avatar Mar 19 '24 10:03 lpil

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

Acepie avatar Mar 19 '24 14:03 Acepie

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

Acepie avatar Mar 21 '24 13:03 Acepie

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.

lpil avatar Mar 21 '24 13:03 lpil

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?

Acepie avatar Mar 21 '24 14:03 Acepie

I would just scan across the string once until we hit the desired line and then see if it starts with import.

lpil avatar Mar 22 '24 15:03 lpil

Ahh fair enough. Probably getting ahead of myself. Lemme try that and get this going

Acepie avatar Mar 22 '24 15:03 Acepie

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)

Acepie avatar Mar 22 '24 23:03 Acepie