Skip to content

Commit

Permalink
Merge pull request #1141 from erlang-ls/1140-do-not-assume-string-des…
Browse files Browse the repository at this point in the history
…criptions-in-make-code

[1140] Do not include error description in code
  • Loading branch information
robertoaloi authored Nov 24, 2021
2 parents d499966 + a1bfa58 commit 4f40375
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
-module(diagnostics_parse_transform_error).

-compile({parse_transform, my_parse_transform}).

-export([ function_a/0 ]).

function_a() ->
ok.
11 changes: 11 additions & 0 deletions apps/els_lsp/priv/code_navigation/src/my_parse_transform.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
-module(my_parse_transform).

-export([ parse_transform/2 ]).

-export([ format_error/1 ]).

parse_transform(_Forms, _Options) ->
[{error, {42, ?MODULE, custom_description}}].

format_error(Desc) ->
lists:flatten(io_lib:format("~p", [Desc])).
5 changes: 2 additions & 3 deletions apps/els_lsp/src/els_compiler_diagnostics.erl
Original file line number Diff line number Diff line change
Expand Up @@ -630,9 +630,8 @@ make_code(erl_parse, "bad " ++ _Str) ->
make_code(erl_parse, _Other) ->
<<"P1799">>;

make_code(Module, Reason) ->
unicode:characters_to_binary(
io_lib:format("~p:~s", [Module, Reason])).
make_code(Module, _Reason) ->
unicode:characters_to_binary(io_lib:format("~p", [Module])).

%-----------------------------------------------------------------------

Expand Down
15 changes: 15 additions & 0 deletions apps/els_lsp/test/els_diagnostics_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
, compiler_with_parse_transform_included/1
, compiler_with_parse_transform_broken/1
, compiler_with_parse_transform_deps/1
, compiler_with_parse_transform_error/1
, compiler_telemetry/1
, code_path_extra_dirs/1
, use_long_names/1
Expand Down Expand Up @@ -348,6 +349,20 @@ compiler_with_parse_transform_deps(_Config) ->
Hints = [],
els_test:run_diagnostics_test(Path, Source, Errors, Warnings, Hints).

%% Issue 1140
-spec compiler_with_parse_transform_error(config()) -> ok.
compiler_with_parse_transform_error(_Config) ->
Path = src_path("diagnostics_parse_transform_error.erl"),
Source = <<"Compiler">>,
Errors = [#{ code => <<"my_parse_transform">>
, message => <<"custom_description">>
, range => {{41, 0}, {42, 0}}
}
],
Warnings = [],
Hints = [],
els_test:run_diagnostics_test(Path, Source, Errors, Warnings, Hints).

-spec compiler_telemetry(config()) -> ok.
compiler_telemetry(Config) ->
Path = src_path("diagnostics.erl"),
Expand Down

0 comments on commit 4f40375

Please sign in to comment.