Skip to content

Commit

Permalink
[#1310] Add a configuration option for advertised LSP providers. (#1341)
Browse files Browse the repository at this point in the history
* add a configuration option for advertised LSP providers

* clean up `is_enabled/0` callbacks
  • Loading branch information
the-mikedavis authored Jul 4, 2022
1 parent 274beb7 commit 9f70a42
Show file tree
Hide file tree
Showing 23 changed files with 192 additions and 135 deletions.
8 changes: 6 additions & 2 deletions apps/els_core/src/els_config.erl
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@
| compiler_telemetry_enabled
| refactorerl
| wrangler
| edoc_custom_tags.
| edoc_custom_tags
| providers.

-type path() :: file:filename().
-type state() :: #{
Expand All @@ -81,7 +82,8 @@
indexing_enabled => boolean(),
compiler_telemetry_enabled => boolean(),
wrangler => map() | 'notconfigured',
refactorerl => map() | 'notconfigured'
refactorerl => map() | 'notconfigured',
providers => map()
}.

%%==============================================================================
Expand Down Expand Up @@ -149,6 +151,7 @@ do_initialize(RootUri, Capabilities, InitOptions, {ConfigPath, Config}) ->
IndexingEnabled = maps:get(<<"indexingEnabled">>, InitOptions, true),

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

%% Initialize and start Wrangler
case maps:get("wrangler", Config, notconfigured) of
Expand Down Expand Up @@ -201,6 +204,7 @@ do_initialize(RootUri, Capabilities, InitOptions, {ConfigPath, Config}) ->
ok = set(macros, Macros),
ok = set(plt_path, DialyzerPltPath),
ok = set(code_reload, CodeReload),
ok = set(providers, Providers),
?LOG_INFO("Config=~p", [Config]),
ok = set(
runtime,
Expand Down
4 changes: 0 additions & 4 deletions apps/els_lsp/src/els_call_hierarchy_provider.erl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
-behaviour(els_provider).

-export([
is_enabled/0,
handle_request/1
]).

Expand All @@ -16,9 +15,6 @@
%%==============================================================================
%% els_provider functions
%%==============================================================================
-spec is_enabled() -> boolean().
is_enabled() -> true.

-spec handle_request(any()) -> {response, any()}.
handle_request({prepare, Params}) ->
{Uri, Line, Char} =
Expand Down
4 changes: 0 additions & 4 deletions apps/els_lsp/src/els_code_action_provider.erl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
-behaviour(els_provider).

-export([
is_enabled/0,
handle_request/1
]).

Expand All @@ -12,9 +11,6 @@
%%==============================================================================
%% els_provider functions
%%==============================================================================
-spec is_enabled() -> boolean().
is_enabled() -> true.

-spec handle_request(any()) -> {response, any()}.
handle_request({document_codeaction, Params}) ->
#{
Expand Down
4 changes: 0 additions & 4 deletions apps/els_lsp/src/els_code_lens_provider.erl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

-behaviour(els_provider).
-export([
is_enabled/0,
options/0,
handle_request/1
]).
Expand All @@ -13,9 +12,6 @@
%%==============================================================================
%% els_provider functions
%%==============================================================================
-spec is_enabled() -> boolean().
is_enabled() -> true.

-spec options() -> map().
options() ->
#{resolveProvider => false}.
Expand Down
4 changes: 0 additions & 4 deletions apps/els_lsp/src/els_definition_provider.erl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
-behaviour(els_provider).

-export([
is_enabled/0,
handle_request/1
]).

Expand All @@ -12,9 +11,6 @@
%%==============================================================================
%% els_provider functions
%%==============================================================================
-spec is_enabled() -> boolean().
is_enabled() -> true.

-spec handle_request(any()) -> {response, any()}.
handle_request({definition, Params}) ->
#{
Expand Down
4 changes: 0 additions & 4 deletions apps/els_lsp/src/els_diagnostics_provider.erl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
-behaviour(els_provider).

-export([
is_enabled/0,
options/0,
handle_request/1
]).
Expand All @@ -22,9 +21,6 @@
%%==============================================================================
%% els_provider functions
%%==============================================================================
-spec is_enabled() -> boolean().
is_enabled() -> true.

-spec options() -> map().
options() ->
#{}.
Expand Down
4 changes: 0 additions & 4 deletions apps/els_lsp/src/els_document_highlight_provider.erl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
-behaviour(els_provider).

-export([
is_enabled/0,
handle_request/1
]).

Expand All @@ -15,9 +14,6 @@
%%==============================================================================
%% els_provider functions
%%==============================================================================
-spec is_enabled() -> boolean().
is_enabled() -> true.

-spec handle_request(any()) -> {response, any()}.
handle_request({document_highlight, Params}) ->
#{
Expand Down
4 changes: 0 additions & 4 deletions apps/els_lsp/src/els_document_symbol_provider.erl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
-behaviour(els_provider).

-export([
is_enabled/0,
handle_request/1
]).

Expand All @@ -12,9 +11,6 @@
%%==============================================================================
%% els_provider functions
%%==============================================================================
-spec is_enabled() -> boolean().
is_enabled() -> true.

-spec handle_request(any()) -> {response, any()}.
handle_request({document_symbol, Params}) ->
#{<<"textDocument">> := #{<<"uri">> := Uri}} = Params,
Expand Down
4 changes: 0 additions & 4 deletions apps/els_lsp/src/els_execute_command_provider.erl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
-behaviour(els_provider).

-export([
is_enabled/0,
options/0,
handle_request/1
]).
Expand All @@ -17,9 +16,6 @@
%%==============================================================================
%% els_provider functions
%%==============================================================================
-spec is_enabled() -> boolean().
is_enabled() -> true.

-spec options() -> map().
options() ->
Commands = [
Expand Down
4 changes: 0 additions & 4 deletions apps/els_lsp/src/els_folding_range_provider.erl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
-include("els_lsp.hrl").

-export([
is_enabled/0,
handle_request/1
]).

Expand All @@ -17,9 +16,6 @@
%%==============================================================================
%% els_provider functions
%%==============================================================================
-spec is_enabled() -> boolean().
is_enabled() -> true.

-spec handle_request(tuple()) -> {response, folding_range_result()}.
handle_request({document_foldingrange, Params}) ->
#{<<"textDocument">> := #{<<"uri">> := Uri}} = Params,
Expand Down
26 changes: 4 additions & 22 deletions apps/els_lsp/src/els_formatting_provider.erl
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@
-behaviour(els_provider).

-export([
handle_request/1,
is_enabled/0,
is_enabled_document/0,
is_enabled_range/0,
is_enabled_on_type/0
handle_request/1
]).

%%==============================================================================
Expand All @@ -23,23 +19,6 @@
%%==============================================================================
%% els_provider functions
%%==============================================================================
%% Keep the behaviour happy
-spec is_enabled() -> boolean().
is_enabled() -> is_enabled_document().

-spec is_enabled_document() -> boolean().
is_enabled_document() -> true.

-spec is_enabled_range() -> boolean().
is_enabled_range() ->
false.

%% NOTE: because erlang_ls does not send incremental document changes
%% via `textDocument/didChange`, this kind of formatting does not
%% make sense.
-spec is_enabled_on_type() -> document_ontypeformatting_options().
is_enabled_on_type() -> false.

-spec handle_request(any()) -> {response, any()}.
handle_request({document_formatting, Params}) ->
#{
Expand All @@ -66,6 +45,9 @@ handle_request({document_rangeformatting, Params}) ->
{ok, Document} = els_utils:lookup_document(Uri),
{ok, TextEdit} = rangeformat_document(Uri, Document, Range, Options),
{response, TextEdit};
%% NOTE: because erlang_ls does not send incremental document changes
%% via `textDocument/didChange`, this kind of formatting does not
%% make sense.
handle_request({document_ontypeformatting, Params}) ->
#{
<<"position">> := #{
Expand Down
Loading

0 comments on commit 9f70a42

Please sign in to comment.