Skip to content

Commit a35f79b

Browse files
lukaszsamsonclaude
andcommitted
Resolve goto-def/refs/hover at the end of a symbol (#1038 / #1027)
Bump elixir_sense to 9f6b3fe, which makes `SurroundContext.Toxic.surround_context` resolve the trailing edge of a symbol. All four navigation locators (definition, references, implementation, hover) consume it, so the cursor placed at the visual end of a name now resolves instead of returning nothing (#1038), and the end of an alias before a `.` resolves to the module rather than the remote call (#1027). Add end-to-end coverage in the definition locator test for both cases. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XRd15BX6wBpZ8ThaNSo232
1 parent 70b128c commit a35f79b

3 files changed

Lines changed: 39 additions & 2 deletions

File tree

apps/language_server/test/providers/definition/locator_test.exs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,43 @@ defmodule ElixirLS.LanguageServer.Providers.Definition.LocatorTest do
1818
assert nil == Locator.definition("__MODULE__", 1, 1)
1919
end
2020

21+
# elixir-lsp/elixir-ls#1038: goto-definition must work when the cursor is at the very end of a
22+
# symbol (one column past its last character), not only when it is on a character of the symbol.
23+
test "find definition with the cursor at the end of the symbol (#1038)" do
24+
buffer = """
25+
defmodule MyModule do
26+
def my_func(a), do: a
27+
28+
def caller do
29+
my_func(1)
30+
end
31+
end
32+
"""
33+
34+
# `my_func` is on line 5 at columns 5..11; column 12 is the end of the symbol.
35+
for col <- [8, 11, 12] do
36+
assert %Location{type: :function, line: 2} = Locator.definition(buffer, 5, col),
37+
"expected my_func/1 definition at line 5 column #{col}"
38+
end
39+
end
40+
41+
# elixir-lsp/elixir-ls#1027: at the end of an alias that is the LHS of a remote call, the cursor
42+
# resolves to the module, not the function.
43+
test "cursor at the end of an alias before `.` resolves the module (#1027)" do
44+
buffer = """
45+
defmodule MyModule do
46+
alias ElixirSenseExample.ModuleWithFunctions
47+
48+
def caller do
49+
ModuleWithFunctions.function_arity_zero()
50+
end
51+
end
52+
"""
53+
54+
# `ModuleWithFunctions` is on line 5 at columns 5..23; column 24 is on the `.` (its end).
55+
assert %Location{type: :module} = Locator.definition(buffer, 5, 24)
56+
end
57+
2158
test "find module definition inside Phoenix's scope" do
2259
_define_existing_atom = ExampleWeb
2360

dep_versions.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[
2-
elixir_sense: "89eda3fc4df9cea0d70c528f3e7e240a70c860f8",
2+
elixir_sense: "9f6b3fe25e64e984c09f74786071356354ec16f7",
33
dialyxir_vendored: "accfec9393079abc4a82b7e79a4997f59f085b67",
44
jason_v: "f1c10fa9c445cb9f300266122ef18671054b2330",
55
erl2ex_vendored: "04f93e55f46d35d0aa3c149616f2c7a6a1ad9311",

mix.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"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"},
33
"deep_merge": {:hex, :deep_merge, "1.0.0", "b4aa1a0d1acac393bdf38b2291af38cb1d4a52806cf7a4906f718e1feb5ee961", [:mix], [], "hexpm", "ce708e5f094b9cd4e8f2be4f00d2f4250c4095be93f8cd6d018c753894885430"},
44
"dialyxir_vendored": {:git, "https://github.com/elixir-lsp/dialyxir.git", "accfec9393079abc4a82b7e79a4997f59f085b67", [ref: "accfec9393079abc4a82b7e79a4997f59f085b67"]},
5-
"elixir_sense": {:git, "https://github.com/elixir-lsp/elixir_sense.git", "89eda3fc4df9cea0d70c528f3e7e240a70c860f8", [ref: "89eda3fc4df9cea0d70c528f3e7e240a70c860f8"]},
5+
"elixir_sense": {:git, "https://github.com/elixir-lsp/elixir_sense.git", "9f6b3fe25e64e984c09f74786071356354ec16f7", [ref: "9f6b3fe25e64e984c09f74786071356354ec16f7"]},
66
"erl2ex_vendored": {:git, "https://github.com/elixir-lsp/erl2ex.git", "04f93e55f46d35d0aa3c149616f2c7a6a1ad9311", [ref: "04f93e55f46d35d0aa3c149616f2c7a6a1ad9311"]},
77
"erlex_vendored": {:git, "https://github.com/elixir-lsp/erlex.git", "50b8307f90451a5d0288fb239fb6405b5ca1f1a4", [ref: "50b8307f90451a5d0288fb239fb6405b5ca1f1a4"]},
88
"jason_v": {:git, "https://github.com/elixir-lsp/jason.git", "f1c10fa9c445cb9f300266122ef18671054b2330", [ref: "f1c10fa9c445cb9f300266122ef18671054b2330"]},

0 commit comments

Comments
 (0)