Skip to content

Commit

Permalink
fix: offset column by 1 to make goto def/refs work when cursor is at …
Browse files Browse the repository at this point in the history
…end of symbol (elixir-lsp#1038)

Co-authored-by: Cocoa <[email protected]>
  • Loading branch information
shinohara-rin and cocoa-xu committed May 7, 2024
1 parent a4809ce commit df44481
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,15 @@ defmodule ElixirLS.LanguageServer.Providers.Definition do
result =
case Locator.definition(source_file.text, line, character, metadata: metadata) do
nil ->
nil
case Locator.definition(source_file.text, line, max(character - 1, 1),
metadata: metadata
) do
nil ->
nil

%ElixirLS.LanguageServer.Location{} = location ->
Protocol.Location.new(location, uri, source_file.text, project_dir)
end

%ElixirLS.LanguageServer.Location{} = location ->
Protocol.Location.new(location, uri, source_file.text, project_dir)
Expand Down
13 changes: 12 additions & 1 deletion apps/language_server/lib/language_server/providers/references.ex
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,18 @@ defmodule ElixirLS.LanguageServer.Providers.References do
Build.with_build_lock(fn ->
trace = ElixirLS.LanguageServer.Tracer.get_trace()

Locator.references(source_file.text, line, character, trace, metadata: metadata)
references =
case Locator.references(source_file.text, line, character, trace, metadata: metadata) do
[] ->
Locator.references(source_file.text, line, max(character - 1, 1), trace,
metadata: metadata
)

references ->
references
end

references
|> Enum.map(fn elixir_sense_reference ->
elixir_sense_reference
|> build_reference(uri, source_file.text, project_dir)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,19 @@ defmodule ElixirLS.LanguageServer.Providers.References.Locator do
alias ElixirSense.Core.Parser

def references(code, line, column, trace, options \\ []) do
case NormalizedCode.Fragment.surround_context(code, {line, column}) do
{context, column} =
case NormalizedCode.Fragment.surround_context(code, {line, column}) do
:none ->
{:none, column}

%{context: {:dot, _, _}} ->
{NormalizedCode.Fragment.surround_context(code, {line, max(column - 1, 1)}), column - 1}

context ->
{context, column}
end

case context do
:none ->
[]

Expand Down

0 comments on commit df44481

Please sign in to comment.