gleam-lang / gleam

⭐️ A friendly language for building type-safe, scalable systems!
https://gleam.run
Apache License 2.0
16.44k stars 688 forks source link

LSP code action: import module #3258

Open gusinacio opened 3 weeks ago

gusinacio commented 3 weeks ago

Right now, if I use a module that exists but was not imported yet I receive an error message:

Unknown module

No module has been found with name `<name>`.

It would be great if we could import directly using a code action

lpil commented 2 weeks ago

I think that's the error for when you have imported a module but there is no module with that name. Would it be a code action that edits the import to the one that exists with the closest name?

gusinacio commented 2 weeks ago

See the following example:

pub fn main() {
  io.print("Hello world")
}

I haven't imported gleam/io yet and that's why I receive the "Unknown module" error.

I'd like to go with my cursor over the io and have a code action to import it from gleam/io or other module suggestions.

johtso commented 2 weeks ago

Should this be quite straightforward now that we have this? https://github.com/gleam-lang/gleam/pull/3219

Acepie commented 2 weeks ago

I'd like to go with my cursor over the io and have a code action to import it from gleam/io or other module suggestions.

FWIW the behavior you are describing here is almost exactly what the new completion behavior is with #3219 though it still has that issue with duplicating the module name. That being said, once #3240 is merged I think this can be closed as completed

lpil commented 2 weeks ago

I think it could still be useful to have a code action for when you did not use the autocompletion, though not as high a priority.

johtso commented 2 weeks ago

I agree, lots of situations where you copy and paste code and need to add imports, rather than typing the code and tab completing