next-ls
next-ls copied to clipboard
completions: insert alias special form for module alias on completion selection
Description
There should be the possibility to create an alias when selection a module alias as a completion candidate.
- There should be a
textEdit
to insert the last item of the alias instead of the full alias (meaning,Baz
instead ofFoo.Bar.Baz
- There should be an
additionalTextEdit
to insert thealias Foo.Bar.Baz
towards the top of the module. - Optional: There should be configuration to enable/disable this feature. A user should be able to select a completion item without creating the textEdits (I think), as they can choose to expand a snippet or not.
Original request by @kybishop
When you accept a module auto-completion that does not yet have an alias, it is auto-added at the top of the file. This is current behavior in ElixirLS.
Without this, one has to seek out the fully qualified module name, then manually add the alias, a significant time-suck.
A totally killer feature would have it also respect the Credo rules for ordering (which ElixirLS does not do, it just sticks it at the top of the module).
At least for me, this is pretty close to a dealbreaker when trying to switch from ElixirLS (hard to shed time saving features once you've had them).
Feature or not, thank you a ton for all your work on this tool!
I transferred this to the Next LS repo as its an Next LS feature, note an editor extension feature.
Feature or not, thank you a ton for all your work on this tool!
Thank you 😄
To clarify the request, the capability you are looking for is
- start typing module name (aka, an alias)
- you select the completion item (lets say,
Foo.Bar.Baz
) - on selection, the text inserted at the cursor is
Baz
- text is also inserted elsewhere in the file probably at/towards the top of the closest
defmodule
that saysalias Foo.Bar.Baz
Key observations:
- the alias that is in the completion list is one that is available in the current environment (ideally, currently completions aren't contextual), meaning if there is already an alias in the module, say
alias Foo.Bar
,Bar
would appear as completion item, along with submodules likeBar.Baz
. If you were to select this completion item, it would insertBaz
at the cursor andalias Bar.Baz
at the top of the module.
Does that sound right @kybishop?
Yep! That's it exactly.
This is probably an easy enough feature for whomever wants to take a crack