live_preview: Show file local components in Library

This commit is contained in:
Tobias Hunger 2024-06-18 14:57:24 +02:00 committed by Tobias Hunger
parent 49d4fc5d0f
commit 15ac565737
2 changed files with 15 additions and 3 deletions

View file

@ -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<ComponentInformation>,
) {
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::<Vec<_>>();
for component in &*doc.inner_components {

View file

@ -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));