Skip to content

Commit b060d23

Browse files
authored
fix(expert): save new configuration after workspace/didChangeConfiguration (#282)
State handler of workspace/didChangeConfiguration message was always returning old configuration, so the changes to dialyzer support were not preserved. This is maybe not super important, as the dialyzer config does not seem to be used anywhere, but it gets the general `didChangeConfiguration` flow right for the future - and I would like to add `projectDir` change handled by `didChangeConfiguration`, as this is default way to tweak the setting per-project in Emacs.
1 parent 1204313 commit b060d23

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

apps/expert/lib/expert/state.ex

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,6 @@ defmodule Expert.State do
9191
GenLSP.request(Expert.get_lsp(), request)
9292
{:ok, %__MODULE__{state | configuration: config}}
9393
end
94-
95-
{:ok, state}
9694
end
9795

9896
def apply(%__MODULE__{} = state, %Notifications.WorkspaceDidChangeWorkspaceFolders{

apps/expert/test/expert_test.exs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,32 @@ defmodule Expert.ExpertTest do
77

88
import Expert.Test.Protocol.TransportSupport
99

10+
describe "workspace/didChangeConfiguration" do
11+
test "updates configuration when settings change" do
12+
with_patched_transport()
13+
14+
patch(Expert.Dialyzer, :check_support, :ok)
15+
16+
project = Fixtures.project()
17+
lsp = initialize_lsp(project)
18+
19+
# dialyzer_enabled? defaults to false
20+
assert GenLSP.Assigns.get(lsp.assigns).state.configuration.dialyzer_enabled? == false
21+
22+
did_change_config = %GenLSP.Notifications.WorkspaceDidChangeConfiguration{
23+
jsonrpc: "2.0",
24+
method: "workspace/didChangeConfiguration",
25+
params: %GenLSP.Structures.DidChangeConfigurationParams{
26+
settings: %{"dialyzerEnabled" => true}
27+
}
28+
}
29+
30+
assert {:noreply, updated_lsp} = Expert.handle_notification(did_change_config, lsp)
31+
32+
assert GenLSP.Assigns.get(updated_lsp.assigns).state.configuration.dialyzer_enabled? == true
33+
end
34+
end
35+
1036
test "sends an error message on engine initialization error" do
1137
with_patched_transport()
1238

0 commit comments

Comments
 (0)