Skip to content

Commit 98e4228

Browse files
committed
Use stacktrace in mix compiled diagnostics on elixir 1.15
remove special handling for token missing error the hint line is extracted elsewhere and populates related info
1 parent ad3473c commit 98e4228

File tree

2 files changed

+11
-50
lines changed

2 files changed

+11
-50
lines changed

apps/language_server/lib/language_server/diagnostics.ex

Lines changed: 11 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,20 @@ defmodule ElixirLS.LanguageServer.Diagnostics do
4646

4747
%__MODULE__{normalized | message: message, file: file, position: position}
4848
else
49-
{type, file, position, stacktrace} =
49+
{_type, file, position, stacktrace} =
5050
extract_message_info(diagnostic.message, root_path)
5151

52+
{file, position} =
53+
get_file_and_position_with_stacktrace_fallback(
54+
{file || diagnostic.file, position || diagnostic.position},
55+
Map.get(diagnostic, :stacktrace, []),
56+
root_path,
57+
mixfile
58+
)
59+
5260
normalized
5361
|> maybe_update_file(file, mixfile)
54-
|> maybe_update_position(type, position, stacktrace)
62+
|> maybe_update_position(position, stacktrace)
5563
end
5664
end
5765

@@ -85,21 +93,7 @@ defmodule ElixirLS.LanguageServer.Diagnostics do
8593
end
8694
end
8795

88-
defp maybe_update_position(diagnostic, "TokenMissingError", position, stacktrace) do
89-
case extract_line_from_missing_hint(diagnostic.message) do
90-
line when is_integer(line) and line > 0 ->
91-
%{diagnostic | position: line}
92-
93-
_ ->
94-
do_maybe_update_position(diagnostic, position, stacktrace)
95-
end
96-
end
97-
98-
defp maybe_update_position(diagnostic, _type, position, stacktrace) do
99-
do_maybe_update_position(diagnostic, position, stacktrace)
100-
end
101-
102-
defp do_maybe_update_position(diagnostic, position, stacktrace) do
96+
defp maybe_update_position(diagnostic, position, stacktrace) do
10397
cond do
10498
position != nil ->
10599
%{diagnostic | position: position}
@@ -191,16 +185,6 @@ defmodule ElixirLS.LanguageServer.Diagnostics do
191185
false
192186
end
193187

194-
defp extract_line_from_missing_hint(message) do
195-
case Regex.run(
196-
~r/starting at line (\d+)\)/u,
197-
message
198-
) do
199-
[_, line] -> String.to_integer(line)
200-
_ -> nil
201-
end
202-
end
203-
204188
defp extract_line_from_stacktrace(file, stacktrace) do
205189
Enum.find_value(stacktrace, fn stack_item ->
206190
with [_, _, file_relative, line] <-

apps/language_server/test/diagnostics_test.exs

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -143,29 +143,6 @@ defmodule ElixirLS.LanguageServer.DiagnosticsTest do
143143
assert diagnostic.position == 13
144144
end
145145

146-
test "if position is nil and error is TokenMissingError, try to retrieve from the hint" do
147-
root_path = Path.join(__DIR__, "fixtures/token_missing_error")
148-
file = Path.join(root_path, "lib/has_error.ex")
149-
position = nil
150-
151-
message = """
152-
** (TokenMissingError) lib/has_error.ex:16:1: missing terminator: end (for "do" starting at line 1)
153-
154-
HINT: it looks like the "do" on line 6 does not have a matching "end"
155-
156-
(elixir 1.12.1) lib/kernel/parallel_compiler.ex:319: anonymous fn/4 in Kernel.ParallelCompiler.spawn_workers/7
157-
"""
158-
159-
diagnostic =
160-
build_diagnostic(message, file, position)
161-
|> Diagnostics.from_mix_task_compiler_diagnostic(
162-
Path.join(root_path, "mix.exs"),
163-
root_path
164-
)
165-
166-
assert diagnostic.position == 1
167-
end
168-
169146
defp build_diagnostic(message, file, position) do
170147
%Mix.Task.Compiler.Diagnostic{
171148
compiler_name: "Elixir",

0 commit comments

Comments
 (0)