From c4eec75cb20732dc4bc03931d0002e788f062ca5 Mon Sep 17 00:00:00 2001 From: Joichiro Hayashi Date: Sat, 2 May 2026 00:39:32 +0900 Subject: [PATCH] fix(lsp): preserve opened buffers across config reload MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit reload_config rebuilt source_cache from disk via load_all_sources, overwriting in-memory buffers for files the client had opened with didOpen. When a cvk.json change event reached the server after a didOpen — common under parallel test load where the FS watcher delivers the cvk.json modification mid-test — the searcher was rebuilt against stale disk content and rename/diagnostics missed unsaved edits. Re-apply opened_documents on top of the fresh source_cache before rebuilding the parse cache and searcher. Co-Authored-By: Claude Opus 4.7 --- crates/css-var-kit/src/commands/lsp.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/crates/css-var-kit/src/commands/lsp.rs b/crates/css-var-kit/src/commands/lsp.rs index 64272e4..05d5684 100644 --- a/crates/css-var-kit/src/commands/lsp.rs +++ b/crates/css-var-kit/src/commands/lsp.rs @@ -365,7 +365,13 @@ impl Server<'_> { match Config::load_for_lsp(&self.lsp_root_dir, self.init_options.clone()) { Ok(new_config) => { self.config = new_config; - self.source_cache = load_all_sources(&self.config); + let mut source_cache = load_all_sources(&self.config); + for (uri, text) in &self.opened_documents { + if let Some(rel_path) = self.uri_to_rel_path(uri) { + source_cache.insert(Rc::::from(rel_path), OwnedStr::from(text)); + } + } + self.source_cache = source_cache; self.parse_cache = build_parse_cache(&self.source_cache); self.searcher = build_searcher(&self.parse_cache, &self.config); self.log("config reloaded");