diff --git a/apps/elixir_ls_debugger/lib/debugger/server.ex b/apps/elixir_ls_debugger/lib/debugger/server.ex index 280f7dc37..55beb5ee6 100644 --- a/apps/elixir_ls_debugger/lib/debugger/server.ex +++ b/apps/elixir_ls_debugger/lib/debugger/server.ex @@ -1157,7 +1157,7 @@ defmodule ElixirLS.Debugger.Server do metadata = ElixirSense.Core.Parser.parse_file(path, false, false, nil) for line <- lines do - env = ElixirSense.Core.Metadata.get_env(metadata, line |> elem(0)) + env = ElixirSense.Core.Metadata.get_env(metadata, {line |> elem(0), 1}) if env.module == nil do {:error, "Could not determine module at line"} diff --git a/apps/language_server/lib/language_server/providers/completion.ex b/apps/language_server/lib/language_server/providers/completion.ex index e632f7b34..269144a29 100644 --- a/apps/language_server/lib/language_server/providers/completion.ex +++ b/apps/language_server/lib/language_server/providers/completion.ex @@ -107,9 +107,7 @@ defmodule ElixirLS.LanguageServer.Providers.Completion do # Can we use ElixirSense.Providers.Suggestion? ElixirSense.suggestions/3 metadata = ElixirSense.Core.Parser.parse_string(text, true, true, line) - env = - metadata - |> ElixirSense.Core.Metadata.get_env(line) + env = ElixirSense.Core.Metadata.get_env(metadata, {line, character}) scope = case env.scope do @@ -147,7 +145,8 @@ defmodule ElixirLS.LanguageServer.Providers.Completion do } position_to_insert_alias = - ElixirSense.Core.Metadata.get_position_to_insert_alias(metadata, line) || {line, 0} + ElixirSense.Core.Metadata.get_position_to_insert_alias(metadata, {line, character}) || + {line, 1} context = Map.put( @@ -243,7 +242,7 @@ defmodule ElixirLS.LanguageServer.Providers.Completion do end defp from_completion_item( - %{type: :attribute, name: name}, + %{type: :attribute, name: name, summary: summary}, %{ prefix: prefix, def_before: nil, @@ -253,21 +252,25 @@ defmodule ElixirLS.LanguageServer.Providers.Completion do _options ) do name_only = String.trim_leading(name, "@") - insert_text = if String.starts_with?(prefix, "@"), do: name_only, else: name - - if name == prefix do - nil - else - %__MODULE__{ - label: name, - kind: :variable, - detail: "module attribute", - insert_text: insert_text, - filter_text: name_only, - priority: 14, - tags: [] - } + insert_text = case String.split(prefix, "@") do + [_ | attribute_prefix] -> if String.starts_with?(name_only, attribute_prefix) do + name_only + else + name + end + _ -> name end + + %__MODULE__{ + label: name, + kind: :variable, + detail: "module attribute", + documentation: name <> "\n" <> (if summary, do: summary, else: ""), + insert_text: insert_text, + filter_text: name_only, + priority: 14, + tags: [] + } end defp from_completion_item( diff --git a/apps/language_server/test/experimental/provider/handlers/goto_definition_test.exs b/apps/language_server/test/experimental/provider/handlers/goto_definition_test.exs index 61115b449..a33ce1f00 100644 --- a/apps/language_server/test/experimental/provider/handlers/goto_definition_test.exs +++ b/apps/language_server/test/experimental/provider/handlers/goto_definition_test.exs @@ -60,9 +60,9 @@ defmodule ElixirLS.Experimental.Provider.Handlers.GotoDefinitionTest do assert definition.uri == uri assert definition.range.start.line == 1 - assert definition.range.start.character == 6 + assert definition.range.start.character == 2 assert definition.range.end.line == 1 - assert definition.range.end.character == 6 + assert definition.range.end.character == 2 end test "find definition remote macro call", %{file_uri: uri} do @@ -80,9 +80,9 @@ defmodule ElixirLS.Experimental.Provider.Handlers.GotoDefinitionTest do assert definition.uri == uri assert definition.range.start.line == 8 - assert definition.range.start.character == 11 + assert definition.range.start.character == 2 assert definition.range.end.line == 8 - assert definition.range.end.character == 11 + assert definition.range.end.character == 2 end test "find definition imported function call", %{file_uri: uri} do @@ -100,9 +100,9 @@ defmodule ElixirLS.Experimental.Provider.Handlers.GotoDefinitionTest do assert definition.uri == uri assert definition.range.start.line == 1 - assert definition.range.start.character == 6 + assert definition.range.start.character == 2 assert definition.range.end.line == 1 - assert definition.range.end.character == 6 + assert definition.range.end.character == 2 end test "find definition imported macro call", %{file_uri: uri} do @@ -120,9 +120,9 @@ defmodule ElixirLS.Experimental.Provider.Handlers.GotoDefinitionTest do assert definition.uri == uri assert definition.range.start.line == 8 - assert definition.range.start.character == 11 + assert definition.range.start.character == 2 assert definition.range.end.line == 8 - assert definition.range.end.character == 11 + assert definition.range.end.character == 2 end test "find definition local function call", %{file_uri: uri} do @@ -140,9 +140,9 @@ defmodule ElixirLS.Experimental.Provider.Handlers.GotoDefinitionTest do assert definition.uri == uri assert definition.range.start.line == 1 - assert definition.range.start.character == 6 + assert definition.range.start.character == 2 assert definition.range.end.line == 1 - assert definition.range.end.character == 6 + assert definition.range.end.character == 2 end test "find definition local macro call", %{file_uri: uri} do @@ -160,9 +160,9 @@ defmodule ElixirLS.Experimental.Provider.Handlers.GotoDefinitionTest do assert definition.uri == uri assert definition.range.start.line == 8 - assert definition.range.start.character == 11 + assert definition.range.start.character == 2 assert definition.range.end.line == 8 - assert definition.range.end.character == 11 + assert definition.range.end.character == 2 end test "find definition variable", %{file_uri: uri} do diff --git a/apps/language_server/test/providers/definition_test.exs b/apps/language_server/test/providers/definition_test.exs index 9b0539e96..09437a6dc 100644 --- a/apps/language_server/test/providers/definition_test.exs +++ b/apps/language_server/test/providers/definition_test.exs @@ -26,8 +26,8 @@ defmodule ElixirLS.LanguageServer.Providers.DefinitionTest do Definition.definition(uri, text, line, char) assert range == %{ - "start" => %{"line" => 1, "character" => 6}, - "end" => %{"line" => 1, "character" => 6} + "start" => %{"line" => 1, "character" => 2}, + "end" => %{"line" => 1, "character" => 2} } end @@ -50,8 +50,8 @@ defmodule ElixirLS.LanguageServer.Providers.DefinitionTest do Definition.definition(uri, text, line, char) assert range == %{ - "start" => %{"line" => 8, "character" => 11}, - "end" => %{"line" => 8, "character" => 11} + "start" => %{"line" => 8, "character" => 2}, + "end" => %{"line" => 8, "character" => 2} } end @@ -74,8 +74,8 @@ defmodule ElixirLS.LanguageServer.Providers.DefinitionTest do Definition.definition(uri, text, line, char) assert range == %{ - "start" => %{"line" => 1, "character" => 6}, - "end" => %{"line" => 1, "character" => 6} + "start" => %{"line" => 1, "character" => 2}, + "end" => %{"line" => 1, "character" => 2} } end @@ -98,8 +98,8 @@ defmodule ElixirLS.LanguageServer.Providers.DefinitionTest do Definition.definition(uri, text, line, char) assert range == %{ - "start" => %{"line" => 8, "character" => 11}, - "end" => %{"line" => 8, "character" => 11} + "start" => %{"line" => 8, "character" => 2}, + "end" => %{"line" => 8, "character" => 2} } end @@ -122,8 +122,8 @@ defmodule ElixirLS.LanguageServer.Providers.DefinitionTest do Definition.definition(uri, text, line, char) assert range == %{ - "start" => %{"line" => 1, "character" => 6}, - "end" => %{"line" => 1, "character" => 6} + "start" => %{"line" => 1, "character" => 2}, + "end" => %{"line" => 1, "character" => 2} } end @@ -146,8 +146,8 @@ defmodule ElixirLS.LanguageServer.Providers.DefinitionTest do Definition.definition(uri, text, line, char) assert range == %{ - "start" => %{"line" => 8, "character" => 11}, - "end" => %{"line" => 8, "character" => 11} + "start" => %{"line" => 8, "character" => 2}, + "end" => %{"line" => 8, "character" => 2} } end diff --git a/apps/language_server/test/providers/implementation_test.exs b/apps/language_server/test/providers/implementation_test.exs index f95f0eca4..6940d59be 100644 --- a/apps/language_server/test/providers/implementation_test.exs +++ b/apps/language_server/test/providers/implementation_test.exs @@ -28,8 +28,8 @@ defmodule ElixirLS.LanguageServer.Providers.ImplementationTest do assert range == %{ - "start" => %{"line" => 5, "character" => 10}, - "end" => %{"line" => 5, "character" => 10} + "start" => %{"line" => 5, "character" => 0}, + "end" => %{"line" => 5, "character" => 0} } end end diff --git a/apps/language_server/test/server_test.exs b/apps/language_server/test/server_test.exs index c0a230640..cc2b5ec5d 100644 --- a/apps/language_server/test/server_test.exs +++ b/apps/language_server/test/server_test.exs @@ -767,15 +767,13 @@ defmodule ElixirLS.LanguageServer.ServerTest do assert_receive( response(1, %{ "range" => %{ - "end" => %{"character" => column, "line" => 0}, - "start" => %{"character" => column, "line" => 0} + "end" => %{"character" => 0, "line" => 0}, + "start" => %{"character" => 0, "line" => 0} }, "uri" => ^uri }), 3000 ) - - assert column > 0 end test "definition not found", %{server: server} do diff --git a/dep_versions.exs b/dep_versions.exs index 288c50461..5ea6aa5a5 100644 --- a/dep_versions.exs +++ b/dep_versions.exs @@ -1,5 +1,5 @@ [ - elixir_sense: "a50b8b616833fac6b45dbb65d6a8c6d9fda3a038", + elixir_sense: "3aea5e26d71d00c160033bd86451b11a69424b9d", dialyxir_vendored: "7e908b4d760c7329046e0ee3076be9156cd784e1", jason_v: "c81537e2a5e1acacb915cf339fe400357e3c2aaa" ] diff --git a/mix.lock b/mix.lock index efe64e9c4..0016c793c 100644 --- a/mix.lock +++ b/mix.lock @@ -2,7 +2,7 @@ "benchee": {:hex, :benchee, "1.1.0", "f3a43817209a92a1fade36ef36b86e1052627fd8934a8b937ac9ab3a76c43062", [:mix], [{:deep_merge, "~> 1.0", [hex: :deep_merge, repo: "hexpm", optional: false]}, {:statistex, "~> 1.0", [hex: :statistex, repo: "hexpm", optional: false]}], "hexpm", "7da57d545003165a012b587077f6ba90b89210fd88074ce3c60ce239eb5e6d93"}, "deep_merge": {:hex, :deep_merge, "1.0.0", "b4aa1a0d1acac393bdf38b2291af38cb1d4a52806cf7a4906f718e1feb5ee961", [:mix], [], "hexpm", "ce708e5f094b9cd4e8f2be4f00d2f4250c4095be93f8cd6d018c753894885430"}, "dialyxir_vendored": {:git, "https://github.com/elixir-lsp/dialyxir.git", "7e908b4d760c7329046e0ee3076be9156cd784e1", [ref: "7e908b4d760c7329046e0ee3076be9156cd784e1"]}, - "elixir_sense": {:git, "https://github.com/elixir-lsp/elixir_sense.git", "a50b8b616833fac6b45dbb65d6a8c6d9fda3a038", [ref: "a50b8b616833fac6b45dbb65d6a8c6d9fda3a038"]}, + "elixir_sense": {:git, "https://github.com/elixir-lsp/elixir_sense.git", "3aea5e26d71d00c160033bd86451b11a69424b9d", [ref: "3aea5e26d71d00c160033bd86451b11a69424b9d"]}, "erl2ex": {:git, "https://github.com/dazuma/erl2ex.git", "244c2d9ed5805ef4855a491d8616b8842fef7ca4", []}, "erlex": {:hex, :erlex, "0.2.6", "c7987d15e899c7a2f34f5420d2a2ea0d659682c06ac607572df55a43753aa12e", [:mix], [], "hexpm", "2ed2e25711feb44d52b17d2780eabf998452f6efda104877a3881c2f8c0c0c75"}, "jason_v": {:git, "https://github.com/elixir-lsp/jason.git", "c81537e2a5e1acacb915cf339fe400357e3c2aaa", [ref: "c81537e2a5e1acacb915cf339fe400357e3c2aaa"]},