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