Skip to content

Commit

Permalink
LSP: autocompletion: de-normalize the element id (#6491)
Browse files Browse the repository at this point in the history
So that it preserves `-` vs. `_` in element id and global names

Fixes #6479

ChangeLog: LSP: preserve `_` when auto-completing element identifiers
  • Loading branch information
ogoffart authored Oct 9, 2024
1 parent b3f19e4 commit 63df45d
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions tools/lsp/language/completion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -648,6 +648,19 @@ fn completion_item_from_expression(str: &str, lookup_result: LookupResult) -> Co
| Expression::PropertyReference(nr) => {
de_normalize_property_name_with_element(&nr.element(), str).into_owned()
}
Expression::ElementReference(e) => e
.upgrade()
.and_then(|e| e.borrow().debug.first().and_then(|d| d.node.parent()))
.and_then(|n| match n.kind() {
SyntaxKind::SubElement => n.child_text(SyntaxKind::Identifier),
// global
SyntaxKind::Component => n
.child_node(SyntaxKind::DeclaredIdentifier)
.and_then(|n| n.child_text(SyntaxKind::Identifier)),
_ => None,
})
.filter(|x| i_slint_compiler::parser::normalize_identifier(x) == str)
.map_or_else(|| str.to_string(), |t| t.to_string()),
_ => str.to_string(),
};

Expand Down Expand Up @@ -968,23 +981,23 @@ mod tests {
fn in_expression() {
let with_semi = r#"
component Bar inherits Text { nope := Rectangle {} property <string> red; }
global Glib { property <int> gama; }
global The_Glib { property <int> gama; }
component Foo {
property <int> alpha;
pure function funi() {}
bobo := Bar {
the_bo-bo := Bar {
property <int> beta;
width: 🔺;
}
}
"#;
let without_semi = r#"
component Bar inherits Text { nope := Rectangle {} property <string> red; }
global Glib { property <int> gama; }
global The_Glib { property <int> gama; }
component Foo {
property <int> alpha;
pure function funi() {}
bobo := Bar {
the_bo-bo := Bar {
property <int> beta;
width: 🔺
}
Expand All @@ -995,11 +1008,11 @@ mod tests {
res.iter().find(|ci| ci.label == "alpha").unwrap();
res.iter().find(|ci| ci.label == "beta").unwrap();
res.iter().find(|ci| ci.label == "funi").unwrap();
res.iter().find(|ci| ci.label == "Glib").unwrap();
res.iter().find(|ci| ci.label == "The_Glib").unwrap();
res.iter().find(|ci| ci.label == "Colors").unwrap();
res.iter().find(|ci| ci.label == "Math").unwrap();
res.iter().find(|ci| ci.label == "animation-tick").unwrap();
res.iter().find(|ci| ci.label == "bobo").unwrap();
res.iter().find(|ci| ci.label == "the_bo-bo").unwrap();
res.iter().find(|ci| ci.label == "true").unwrap();
res.iter().find(|ci| ci.label == "self").unwrap();
res.iter().find(|ci| ci.label == "root").unwrap();
Expand Down

0 comments on commit 63df45d

Please sign in to comment.