Skip to content

Commit f0260a5

Browse files
authored
config: Remove all code related to "static setting" (#307)
Our configuration system has had two concepts: "dynamic setting" and "static setting". However, in practice, static settings were never actually used. Static settings require server restart, but such configurations should actually be specified as `init_params.initializationOptions` and should be handled in the initialization lifecycle. For these reasons, the "static setting" concept in `ConfigManager` is unnecessary, so this commit removes all related code.
1 parent 65d1f44 commit f0260a5

File tree

7 files changed

+50
-267
lines changed

7 files changed

+50
-267
lines changed

src/config.jl

Lines changed: 4 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -180,23 +180,11 @@ so `config` is guaranteed to not be `nothing`.
180180
"""
181181
Base.@constprop :aggressive function get_config(manager::ConfigManager, key_path::Symbol...)
182182
data = load(manager)
183-
config = if is_static_setting(key_path...)
184-
getobjpath(data.__filled_static_settings__, key_path...)
185-
else
186-
getobjpath(data.__filled_settings__, key_path...)
187-
end
183+
config = getobjpath(data.__filled_settings__, key_path...)
188184
@assert !isnothing(config) "Invalid default configuration values"
189185
return config
190186
end
191187

192-
function fix_static_settings!(manager::ConfigManager)
193-
store!(manager) do old_data::ConfigManagerData
194-
new_static = get_settings(old_data)
195-
new_data = ConfigManagerData(old_data; static_settings=new_static)
196-
return new_data, new_static
197-
end
198-
end
199-
200188
struct ConfigChange
201189
path::String
202190
old_val
@@ -206,19 +194,14 @@ end
206194

207195
mutable struct ConfigChangeTracker
208196
changed_settings::Vector{ConfigChange}
209-
changed_static_settings::Vector{ConfigChange}
210197
diagnostic_setting_changed::Bool
211198
end
212-
ConfigChangeTracker() = ConfigChangeTracker(ConfigChange[], ConfigChange[], false)
199+
ConfigChangeTracker() = ConfigChangeTracker(ConfigChange[], false)
213200

214201
function (tracker::ConfigChangeTracker)(old_val, new_val, path::Tuple{Vararg{Symbol}})
215202
if old_val !== new_val
216203
path_str = join(path, ".")
217-
if is_static_setting(path...)
218-
push!(tracker.changed_static_settings, ConfigChange(path_str, old_val, new_val))
219-
else
220-
push!(tracker.changed_settings, ConfigChange(path_str, old_val, new_val))
221-
end
204+
push!(tracker.changed_settings, ConfigChange(path_str, old_val, new_val))
222205
if !isempty(path) && first(path) === :diagnostic
223206
tracker.diagnostic_setting_changed = true
224207
end
@@ -235,34 +218,12 @@ function changed_settings_message(changed_settings::Vector{ConfigChange})
235218
return "Changes applied: $body"
236219
end
237220

238-
function changed_static_settings_message(changed_settings::Vector{ConfigChange})
239-
body = map(changed_settings) do config_change
240-
old_repr = repr(config_change.old_val)
241-
new_repr = repr(config_change.new_val)
242-
"`$(config_change.path)` (`$old_repr` => `$new_repr`)"
243-
end |> (x -> join(x, ", "))
244-
return "Static settings affected (requires restart to apply): $body"
245-
end
246-
247221
function notify_config_changes(
248222
server::Server,
249223
tracker::ConfigChangeTracker,
250224
source::AbstractString
251225
)
252-
if !isempty(tracker.changed_static_settings) && !isempty(tracker.changed_settings)
253-
show_warning_message(server, """
254-
Configuration changed.
255-
Source: $source
256-
$(changed_settings_message(tracker.changed_settings))
257-
$(changed_static_settings_message(tracker.changed_static_settings))
258-
""")
259-
elseif !isempty(tracker.changed_static_settings)
260-
show_warning_message(server, """
261-
Configuration changed.
262-
Source: $source
263-
$(changed_static_settings_message(tracker.changed_static_settings))
264-
""")
265-
elseif !isempty(tracker.changed_settings)
226+
if !isempty(tracker.changed_settings)
266227
show_info_message(server, """
267228
Configuration changed.
268229
Source: $source

src/initialize.jl

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
# NOTE: Static server settings that require a server restart to take effect should be
2+
# accessed during server initialization via `state.init_params.initializationOptions`.
3+
# These settings differ from dynamic configuration options managed by `ConfigManager`
4+
# that can be changed at throughout server lifecycle.
5+
16
"""
27
Receives `msg::InitializeRequest` and sets up the `server.state` based on `msg.params`.
38
As a response to this `msg`, it returns an `InitializeResponse` and performs registration of
@@ -268,9 +273,7 @@ function handle_InitializedNotification(server::Server)
268273
end
269274
end
270275
# - Load LSP configuration
271-
# In a case when client doesn't support the pull model configuration,
272-
# use `init_params.initializationOptions` as the fallback
273-
load_lsp_config!(server, state.init_params.initializationOptions, "[LSP] initialize"; on_init=true)
276+
load_lsp_config!(server, nothing, "[LSP] initialize"; on_init=true)
274277

275278
registrations = Registration[]
276279

src/types.jl

Lines changed: 4 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -310,8 +310,6 @@ Note that `TypeX` should not be defined to include the possibility of being `not
310310
In such cases, a further inner configuration level should be used.
311311
312312
Then, overload the following methods properly:
313-
- `is_static_setting(::Type{NewConfig}, field::Symbol) -> Bool`
314-
Returns whether a setting requires server restart.
315313
- `default_config(::Type{NewConfig}) -> NewConfig`
316314
Returns the default configuration values.
317315
@@ -325,15 +323,11 @@ _unwrap_maybe(::Type{T}) where {T} = T
325323
@option struct FullAnalysisConfig <: ConfigSection
326324
debounce::Maybe{Float64}
327325
end
328-
329-
is_static_setting(::Type{FullAnalysisConfig}, ::Symbol) = false
330326
default_config(::Type{FullAnalysisConfig}) = FullAnalysisConfig(1.0)
331327

332328
@option struct TestRunnerConfig <: ConfigSection
333329
executable::Maybe{String}
334330
end
335-
336-
is_static_setting(::Type{TestRunnerConfig}, ::Symbol) = false
337331
default_config(::Type{TestRunnerConfig}) = TestRunnerConfig(@static Sys.iswindows() ? "testrunner.bat" : "testrunner")
338332

339333
@option "custom" struct CustomFormatterConfig
@@ -342,9 +336,6 @@ default_config(::Type{TestRunnerConfig}) = TestRunnerConfig(@static Sys.iswindow
342336
end
343337

344338
const FormatterConfig = Union{String,CustomFormatterConfig}
345-
346-
is_static_setting(::Type{FormatterConfig}) = false
347-
is_static_setting(::Type{FormatterConfig}, ::Symbol) = false
348339
default_config(::Type{FormatterConfig}) = "Runic"
349340

350341
function default_executable(formatter::String)
@@ -407,39 +398,20 @@ Base.convert(::Type{DiagnosticPattern}, x::AbstractDict{String}) =
407398
enabled::Maybe{Bool}
408399
patterns::Maybe{Vector{DiagnosticPattern}}
409400
end
410-
411-
is_static_setting(::Type{DiagnosticConfig}, ::Symbol) = false
412401
default_config(::Type{DiagnosticConfig}) = DiagnosticConfig(true, DiagnosticPattern[])
413402

414-
# configuration item for test purpose
415-
@option struct InternalConfig <: ConfigSection
416-
static_setting::Maybe{Int}
417-
dynamic_setting::Maybe{Int}
418-
end
419-
420-
is_static_setting(::Type{InternalConfig}, field::Symbol) = field == :static_setting
421-
default_config(::Type{InternalConfig}) = InternalConfig(0, 0)
422-
423403
@option struct JETLSConfig <: ConfigSection
424404
diagnostic::Maybe{DiagnosticConfig}
425405
full_analysis::Maybe{FullAnalysisConfig}
426406
testrunner::Maybe{TestRunnerConfig}
427407
formatter::Maybe{FormatterConfig}
428-
internal::Maybe{InternalConfig}
429408
end
430409

431-
is_static_setting(path::Symbol...) =
432-
is_static_setting(JETLSConfig, path...)
433-
is_static_setting(::Type{<:ConfigSection}) = false
434-
is_static_setting(::Type{T}, head::Symbol, rest::Symbol...) where {T<:ConfigSection} =
435-
is_static_setting(_unwrap_maybe(fieldtype(T, head)), rest...)
436-
437410
const DEFAULT_CONFIG = JETLSConfig(
438411
diagnostic = default_config(DiagnosticConfig),
439412
full_analysis = default_config(FullAnalysisConfig),
440413
testrunner = default_config(TestRunnerConfig),
441414
formatter = default_config(FormatterConfig),
442-
internal = default_config(InternalConfig)
443415
)
444416

445417
function get_default_config(path::Symbol...)
@@ -451,15 +423,12 @@ end
451423
const EMPTY_CONFIG = JETLSConfig()
452424

453425
struct ConfigManagerData
454-
static_settings::JETLSConfig
455426
file_config::JETLSConfig
456427
lsp_config::JETLSConfig
457428
file_config_path::Union{Nothing,String}
458429
__settings__::JETLSConfig
459-
__filled_static_settings__::JETLSConfig
460430
__filled_settings__::JETLSConfig
461431
function ConfigManagerData(
462-
static_settings::JETLSConfig,
463432
file_config::JETLSConfig,
464433
lsp_config::JETLSConfig,
465434
file_config_path::Union{Nothing,String}
@@ -476,23 +445,21 @@ struct ConfigManagerData
476445
__settings__ = merge_setting(__settings__, lsp_config)
477446
__settings__ = merge_setting(__settings__, file_config)
478447
# Create setting structs without `nothing` values for use by `get_config`
479-
__filled_static_settings__ = merge_setting(DEFAULT_CONFIG, static_settings)
480448
__filled_settings__ = merge_setting(DEFAULT_CONFIG, __settings__)
481-
return new(static_settings, file_config, lsp_config, file_config_path,
482-
__settings__, __filled_static_settings__, __filled_settings__)
449+
return new(file_config, lsp_config, file_config_path,
450+
__settings__, __filled_settings__)
483451
end
484452
end
485453

486-
ConfigManagerData() = ConfigManagerData(DEFAULT_CONFIG, EMPTY_CONFIG, EMPTY_CONFIG, nothing)
454+
ConfigManagerData() = ConfigManagerData(EMPTY_CONFIG, EMPTY_CONFIG, nothing)
487455

488456
function ConfigManagerData(
489457
data::ConfigManagerData;
490-
static_settings::JETLSConfig = data.static_settings,
491458
file_config::JETLSConfig = data.file_config,
492459
lsp_config::JETLSConfig = data.lsp_config,
493460
file_config_path::Union{Nothing,String} = data.file_config_path
494461
)
495-
return ConfigManagerData(static_settings, file_config, lsp_config, file_config_path)
462+
return ConfigManagerData(file_config, lsp_config, file_config_path)
496463
end
497464

498465
get_settings(data::ConfigManagerData) = data.__settings__

src/workspace-configuration.jl

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ function (handler::LoadLSPConfigHandler)(server::Server, @nospecialize(config_va
1313
end
1414
if handler.on_init
1515
# Don't notify even if values different from defaults are loaded initially
16-
fix_static_settings!(server.state.config_manager)
1716
else
1817
notify_config_changes(handler.server, tracker, handler.source)
1918
if tracker.diagnostic_setting_changed
@@ -105,7 +104,6 @@ function load_lsp_config!(
105104
store_lsp_config!(tracker, server, settings, source)
106105
if on_init
107106
# Don't notify even if values different from defaults are loaded initially
108-
fix_static_settings!(server.state.config_manager)
109107
else
110108
notify_config_changes(server, tracker, source)
111109
if tracker.diagnostic_setting_changed

test/test_config.jl

Lines changed: 5 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -12,35 +12,24 @@ using JETLS
1212
@test_throws FieldError JETLS.get_default_config(:full_analysis, :nonexistent)
1313
end
1414

15-
@testset "`is_static_setting`" begin
16-
@test !JETLS.is_static_setting(:internal, :dynamic_setting)
17-
@test JETLS.is_static_setting(:internal, :static_setting)
18-
@test !JETLS.is_static_setting(:testrunner, :executable)
19-
end
20-
2115
@testset "`merge_setting`" begin
2216
base_config = JETLS.JETLSConfig(;
2317
full_analysis=JETLS.FullAnalysisConfig(1.0),
2418
testrunner=JETLS.TestRunnerConfig("base_runner"),
25-
internal=JETLS.InternalConfig(10, 20)
2619
)
2720
overlay_config = JETLS.JETLSConfig(;
2821
full_analysis=JETLS.FullAnalysisConfig(2.0),
29-
internal=JETLS.InternalConfig(30, nothing)
3022
)
3123
merged = JETLS.merge_setting(base_config, overlay_config)
3224

3325
@test JETLS.getobjpath(merged, :full_analysis, :debounce) == 2.0
3426
@test JETLS.getobjpath(merged, :testrunner, :executable) == "base_runner"
35-
@test JETLS.getobjpath(merged, :internal, :static_setting) == 30
36-
@test JETLS.getobjpath(merged, :internal, :dynamic_setting) == 20
3727
end
3828

3929
@testset "`on_difference`" begin
4030
let config1 = JETLS.JETLSConfig(;
4131
full_analysis=JETLS.FullAnalysisConfig(1.0),
4232
testrunner=JETLS.TestRunnerConfig("runner1"),
43-
internal=JETLS.InternalConfig(1, 1)
4433
)
4534
config2 = JETLS.JETLSConfig(;
4635
full_analysis=JETLS.FullAnalysisConfig(2.0),
@@ -54,8 +43,6 @@ using JETLS
5443
@test Set(paths_called) == Set([
5544
(:full_analysis, :debounce),
5645
(:testrunner, :executable),
57-
(:internal, :static_setting),
58-
(:internal, :dynamic_setting) # even though new_val is nothing, track the path
5946
])
6047
end
6148
end
@@ -131,23 +118,21 @@ end
131118
test_config = JETLS.JETLSConfig(;
132119
full_analysis=JETLS.FullAnalysisConfig(2.0),
133120
testrunner=JETLS.TestRunnerConfig("test_runner"),
134-
internal=JETLS.InternalConfig(5, nothing)
135121
)
136122

137123
store_file_config!(manager, "/foo/bar/.JETLSConfig.toml", test_config)
138-
JETLS.fix_static_settings!(manager)
139124

140125
@test JETLS.get_config(manager, :full_analysis, :debounce) === 2.0
141126
@test JETLS.get_config(manager, :testrunner, :executable) === "test_runner"
142127
@test_throws FieldError JETLS.get_config(manager, :nonexistent)
143128

144129
# Type stability check (N.B: Nothing is not allowed)
145130
@test Base.infer_return_type((typeof(manager),)) do manager
146-
JETLS.get_config(manager, :internal, :dynamic_setting)
147-
end == Int
131+
JETLS.get_config(manager, :full_analysis, :debounce)
132+
end == Float64
148133
@test Base.infer_return_type((typeof(manager),)) do manager
149-
JETLS.get_config(manager, :internal, :static_setting)
150-
end == Int
134+
JETLS.get_config(manager, :formatter)
135+
end == JETLS.FormatterConfig
151136

152137
# Test priority: file config has higher priority than LSP config
153138
lsp_config = JETLS.JETLSConfig(;
@@ -161,49 +146,13 @@ end
161146

162147
# Test updating config
163148
store_lsp_config!(manager, JETLS.EMPTY_CONFIG)
164-
changed_static_keys = Set{String}()
165149
updated_config = JETLS.JETLSConfig(;
166150
full_analysis=JETLS.FullAnalysisConfig(3.0),
167151
testrunner=JETLS.TestRunnerConfig("new_runner"),
168-
internal=JETLS.InternalConfig(10, nothing)
169152
)
170-
let data = JETLS.load(manager)
171-
current_config = data.file_config
172-
JETLS.on_difference(current_config, updated_config) do _, new_val, path
173-
if JETLS.is_static_setting(JETLS.JETLSConfig, path...)
174-
push!(changed_static_keys, join(path, "."))
175-
end
176-
return new_val
177-
end
178-
end
179153
store_file_config!(manager, "/foo/bar/.JETLSConfig.toml", updated_config)
180-
181-
# `on_static_setting` should be called for static keys
182-
@test changed_static_keys == Set(["internal.static_setting"])
183-
# non static keys should be changed dynamically
184-
@test JETLS.get_config(manager, :testrunner, :executable) == "new_runner"
185154
@test JETLS.get_config(manager, :full_analysis, :debounce) == 3.0
186-
# static keys should NOT change (they stay at the fixed values)
187-
@test JETLS.get_config(manager, :internal, :static_setting) == 5
188-
end
189-
190-
@testset "`fix_static_settings!`" begin
191-
manager = JETLS.ConfigManager(JETLS.ConfigManagerData())
192-
file_config = JETLS.JETLSConfig(;
193-
internal=JETLS.InternalConfig(2, nothing)
194-
)
195-
lsp_config = JETLS.JETLSConfig(;
196-
internal=JETLS.InternalConfig(999, nothing),
197-
testrunner=JETLS.TestRunnerConfig("custom")
198-
)
199-
200-
store_file_config!(manager, "/path/.JETLSConfig.toml", file_config)
201-
store_lsp_config!(manager, lsp_config)
202-
JETLS.fix_static_settings!(manager)
203-
204-
# File config (higher priority) should win for the static keys
205-
data = JETLS.load(manager)
206-
@test JETLS.getobjpath(data.static_settings, :internal, :static_setting) == 2
155+
@test JETLS.get_config(manager, :testrunner, :executable) == "new_runner"
207156
end
208157

209158
@testset "LSP configuration priority and merging" begin
@@ -229,14 +178,11 @@ end
229178

230179
@testset "LSP configuration merging without file config" begin
231180
manager = JETLS.ConfigManager(JETLS.ConfigManagerData())
232-
233181
lsp_config = JETLS.JETLSConfig(;
234182
full_analysis=JETLS.FullAnalysisConfig(3.0),
235183
testrunner=JETLS.TestRunnerConfig("lsp_runner")
236184
)
237-
238185
store_lsp_config!(manager, lsp_config)
239-
240186
@test JETLS.get_config(manager, :testrunner, :executable) == "lsp_runner"
241187
@test JETLS.get_config(manager, :full_analysis, :debounce) == 3.0
242188
end

test/test_diagnostics.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ end
215215

216216
function make_test_manager(config_dict::Dict{String,Any})
217217
lsp_config = JETLS.Configurations.from_dict(JETLS.JETLSConfig, config_dict)
218-
data = JETLS.ConfigManagerData(JETLS.DEFAULT_CONFIG, JETLS.EMPTY_CONFIG, lsp_config, nothing)
218+
data = JETLS.ConfigManagerData(JETLS.EMPTY_CONFIG, lsp_config, nothing)
219219
return JETLS.ConfigManager(data)
220220
end
221221

0 commit comments

Comments
 (0)