diff --git a/tools/lsp/common/component_catalog.rs b/tools/lsp/common/component_catalog.rs index 63a5cca65..5403571c0 100644 --- a/tools/lsp/common/component_catalog.rs +++ b/tools/lsp/common/component_catalog.rs @@ -96,7 +96,7 @@ fn exported_project_component_info( } } -#[cfg(test)] +#[cfg(feature = "preview-engine")] fn file_local_component_info(name: &str, position: Position) -> ComponentInformation { ComponentInformation { name: name.to_string(), @@ -171,13 +171,13 @@ pub fn all_exported_components( result.dedup_by(|a, b| a.name == b.name); } -#[cfg(test)] +#[cfg(feature = "preview-engine")] pub fn file_local_components( document_cache: &DocumentCache, url: &lsp_types::Url, result: &mut Vec, ) { - let Some(doc) = document_cache.get_document(url) else { return }; + let Some(doc) = document_cache.get_document(url) else { return; }; let exported_components = doc.exports.iter().filter_map(|(_, e)| e.as_ref().left()).cloned().collect::>(); for component in &*doc.inner_components { diff --git a/tools/lsp/preview.rs b/tools/lsp/preview.rs index f3c26fe06..7edf23e8f 100644 --- a/tools/lsp/preview.rs +++ b/tools/lsp/preview.rs @@ -462,6 +462,11 @@ fn finish_parsing(ok: bool) { send_status("Preview not updated", Health::Error); } + let previewed_url = { + let cache = CONTENT_CACHE.get_or_init(Default::default).lock().unwrap(); + cache.current.as_ref().map(|pc| pc.url.clone()) + }; + if let Some(document_cache) = document_cache() { let mut components = Vec::new(); // `_SLINT_LivePreview` gets returned as `-SLINT-LivePreview`, which is unfortunately not a valid identifier. @@ -473,6 +478,13 @@ fn finish_parsing(ok: bool) { &mut |ci| !(ci.is_global || ci.name == private_preview_component), &mut components, ); + if let Some(previewed_url) = previewed_url { + component_catalog::file_local_components( + &document_cache, + &previewed_url, + &mut components, + ); + } components.sort_by(|a, b| a.name.cmp(&b.name));