Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lsp: Update ElementRcNode to return the full debug info #8012

Merged
merged 1 commit into from
Apr 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions tools/lsp/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,14 +177,11 @@ impl ElementRcNode {
/// Run with all the debug information on the node
pub fn with_element_debug<R>(
&self,
func: impl Fn(
&i_slint_compiler::parser::syntax_nodes::Element,
&Option<i_slint_compiler::layout::Layout>,
) -> R,
func: impl Fn(&i_slint_compiler::object_tree::ElementDebugInfo) -> R,
) -> R {
let elem = self.element.borrow();
let d = &elem.debug.get(self.debug_index).unwrap();
func(&d.node, &d.layout)
let d = elem.debug.get(self.debug_index).unwrap();
func(d)
}

/// Run with the `Element` node
Expand Down
13 changes: 8 additions & 5 deletions tools/lsp/preview/element_selection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,8 +332,9 @@ pub fn selection_stack_at(
selected.as_ref() == Some(&en)
};

let (type_name, id, is_layout) = en.with_element_debug(|el, layout| {
let id = el
let (type_name, id, is_layout) = en.with_element_debug(|di| {
let id = di
.node
.parent()
.and_then(|p| {
if p.kind() == SyntaxKind::SubElement {
Expand All @@ -346,7 +347,8 @@ pub fn selection_stack_at(
.unwrap_or_default();

let type_name = {
el.parent()
di.node
.parent()
.and_then(|p| {
if p.kind() == SyntaxKind::Component {
p.child_node(SyntaxKind::DeclaredIdentifier)
Expand All @@ -356,15 +358,16 @@ pub fn selection_stack_at(
}
})
.or_else(|| {
el.QualifiedName()
di.node
.QualifiedName()
.map(|qn| qn.text().to_string().trim().to_string())
})
.unwrap_or_default()
.trim()
.to_string()
};

(type_name, id, layout.is_some())
(type_name, id, di.layout.is_some())
});

(type_name, id, is_layout, is_selected, path, offset)
Expand Down
2 changes: 1 addition & 1 deletion tools/lsp/preview/ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ pub trait ElementRcNodeExt {

impl ElementRcNodeExt for common::ElementRcNode {
fn layout_kind(&self) -> crate::preview::ui::LayoutKind {
self.with_element_debug(|_, l| match l {
self.with_element_debug(|di| match &di.layout {
Some(layout::Layout::GridLayout(_)) => ui::LayoutKind::Grid,
Some(layout::Layout::BoxLayout(layout::BoxLayout {
orientation: layout::Orientation::Horizontal,
Expand Down