mirror of
https://github.com/livebook-dev/livebook.git
synced 2024-09-20 18:15:56 +08:00
Fix identifier details on local calls (#509)
This commit is contained in:
parent
0b5a4da6e2
commit
87b6f6160e
|
@ -47,7 +47,7 @@ defmodule Livebook.Intellisense.IdentifierMatcher do
|
|||
def completion_identifiers(hint, binding, env) do
|
||||
context = cursor_context(hint)
|
||||
ctx = %{binding: binding, env: env, matcher: @prefix_matcher}
|
||||
context_to_matches(context, ctx)
|
||||
context_to_matches(context, ctx, :completion)
|
||||
end
|
||||
|
||||
@doc """
|
||||
|
@ -66,7 +66,7 @@ defmodule Livebook.Intellisense.IdentifierMatcher do
|
|||
case surround_context(line, {1, column}) do
|
||||
%{context: context, begin: {_, from}, end: {_, to}} ->
|
||||
ctx = %{binding: binding, env: env, matcher: @exact_matcher}
|
||||
matches = context_to_matches(context, ctx)
|
||||
matches = context_to_matches(context, ctx, :locate)
|
||||
%{matches: matches, range: %{from: from, to: to}}
|
||||
|
||||
:none ->
|
||||
|
@ -77,7 +77,7 @@ defmodule Livebook.Intellisense.IdentifierMatcher do
|
|||
# Takes a context returned from Code.Fragment.cursor_context
|
||||
# or Code.Fragment.surround_context and looks up matching
|
||||
# identifier items
|
||||
defp context_to_matches(context, ctx) do
|
||||
defp context_to_matches(context, ctx, type) do
|
||||
case context do
|
||||
{:alias, alias} ->
|
||||
match_alias(List.to_string(alias), ctx)
|
||||
|
@ -103,8 +103,11 @@ defmodule Livebook.Intellisense.IdentifierMatcher do
|
|||
{:local_arity, local} ->
|
||||
match_local(List.to_string(local), %{ctx | matcher: @exact_matcher})
|
||||
|
||||
{:local_call, _local} ->
|
||||
match_default(ctx)
|
||||
{:local_call, local} ->
|
||||
case type do
|
||||
:completion -> match_default(ctx)
|
||||
:locate -> match_local(List.to_string(local), %{ctx | matcher: @exact_matcher})
|
||||
end
|
||||
|
||||
{:operator, operator} ->
|
||||
match_local_or_var(List.to_string(operator), ctx)
|
||||
|
|
|
@ -43,6 +43,7 @@ defmodule Livebook.IntellisenseTest do
|
|||
}
|
||||
|
||||
assert length_item in Intellisense.get_completion_items("", binding, env)
|
||||
assert length_item in Intellisense.get_completion_items("to_string(", binding, env)
|
||||
assert length_item in Intellisense.get_completion_items("Enum.map(list, ", binding, env)
|
||||
end
|
||||
|
||||
|
@ -1077,5 +1078,14 @@ defmodule Livebook.IntellisenseTest do
|
|||
assert %{contents: [match_op]} = Intellisense.get_details("x = 1", 3, binding, env)
|
||||
assert match_op =~ "Match operator."
|
||||
end
|
||||
|
||||
test "handles local calls" do
|
||||
{binding, env} = eval(do: nil)
|
||||
|
||||
assert %{contents: [to_string_fn]} =
|
||||
Intellisense.get_details("to_string(1)", 3, binding, env)
|
||||
|
||||
assert to_string_fn =~ "Converts the argument to a string"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue