gleam-lang / gleam

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

LSP code action: Toggle between qualified and unqualified import #3603

Open george-grec opened 3 weeks ago

george-grec commented 3 weeks ago

Currently, when you take a suggested auto import from the LSP for a type like here:

pub fn wibble() {
  Som|
}

and select the Some variant from the gleam/option module you get the following code:

import gleam/option

pub fn wibble() {
  option.Some|
}

In many cases, you actually want to use an unqualified import for a type or variant because you (plan to) use it heavily, e.g. Option, Some, None, lustre elements, Dynamic. To do that right now you have to go to the top of the file and find your way back to where you were. This breaks your developer flow so it would be great if there was a code action when hovering the type or variant to change the import to an unqualified one or vice versa.

lpil commented 3 weeks ago

Great idea!! thank you

AcnoSaga commented 3 weeks ago

I'd love to start hacking on this. Where can I find the LSP code? Still familiarising myself with the codebase.

lpil commented 3 weeks ago

In here! https://github.com/gleam-lang/gleam/blob/main/compiler-core/src/language_server.rs

giacomocavalieri commented 3 weeks ago

Do we want to allow this just for record constructors or for all kind of functions? I think making it easier to use functions unqualified would be a net loss given we want to encourage the opposite style

lpil commented 2 weeks ago

Unqualify: types, record constructors qualify: everything

giacomocavalieri commented 2 weeks ago

Sounds great to me!

Frank-III commented 1 week ago

I'd love to start hacking on this. Where can I find the LSP code? Still familiarising myself with the codebase.

Hi @AcnoSaga, are you still looking into this? if not, I would like to give it a shot!