Skip to content

Commit 1f1922d

Browse files
authored
Bump elixir sense (#657)
* complete bitstring options * add trigger charakter * bump elixir_sense bring in fixes and complete improvements
1 parent 442c698 commit 1f1922d

File tree

3 files changed

+35
-11
lines changed

3 files changed

+35
-11
lines changed

apps/language_server/lib/language_server/providers/completion.ex

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,9 @@ defmodule ElixirLS.LanguageServer.Providers.Completion do
7979

8080
def trigger_characters do
8181
# VS Code's 24x7 autocompletion triggers automatically on alphanumeric characters. We add these
82-
# for "SomeModule." calls, @module_attrs, function capture, variable pinning, erlang module calls
83-
[".", "@", "&", "%", "^", ":", "!"]
82+
# for "SomeModule." calls, @module_attrs, function capture, variable pinning, erlang module calls,
83+
# bitstring options and sigils
84+
[".", "@", "&", "%", "^", ":", "!", "-", "~"]
8485
end
8586

8687
def completion(text, line, character, options) do
@@ -452,6 +453,30 @@ defmodule ElixirLS.LanguageServer.Providers.Completion do
452453
}
453454
end
454455

456+
defp from_completion_item(
457+
%{type: :bitstring_option, name: name},
458+
_context,
459+
options
460+
) do
461+
insert_text =
462+
case name do
463+
name when name in ["size", "unit"] ->
464+
function_snippet(name, ["integer"], 1, options |> Keyword.merge(with_parens?: true))
465+
466+
other ->
467+
other
468+
end
469+
470+
%__MODULE__{
471+
label: name,
472+
detail: "bitstring option",
473+
insert_text: insert_text,
474+
priority: 10,
475+
kind: :type_parameter,
476+
tags: []
477+
}
478+
end
479+
455480
defp from_completion_item(
456481
%{type: :type_spec, metadata: metadata} = suggestion,
457482
_context,
@@ -771,10 +796,9 @@ defmodule ElixirLS.LanguageServer.Providers.Completion do
771796

772797
{label, insert_text} =
773798
cond do
774-
match?("sigil_" <> _, name) ->
775-
"sigil_" <> sigil_name = name
776-
text = "~#{sigil_name}"
777-
{text, text}
799+
match?("~" <> _, name) ->
800+
"~" <> sigil_name = name
801+
{name, sigil_name}
778802

779803
use_name_only?(origin, name) or String.starts_with?(text_after_cursor, "(") ->
780804
{name, name}

apps/language_server/test/providers/completion_test.exs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -437,12 +437,12 @@ defmodule ElixirLS.LanguageServer.Providers.CompletionTest do
437437
438438
def dummy_function(var = %MyModule{}) do
439439
%{var |
440-
# ^
440+
# ^
441441
end
442442
end
443443
"""
444444

445-
{line, char} = {4, 11}
445+
{line, char} = {4, 12}
446446
TestUtils.assert_has_cursor_char(text, line, char)
447447
{:ok, %{"items" => items}} = Completion.completion(text, line, char, @supports)
448448

@@ -457,12 +457,12 @@ defmodule ElixirLS.LanguageServer.Providers.CompletionTest do
457457
defmodule MyModule do
458458
def dummy_function(var = %{some: nil, other: 1}) do
459459
%{var |
460-
# ^
460+
# ^
461461
end
462462
end
463463
"""
464464

465-
{line, char} = {2, 11}
465+
{line, char} = {2, 12}
466466
TestUtils.assert_has_cursor_char(text, line, char)
467467
{:ok, %{"items" => items}} = Completion.completion(text, line, char, @supports)
468468

mix.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
%{
22
"dialyxir": {:hex, :dialyxir, "1.1.0", "c5aab0d6e71e5522e77beff7ba9e08f8e02bad90dfbeffae60eaf0cb47e29488", [:mix], [{:erlex, ">= 0.2.6", [hex: :erlex, repo: "hexpm", optional: false]}], "hexpm", "07ea8e49c45f15264ebe6d5b93799d4dd56a44036cf42d0ad9c960bc266c0b9a"},
33
"docsh": {:hex, :docsh, "0.7.2", "f893d5317a0e14269dd7fe79cf95fb6b9ba23513da0480ec6e77c73221cae4f2", [:rebar3], [{:providers, "1.8.1", [hex: :providers, repo: "hexpm", optional: false]}], "hexpm", "4e7db461bb07540d2bc3d366b8513f0197712d0495bb85744f367d3815076134"},
4-
"elixir_sense": {:git, "https://github.com/elixir-lsp/elixir_sense.git", "3aff3709d78f79c641fc0df47b0976aa7217b45e", []},
4+
"elixir_sense": {:git, "https://github.com/elixir-lsp/elixir_sense.git", "33df514a1254455f54cb069999454c7e8586eb2d", []},
55
"erl2ex": {:git, "https://github.com/dazuma/erl2ex.git", "244c2d9ed5805ef4855a491d8616b8842fef7ca4", []},
66
"erlex": {:hex, :erlex, "0.2.6", "c7987d15e899c7a2f34f5420d2a2ea0d659682c06ac607572df55a43753aa12e", [:mix], [], "hexpm", "2ed2e25711feb44d52b17d2780eabf998452f6efda104877a3881c2f8c0c0c75"},
77
"getopt": {:hex, :getopt, "1.0.1", "c73a9fa687b217f2ff79f68a3b637711bb1936e712b521d8ce466b29cbf7808a", [:rebar3], [], "hexpm", "53e1ab83b9ceb65c9672d3e7a35b8092e9bdc9b3ee80721471a161c10c59959c"},

0 commit comments

Comments
 (0)