Skip to content

Commit b653ef8

Browse files
authored
Ensure to pass an absolute path to the els_uri:uri/1 function (#1357)
The `compile:file/1` function can return a relative path depending on the directory the emulator is started on. This corner case was resulting in occasional crashes for the users which prevented diagnostics to appear if an included file contained errors.
1 parent 494bc0e commit b653ef8

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

apps/els_lsp/src/els_compiler_diagnostics.erl

+8-3
Original file line numberDiff line numberDiff line change
@@ -680,18 +680,23 @@ inclusion_range(IncludePath, Document, include) ->
680680
[Range || #{id := Id, range := Range} <- POIs, Id =:= IncludeId];
681681
inclusion_range(IncludePath, Document, include_lib) ->
682682
POIs = els_dt_document:pois(Document, [include_lib]),
683-
IncludeId = els_utils:include_lib_id(IncludePath),
683+
IncludeId = els_utils:include_lib_id(absolute_path(IncludePath)),
684684
[Range || #{id := Id, range := Range} <- POIs, Id =:= IncludeId];
685685
inclusion_range(IncludePath, Document, behaviour) ->
686686
POIs = els_dt_document:pois(Document, [behaviour]),
687-
BehaviourId = els_uri:module(els_uri:uri(els_utils:to_binary(IncludePath))),
687+
BehaviourId = els_uri:module(els_uri:uri(els_utils:to_binary(absolute_path(IncludePath)))),
688688
[Range || #{id := Id, range := Range} <- POIs, Id =:= BehaviourId];
689689
inclusion_range(IncludePath, Document, parse_transform) ->
690690
POIs = els_dt_document:pois(Document, [parse_transform]),
691691
ParseTransformId =
692-
els_uri:module(els_uri:uri(els_utils:to_binary(IncludePath))),
692+
els_uri:module(els_uri:uri(els_utils:to_binary(absolute_path(IncludePath)))),
693693
[Range || #{id := Id, range := Range} <- POIs, Id =:= ParseTransformId].
694694

695+
-spec absolute_path(string()) -> string().
696+
absolute_path(Path) ->
697+
{ok, Cwd} = file:get_cwd(),
698+
filename:join(Cwd, Path).
699+
695700
-spec macro_options() -> [macro_option()].
696701
macro_options() ->
697702
Macros = els_config:get(macros),

0 commit comments

Comments
 (0)