Skip to content

Resolve goto-def/refs/hover at the end of a symbol (#1038 / #1027)#1270

Merged
lukaszsamson merged 3 commits into
masterfrom
fix-1038-end-of-symbol
Jul 4, 2026
Merged

Resolve goto-def/refs/hover at the end of a symbol (#1038 / #1027)#1270
lukaszsamson merged 3 commits into
masterfrom
fix-1038-end-of-symbol

Conversation

@lukaszsamson

Copy link
Copy Markdown
Collaborator

Fixes #1038. Addresses the #1027 cases. Supersedes #1087 (the retry-with-char-to-the-left workaround).

Problem

SurroundContext.Toxic.surround_context/2 mirrored Code.Fragment.surround_context/2, which returns :none when the cursor is one column past the last character of a symbol, and returns the enclosing remote call when the cursor is at the end of an alias before a .. So goto-definition / references / hover fail when the caret is at the visual end of a name (#1038), and an alias at its end resolves to the function instead of the module (#1027; the upstream lexical fix elixir-lang/elixir#13150 was reverted as it only handled a few cases).

Fix

The fix is in elixir_sense (PR elixir-lsp/elixir_sense#340); this PR bumps the dependency and adds end-to-end coverage. Because toxic2 gives every node an exact end-exclusive range, the classifier now resolves the trailing edge precisely:

All four locators (definition/references/implementation/hover) consume surround_context, so they are fixed together.

Safety

Fuzzed across lib + fixtures at every column: 0 results where the cursor falls outside the returned [begin, end], and by construction the result is :none only where the pre-existing classification was — nothing regresses. The 285 existing navigation-locator tests still pass.

Note: the elixir_sense dep is pinned to the #340 branch SHA; it should be advanced to the merge commit once #340 lands.

🤖 Generated with Claude Code

lukaszsamson and others added 2 commits July 4, 2026 14:42
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
…hover)

elixir_sense ee88a26f restricts the end-of-alias-before-dot override to `:alias`
only, so hovering the `.` in an erlang remote call like `:timer.sleep(...)` keeps
resolving the function instead of the module.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XRd15BX6wBpZ8ThaNSo232
@lukaszsamson lukaszsamson requested a review from Copilot July 4, 2026 13:03
@lukaszsamson

Copy link
Copy Markdown
Collaborator Author

@codex review

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the pinned elixir_sense dependency to pick up fixes for trailing-edge cursor classification (cursor one column past a symbol / at the end of an alias before .), and adds regression tests in ElixirLS to ensure goto-definition works correctly in those positions.

Changes:

  • Bump elixir_sense git ref SHA to a newer commit that includes the trailing-edge surround-context fix.
  • Update the repository’s recorded dependency SHA (dep_versions.exs) to match the new pin.
  • Add definition-locator regression tests for “cursor at end of symbol” (#1038) and “alias end before . resolves module” (#1027).

Reviewed changes

Copilot reviewed 2 out of 3 changed files in this pull request and generated 1 comment.

File Description
mix.lock Pins elixir_sense to the updated git SHA.
dep_versions.exs Updates the tracked elixir_sense SHA to match the lockfile.
apps/language_server/test/providers/definition/locator_test.exs Adds regression coverage for end-of-symbol and alias-before-dot behavior in goto-definition.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +21 to +23
# elixir-lsp/elixir-ls#1038: goto-definition must work when the cursor is at the very end of a
# symbol (one column past its last character), not only when it is on a character of the symbol.
test "find definition with the cursor at the end of the symbol (#1038)" do
…hover

Per review of #1270, the trailing-edge regression coverage previously only
exercised the definition locator. Add equivalent "cursor at end of symbol / end
of alias before `.`" cases for the References and Implementation locators and the
Hover provider, which share the same SurroundContext.Toxic resolution, so those
paths can't regress independently.

Also bump elixir_sense to 9460c606 (review fixes: lazy classification, operator
contexts preserved, qualified-alias override).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XRd15BX6wBpZ8ThaNSo232
@lukaszsamson lukaszsamson merged commit 5985a23 into master Jul 4, 2026
42 of 44 checks passed
@lukaszsamson lukaszsamson deleted the fix-1038-end-of-symbol branch July 4, 2026 14:21
lukaszsamson added a commit that referenced this pull request Jul 4, 2026
… branch

Pin conflict resolved keeping ours: master pins elixir_sense 9460c606, which
is an ancestor of our 9788101d (the #334 merge commit on elixir_sense
master). Gates: compile 0 warnings, format clean, language_server suite
1624 passed.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NvwMWQayfdxowBDrnt5iYM
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants