Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions apps/expert/lib/expert/configuration.ex
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ defmodule Expert.Configuration do
maybe_watched_extensions_request(new_config, settings)
end

defp apply_config_change(%__MODULE__{} = old_config, _settings) do
{:ok, old_config}
end

defp set_lsp_log_level(%__MODULE__{} = config, settings) do
%__MODULE__{config | log_level: parse_lsp_log_level(settings)}
end
Expand Down
39 changes: 39 additions & 0 deletions apps/expert/test/expert/configuration_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,20 @@ defmodule Expert.ConfigurationTest do

assert updated.log_level == :info
end

test "ignores non-map settings values" do
change = build_change(%{"logLevel" => "warning"})
{:ok, updated} = Configuration.on_change(change)

assert updated.log_level == :warning

for settings <- [nil, [], "bad", 123, true] do
assert {:ok, updated} = Configuration.on_change(build_change(settings))

assert updated.log_level == :warning
assert updated.workspace_symbols.min_query_length == 2
end
end
end

describe "on_change/1 with workspace_symbols.min_query_length" do
Expand Down Expand Up @@ -227,6 +241,31 @@ defmodule Expert.ConfigurationTest do
end
end

describe "on_change/1 watched files registration" do
test "does not register watched files for non-map settings" do
assert {:ok, updated} = Configuration.on_change(build_change(nil))

assert updated.additional_watched_extensions == nil
end

test "nil settings do not reset previously configured values" do
change =
build_change(%{
"logLevel" => "warning",
"workspaceSymbols" => %{"minQueryLength" => 5}
})

{:ok, updated} = Configuration.on_change(change)
assert updated.log_level == :warning
assert updated.workspace_symbols.min_query_length == 5

{:ok, after_nil} = Configuration.on_change(build_change(nil))

assert after_nil.log_level == :warning
assert after_nil.workspace_symbols.min_query_length == 5
end
end

defp build_change(settings) do
%WorkspaceDidChangeConfiguration{
params: %DidChangeConfigurationParams{
Expand Down
18 changes: 18 additions & 0 deletions apps/expert/test/expert_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ defmodule Expert.ExpertTest do
alias Expert.State
alias Forge.Project
alias Forge.Test.Fixtures
alias GenLSP.Notifications.WorkspaceDidChangeConfiguration
alias GenLSP.Structures.DidChangeConfigurationParams

setup do
:persistent_term.erase(Expert.Configuration)
Expand Down Expand Up @@ -104,6 +106,22 @@ defmodule Expert.ExpertTest do
}}
end

test "accepts didChangeConfiguration notifications with null settings" do
project = Fixtures.project()

{:ok, _response, state} = State.initialize(State.new(), initialize_request(project, []))

notification = %WorkspaceDidChangeConfiguration{
params: %DidChangeConfigurationParams{settings: nil}
}

assert {:ok, ^state} = State.apply(state, notification)

config = Expert.Configuration.get()
assert config.log_level == :info
assert config.workspace_symbols.min_query_length == 2
end

defp initialize_lsp(project, opts \\ []) do
assigns = start_supervised!(GenLSP.Assigns, id: make_ref())

Expand Down
Loading