mirror of
https://github.com/livebook-dev/livebook.git
synced 2025-10-24 12:26:07 +08:00
Fix intellisense crash when hovering over bitstring modifiers (#1917)
This commit is contained in:
parent
3ada5c9146
commit
8e4f3067da
2 changed files with 14 additions and 8 deletions
|
|
@ -393,21 +393,20 @@ defmodule Livebook.Intellisense do
|
||||||
"""
|
"""
|
||||||
@spec get_details(String.t(), pos_integer(), context()) :: Runtime.details_response() | nil
|
@spec get_details(String.t(), pos_integer(), context()) :: Runtime.details_response() | nil
|
||||||
def get_details(line, column, context) do
|
def get_details(line, column, context) do
|
||||||
case IdentifierMatcher.locate_identifier(line, column, context) do
|
%{matches: matches, range: range} = IdentifierMatcher.locate_identifier(line, column, context)
|
||||||
%{matches: []} ->
|
|
||||||
|
case Enum.filter(matches, &include_in_details?/1) do
|
||||||
|
[] ->
|
||||||
nil
|
nil
|
||||||
|
|
||||||
%{matches: matches, range: range} ->
|
matches ->
|
||||||
contents =
|
contents = Enum.map(matches, &format_details_item/1)
|
||||||
matches
|
|
||||||
|> Enum.filter(&include_in_details?/1)
|
|
||||||
|> Enum.map(&format_details_item/1)
|
|
||||||
|
|
||||||
%{range: range, contents: contents}
|
%{range: range, contents: contents}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
defp include_in_details?(%{kind: :function, from_default: true}), do: false
|
defp include_in_details?(%{kind: :function, from_default: true}), do: false
|
||||||
|
defp include_in_details?(%{kind: :bitstring_modifier}), do: false
|
||||||
defp include_in_details?(_), do: true
|
defp include_in_details?(_), do: true
|
||||||
|
|
||||||
defp format_details_item(%{kind: :variable, name: name}), do: code(name)
|
defp format_details_item(%{kind: :variable, name: name}), do: code(name)
|
||||||
|
|
|
||||||
|
|
@ -1285,6 +1285,13 @@ defmodule Livebook.IntellisenseTest do
|
||||||
assert to_string_fn =~ "Converts the argument to a string"
|
assert to_string_fn =~ "Converts the argument to a string"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "returns nil for bitstring modifiers" do
|
||||||
|
context = eval(do: nil)
|
||||||
|
|
||||||
|
assert nil == Intellisense.get_details("<<x :: integer>>", 6, context)
|
||||||
|
assert nil == Intellisense.get_details("<<x :: integer>>", 10, context)
|
||||||
|
end
|
||||||
|
|
||||||
test "includes full module name in the docs" do
|
test "includes full module name in the docs" do
|
||||||
context = eval(do: nil)
|
context = eval(do: nil)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue