Skip to content

Commit ac49290

Browse files
committed
Apply flowing suggestions
1 parent d9b2abe commit ac49290

File tree

2 files changed

+19
-15
lines changed

2 files changed

+19
-15
lines changed

apps/language_server/lib/language_server/experimental/provider/handlers/goto_definition.ex

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,26 @@ defmodule ElixirLS.LanguageServer.Experimental.Provider.Handlers.GotoDefinition
99
source_file = request.source_file
1010
pos = request.position
1111

12-
source_file_string = SourceFile.to_string(source_file)
12+
maybe_location =
13+
source_file |> SourceFile.to_string() |> ElixirSense.definition(pos.line, pos.character + 1)
1314

14-
with %ElixirSense.Location{} = location <-
15-
ElixirSense.definition(source_file_string, pos.line, pos.character + 1),
16-
{:ok, lsp_location} <- Conversions.to_lsp(location, source_file) do
17-
{:reply, Responses.GotoDefinition.new(request.id, lsp_location)}
18-
else
19-
nil ->
20-
{:reply, Responses.GotoDefinition.new(request.id, nil)}
15+
case to_response(request.id, maybe_location, source_file) do
16+
{:ok, response} ->
17+
{:reply, response}
2118

2219
{:error, reason} ->
23-
Logger.error("GotoDefinition failed: #{inspect(reason)}")
20+
Logger.error("GotoDefinition conversion failed: #{inspect(reason)}")
2421
{:error, Responses.GotoDefinition.error(request.id, :request_failed, inspect(reason))}
2522
end
2623
end
24+
25+
defp to_response(request_id, %ElixirSense.Location{} = location, %SourceFile{} = source_file) do
26+
with {:ok, lsp_location} <- Conversions.to_lsp(location, source_file) do
27+
{:ok, Responses.GotoDefinition.new(request_id, lsp_location)}
28+
end
29+
end
30+
31+
defp to_response(request_id, nil, _source_file) do
32+
{:ok, Responses.GoToDefinition.new(request_id, nil)}
33+
end
2734
end

apps/language_server/lib/language_server/experimental/source_file/conversions.ex

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -103,13 +103,10 @@ defmodule ElixirLS.LanguageServer.Experimental.SourceFile.Conversions do
103103
{:ok, range}
104104
end
105105

106-
def to_lsp(
107-
%ElixirSense.Location{line: line, column: column} = elixir_sense_location,
108-
%SourceFile{} = source_file
109-
) do
110-
position = SourceFile.Position.new(line, column - 1)
106+
def to_lsp(%ElixirSense.Location{} = location, %SourceFile{} = source_file) do
107+
position = SourceFile.Position.new(location.line, location.column - 1)
111108

112-
with {:ok, source_file} <- fetch_source_file(elixir_sense_location, source_file),
109+
with {:ok, source_file} <- fetch_source_file(location, source_file),
113110
{:ok, ls_position} <- to_lsp(position, source_file) do
114111
ls_range = %LSRange{start: ls_position, end: ls_position}
115112
{:ok, LSLocation.new(uri: source_file.uri, range: ls_range)}

0 commit comments

Comments
 (0)