Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add alias as additionalTextEdits #722

Merged

Conversation

ajayvigneshk
Copy link
Contributor

@ajayvigneshk ajayvigneshk commented Aug 27, 2022

Adds alias to the current module as LSP's additional text edits. Essentially this PR attempts to get suggestions as mentioned in #161.

NOTE: The changes on this PR depend on elixir-lsp/elixir_sense#155 (so I've specified that as a dependency over here)

The default sort order of all the modules is not useful on large projects, so some ranking (maybe based on most used modules) would be a good next step.

@@ -25,7 +25,8 @@ defmodule ElixirLS.Debugger.Mixfile do

defp deps do
[
{:elixir_sense, github: "elixir-lsp/elixir_sense"},
{:elixir_sense,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please revert that change

context =
case position_to_insert_alias do
{line_to_insert_alias, column_to_insert_alias} ->
# Don't know why - 1 is needed here
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use SourceFile function for converting positions from utf8 1 besed to utf16 0 based. It's not trivial and it's already solved

},
_options
) do
detail =
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this case is almost identical to existing one, please extract common part

@@ -27,7 +27,8 @@ defmodule ElixirLS.LanguageServer.Mixfile do
defp deps do
[
{:elixir_ls_utils, in_umbrella: true},
{:elixir_sense, github: "elixir-lsp/elixir_sense"},
{:elixir_sense,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please revert that change

mix.lock Outdated
@@ -1,7 +1,7 @@
%{
"dialyxir": {:hex, :dialyxir, "1.1.0", "c5aab0d6e71e5522e77beff7ba9e08f8e02bad90dfbeffae60eaf0cb47e29488", [:mix], [{:erlex, ">= 0.2.6", [hex: :erlex, repo: "hexpm", optional: false]}], "hexpm", "07ea8e49c45f15264ebe6d5b93799d4dd56a44036cf42d0ad9c960bc266c0b9a"},
"docsh": {:hex, :docsh, "0.7.2", "f893d5317a0e14269dd7fe79cf95fb6b9ba23513da0480ec6e77c73221cae4f2", [:rebar3], [{:providers, "1.8.1", [hex: :providers, repo: "hexpm", optional: false]}], "hexpm", "4e7db461bb07540d2bc3d366b8513f0197712d0495bb85744f367d3815076134"},
"elixir_sense": {:git, "https://github.com/elixir-lsp/elixir_sense.git", "08bac2a5a0ad867908d77a7087eac756bf7cce43", []},
"elixir_sense": {:git, "https://github.com/ajayvigneshk/elixir_sense.git", "ac18bb9e1ebb7370907a355c1c7ea85314ed0878", [branch: "find_elixir_mod_requiring_alias"]},
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please revert that change

assert item["kind"] == 22
assert item["label"] == "ExampleStruct (struct)"

assert [%{newText: "alias ElixirLS.LanguageServer.Fixtures.ExampleStruct\n"}] =
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The assertion before using the SourceFile module to convert positions was (notice the leading space characters)

assert [%{newText: "  alias ElixirLS.LanguageServer.Fixtures.ExampleStruct\n"}] =
               item["additionalTextEdits"]

@ajayvigneshk
Copy link
Contributor Author

ajayvigneshk commented Oct 17, 2022

I've done the suggestions. I'm not sure if the tests would succeed without pointing to elixir-sense master

@lukaszsamson lukaszsamson merged commit e996a38 into elixir-lsp:master Nov 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants