@@ -153,6 +153,161 @@ defmodule ElixirLS.LanguageServer.Providers.CodeLens.TestTest do
153
153
)
154
154
end
155
155
156
+ describe "in large files" do
157
+ setup do
158
+ text = """
159
+ defmodule ElixirLS.LanguageServer.DiagnosticsTest do
160
+ alias ElixirLS.LanguageServer.Diagnostics
161
+ use ExUnit.Case
162
+
163
+ describe "normalize/2" do
164
+ test "extract the stacktrace from the message and format it" do
165
+ root_path = Path.join(__DIR__, "fixtures/build_errors")
166
+ file = Path.join(root_path, "lib/has_error.ex")
167
+ position = 2
168
+
169
+ message = \" ""
170
+ ** (CompileError) some message
171
+
172
+ Hint: Some hint
173
+ (elixir 1.10.1) lib/macro.ex:304: Macro.pipe/3
174
+ (stdlib 3.7.1) lists.erl:1263: :lists.foldl/3
175
+ (elixir 1.10.1) expanding macro: Kernel.|>/2
176
+ expanding macro: SomeModule.sigil_L/2
177
+ lib/my_app/my_module.ex:10: MyApp.MyModule.render/1
178
+ \" ""
179
+
180
+ [diagnostic | _] =
181
+ [build_diagnostic(message, file, position)]
182
+ |> Diagnostics.normalize(root_path)
183
+
184
+ assert diagnostic.message == \" ""
185
+ (CompileError) some message
186
+
187
+ Hint: Some hint
188
+
189
+ Stacktrace:
190
+ │ (elixir 1.10.1) lib/macro.ex:304: Macro.pipe/3
191
+ │ (stdlib 3.7.1) lists.erl:1263: :lists.foldl/3
192
+ │ (elixir 1.10.1) expanding macro: Kernel.|>/2
193
+ │ expanding macro: SomeModule.sigil_L/2
194
+ │ lib/my_app/my_module.ex:10: MyApp.MyModule.render/1
195
+ \" ""
196
+ end
197
+
198
+ test "update file and position if file is present in the message" do
199
+ root_path = Path.join(__DIR__, "fixtures/build_errors")
200
+ file = Path.join(root_path, "lib/has_error.ex")
201
+ position = 2
202
+
203
+ message = \" ""
204
+ ** (CompileError) lib/has_error.ex:3: some message
205
+ lib/my_app/my_module.ex:10: MyApp.MyModule.render/1
206
+ \" ""
207
+
208
+ [diagnostic | _] =
209
+ [build_diagnostic(message, file, position)]
210
+ |> Diagnostics.normalize(root_path)
211
+
212
+ assert diagnostic.message == \" ""
213
+ (CompileError) some message
214
+
215
+ Stacktrace:
216
+ │ lib/my_app/my_module.ex:10: MyApp.MyModule.render/1
217
+ \" ""
218
+
219
+ assert diagnostic.position == 3
220
+ end
221
+
222
+ test "update file and position if file is present in the message (umbrella)" do
223
+ root_path = Path.join(__DIR__, "fixtures/umbrella")
224
+ file = Path.join(root_path, "lib/file_to_be_replaced.ex")
225
+ position = 3
226
+
227
+ message = \" ""
228
+ ** (CompileError) lib/app2.ex:5: some message
229
+ (elixir 1.10.1) lib/macro.ex:304: Macro.pipe/3
230
+ lib/my_app/my_module.ex:10: MyApp.MyModule.render/1
231
+ \" ""
232
+
233
+ [diagnostic | _] =
234
+ [build_diagnostic(message, file, position)]
235
+ |> Diagnostics.normalize(root_path)
236
+
237
+ assert diagnostic.message =~ "(CompileError) some message"
238
+ assert diagnostic.file =~ "umbrella/apps/app2/lib/app2.ex"
239
+ assert diagnostic.position == 5
240
+ end
241
+
242
+ test "don't update file nor position if file in message does not exist" do
243
+ root_path = Path.join(__DIR__, "fixtures/build_errors_on_external_resource")
244
+ file = Path.join(root_path, "lib/has_error.ex")
245
+ position = 2
246
+
247
+ message = \" ""
248
+ ** (CompileError) lib/non_existing.ex:3: some message
249
+ lib/my_app/my_module.ex:10: MyApp.MyModule.render/1
250
+ \" ""
251
+
252
+ [diagnostic | _] =
253
+ [build_diagnostic(message, file, position)]
254
+ |> Diagnostics.normalize(root_path)
255
+
256
+ assert diagnostic.message == \" ""
257
+ (CompileError) lib/non_existing.ex:3: some message
258
+
259
+ Stacktrace:
260
+ │ lib/my_app/my_module.ex:10: MyApp.MyModule.render/1
261
+ \" ""
262
+
263
+ assert diagnostic.position == 2
264
+ end
265
+
266
+ defp build_diagnostic(message, file, position) do
267
+ %Mix.Task.Compiler.Diagnostic{
268
+ compiler_name: "Elixir",
269
+ details: nil,
270
+ file: file,
271
+ message: message,
272
+ position: position,
273
+ severity: :error
274
+ }
275
+ end
276
+ end
277
+ end
278
+ """
279
+
280
+ % { text: text }
281
+ end
282
+
283
+ test "returns module lens on the module declaration line" , % { text: text } do
284
+ uri = "file://project/file.ex"
285
+
286
+ { :ok , lenses } = CodeLens.Test . code_lens ( uri , text )
287
+
288
+ assert Enum . member? (
289
+ lenses ,
290
+ build_code_lens ( 0 , :module , "/file.ex" , % {
291
+ "module" => ElixirLS.LanguageServer.DiagnosticsTest
292
+ } )
293
+ )
294
+ end
295
+
296
+ test "returns test lenses with describe info" , % { text: text } do
297
+ uri = "file://project/file.ex"
298
+
299
+ { :ok , lenses } = CodeLens.Test . code_lens ( uri , text )
300
+
301
+ assert Enum . member? (
302
+ lenses ,
303
+ build_code_lens ( 5 , :test , "/file.ex" , % {
304
+ "testName" => "extract the stacktrace from the message and format it" ,
305
+ "describe" => "normalize/2"
306
+ } )
307
+ )
308
+ end
309
+ end
310
+
156
311
defp build_code_lens ( line , target , file_path , args ) do
157
312
arguments =
158
313
% {
0 commit comments