1
1
defmodule ElixirLS.LanguageServer.Experimental.Provider.Handlers.GotoDefinition do
2
2
alias ElixirLS.LanguageServer.Experimental.Protocol.Requests.GotoDefinition
3
3
alias ElixirLS.LanguageServer.Experimental.Protocol.Responses
4
- alias ElixirLS.LanguageServer.Experimental.Protocol.Types.Location
5
- alias ElixirLS.LanguageServer.Experimental.Protocol.Types.Range , as: LSRange
4
+ alias ElixirLS.LanguageServer.Experimental.CodeMod.Location , as: CodeModLocation
6
5
alias ElixirLS.LanguageServer.Experimental.SourceFile
7
- alias ElixirLS.LanguageServer.Experimental.SourceFile.Conversions
8
6
require Logger
9
7
10
8
def handle ( % GotoDefinition { } = request , _ ) do
@@ -15,7 +13,7 @@ defmodule ElixirLS.LanguageServer.Experimental.Provider.Handlers.GotoDefinition
15
13
16
14
with % ElixirSense.Location { } = location <-
17
15
ElixirSense . definition ( source_file_string , pos . line , pos . character + 1 ) ,
18
- { :ok , definition } <- build_definition ( location , source_file ) do
16
+ { :ok , definition } <- CodeModLocation . to_lsp ( location , source_file ) do
19
17
{ :reply , Responses.GotoDefinition . new ( request . id , definition ) }
20
18
else
21
19
nil ->
@@ -26,25 +24,4 @@ defmodule ElixirLS.LanguageServer.Experimental.Provider.Handlers.GotoDefinition
26
24
{ :error , Responses.GotoDefinition . error ( request . id , :request_failed , reason ) }
27
25
end
28
26
end
29
-
30
- defp build_definition (
31
- % { line: line , column: column } = elixir_sense_definition ,
32
- current_source_file
33
- ) do
34
- position = SourceFile.Position . new ( line , column - 1 )
35
-
36
- with { :ok , source_file } <- get_source_file ( elixir_sense_definition , current_source_file ) ,
37
- { :ok , ls_position } <- Conversions . to_lsp ( position , source_file ) do
38
- ls_range = % LSRange { start: ls_position , end: ls_position }
39
- { :ok , Location . new ( uri: source_file . uri , range: ls_range ) }
40
- end
41
- end
42
-
43
- defp get_source_file ( % { file: nil } , current_source_file ) do
44
- { :ok , current_source_file }
45
- end
46
-
47
- defp get_source_file ( % { file: path } , _ ) do
48
- SourceFile.Store . open_temporary ( path )
49
- end
50
27
end
0 commit comments