Skip to content

Commit

Permalink
Don't crash if custom snippets directory isn't available (#1540)
Browse files Browse the repository at this point in the history
Fixes #1428 .
  • Loading branch information
plux authored Sep 18, 2024
1 parent d38dc66 commit 527c0c8
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions apps/els_lsp/src/els_snippets_server.erl
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,12 @@ snippets_from_escript() ->
-spec custom_snippets() -> [snippet()].
custom_snippets() ->
Dir = custom_snippets_dir(),
ensure_dir(Dir),
snippets_from_dir(Dir).
case ensure_dir(Dir) of
ok ->
snippets_from_dir(Dir);
{error, _} ->
[]
end.

-spec snippets_from_dir(file:filename_all()) -> [snippet()].
snippets_from_dir(Dir) ->
Expand All @@ -141,9 +145,9 @@ snippet_from_file(Dir, Filename) ->
{ok, Content} = file:read_file(filename:join(Dir, Filename)),
{Filename, Content}.

-spec ensure_dir(file:filename_all()) -> ok.
-spec ensure_dir(file:filename_all()) -> 'ok' | {'error', _}.
ensure_dir(Dir) ->
ok = filelib:ensure_dir(filename:join(Dir, "dummy")).
filelib:ensure_dir(filename:join(Dir, "dummy")).

-spec build_snippet({binary(), binary()}) -> completion_item().
build_snippet({Name, Snippet}) ->
Expand Down

0 comments on commit 527c0c8

Please sign in to comment.