lexical-lsp / lexical

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

Fix the interference issue caused by organizing aliases. #761

Open scottming opened 1 month ago

scottming commented 1 month ago

When I'm writing functions, I occasionally need to handle unused variables, but I find that organizing aliases still returns results. This causes a lot of interference, especially when there's a bug in nvim, as pressing keys quickly can mess up my code.

CleanShot 2024-06-01 at 10 19 06@2x

We should not return the results of organizing aliases when the cursor is not on a line with an alias or when the current token is not an alias.

scohen commented 4 weeks ago

I would also like organize aliases to show up if you're inside of a scope with aliases, for example

defmodule WithAliases do
  alias Foo.Bar
  alias Baz.Quux

  |
end
scottming commented 4 weeks ago

I would also like organize aliases to show up if you're inside of a scope with aliases, for example

Do you have any suggestions regarding the implementation for it? It seems to conflict somewhat with the goals of this PR. @scohen

scohen commented 3 weeks ago

the implementation would be something like:

  1. Get the scope of the cursor
  2. determine if the immediate parent is a module
  3. determine if that module has any aliases
scottming commented 3 weeks ago

determine if the immediate parent is a module

Checking this is a bit cumbersome because its ancestors include these before reaching defmodule.

{:__block__, [],
{{:__block__, [line: 1, column: 17], [:do]},
{{:__block__, [line: 1, column: 17], [:do]},

so I think maybe we could just check that both before and after the current cursor are blanks.

scohen commented 2 weeks ago

Checking this is a bit cumbersome because its ancestors include these before reaching

This feels like a problem that can be solved.

scohen commented 2 weeks ago

(also, blocks are annoying)

scottming commented 1 week ago

This feels like a problem that can be solved.

Please take a look when you have a chance. The block is really annoying, but I think the last commit has limited room for improvement.