diff --git a/tools/lsp/common/rename_component.rs b/tools/lsp/common/rename_component.rs index 7085581ed3b..09cc9f6ca73 100644 --- a/tools/lsp/common/rename_component.rs +++ b/tools/lsp/common/rename_component.rs @@ -381,27 +381,6 @@ mod tests { changed_text } - fn find_component_declared_identifier( - document_node: &syntax_nodes::Document, - name: &str, - ) -> Option { - for c in document_node.Component() { - let cid = c.DeclaredIdentifier(); - if cid.text().to_string().trim() == name { - return Some(cid); - } - } - for e in document_node.ExportsList() { - if let Some(c) = e.Component() { - let cid = c.DeclaredIdentifier(); - if cid.text().to_string().trim() == name { - return Some(cid); - } - } - } - None - } - #[test] fn test_rename_component_from_definition_ok() { let document_cache = test::compile_test_with_sources( @@ -437,7 +416,7 @@ export component Bar { let doc = document_cache.get_document_by_path(&test::main_test_file_name()).unwrap(); let foo_identifier = - find_component_declared_identifier(doc.node.as_ref().unwrap(), "Foo").unwrap(); + preview::find_component_identifier(doc.node.as_ref().unwrap(), "Foo").unwrap(); let edit = rename_component_from_definition(&document_cache, &foo_identifier, "XxxYyyZzz") .unwrap(); @@ -462,7 +441,7 @@ export component Bar { let doc = document_cache.get_document_by_path(&test::main_test_file_name()).unwrap(); let foo_identifier = - find_component_declared_identifier(doc.node.as_ref().unwrap(), "Foo").unwrap(); + preview::find_component_identifier(doc.node.as_ref().unwrap(), "Foo").unwrap(); let edit = rename_component_from_definition(&document_cache, &foo_identifier, "FooXXX").unwrap(); @@ -503,7 +482,7 @@ export { Foo as FExport } document_cache.get_document_by_path(&test::test_file_name("source.slint")).unwrap(); let foo_identifier = - find_component_declared_identifier(doc.node.as_ref().unwrap(), "Foo").unwrap(); + preview::find_component_identifier(doc.node.as_ref().unwrap(), "Foo").unwrap(); let edit = rename_component_from_definition(&document_cache, &foo_identifier, "XxxYyyZzz") .unwrap(); @@ -597,7 +576,7 @@ export { Foo as User4Fxx } document_cache.get_document_by_path(&test::test_file_name("source.slint")).unwrap(); let foo_identifier = - find_component_declared_identifier(doc.node.as_ref().unwrap(), "Foo").unwrap(); + preview::find_component_identifier(doc.node.as_ref().unwrap(), "Foo").unwrap(); let edit = rename_component_from_definition(&document_cache, &foo_identifier, "XxxYyyZzz") .unwrap(); @@ -712,7 +691,7 @@ export { Foo as User4Fxx } document_cache.get_document_by_path(&test::test_file_name("s/source.slint")).unwrap(); let foo_identifier = - find_component_declared_identifier(doc.node.as_ref().unwrap(), "Foo").unwrap(); + preview::find_component_identifier(doc.node.as_ref().unwrap(), "Foo").unwrap(); let edit = rename_component_from_definition(&document_cache, &foo_identifier, "XxxYyyZzz") .unwrap(); @@ -788,7 +767,7 @@ export component Foo { } document_cache.get_document_by_path(&test::test_file_name("user1.slint")).unwrap(); let foo_identifier = - find_component_declared_identifier(doc.node.as_ref().unwrap(), "Foo").unwrap(); + preview::find_component_identifier(doc.node.as_ref().unwrap(), "Foo").unwrap(); let edit = rename_component_from_definition(&document_cache, &foo_identifier, "XxxYyyZzz") .unwrap(); @@ -811,7 +790,7 @@ export component Foo { } document_cache.get_document_by_path(&test::test_file_name("user2.slint")).unwrap(); let foo_identifier = - find_component_declared_identifier(doc.node.as_ref().unwrap(), "Foo").unwrap(); + preview::find_component_identifier(doc.node.as_ref().unwrap(), "Foo").unwrap(); let edit = rename_component_from_definition(&document_cache, &foo_identifier, "XxxYyyZzz") .unwrap(); @@ -863,7 +842,7 @@ export component Bar { let doc = document_cache.get_document_by_path(&test::main_test_file_name()).unwrap(); let foo_identifier = - find_component_declared_identifier(doc.node.as_ref().unwrap(), "Foo").unwrap(); + preview::find_component_identifier(doc.node.as_ref().unwrap(), "Foo").unwrap(); assert!(rename_component_from_definition(&document_cache, &foo_identifier, "Foo").is_err()); assert!(rename_component_from_definition(&document_cache, &foo_identifier, "UsedStruct")