Fix intellisense crash when hovering over bitstring modifiers (#1917)

This commit is contained in:
Jonatan Kłosko 2023-05-23 00:21:44 +02:00 committed by GitHub
parent 3ada5c9146
commit 8e4f3067da
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 8 deletions

View file

@ -393,21 +393,20 @@ defmodule Livebook.Intellisense do
"""
@spec get_details(String.t(), pos_integer(), context()) :: Runtime.details_response() | nil
def get_details(line, column, context) do
case IdentifierMatcher.locate_identifier(line, column, context) do
%{matches: []} ->
%{matches: matches, range: range} = IdentifierMatcher.locate_identifier(line, column, context)
case Enum.filter(matches, &include_in_details?/1) do
[] ->
nil
%{matches: matches, range: range} ->
contents =
matches
|> Enum.filter(&include_in_details?/1)
|> Enum.map(&format_details_item/1)
matches ->
contents = Enum.map(matches, &format_details_item/1)
%{range: range, contents: contents}
end
end
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 format_details_item(%{kind: :variable, name: name}), do: code(name)

View file

@ -1285,6 +1285,13 @@ defmodule Livebook.IntellisenseTest do
assert to_string_fn =~ "Converts the argument to a string"
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
context = eval(do: nil)