next-ls icon indicating copy to clipboard operation
next-ls copied to clipboard

completions: insert alias special form for module alias on completion selection

Open kybishop opened this issue 4 months ago • 4 comments

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 of Foo.Bar.Baz
  • There should be an additionalTextEdit to insert the alias 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!

kybishop avatar Feb 20 '24 18:02 kybishop

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 😄

mhanberg avatar Feb 20 '24 20:02 mhanberg

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 says alias 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 like Bar.Baz. If you were to select this completion item, it would insert Baz at the cursor and alias Bar.Baz at the top of the module.

Does that sound right @kybishop?

mhanberg avatar Feb 20 '24 20:02 mhanberg

Yep! That's it exactly.

kybishop avatar Feb 20 '24 21:02 kybishop

This is probably an easy enough feature for whomever wants to take a crack

mhanberg avatar Feb 21 '24 01:02 mhanberg