diff --git a/internal/core/items/component_container.rs b/internal/core/items/component_container.rs index 9e4ba3092..2b781b7fa 100644 --- a/internal/core/items/component_container.rs +++ b/internal/core/items/component_container.rs @@ -124,10 +124,7 @@ impl ComponentContainer { } pub fn subtree_component(self: Pin<&Self>) -> ItemTreeWeak { - self.item_tree - .borrow() - .as_ref() - .map_or(ItemTreeWeak::default(), |rc| vtable::VRc::downgrade(rc)) + self.item_tree.borrow().as_ref().map_or(ItemTreeWeak::default(), vtable::VRc::downgrade) } pub fn visit_children_item( diff --git a/tools/lsp/common.rs b/tools/lsp/common.rs index e71f79cad..0fe6bbefa 100644 --- a/tools/lsp/common.rs +++ b/tools/lsp/common.rs @@ -12,7 +12,7 @@ pub type Result = std::result::Result; pub type UrlVersion = Option; /// A versioned file -#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)] +#[derive(Clone, serde::Deserialize, serde::Serialize)] pub struct VersionedUrl { /// The file url pub url: Url, @@ -20,6 +20,13 @@ pub struct VersionedUrl { pub version: UrlVersion, } +impl std::fmt::Debug for VersionedUrl { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + let version = self.version.map(|v| format!("v{v}")).unwrap_or_else(|| "none".to_string()); + write!(f, "{}@{}", self.url, version) + } +} + /// A versioned file #[derive(Clone, Debug, serde::Deserialize, serde::Serialize)] pub struct Position { diff --git a/tools/lsp/language.rs b/tools/lsp/language.rs index c17eeda16..391902821 100644 --- a/tools/lsp/language.rs +++ b/tools/lsp/language.rs @@ -83,14 +83,21 @@ fn create_show_preview_command( #[cfg(feature = "preview-external")] pub fn request_state(ctx: &std::rc::Rc) { - use i_slint_compiler::{diagnostics::Spanned, pathutils::to_url}; + use i_slint_compiler::diagnostics::Spanned; let cache = ctx.document_cache.borrow(); let documents = &cache.documents; for (p, d) in documents.all_file_documents() { if let Some(node) = &d.node { - let Some(url) = to_url(&p.to_string_lossy()) else { + if p.starts_with("builtin:/") { + continue; // The preview knows these, too. + } + let Ok(url) = Url::from_file_path(p) else { + i_slint_core::debug_log!( + "Could not sent contents of file {p:?}: NOT AN URL (request state!)" + ); + continue; }; let url = VersionedUrl { url, version: node.source_file().and_then(|sf| sf.version()) }; diff --git a/tools/lsp/main.rs b/tools/lsp/main.rs index d6f1ead7f..25e4adb74 100644 --- a/tools/lsp/main.rs +++ b/tools/lsp/main.rs @@ -14,7 +14,6 @@ mod preview; pub mod util; use common::{ComponentInformation, PreviewApi, Result, VersionedUrl}; -use i_slint_compiler::pathutils::to_url; use language::*; use i_slint_compiler::CompilerConfiguration; @@ -341,8 +340,12 @@ fn main_loop(connection: Connection, init_param: InitializeParams, cli_args: Cli Box::pin(async move { let contents = std::fs::read_to_string(&path); if let Ok(contents) = &contents { - if let Some(url) = to_url(&path) { + if let Ok(url) = Url::from_file_path(&path) { preview_notifier.set_contents(&VersionedUrl { url, version: None }, contents); + } else { + i_slint_core::debug_log!( + "Could not sent contents of file {path:?}: NOT AN URL" + ); } } Some(contents)