Skip to content

Commit

Permalink
Add edoc_parse_enabled to config (erlang-ls#1464)
Browse files Browse the repository at this point in the history
Add config option to disable edoc parsing.

Found that parsing some files took very long
time to edoc parsewhich made completion break.

Simple solution, add an option to disable the
edoc parsing ifone runs into such issues.
  • Loading branch information
plux committed Dec 20, 2023
1 parent b2b9945 commit cee4096
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 15 deletions.
2 changes: 2 additions & 0 deletions apps/els_core/src/els_config.erl
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ do_initialize(RootUri, Capabilities, InitOptions, {ConfigPath, Config}) ->

RefactorErl = maps:get("refactorerl", Config, notconfigured),
Providers = maps:get("providers", Config, #{}),
EdocParseEnabled = maps:get("edoc_parse_enabled", Config, true),

%% Initialize and start Wrangler
case maps:get("wrangler", Config, notconfigured) of
Expand Down Expand Up @@ -236,6 +237,7 @@ do_initialize(RootUri, Capabilities, InitOptions, {ConfigPath, Config}) ->
ok = set(elvis_config_path, ElvisConfigPath),
ok = set(compiler_telemetry_enabled, CompilerTelemetryEnabled),
ok = set(edoc_custom_tags, EDocCustomTags),
ok = set(edoc_parse_enabled, EdocParseEnabled),
ok = set(incremental_sync, IncrementalSync),
ok = set(
indexing,
Expand Down
54 changes: 39 additions & 15 deletions apps/els_lsp/src/els_docs.erl
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
-type application_type() :: 'local' | 'remote'.

%%==============================================================================
%% Dialyer Ignores (due to upstream bug, see ERL-1262
%% Dialyzer Ignores (due to upstream bug, see ERL-1262
%%==============================================================================
-dialyzer({nowarn_function, function_docs/4}).

Expand Down Expand Up @@ -103,18 +103,33 @@ docs(_M, _POI) ->
-spec function_docs(application_type(), atom(), atom(), non_neg_integer()) ->
[els_markup_content:doc_entry()].
function_docs(Type, M, F, A) ->
%% call via ?MODULE to enable mocking in tests
case ?MODULE:eep48_docs(function, M, F, A) of
{ok, Docs} ->
[{text, Docs}];
{error, not_available} ->
%% We cannot fetch the EEP-48 style docs, so instead we create
%% something similar using the tools we have.
case edoc_parse_enabled() of
true ->
%% call via ?MODULE to enable mocking in tests
case ?MODULE:eep48_docs(function, M, F, A) of
{ok, Docs} ->
[{text, Docs}];
{error, not_available} ->
%% We cannot fetch the EEP-48 style docs, so instead we create
%% something similar using the tools we have.
Sig = {h2, signature(Type, M, F, A)},
L = [
function_clauses(M, F, A),
specs(M, F, A),
edoc(M, F, A)
],
case lists:append(L) of
[] ->
[Sig];
Docs ->
[Sig, {text, "---"} | Docs]
end
end;
false ->
Sig = {h2, signature(Type, M, F, A)},
L = [
function_clauses(M, F, A),
specs(M, F, A),
edoc(M, F, A)
specs(M, F, A)
],
case lists:append(L) of
[] ->
Expand All @@ -127,11 +142,16 @@ function_docs(Type, M, F, A) ->
-spec type_docs(application_type(), atom(), atom(), non_neg_integer()) ->
[els_markup_content:doc_entry()].
type_docs(_Type, M, F, A) ->
%% call via ?MODULE to enable mocking in tests
case ?MODULE:eep48_docs(type, M, F, A) of
{ok, Docs} ->
[{text, Docs}];
{error, not_available} ->
case edoc_parse_enabled() of
true ->
%% call via ?MODULE to enable mocking in tests
case ?MODULE:eep48_docs(type, M, F, A) of
{ok, Docs} ->
[{text, Docs}];
{error, not_available} ->
type(M, F, A)
end;
false ->
type(M, F, A)
end.

Expand Down Expand Up @@ -495,3 +515,7 @@ spawn_group_proxy(Acc) ->
M ->
spawn_group_proxy([M | Acc])
end.

-spec edoc_parse_enabled() -> boolean().
edoc_parse_enabled() ->
true == els_config:get(edoc_parse_enabled).

0 comments on commit cee4096

Please sign in to comment.