@@ -4,13 +4,13 @@ defmodule ElixirLS.LanguageServer.Diagnostics do
4
4
5
5
def normalize ( diagnostics , root_path ) do
6
6
for diagnostic <- diagnostics do
7
- { type , file , line , description , stacktrace } =
7
+ { type , file , position , description , stacktrace } =
8
8
extract_message_info ( diagnostic . message , root_path )
9
9
10
10
diagnostic
11
11
|> update_message ( type , description , stacktrace )
12
12
|> maybe_update_file ( file )
13
- |> maybe_update_position ( type , line , stacktrace )
13
+ |> maybe_update_position ( type , position , stacktrace )
14
14
end
15
15
end
16
16
@@ -32,9 +32,9 @@ defmodule ElixirLS.LanguageServer.Diagnostics do
32
32
stacktrace = reversed_stacktrace |> Enum . map ( & String . trim / 1 ) |> Enum . reverse ( )
33
33
34
34
{ type , message_without_type } = split_type_and_message ( message )
35
- { file , line , description } = split_file_and_description ( message_without_type , root_path )
35
+ { file , position , description } = split_file_and_description ( message_without_type , root_path )
36
36
37
- { type , file , line , description , stacktrace }
37
+ { type , file , position , description , stacktrace }
38
38
end
39
39
40
40
defp update_message ( diagnostic , type , description , stacktrace ) do
@@ -68,31 +68,31 @@ defmodule ElixirLS.LanguageServer.Diagnostics do
68
68
end
69
69
end
70
70
71
- defp maybe_update_position ( diagnostic , "TokenMissingError" , line , stacktrace ) do
71
+ defp maybe_update_position ( diagnostic , "TokenMissingError" , position , stacktrace ) do
72
72
case extract_line_from_missing_hint ( diagnostic . message ) do
73
- line when is_integer ( line ) ->
73
+ line when is_integer ( line ) and line > 0 ->
74
74
% { diagnostic | position: line }
75
75
76
76
_ ->
77
- do_maybe_update_position ( diagnostic , line , stacktrace )
77
+ do_maybe_update_position ( diagnostic , position , stacktrace )
78
78
end
79
79
end
80
80
81
- defp maybe_update_position ( diagnostic , _type , line , stacktrace ) do
82
- do_maybe_update_position ( diagnostic , line , stacktrace )
81
+ defp maybe_update_position ( diagnostic , _type , position , stacktrace ) do
82
+ do_maybe_update_position ( diagnostic , position , stacktrace )
83
83
end
84
84
85
- defp do_maybe_update_position ( diagnostic , line , stacktrace ) do
85
+ defp do_maybe_update_position ( diagnostic , position , stacktrace ) do
86
86
cond do
87
- line ->
88
- % { diagnostic | position: line }
87
+ position != nil ->
88
+ % { diagnostic | position: position }
89
89
90
90
diagnostic . position ->
91
91
diagnostic
92
92
93
93
true ->
94
94
line = extract_line_from_stacktrace ( diagnostic . file , stacktrace )
95
- % { diagnostic | position: line }
95
+ % { diagnostic | position: max ( line , 0 ) }
96
96
end
97
97
end
98
98
@@ -107,9 +107,18 @@ defmodule ElixirLS.LanguageServer.Diagnostics do
107
107
end
108
108
109
109
defp split_file_and_description ( message , root_path ) do
110
- with { file , line , _column , description } <- get_message_parts ( message ) ,
110
+ with { file , line , column , description } <- get_message_parts ( message ) ,
111
111
{ :ok , path } <- file_path ( file , root_path ) do
112
- { path , String . to_integer ( line ) , description }
112
+ line = String . to_integer ( line )
113
+
114
+ position =
115
+ cond do
116
+ line == 0 -> 0
117
+ column == "" -> line
118
+ true -> { line , String . to_integer ( column ) }
119
+ end
120
+
121
+ { path , position , description }
113
122
else
114
123
_ ->
115
124
{ nil , nil , message }
@@ -279,7 +288,7 @@ defmodule ElixirLS.LanguageServer.Diagnostics do
279
288
lines = SourceFile . lines ( source_file )
280
289
# line is 1 based
281
290
start_line = Enum . at ( lines , line_start - 1 )
282
- # SourceFile.elixir_character_to_lsp assumes char to be 1 based but it's 0 based bere
291
+ # SourceFile.elixir_character_to_lsp assumes char to be 1 based but it's 0 based here
283
292
character = SourceFile . elixir_character_to_lsp ( start_line , char_start + 1 )
284
293
285
294
% {
@@ -303,7 +312,7 @@ defmodule ElixirLS.LanguageServer.Diagnostics do
303
312
start_line = Enum . at ( lines , line_start - 1 )
304
313
end_line = Enum . at ( lines , line_end - 1 )
305
314
306
- # SourceFile.elixir_character_to_lsp assumes char to be 1 based but it's 0 based bere
315
+ # SourceFile.elixir_character_to_lsp assumes char to be 1 based but it's 0 based here
307
316
start_char = SourceFile . elixir_character_to_lsp ( start_line , char_start + 1 )
308
317
end_char = SourceFile . elixir_character_to_lsp ( end_line , char_end + 1 )
309
318
@@ -319,16 +328,10 @@ defmodule ElixirLS.LanguageServer.Diagnostics do
319
328
}
320
329
end
321
330
322
- # position is 0 which means unknown
323
- # we return the full file range
324
- defp range ( 0 , source_file ) when not is_nil ( source_file ) do
325
- SourceFile . full_range ( source_file )
326
- end
327
-
328
- # source file is unknown
331
+ # source file is unknown, position is 0 or invalid
329
332
# we discard any position information as it is meaningless
330
333
# unfortunately LSP does not allow `null` range so we need to return something
331
- defp range ( _ , nil ) do
334
+ defp range ( _ , _ ) do
332
335
# we don't care about utf16 positions here as we send 0
333
336
% { "start" => % { "line" => 0 , "character" => 0 } , "end" => % { "line" => 0 , "character" => 0 } }
334
337
end
0 commit comments