mirror of
https://github.com/slint-ui/slint.git
synced 2025-10-26 18:06:26 +00:00
FIX: lsp: Improve URL encoding
This commit is contained in:
parent
e7ff4c196e
commit
fe0ac9d6e8
4 changed files with 23 additions and 9 deletions
|
|
@ -124,10 +124,7 @@ impl ComponentContainer {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn subtree_component(self: Pin<&Self>) -> ItemTreeWeak {
|
pub fn subtree_component(self: Pin<&Self>) -> ItemTreeWeak {
|
||||||
self.item_tree
|
self.item_tree.borrow().as_ref().map_or(ItemTreeWeak::default(), vtable::VRc::downgrade)
|
||||||
.borrow()
|
|
||||||
.as_ref()
|
|
||||||
.map_or(ItemTreeWeak::default(), |rc| vtable::VRc::downgrade(rc))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn visit_children_item(
|
pub fn visit_children_item(
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ pub type Result<T> = std::result::Result<T, Error>;
|
||||||
pub type UrlVersion = Option<i32>;
|
pub type UrlVersion = Option<i32>;
|
||||||
|
|
||||||
/// A versioned file
|
/// A versioned file
|
||||||
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
|
#[derive(Clone, serde::Deserialize, serde::Serialize)]
|
||||||
pub struct VersionedUrl {
|
pub struct VersionedUrl {
|
||||||
/// The file url
|
/// The file url
|
||||||
pub url: Url,
|
pub url: Url,
|
||||||
|
|
@ -20,6 +20,13 @@ pub struct VersionedUrl {
|
||||||
pub version: UrlVersion,
|
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
|
/// A versioned file
|
||||||
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
|
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
|
||||||
pub struct Position {
|
pub struct Position {
|
||||||
|
|
|
||||||
|
|
@ -83,14 +83,21 @@ fn create_show_preview_command(
|
||||||
|
|
||||||
#[cfg(feature = "preview-external")]
|
#[cfg(feature = "preview-external")]
|
||||||
pub fn request_state(ctx: &std::rc::Rc<Context>) {
|
pub fn request_state(ctx: &std::rc::Rc<Context>) {
|
||||||
use i_slint_compiler::{diagnostics::Spanned, pathutils::to_url};
|
use i_slint_compiler::diagnostics::Spanned;
|
||||||
|
|
||||||
let cache = ctx.document_cache.borrow();
|
let cache = ctx.document_cache.borrow();
|
||||||
let documents = &cache.documents;
|
let documents = &cache.documents;
|
||||||
|
|
||||||
for (p, d) in documents.all_file_documents() {
|
for (p, d) in documents.all_file_documents() {
|
||||||
if let Some(node) = &d.node {
|
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;
|
continue;
|
||||||
};
|
};
|
||||||
let url = VersionedUrl { url, version: node.source_file().and_then(|sf| sf.version()) };
|
let url = VersionedUrl { url, version: node.source_file().and_then(|sf| sf.version()) };
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,6 @@ mod preview;
|
||||||
pub mod util;
|
pub mod util;
|
||||||
|
|
||||||
use common::{ComponentInformation, PreviewApi, Result, VersionedUrl};
|
use common::{ComponentInformation, PreviewApi, Result, VersionedUrl};
|
||||||
use i_slint_compiler::pathutils::to_url;
|
|
||||||
use language::*;
|
use language::*;
|
||||||
|
|
||||||
use i_slint_compiler::CompilerConfiguration;
|
use i_slint_compiler::CompilerConfiguration;
|
||||||
|
|
@ -341,8 +340,12 @@ fn main_loop(connection: Connection, init_param: InitializeParams, cli_args: Cli
|
||||||
Box::pin(async move {
|
Box::pin(async move {
|
||||||
let contents = std::fs::read_to_string(&path);
|
let contents = std::fs::read_to_string(&path);
|
||||||
if let Ok(contents) = &contents {
|
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);
|
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)
|
Some(contents)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue