fix: Adding tuple fields in ADT, chore: test action section
unindentation
@@ -100,6 +100,8 @@ pub(crate) fn extract_module(acc: &mut Assists, ctx: &AssistContext) -> Option<(
"Extract Module",
module.text_range,
|builder| {
+ let _ = &module;
+
let mut body_items = Vec::new();
let new_item_indent = old_item_indent + 1;
for item in module.body_items {
@@ -148,7 +150,7 @@ struct Module {
}
fn extract_target(node: &SyntaxNode, selection_range: TextRange) -> Option<Module> {
- let body_items: Vec<ast::Item> = node
+ let mut body_items: Vec<ast::Item> = node
.children()
.filter_map(|child| {
if let Some(item) = ast::Item::cast(child.clone()) {
@@ -161,6 +163,10 @@ fn extract_target(node: &SyntaxNode, selection_range: TextRange) -> Option<Modul
})
.collect();
+ if let Some(node_item) = ast::Item::cast(node.clone()) {
+ body_items.push(node_item);
+ }
+
Some(Module { text_range: selection_range, name: "modname".to_string(), body_items })
}
@@ -169,7 +175,7 @@ impl Module {
&self,
ctx: &AssistContext,
) -> (HashMap<FileId, Vec<(TextRange, String)>>, Vec<SyntaxNode>) {
- let mut record_fields = Vec::new();
+ let mut adt_fields = Vec::new();
let mut refs: HashMap<FileId, Vec<(TextRange, String)>> = HashMap::new();
//Here impl is not included as each item inside impl will be tied to the parent of
@@ -183,18 +189,31 @@ impl Module {
let node_def = Definition::ModuleDef(nod.into());
self.expand_and_group_usages_file_wise(ctx, node_def, &mut refs);
- let mut get_record_fields = |it: ast::Adt| {
- for desc in it.syntax().descendants() {
- if let Some(record_field) = ast::RecordField::cast(desc) {
- record_fields.push(record_field.syntax().clone());
- }
- }
- };
-
//Enum Fields are not allowed to explicitly specify pub, it is implied
match it {
- ast::Adt::Struct(_) => get_record_fields(it),
- ast::Adt::Union(_) => get_record_fields(it),
+ ast::Adt::Struct(x) => {
+ if let Some(field_list) = x.field_list() {
+ match field_list {
+ ast::FieldList::RecordFieldList(record_field_list) => {
+ record_field_list.fields().for_each(|record_field| {
+ adt_fields.push(record_field.syntax().clone());
+ });
+ },
+ ast::FieldList::TupleFieldList(tuple_field_list) => {
+ tuple_field_list.fields().for_each(|tuple_field| {
+ adt_fields.push(tuple_field.syntax().clone());
+ });
+ },
+ }
+ }
+ },
+ ast::Adt::Union(x) => {
+ if let Some(record_field_list) = x.record_field_list() {
+ record_field_list.fields().for_each(|record_field| {
+ adt_fields.push(record_field.syntax().clone());
+ });
+ }
+ },
ast::Adt::Enum(_) => {},
}
}
@@ -228,7 +247,7 @@ impl Module {
}
});
- return (refs, record_fields);
+ return (refs, adt_fields);
}
fn expand_and_group_usages_file_wise(
