Avoid crashes on diagnostics with tabs, closes #14073
This commit is contained in:
@@ -216,12 +216,12 @@ highlight_at_position(Column, Severity, Length) ->
|
||||
|
||||
highlight_below_line(Line, Severity) ->
|
||||
% Don't highlight leading whitespaces in line
|
||||
{_, SpacesMatched} = trim_line(Line, 0),
|
||||
{Rest, SpacesMatched} = trim_line(Line, 0),
|
||||
|
||||
Length = string:length(Line),
|
||||
Length = string:length(Rest),
|
||||
Highlight = case Severity of
|
||||
warning -> highlight(lists:duplicate(Length - SpacesMatched, $~), warning);
|
||||
error -> highlight(lists:duplicate(Length - SpacesMatched, $^), error)
|
||||
warning -> highlight(lists:duplicate(Length, $~), warning);
|
||||
error -> highlight(lists:duplicate(Length, $^), error)
|
||||
end,
|
||||
|
||||
[n_spaces(SpacesMatched), Highlight].
|
||||
|
||||
@@ -859,6 +859,35 @@ defmodule Kernel.DiagnosticsTest do
|
||||
purge(Sample)
|
||||
end
|
||||
|
||||
@tag :tmp_dir
|
||||
test "simple warning with tabs (line + file)", %{tmp_dir: tmp_dir} do
|
||||
path = make_relative_tmp(tmp_dir, "long-warning.ex")
|
||||
|
||||
source = """
|
||||
defmodule Sample do
|
||||
\t@file "#{path}"
|
||||
\tdefp a do
|
||||
\t\tUnknown.b()
|
||||
\tend
|
||||
end
|
||||
"""
|
||||
|
||||
File.write!(path, source)
|
||||
|
||||
expected = """
|
||||
warning: Unknown.b/0 is undefined (module Unknown is not available or is yet to be defined). Make sure the module name is correct and has been specified in full (or that an alias has been defined)
|
||||
│
|
||||
4 │ \t\tUnknown.b()
|
||||
│ ~~~~~~~~~~~
|
||||
│
|
||||
└─ #{path}:4: Sample.a/0
|
||||
"""
|
||||
|
||||
assert capture_eval(source, columns: false) =~ expected
|
||||
after
|
||||
purge(Sample)
|
||||
end
|
||||
|
||||
test "simple warning (no file)" do
|
||||
source = """
|
||||
defmodule Sample do
|
||||
|
||||
Reference in New Issue
Block a user