mirror of
https://github.com/slint-ui/slint.git
synced 2025-11-02 12:58:23 +00:00
live-preview: Use PathBuf in DeclarationInformation
This commit is contained in:
parent
0f0b76e952
commit
6d81096ac6
4 changed files with 10 additions and 18 deletions
|
|
@ -15,6 +15,7 @@ use i_slint_compiler::parser::{syntax_nodes, Language, SyntaxKind, TextRange, Te
|
|||
use lsp_types::Url;
|
||||
|
||||
use std::collections::HashSet;
|
||||
use std::path::PathBuf;
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct DefinitionInformation {
|
||||
|
|
@ -26,7 +27,7 @@ pub struct DefinitionInformation {
|
|||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct DeclarationInformation {
|
||||
pub uri: Url,
|
||||
pub path: PathBuf,
|
||||
pub start_position: TextSize,
|
||||
}
|
||||
|
||||
|
|
@ -98,8 +99,7 @@ fn add_element_properties(
|
|||
}
|
||||
|
||||
let declared_at = value.type_node().as_ref().map(|n| DeclarationInformation {
|
||||
uri: Url::from_file_path(n.source_file.path())
|
||||
.unwrap_or_else(|_| Url::parse("file:///unnamed").unwrap()),
|
||||
path: n.source_file.path().to_path_buf(),
|
||||
start_position: n.text_range().start(),
|
||||
});
|
||||
Some(PropertyInformation {
|
||||
|
|
@ -1299,7 +1299,6 @@ component MainWindow inherits Window {
|
|||
}
|
||||
}
|
||||
"#.to_string());
|
||||
let file_url = url.clone();
|
||||
|
||||
let doc = dc.get_document(&url).unwrap();
|
||||
let source = &doc.node.as_ref().unwrap().source_file;
|
||||
|
|
@ -1312,7 +1311,7 @@ component MainWindow inherits Window {
|
|||
|
||||
let declaration = foo_property.declared_at.as_ref().unwrap();
|
||||
let start_position = util::text_size_to_lsp_position(&source, declaration.start_position);
|
||||
assert_eq!(declaration.uri, file_url);
|
||||
assert_eq!(declaration.path, source.path());
|
||||
assert_eq!(start_position.line, 3);
|
||||
assert_eq!(start_position.character, 20); // This should probably point to the start of
|
||||
// `property<int> foo = 42`, not to the `<`
|
||||
|
|
@ -1344,7 +1343,7 @@ component SomeRect inherits Rectangle {
|
|||
assert_eq!(glob_property.type_name, "int");
|
||||
let declaration = glob_property.declared_at.as_ref().unwrap();
|
||||
let start_position = util::text_size_to_lsp_position(&source, declaration.start_position);
|
||||
assert_eq!(declaration.uri, url);
|
||||
assert_eq!(declaration.path, source.path());
|
||||
assert_eq!(start_position.line, 2);
|
||||
assert_eq!(glob_property.group, "");
|
||||
assert_eq!(find_property(&result, "width"), None);
|
||||
|
|
@ -1354,7 +1353,7 @@ component SomeRect inherits Rectangle {
|
|||
assert_eq!(abcd_property.type_name, "int");
|
||||
let declaration = abcd_property.declared_at.as_ref().unwrap();
|
||||
let start_position = util::text_size_to_lsp_position(&source, declaration.start_position);
|
||||
assert_eq!(declaration.uri, url);
|
||||
assert_eq!(declaration.path, source.path());
|
||||
assert_eq!(start_position.line, 7);
|
||||
assert_eq!(abcd_property.group, "");
|
||||
|
||||
|
|
|
|||
|
|
@ -224,16 +224,11 @@ fn map_property_declaration(
|
|||
declared_at: &Option<properties::DeclarationInformation>,
|
||||
) -> Option<PropertyDeclaration> {
|
||||
let da = declared_at.as_ref()?;
|
||||
|
||||
let doc = document_cache.get_document(&da.uri)?;
|
||||
let doc_node = doc.node.as_ref()?;
|
||||
let source_version =
|
||||
document_cache.document_version_by_path(doc_node.source_file.path()).unwrap_or(-1);
|
||||
|
||||
let source_version = document_cache.document_version_by_path(&da.path).unwrap_or(-1);
|
||||
let pos = TextRange::new(da.start_position, da.start_position);
|
||||
|
||||
Some(PropertyDeclaration {
|
||||
source_uri: da.uri.to_string().into(),
|
||||
source_path: da.path.to_string_lossy().to_string().into(),
|
||||
source_version,
|
||||
range: to_ui_range(pos)?,
|
||||
})
|
||||
|
|
@ -414,7 +409,7 @@ fn map_properties_to_ui(
|
|||
for pi in &properties.properties {
|
||||
let declared_at = map_property_declaration(document_cache, &pi.declared_at).unwrap_or(
|
||||
PropertyDeclaration {
|
||||
source_uri: String::new().into(),
|
||||
source_path: String::new().into(),
|
||||
source_version: -1,
|
||||
range: Range { start: 0, end: 0 },
|
||||
},
|
||||
|
|
|
|||
|
|
@ -62,8 +62,6 @@ impl PreviewConnector {
|
|||
) -> Result<PreviewConnectorPromise, JsValue> {
|
||||
console_error_panic_hook::set_once();
|
||||
|
||||
i_slint_core::debug_log!("PreviewConnector: Enable experimental? {experimental}");
|
||||
|
||||
WASM_CALLBACKS.set(Some(WasmCallbacks { lsp_notifier, resource_url_mapper }));
|
||||
|
||||
Ok(JsValue::from(js_sys::Promise::new(&mut move |resolve, reject| {
|
||||
|
|
|
|||
|
|
@ -88,7 +88,7 @@ export struct PropertyDefinition {
|
|||
|
||||
/// The Property Declaration
|
||||
export struct PropertyDeclaration {
|
||||
source-uri: string,
|
||||
source-path: string,
|
||||
source-version: int,
|
||||
range: Range,
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue