@@ -5,11 +5,13 @@ defmodule ElixirLS.LanguageServer.Providers.DefinitionTest do
5
5
alias ElixirLS.LanguageServer.Protocol.Location
6
6
alias ElixirLS.LanguageServer.SourceFile
7
7
alias ElixirLS.LanguageServer.Test.FixtureHelpers
8
+ alias ElixirLS.LanguageServer.Test.ParserContextBuilder
8
9
require ElixirLS.Test.TextLoc
9
10
10
11
test "find definition remote function call" do
11
12
file_path = FixtureHelpers . get_path ( "references_remote.ex" )
12
- text = File . read! ( file_path )
13
+ parser_context = ParserContextBuilder . from_path ( file_path )
14
+
13
15
uri = SourceFile.Path . to_uri ( file_path )
14
16
15
17
b_file_path = FixtureHelpers . get_path ( "references_referenced.ex" )
@@ -22,8 +24,10 @@ defmodule ElixirLS.LanguageServer.Providers.DefinitionTest do
22
24
^
23
25
""" )
24
26
27
+ { line , char } = SourceFile . lsp_position_to_elixir ( parser_context . source_file . text , { line , char } )
28
+
25
29
assert { :ok , % Location { uri: ^ b_uri , range: range } } =
26
- Definition . definition ( uri , text , line , char , File . cwd! ( ) )
30
+ Definition . definition ( uri , parser_context , line , char , File . cwd! ( ) )
27
31
28
32
assert range == % {
29
33
"start" => % { "line" => 1 , "character" => 2 } ,
@@ -33,7 +37,7 @@ defmodule ElixirLS.LanguageServer.Providers.DefinitionTest do
33
37
34
38
test "find definition remote macro call" do
35
39
file_path = FixtureHelpers . get_path ( "references_remote.ex" )
36
- text = File . read! ( file_path )
40
+ parser_context = ParserContextBuilder . from_path ( file_path )
37
41
uri = SourceFile.Path . to_uri ( file_path )
38
42
39
43
b_file_path = FixtureHelpers . get_path ( "references_referenced.ex" )
@@ -46,8 +50,10 @@ defmodule ElixirLS.LanguageServer.Providers.DefinitionTest do
46
50
^
47
51
""" )
48
52
53
+ { line , char } = SourceFile . lsp_position_to_elixir ( parser_context . source_file . text , { line , char } )
54
+
49
55
assert { :ok , % Location { uri: ^ b_uri , range: range } } =
50
- Definition . definition ( uri , text , line , char , File . cwd! ( ) )
56
+ Definition . definition ( uri , parser_context , line , char , File . cwd! ( ) )
51
57
52
58
assert range == % {
53
59
"start" => % { "line" => 8 , "character" => 2 } ,
@@ -57,7 +63,7 @@ defmodule ElixirLS.LanguageServer.Providers.DefinitionTest do
57
63
58
64
test "find definition imported function call" do
59
65
file_path = FixtureHelpers . get_path ( "references_imported.ex" )
60
- text = File . read! ( file_path )
66
+ parser_context = ParserContextBuilder . from_path ( file_path )
61
67
uri = SourceFile.Path . to_uri ( file_path )
62
68
63
69
b_file_path = FixtureHelpers . get_path ( "references_referenced.ex" )
@@ -70,8 +76,10 @@ defmodule ElixirLS.LanguageServer.Providers.DefinitionTest do
70
76
^
71
77
""" )
72
78
79
+ { line , char } = SourceFile . lsp_position_to_elixir ( parser_context . source_file . text , { line , char } )
80
+
73
81
assert { :ok , % Location { uri: ^ b_uri , range: range } } =
74
- Definition . definition ( uri , text , line , char , File . cwd! ( ) )
82
+ Definition . definition ( uri , parser_context , line , char , File . cwd! ( ) )
75
83
76
84
assert range == % {
77
85
"start" => % { "line" => 1 , "character" => 2 } ,
@@ -81,7 +89,7 @@ defmodule ElixirLS.LanguageServer.Providers.DefinitionTest do
81
89
82
90
test "find definition imported macro call" do
83
91
file_path = FixtureHelpers . get_path ( "references_imported.ex" )
84
- text = File . read! ( file_path )
92
+ parser_context = ParserContextBuilder . from_path ( file_path )
85
93
uri = SourceFile.Path . to_uri ( file_path )
86
94
87
95
b_file_path = FixtureHelpers . get_path ( "references_referenced.ex" )
@@ -94,8 +102,10 @@ defmodule ElixirLS.LanguageServer.Providers.DefinitionTest do
94
102
^
95
103
""" )
96
104
105
+ { line , char } = SourceFile . lsp_position_to_elixir ( parser_context . source_file . text , { line , char } )
106
+
97
107
assert { :ok , % Location { uri: ^ b_uri , range: range } } =
98
- Definition . definition ( uri , text , line , char , File . cwd! ( ) )
108
+ Definition . definition ( uri , parser_context , line , char , File . cwd! ( ) )
99
109
100
110
assert range == % {
101
111
"start" => % { "line" => 8 , "character" => 2 } ,
@@ -105,7 +115,7 @@ defmodule ElixirLS.LanguageServer.Providers.DefinitionTest do
105
115
106
116
test "find definition local function call" do
107
117
file_path = FixtureHelpers . get_path ( "references_referenced.ex" )
108
- text = File . read! ( file_path )
118
+ parser_context = ParserContextBuilder . from_path ( file_path )
109
119
uri = SourceFile.Path . to_uri ( file_path )
110
120
111
121
b_file_path = FixtureHelpers . get_path ( "references_referenced.ex" )
@@ -118,8 +128,10 @@ defmodule ElixirLS.LanguageServer.Providers.DefinitionTest do
118
128
^
119
129
""" )
120
130
131
+ { line , char } = SourceFile . lsp_position_to_elixir ( parser_context . source_file . text , { line , char } )
132
+
121
133
assert { :ok , % Location { uri: ^ b_uri , range: range } } =
122
- Definition . definition ( uri , text , line , char , File . cwd! ( ) )
134
+ Definition . definition ( uri , parser_context , line , char , File . cwd! ( ) )
123
135
124
136
assert range == % {
125
137
"start" => % { "line" => 1 , "character" => 2 } ,
@@ -129,7 +141,7 @@ defmodule ElixirLS.LanguageServer.Providers.DefinitionTest do
129
141
130
142
test "find definition local macro call" do
131
143
file_path = FixtureHelpers . get_path ( "references_referenced.ex" )
132
- text = File . read! ( file_path )
144
+ parser_context = ParserContextBuilder . from_path ( file_path )
133
145
uri = SourceFile.Path . to_uri ( file_path )
134
146
135
147
b_file_path = FixtureHelpers . get_path ( "references_referenced.ex" )
@@ -142,8 +154,10 @@ defmodule ElixirLS.LanguageServer.Providers.DefinitionTest do
142
154
^
143
155
""" )
144
156
157
+ { line , char } = SourceFile . lsp_position_to_elixir ( parser_context . source_file . text , { line , char } )
158
+
145
159
assert { :ok , % Location { uri: ^ b_uri , range: range } } =
146
- Definition . definition ( uri , text , line , char , File . cwd! ( ) )
160
+ Definition . definition ( uri , parser_context , line , char , File . cwd! ( ) )
147
161
148
162
assert range == % {
149
163
"start" => % { "line" => 8 , "character" => 2 } ,
@@ -153,7 +167,7 @@ defmodule ElixirLS.LanguageServer.Providers.DefinitionTest do
153
167
154
168
test "find definition variable" do
155
169
file_path = FixtureHelpers . get_path ( "references_referenced.ex" )
156
- text = File . read! ( file_path )
170
+ parser_context = ParserContextBuilder . from_path ( file_path )
157
171
uri = SourceFile.Path . to_uri ( file_path )
158
172
159
173
b_file_path = FixtureHelpers . get_path ( "references_referenced.ex" )
@@ -166,8 +180,10 @@ defmodule ElixirLS.LanguageServer.Providers.DefinitionTest do
166
180
^
167
181
""" )
168
182
183
+ { line , char } = SourceFile . lsp_position_to_elixir ( parser_context . source_file . text , { line , char } )
184
+
169
185
assert { :ok , % Location { uri: ^ b_uri , range: range } } =
170
- Definition . definition ( uri , text , line , char , File . cwd! ( ) )
186
+ Definition . definition ( uri , parser_context , line , char , File . cwd! ( ) )
171
187
172
188
assert range == % {
173
189
"start" => % { "line" => 2 , "character" => 4 } ,
@@ -177,7 +193,7 @@ defmodule ElixirLS.LanguageServer.Providers.DefinitionTest do
177
193
178
194
test "find definition attribute" do
179
195
file_path = FixtureHelpers . get_path ( "references_referenced.ex" )
180
- text = File . read! ( file_path )
196
+ parser_context = ParserContextBuilder . from_path ( file_path )
181
197
uri = SourceFile.Path . to_uri ( file_path )
182
198
183
199
b_file_path = FixtureHelpers . get_path ( "references_referenced.ex" )
@@ -190,8 +206,10 @@ defmodule ElixirLS.LanguageServer.Providers.DefinitionTest do
190
206
^
191
207
""" )
192
208
209
+ { line , char } = SourceFile . lsp_position_to_elixir ( parser_context . source_file . text , { line , char } )
210
+
193
211
assert { :ok , % Location { uri: ^ b_uri , range: range } } =
194
- Definition . definition ( uri , text , line , char , File . cwd! ( ) )
212
+ Definition . definition ( uri , parser_context , line , char , File . cwd! ( ) )
195
213
196
214
assert range == % {
197
215
"start" => % { "line" => 24 , "character" => 2 } ,
0 commit comments