use lsp_types::DidChangeConfigurationParams;
use serde_json::Value;
use crate::lsp::dispatch::runtime_incremental_parsing_from_value;
use crate::lsp::documents;
use crate::lsp::global_state::GlobalState;
pub(crate) fn did_change_configuration(gs: &mut GlobalState, params: DidChangeConfigurationParams) {
if !params.settings.is_null() {
apply_runtime_settings(gs, ¶ms.settings);
}
gs.pull_configuration();
reload_and_settle(gs);
}
pub(crate) fn apply_pulled_configuration(gs: &mut GlobalState, value: Value) {
let Some(section) = value.as_array().and_then(|items| items.first()) else {
return;
};
if section.is_null() {
return;
}
apply_runtime_settings(gs, section);
reload_and_settle(gs);
}
fn apply_runtime_settings(gs: &mut GlobalState, value: &Value) {
if let Some(incremental) = crate::lsp::dispatch::incremental_parsing_env_override()
.or_else(|| runtime_incremental_parsing_from_value(value))
&& gs.runtime_settings.experimental_incremental_parsing != incremental
{
log::debug!(
"lsp runtime setting experimental.incrementalParsing={incremental} (client settings)"
);
gs.runtime_settings.experimental_incremental_parsing = incremental;
if incremental {
let open: Vec<(crate::salsa::FileText, crate::salsa::FileConfig)> = gs
.document_map
.values()
.map(|state| (state.salsa_file, state.salsa_config))
.collect();
for (file, config) in open {
gs.salsa.reparse_admit(file, config);
}
} else {
gs.salsa.reparse_clear();
}
}
}
fn reload_and_settle(gs: &mut GlobalState) {
documents::reload_open_documents_config(gs);
gs.arm_settle();
}