Skip to content

Commit

Permalink
adopt elixir_sense changes
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaszsamson committed Apr 21, 2024
1 parent e24db35 commit 8486de4
Show file tree
Hide file tree
Showing 15 changed files with 45 additions and 66 deletions.
3 changes: 1 addition & 2 deletions apps/elixir_ls_utils/lib/completion_engine.ex
Original file line number Diff line number Diff line change
Expand Up @@ -484,8 +484,7 @@ defmodule ElixirLS.Utils.CompletionEngine do
match_module_funs(env.module, hint, exact?, false, :all, env, metadata, cursor_position)

imported_locals =
env.imports
|> Introspection.expand_imports(metadata.mods_funs_to_positions)
{env.functions, env.macros}
|> Introspection.combine_imports()
|> Enum.flat_map(fn {scope_import, imported} ->
match_module_funs(
Expand Down
32 changes: 4 additions & 28 deletions apps/elixir_ls_utils/test/complete_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@ defmodule ElixirLS.Utils.CompletionEngineTest do

def expand(
expr,
env \\ %Env{
imports: [{Kernel, []}]
},
env \\ %Env{functions: :elixir_env.new().functions, macros: :elixir_env.new().macros},
metadata \\ %Metadata{},
opts \\ []
) do
Expand Down Expand Up @@ -1237,34 +1235,26 @@ defmodule ElixirLS.Utils.CompletionEngineTest do
metadata = %Metadata{
mods_funs_to_positions: %{
{MyModule, nil, nil} => %ModFunInfo{type: :defmodule},
{MyModule, :my_fun_priv, nil} => %ModFunInfo{type: :defp},
{MyModule, :my_fun_priv, 2} => %ModFunInfo{
type: :defp,
params: [[{:some, [], nil}, {:other, [], nil}]]
},
{MyModule, :my_fun_pub, nil} => %ModFunInfo{type: :def},
{MyModule, :my_fun_pub, 1} => %ModFunInfo{type: :def, params: [[{:some, [], nil}]]},
{MyModule, :my_macro_priv, nil} => %ModFunInfo{type: :defmacrop},
{MyModule, :my_macro_priv, 1} => %ModFunInfo{
type: :defmacrop,
params: [[{:some, [], nil}]]
},
{MyModule, :my_macro_pub, nil} => %ModFunInfo{type: :defmacro},
{MyModule, :my_macro_pub, 1} => %ModFunInfo{type: :defmacro, params: [[{:some, [], nil}]]},
{MyModule, :my_guard_priv, nil} => %ModFunInfo{type: :defguardp},
{MyModule, :my_guard_priv, 1} => %ModFunInfo{
type: :defguardp,
params: [[{:some, [], nil}]]
},
{MyModule, :my_guard_pub, nil} => %ModFunInfo{type: :defguard},
{MyModule, :my_guard_pub, 1} => %ModFunInfo{type: :defguard, params: [[{:some, [], nil}]]},
{MyModule, :my_delegated, nil} => %ModFunInfo{type: :defdelegate},
{MyModule, :my_delegated, 1} => %ModFunInfo{
type: :defdelegate,
params: [[{:some, [], nil}]]
},
{OtherModule, nil, nil} => %ModFunInfo{},
{OtherModule, :my_fun_pub_other, nil} => %ModFunInfo{type: :def},
{OtherModule, :my_fun_pub_other, 1} => %ModFunInfo{
type: :def,
params: [[{:some, [], nil}]]
Expand Down Expand Up @@ -1318,18 +1308,16 @@ defmodule ElixirLS.Utils.CompletionEngineTest do
test "complete remote funs from imported module" do
env = %Env{
module: MyModule,
imports: [{OtherModule, []}, {Kernel, []}]
functions: [{OtherModule, [{:my_fun_other_pub, 1}]}]
}

metadata = %Metadata{
mods_funs_to_positions: %{
{OtherModule, nil, nil} => %ModFunInfo{type: :defmodule},
{OtherModule, :my_fun_other_pub, nil} => %ModFunInfo{type: :def},
{OtherModule, :my_fun_other_pub, 1} => %ModFunInfo{
type: :def,
params: [[{:some, [], nil}]]
},
{OtherModule, :my_fun_other_priv, nil} => %ModFunInfo{type: :defp},
{OtherModule, :my_fun_other_priv, 1} => %ModFunInfo{
type: :defp,
params: [[{:some, [], nil}]]
Expand All @@ -1345,13 +1333,12 @@ defmodule ElixirLS.Utils.CompletionEngineTest do
test "complete remote funs from imported module - needed import" do
env = %Env{
module: MyModule,
imports: [{OtherModule, [only: [{:my_fun_other_pub, 1}]]}, {Kernel, []}]
functions: [{OtherModule, [{:my_fun_other_pub, 1}]}]
}

metadata = %Metadata{
mods_funs_to_positions: %{
{OtherModule, nil, nil} => %ModFunInfo{type: :defmodule},
{OtherModule, :my_fun_other_pub, nil} => %ModFunInfo{type: :def},
{OtherModule, :my_fun_other_pub, 1} => %ModFunInfo{
type: :def,
params: [[{:some, [], nil}]]
Expand All @@ -1360,7 +1347,6 @@ defmodule ElixirLS.Utils.CompletionEngineTest do
type: :def,
params: [[{:some, [], nil}]]
},
{OtherModule, :my_fun_other_priv, nil} => %ModFunInfo{type: :defp},
{OtherModule, :my_fun_other_priv, 1} => %ModFunInfo{
type: :defp,
params: [[{:some, [], nil}]]
Expand All @@ -1386,12 +1372,10 @@ defmodule ElixirLS.Utils.CompletionEngineTest do
metadata = %Metadata{
mods_funs_to_positions: %{
{Some.OtherModule, nil, nil} => %ModFunInfo{type: :defmodule},
{Some.OtherModule, :my_fun_other_pub, nil} => %ModFunInfo{type: :def},
{Some.OtherModule, :my_fun_other_pub, 1} => %ModFunInfo{
type: :def,
params: [[{:some, [], nil}]]
},
{Some.OtherModule, :my_fun_other_priv, nil} => %ModFunInfo{type: :defp},
{Some.OtherModule, :my_fun_other_priv, 1} => %ModFunInfo{
type: :defp,
params: [[{:some, [], nil}]]
Expand All @@ -1413,12 +1397,10 @@ defmodule ElixirLS.Utils.CompletionEngineTest do
metadata = %Metadata{
mods_funs_to_positions: %{
{Some.OtherModule, nil, nil} => %ModFunInfo{type: :defmodule},
{Some.OtherModule, :my_fun_other_pub, nil} => %ModFunInfo{type: :def},
{Some.OtherModule, :my_fun_other_pub, 1} => %ModFunInfo{
type: :def,
params: [[{:some, [], nil}]]
},
{Some.OtherModule, :my_fun_other_priv, nil} => %ModFunInfo{type: :defp},
{Some.OtherModule, :my_fun_other_priv, 1} => %ModFunInfo{
type: :defp,
params: [[{:some, [], nil}]]
Expand Down Expand Up @@ -1465,12 +1447,10 @@ defmodule ElixirLS.Utils.CompletionEngineTest do
metadata = %Metadata{
mods_funs_to_positions: %{
{Some.OtherModule, nil, nil} => %ModFunInfo{type: :defmodule},
{Some.OtherModule, :my_fun_other_pub, nil} => %ModFunInfo{type: :def},
{Some.OtherModule, :my_fun_other_pub, 1} => %ModFunInfo{
type: :def,
params: [[{:some, [], nil}]]
},
{Some.OtherModule, :my_fun_other_priv, nil} => %ModFunInfo{type: :defp},
{Some.OtherModule, :my_fun_other_priv, 1} => %ModFunInfo{
type: :defp,
params: [[{:some, [], nil}]]
Expand Down Expand Up @@ -1529,8 +1509,7 @@ defmodule ElixirLS.Utils.CompletionEngineTest do
metadata = %Metadata{
mods_funs_to_positions: %{
{MyKeyword, nil, nil} => %ModFunInfo{type: :defmodule},
{MyKeyword, :values1, 0} => %ModFunInfo{type: :def, params: [[]]},
{MyKeyword, :values1, nil} => %ModFunInfo{type: :def}
{MyKeyword, :values1, 0} => %ModFunInfo{type: :def, params: [[]]}
}
}

Expand Down Expand Up @@ -1826,10 +1805,8 @@ defmodule ElixirLS.Utils.CompletionEngineTest do
metadata = %Metadata{
mods_funs_to_positions: %{
{MyModule, nil, nil} => %ModFunInfo{type: :defmodule},
{MyModule, :module_info, nil} => %ModFunInfo{type: :def},
{MyModule, :module_info, 0} => %ModFunInfo{type: :def, params: [[]]},
{MyModule, :module_info, 1} => %ModFunInfo{type: :def, params: [[{:atom, [], nil}]]},
{MyModule, :__info__, nil} => %ModFunInfo{type: :def},
{MyModule, :__info__, 1} => %ModFunInfo{type: :def, params: [[{:atom, [], nil}]]}
}
}
Expand Down Expand Up @@ -2167,7 +2144,6 @@ defmodule ElixirLS.Utils.CompletionEngineTest do
metadata = %Metadata{
mods_funs_to_positions: %{
{MyModule, nil, nil} => %ElixirSense.Core.State.ModFunInfo{},
{MyModule, :info, nil} => macro_info,
{MyModule, :info, 1} => macro_info
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ defmodule ElixirLS.LanguageServer.Providers.Completion.Reducers.Params do
prefix = cursor_context.text_before

%State.Env{
imports: imports,
requires: requires,
aliases: aliases,
module: module,
Expand All @@ -51,7 +50,8 @@ defmodule ElixirLS.LanguageServer.Providers.Completion.Reducers.Params do
{mod, fun, true, :mod_fun} <-
Introspection.actual_mod_fun(
{mod, fun},
imports,
env.functions,
env.macros,
requires,
if(elixir_prefix, do: [], else: aliases),
module,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ defmodule ElixirLS.LanguageServer.Providers.Completion.Reducers.Struct do
module: module,
vars: vars,
attributes: attributes,
imports: imports,
aliases: aliases
} = env

Expand All @@ -70,7 +69,8 @@ defmodule ElixirLS.LanguageServer.Providers.Completion.Reducers.Struct do
attributes: attributes,
variables: vars,
structs: structs,
imports: imports,
functions: env.functions,
macros: env.macros,
current_module: module,
specs: specs,
types: metadata_types,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,6 @@ defmodule ElixirLS.LanguageServer.Providers.Definition.Locator do
) do
%State.Env{
module: current_module,
imports: imports,
requires: requires,
aliases: aliases,
scope: scope
Expand All @@ -212,7 +211,8 @@ defmodule ElixirLS.LanguageServer.Providers.Definition.Locator do

case {m, function}
|> Introspection.actual_mod_fun(
imports,
env.functions,
env.macros,
requires,
aliases,
current_module,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,16 @@ defmodule ElixirLS.LanguageServer.Providers.ExecuteCommand.ExpandMacro do
do_expand_full(code, env)
end

def do_expand_full(code, %State.Env{requires: requires, imports: imports, module: module}) do
def do_expand_full(code, %State.Env{} = env) do
# TODO function and other
env =
%Macro.Env{macros: __ENV__.macros}
|> Ast.set_module_for_env(module)
|> Ast.add_requires_to_env(requires)
|> Ast.add_imports_to_env(imports)
%Macro.Env{
macros: env.macros,
functions: env.functions,
module: env.module,
requires: env.requires,
aliases: env.aliases
}

try do
{:ok, expr} = code |> Code.string_to_quoted()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,8 @@ defmodule ElixirLS.LanguageServer.Providers.Hover.Docs do
{Binding.expand(binding_env, mod), fun}
|> expand(env.aliases)
|> Introspection.actual_mod_fun(
env.imports,
env.functions,
env.macros,
env.requires,
env.aliases,
env.module,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,15 +253,15 @@ defmodule ElixirLS.LanguageServer.Providers.Implementation.Locator do
) do
%State.Env{
module: current_module,
imports: imports,
requires: requires,
aliases: aliases,
scope: scope
} = env

case {module, function}
|> Introspection.actual_mod_fun(
imports,
env.functions,
env.macros,
requires,
aliases,
current_module,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ defmodule ElixirLS.LanguageServer.Plugins.Util do

def actual_mod_fun({mod, fun}, elixir_prefix, env, buffer_metadata) do
%State.Env{
imports: imports,
requires: requires,
aliases: aliases,
module: module,
Expand All @@ -51,7 +50,8 @@ defmodule ElixirLS.LanguageServer.Plugins.Util do

Introspection.actual_mod_fun(
{mod, fun},
imports,
env.functions,
env.macros,
requires,
if(elixir_prefix, do: [], else: aliases),
module,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ defmodule ElixirLS.LanguageServer.Providers.References.Locator do
def find(
context,
%State.Env{
imports: imports,
requires: requires,
aliases: aliases,
module: module,
Expand All @@ -119,7 +118,8 @@ defmodule ElixirLS.LanguageServer.Providers.References.Locator do
{mod, function}
|> expand(binding_env, module, aliases)
|> Introspection.actual_mod_fun(
imports,
env.functions,
env.macros,
requires,
aliases,
module,
Expand Down Expand Up @@ -149,7 +149,8 @@ defmodule ElixirLS.LanguageServer.Providers.References.Locator do
|> wrap_atom
|> expand(binding_env, module, aliases)
|> Introspection.actual_mod_fun(
env.imports,
env.functions,
env.macros,
env.requires,
env.aliases,
env.module,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ defmodule ElixirLS.LanguageServer.Providers.SignatureHelp.Signature do
signature_info | :none
def find(prefix, cursor_position, env, metadata) do
%State.Env{
imports: imports,
requires: requires,
aliases: aliases,
module: module,
Expand All @@ -50,7 +49,8 @@ defmodule ElixirLS.LanguageServer.Providers.SignatureHelp.Signature do
{mod, fun, true, kind} <-
Introspection.actual_mod_fun(
{m, f},
imports,
env.functions,
env.macros,
requires,
if(elixir_prefix, do: [], else: aliases),
module,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ defmodule ElixirLS.LanguageServer.Plugins.Phoenix.ScopeTest do
}
],
current_module: ExampleWeb.Router,
imports: [{Kernel, []}, {Phoenix.Router, []}],
specs: %{},
types: %{},
mods_funs: %{}
Expand Down Expand Up @@ -98,7 +97,6 @@ defmodule ElixirLS.LanguageServer.Plugins.Phoenix.ScopeTest do
],
attributes: [],
current_module: ExampleWeb.Router,
imports: [{Kernel, []}, {Phoenix.Router, []}],
specs: %{},
types: %{},
mods_funs: %{}
Expand Down
22 changes: 11 additions & 11 deletions apps/language_server/test/providers/references/locator_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -1657,6 +1657,13 @@ defmodule ElixirLS.LanguageServer.Providers.References.LocatorTest do

test "find references of public metadata functions from definition", %{trace: trace} do
buffer = """
defmodule MyCalleeModule.Some do
def public_fun do
# ^
:ok
end
end
defmodule MyModule do
def calls_public do
MyCalleeModule.Some.public_fun()
Expand All @@ -1672,21 +1679,14 @@ defmodule ElixirLS.LanguageServer.Providers.References.LocatorTest do
public_fun()
end
end
defmodule MyCalleeModule.Some do
def public_fun do
# ^
:ok
end
end
"""

references = Locator.references(buffer, 18, 15, trace)
references = Locator.references(buffer, 2, 15, trace)

assert references == [
%{uri: nil, range: %{start: %{line: 3, column: 25}, end: %{line: 3, column: 35}}},
%{uri: nil, range: %{start: %{line: 8, column: 10}, end: %{line: 8, column: 20}}},
%{uri: nil, range: %{start: %{line: 13, column: 5}, end: %{line: 13, column: 15}}}
%{uri: nil, range: %{start: %{line: 10, column: 25}, end: %{line: 10, column: 35}}},
%{uri: nil, range: %{start: %{line: 15, column: 10}, end: %{line: 15, column: 20}}},
%{uri: nil, range: %{start: %{line: 20, column: 5}, end: %{line: 20, column: 15}}}
]
end

Expand Down
2 changes: 1 addition & 1 deletion dep_versions.exs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[
elixir_sense: "33c9113324a6ed716612499afcfef2c3049730d6",
elixir_sense: "ec46edb5475d61769839b1945546c5520d1a53f3",
dialyxir_vendored: "d50dcd7101c6ebd37b57b7ee4a7888d8cb634782",
jason_v: "c81537e2a5e1acacb915cf339fe400357e3c2aaa",
erl2ex_vendored: "073ac6b9a44282e718b6050c7b27cedf9217a12a",
Expand Down
Loading

0 comments on commit 8486de4

Please sign in to comment.