@@ -9,19 +9,26 @@ defmodule ElixirLS.LanguageServer.Experimental.Provider.Handlers.GotoDefinition
9
9
source_file = request . source_file
10
10
pos = request . position
11
11
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 )
13
14
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 }
21
18
22
19
{ :error , reason } ->
23
- Logger . error ( "GotoDefinition failed: #{ inspect ( reason ) } " )
20
+ Logger . error ( "GotoDefinition conversion failed: #{ inspect ( reason ) } " )
24
21
{ :error , Responses.GotoDefinition . error ( request . id , :request_failed , inspect ( reason ) ) }
25
22
end
26
23
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
27
34
end
0 commit comments