From eabd9e88ed1b7a3718e7d482220653acc37248e9 Mon Sep 17 00:00:00 2001 From: Tobias Hunger Date: Fri, 29 Nov 2024 12:26:01 +0100 Subject: [PATCH] lsp: Invalidate rust files that get their slint! macro removed ... so we do not keep stray code lenses around (and probably not end up having other issues down the line). --- tools/lsp/language.rs | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/tools/lsp/language.rs b/tools/lsp/language.rs index 25e87655ac0..eed8f1c846b 100644 --- a/tools/lsp/language.rs +++ b/tools/lsp/language.rs @@ -729,19 +729,35 @@ pub(crate) async fn reload_document_impl( content = match i_slint_compiler::lexer::extract_rust_macro(content) { Some(content) => content, // A rust file without a rust macro, just ignore it - None => return [(url, vec![])].into_iter().collect(), + None => { + if document_cache.get_document(&url).is_some() { + // This had contents before: Continue so we can invalidate it! + String::new() + } else { + return [(url, vec![])].into_iter().collect(); + } + } }; } if let Some(ctx) = ctx { - ctx.server_notifier.send_message_to_preview(common::LspToPreviewMessage::SetContents { - url: common::VersionedUrl::new(url.clone(), version), - contents: content.clone(), - }); + if content.is_empty() { + ctx.server_notifier.send_message_to_preview(common::LspToPreviewMessage::FileLost { + url: url.clone(), + }); + } else { + ctx.server_notifier.send_message_to_preview(common::LspToPreviewMessage::SetContents { + url: common::VersionedUrl::new(url.clone(), version), + contents: content.clone(), + }); + } } let dependencies = document_cache.invalidate_url(&url); let mut diag = BuildDiagnostics::default(); - let _ = document_cache.load_url(&url, version, content, &mut diag).await; // ignore url conversion errors + if !content.is_empty() { + let _ = document_cache.load_url(&url, version, content, &mut diag).await; + // ignore url conversion errors + } for dep in &dependencies { if ctx.is_some_and(|ctx| ctx.open_urls.borrow().contains(dep)) {