Skip to content

Commit

Permalink
Do not report an error for doc attributes file invalid in erlang module
Browse files Browse the repository at this point in the history
Summary:
The `erlang` module for OTP 27 has a doc attribute

```
-doc {file,"../../doc/src/erlang_system_info.md"}.
```

The referenced file is not included in all erlang binary packages, so silence the error if it is not found.

Also, some errors emitted by `elp_epp` were referring to `epp`, not `elp_epp`, so were not being formatted correctly.

Reviewed By: RobinMorisset

Differential Revision: D60166779

fbshipit-source-id: 5c2f77bd458396cb826df4c2c6352ac94f636fe8
  • Loading branch information
alanz authored and facebook-github-bot committed Jul 24, 2024
1 parent 5885bbd commit b531363
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 10 deletions.
31 changes: 31 additions & 0 deletions crates/ide/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2274,4 +2274,35 @@ baz(1)->4.
"#,
);
}

#[test]
fn file_not_found_doc_attribute() {
check_diagnostics(
r#"
//- erlang_service
//- native
//- /my_app/src/a_file.erl
-module(a_file).
-doc {file,"../../doc/src/info.md"}.
%% ^^^^^^^^^^^^^^^^^^^^^^^ error: can't find doc file "../../doc/src/info.md"
"#,
);
}

#[test]
fn file_not_found_doc_attribute_ignored_in_erlang() {
check_diagnostics(
r#"
//- erlang_service
//- native
//- /my_app/src/erlang.erl
-module(erlang).
-doc {file,"../../doc/src/info.md"}.
"#,
);
}
}
33 changes: 23 additions & 10 deletions erlang_service/src/elp_epp.erl
Original file line number Diff line number Diff line change
Expand Up @@ -1017,10 +1017,10 @@ scan_filedoc(
scan_filedoc_content(DocFilename, Dot, DocType, From, St);
scan_filedoc([{'(', _}, {'{', _}, {atom, _, file} | _] = Toks, DocType, From, St) ->
T = find_mismatch(['(', '{', atom, ',', string, '}', ')', dot], Toks, DocType),
epp_reply(From, {error, {loc(T), epp, {bad, DocType}}}),
epp_reply(From, {error, {loc(T), elp_epp, {bad, DocType}}}),
wait_req_scan(St);
scan_filedoc([{'(', _}, {'{', _}, T | _], DocType, From, St) ->
epp_reply(From, {error, {loc(T), epp, {DocType, invalid, file}}}),
epp_reply(From, {error, {loc(T), elp_epp, {DocType, invalid, file}}}),
wait_req_scan(St);
scan_filedoc(
[
Expand All @@ -1038,18 +1038,18 @@ scan_filedoc(
scan_filedoc_content(DocFilename, Dot, DocType, From, St);
scan_filedoc([{'{', _}, {atom, _, file} | _] = Toks, {atom, _, DocType}, From, St) ->
T = find_mismatch(['{', {atom, file}, ',', string, '}', dot], Toks, DocType),
epp_reply(From, {error, {loc(T), epp, {bad, DocType}}}),
epp_reply(From, {error, {loc(T), elp_epp, {bad, DocType}}}),
wait_req_scan(St);
scan_filedoc([{'{', _}, T | _], {atom, _, DocType}, From, St) ->
epp_reply(From, {error, {loc(T), epp, {DocType, invalid, file}}}),
epp_reply(From, {error, {loc(T), elp_epp, {DocType, invalid, file}}}),
wait_req_scan(St).

%% Reads the content of the file and rewrites the AST as if
%% the content had been written in-place.
scan_filedoc_content(
{string, _A, DocFilename},
{string, DocLoc, DocFilename},
Dot,
{atom, DocLoc, Doc},
{atom, _DocLoc, Doc},
From,
#epp{name = CurrentFilename} = St
) ->
Expand Down Expand Up @@ -1085,11 +1085,24 @@ scan_filedoc_content(
wait_req_scan(St);
{error, _} ->
ok = file:close(NewF),
epp_reply(From, {error, {DocLoc, epp, {Doc, file, DocFilename}}}),
epp_reply(From, {error, {DocLoc, elp_epp, {Doc, file, DocFilename}}}),
wait_req_scan(St)
end;
{error, _} ->
epp_reply(From, {error, {DocLoc, epp, {Doc, file, DocFilename}}}),
%% We are unable to load the specified include file for the doc contents.
%% The `erlang.erl` OTP file tries to include files not shipped. So skip them.
case maps:get('MODULE', St#epp.macs) of
{none, [{atom, _, erlang}]} ->
Loc = DocLoc,
epp_reply(
From,
{ok,
[{'-', Loc}, {atom, Loc, Doc}] ++
[{string, Loc, unicode:characters_to_list("**skipping**")}, {dot, Loc}]}
);
_ ->
epp_reply(From, {error, {DocLoc, elp_epp, {Doc, file, DocFilename}}})
end,
wait_req_scan(St)
end.

Expand Down Expand Up @@ -1525,9 +1538,9 @@ scan_if([{'(', _} | _] = Toks, If, From, St) ->
{_, erl_parse, _} ->
{error, Error0};
{error, ErrL, What} ->
{error, {ErrL, epp, What}};
{error, {ErrL, elp_epp, What}};
_ ->
{error, {loc(If), epp, Error0}}
{error, {loc(If), elp_epp, Error0}}
end,
epp_reply(From, Error),
wait_req_skip(St, ['if'])
Expand Down

0 comments on commit b531363

Please sign in to comment.