lexical-lsp / lexical

Lexical is a next-generation elixir language server
776 stars 77 forks source link

Code Action: Add alias #740

Closed scohen closed 1 month ago

scohen commented 1 month ago

When coding, it is more convenient to type what you mean, and then come back later and clean up things like aliases. This change implements a code action that understands your current editing context and adds aliases as you type. It finds suggestions using our fuzzy matcher (though it has a bit stricter fuzziness), then provides code actions for each suggestion.

It will fix the following alias types:

Foo.Bar.Baz| will result in aliases for modules similar to Baz %Foo.Bar.Baz|{} will result in aliases similar to Baz, but only those that have structs defined in them Foo.Bar.baz.function| will result in aliases for modules with a function with a name similar to function

This PR also pulled a bunch of common code out of orgaize_aliases and moved it to a code mod file, which resulted in organize_aliases having very little code left in it.

Fixes #716

zachallaun commented 1 month ago

Nice!

I don't have time to dig in at the moment, but a couple quick thoughts:

scohen commented 1 month ago

@zachallaun I actually think the newline should be added to the first condition to keep the existing formatting, agreed about where to place an initial alias, I'll write some tests for that.