From 5b18a4eef9e69260ce2f105b33553c929cb7d827 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 23 Aug 2019 15:55:21 +0300 Subject: rename struct -> record, pos -> tuple --- crates/ra_ide_api/src/completion.rs | 8 +- crates/ra_ide_api/src/completion/complete_dot.rs | 2 +- .../src/completion/complete_record_literal.rs | 132 +++++++++++++++++++++ .../src/completion/complete_record_pattern.rs | 94 +++++++++++++++ .../src/completion/complete_struct_literal.rs | 132 --------------------- .../src/completion/complete_struct_pattern.rs | 94 --------------- .../src/completion/completion_context.rs | 16 +-- crates/ra_ide_api/src/completion/presentation.rs | 2 +- crates/ra_ide_api/src/diagnostics.rs | 18 +-- crates/ra_ide_api/src/display/navigation_target.rs | 4 +- crates/ra_ide_api/src/display/short_label.rs | 2 +- crates/ra_ide_api/src/display/structure.rs | 4 +- crates/ra_ide_api/src/extend_selection.rs | 8 +- crates/ra_ide_api/src/folding_ranges.rs | 10 +- crates/ra_ide_api/src/goto_definition.rs | 12 +- crates/ra_ide_api/src/hover.rs | 2 +- crates/ra_ide_api/src/inlay_hints.rs | 10 +- crates/ra_ide_api/src/marks.rs | 2 +- crates/ra_ide_api/src/name_ref_kind.rs | 8 +- crates/ra_ide_api/src/syntax_highlighting.rs | 2 +- 20 files changed, 284 insertions(+), 278 deletions(-) create mode 100644 crates/ra_ide_api/src/completion/complete_record_literal.rs create mode 100644 crates/ra_ide_api/src/completion/complete_record_pattern.rs delete mode 100644 crates/ra_ide_api/src/completion/complete_struct_literal.rs delete mode 100644 crates/ra_ide_api/src/completion/complete_struct_pattern.rs (limited to 'crates/ra_ide_api/src') diff --git a/crates/ra_ide_api/src/completion.rs b/crates/ra_ide_api/src/completion.rs index a6b68be75..a4f080adc 100644 --- a/crates/ra_ide_api/src/completion.rs +++ b/crates/ra_ide_api/src/completion.rs @@ -3,8 +3,8 @@ mod completion_context; mod presentation; mod complete_dot; -mod complete_struct_literal; -mod complete_struct_pattern; +mod complete_record_literal; +mod complete_record_pattern; mod complete_pattern; mod complete_fn_param; mod complete_keyword; @@ -65,8 +65,8 @@ pub(crate) fn completions(db: &db::RootDatabase, position: FilePosition) -> Opti complete_path::complete_path(&mut acc, &ctx); complete_scope::complete_scope(&mut acc, &ctx); complete_dot::complete_dot(&mut acc, &ctx); - complete_struct_literal::complete_struct_literal(&mut acc, &ctx); - complete_struct_pattern::complete_struct_pattern(&mut acc, &ctx); + complete_record_literal::complete_record_literal(&mut acc, &ctx); + complete_record_pattern::complete_record_pattern(&mut acc, &ctx); complete_pattern::complete_pattern(&mut acc, &ctx); complete_postfix::complete_postfix(&mut acc, &ctx); Some(acc) diff --git a/crates/ra_ide_api/src/completion/complete_dot.rs b/crates/ra_ide_api/src/completion/complete_dot.rs index d43ff2eec..27256f879 100644 --- a/crates/ra_ide_api/src/completion/complete_dot.rs +++ b/crates/ra_ide_api/src/completion/complete_dot.rs @@ -45,7 +45,7 @@ fn complete_fields(acc: &mut Completions, ctx: &CompletionContext, receiver: Ty) // FIXME unions TypeCtor::Tuple { .. } => { for (i, ty) in a_ty.parameters.iter().enumerate() { - acc.add_pos_field(ctx, i, ty); + acc.add_tuple_field(ctx, i, ty); } } _ => {} diff --git a/crates/ra_ide_api/src/completion/complete_record_literal.rs b/crates/ra_ide_api/src/completion/complete_record_literal.rs new file mode 100644 index 000000000..6b929a8ac --- /dev/null +++ b/crates/ra_ide_api/src/completion/complete_record_literal.rs @@ -0,0 +1,132 @@ +use hir::Substs; + +use crate::completion::{CompletionContext, Completions}; + +/// Complete fields in fields literals. +pub(super) fn complete_record_literal(acc: &mut Completions, ctx: &CompletionContext) { + let (ty, variant) = match ctx.record_lit_syntax.as_ref().and_then(|it| { + Some(( + ctx.analyzer.type_of(ctx.db, &it.clone().into())?, + ctx.analyzer.resolve_record_literal(it)?, + )) + }) { + Some(it) => it, + _ => return, + }; + let substs = &ty.substs().unwrap_or_else(Substs::empty); + + for field in variant.fields(ctx.db) { + acc.add_field(ctx, field, substs); + } +} + +#[cfg(test)] +mod tests { + use crate::completion::{do_completion, CompletionItem, CompletionKind}; + use insta::assert_debug_snapshot_matches; + + fn complete(code: &str) -> Vec { + do_completion(code, CompletionKind::Reference) + } + + #[test] + fn test_record_literal_field() { + let completions = complete( + r" + struct A { the_field: u32 } + fn foo() { + A { the<|> } + } + ", + ); + assert_debug_snapshot_matches!(completions, @r###" + ⋮[ + ⋮ CompletionItem { + ⋮ label: "the_field", + ⋮ source_range: [83; 86), + ⋮ delete: [83; 86), + ⋮ insert: "the_field", + ⋮ kind: Field, + ⋮ detail: "u32", + ⋮ }, + ⋮] + "###); + } + + #[test] + fn test_record_literal_enum_variant() { + let completions = complete( + r" + enum E { + A { a: u32 } + } + fn foo() { + let _ = E::A { <|> } + } + ", + ); + assert_debug_snapshot_matches!(completions, @r###" + ⋮[ + ⋮ CompletionItem { + ⋮ label: "a", + ⋮ source_range: [119; 119), + ⋮ delete: [119; 119), + ⋮ insert: "a", + ⋮ kind: Field, + ⋮ detail: "u32", + ⋮ }, + ⋮] + "###); + } + + #[test] + fn test_record_literal_two_structs() { + let completions = complete( + r" + struct A { a: u32 } + struct B { b: u32 } + + fn foo() { + let _: A = B { <|> } + } + ", + ); + assert_debug_snapshot_matches!(completions, @r###" + ⋮[ + ⋮ CompletionItem { + ⋮ label: "b", + ⋮ source_range: [119; 119), + ⋮ delete: [119; 119), + ⋮ insert: "b", + ⋮ kind: Field, + ⋮ detail: "u32", + ⋮ }, + ⋮] + "###); + } + + #[test] + fn test_record_literal_generic_struct() { + let completions = complete( + r" + struct A { a: T } + + fn foo() { + let _: A = A { <|> } + } + ", + ); + assert_debug_snapshot_matches!(completions, @r###" + ⋮[ + ⋮ CompletionItem { + ⋮ label: "a", + ⋮ source_range: [93; 93), + ⋮ delete: [93; 93), + ⋮ insert: "a", + ⋮ kind: Field, + ⋮ detail: "u32", + ⋮ }, + ⋮] + "###); + } +} diff --git a/crates/ra_ide_api/src/completion/complete_record_pattern.rs b/crates/ra_ide_api/src/completion/complete_record_pattern.rs new file mode 100644 index 000000000..8c8b47ea4 --- /dev/null +++ b/crates/ra_ide_api/src/completion/complete_record_pattern.rs @@ -0,0 +1,94 @@ +use hir::Substs; + +use crate::completion::{CompletionContext, Completions}; + +pub(super) fn complete_record_pattern(acc: &mut Completions, ctx: &CompletionContext) { + let (ty, variant) = match ctx.record_lit_pat.as_ref().and_then(|it| { + Some(( + ctx.analyzer.type_of_pat(ctx.db, &it.clone().into())?, + ctx.analyzer.resolve_record_pattern(it)?, + )) + }) { + Some(it) => it, + _ => return, + }; + let substs = &ty.substs().unwrap_or_else(Substs::empty); + + for field in variant.fields(ctx.db) { + acc.add_field(ctx, field, substs); + } +} + +#[cfg(test)] +mod tests { + use crate::completion::{do_completion, CompletionItem, CompletionKind}; + use insta::assert_debug_snapshot_matches; + + fn complete(code: &str) -> Vec { + do_completion(code, CompletionKind::Reference) + } + + #[test] + fn test_record_pattern_field() { + let completions = complete( + r" + struct S { foo: u32 } + + fn process(f: S) { + match f { + S { f<|>: 92 } => (), + } + } + ", + ); + assert_debug_snapshot_matches!(completions, @r###" + ⋮[ + ⋮ CompletionItem { + ⋮ label: "foo", + ⋮ source_range: [117; 118), + ⋮ delete: [117; 118), + ⋮ insert: "foo", + ⋮ kind: Field, + ⋮ detail: "u32", + ⋮ }, + ⋮] + "###); + } + + #[test] + fn test_record_pattern_enum_variant() { + let completions = complete( + r" + enum E { + S { foo: u32, bar: () } + } + + fn process(e: E) { + match e { + E::S { <|> } => (), + } + } + ", + ); + assert_debug_snapshot_matches!(completions, @r###" + ⋮[ + ⋮ CompletionItem { + ⋮ label: "bar", + ⋮ source_range: [161; 161), + ⋮ delete: [161; 161), + ⋮ insert: "bar", + ⋮ kind: Field, + ⋮ detail: "()", + ⋮ }, + ⋮ CompletionItem { + ⋮ label: "foo", + ⋮ source_range: [161; 161), + ⋮ delete: [161; 161), + ⋮ insert: "foo", + ⋮ kind: Field, + ⋮ detail: "u32", + ⋮ }, + ⋮] + "###); + } +} diff --git a/crates/ra_ide_api/src/completion/complete_struct_literal.rs b/crates/ra_ide_api/src/completion/complete_struct_literal.rs deleted file mode 100644 index 6aa41f498..000000000 --- a/crates/ra_ide_api/src/completion/complete_struct_literal.rs +++ /dev/null @@ -1,132 +0,0 @@ -use hir::Substs; - -use crate::completion::{CompletionContext, Completions}; - -/// Complete fields in fields literals. -pub(super) fn complete_struct_literal(acc: &mut Completions, ctx: &CompletionContext) { - let (ty, variant) = match ctx.struct_lit_syntax.as_ref().and_then(|it| { - Some(( - ctx.analyzer.type_of(ctx.db, &it.clone().into())?, - ctx.analyzer.resolve_struct_literal(it)?, - )) - }) { - Some(it) => it, - _ => return, - }; - let substs = &ty.substs().unwrap_or_else(Substs::empty); - - for field in variant.fields(ctx.db) { - acc.add_field(ctx, field, substs); - } -} - -#[cfg(test)] -mod tests { - use crate::completion::{do_completion, CompletionItem, CompletionKind}; - use insta::assert_debug_snapshot_matches; - - fn complete(code: &str) -> Vec { - do_completion(code, CompletionKind::Reference) - } - - #[test] - fn test_struct_literal_field() { - let completions = complete( - r" - struct A { the_field: u32 } - fn foo() { - A { the<|> } - } - ", - ); - assert_debug_snapshot_matches!(completions, @r###" - ⋮[ - ⋮ CompletionItem { - ⋮ label: "the_field", - ⋮ source_range: [83; 86), - ⋮ delete: [83; 86), - ⋮ insert: "the_field", - ⋮ kind: Field, - ⋮ detail: "u32", - ⋮ }, - ⋮] - "###); - } - - #[test] - fn test_struct_literal_enum_variant() { - let completions = complete( - r" - enum E { - A { a: u32 } - } - fn foo() { - let _ = E::A { <|> } - } - ", - ); - assert_debug_snapshot_matches!(completions, @r###" - ⋮[ - ⋮ CompletionItem { - ⋮ label: "a", - ⋮ source_range: [119; 119), - ⋮ delete: [119; 119), - ⋮ insert: "a", - ⋮ kind: Field, - ⋮ detail: "u32", - ⋮ }, - ⋮] - "###); - } - - #[test] - fn test_struct_literal_two_structs() { - let completions = complete( - r" - struct A { a: u32 } - struct B { b: u32 } - - fn foo() { - let _: A = B { <|> } - } - ", - ); - assert_debug_snapshot_matches!(completions, @r###" - ⋮[ - ⋮ CompletionItem { - ⋮ label: "b", - ⋮ source_range: [119; 119), - ⋮ delete: [119; 119), - ⋮ insert: "b", - ⋮ kind: Field, - ⋮ detail: "u32", - ⋮ }, - ⋮] - "###); - } - - #[test] - fn test_struct_literal_generic_struct() { - let completions = complete( - r" - struct A { a: T } - - fn foo() { - let _: A = A { <|> } - } - ", - ); - assert_debug_snapshot_matches!(completions, @r###" - ⋮[ - ⋮ CompletionItem { - ⋮ label: "a", - ⋮ source_range: [93; 93), - ⋮ delete: [93; 93), - ⋮ insert: "a", - ⋮ kind: Field, - ⋮ detail: "u32", - ⋮ }, - ⋮] - "###); - } -} diff --git a/crates/ra_ide_api/src/completion/complete_struct_pattern.rs b/crates/ra_ide_api/src/completion/complete_struct_pattern.rs deleted file mode 100644 index d0dde5930..000000000 --- a/crates/ra_ide_api/src/completion/complete_struct_pattern.rs +++ /dev/null @@ -1,94 +0,0 @@ -use hir::Substs; - -use crate::completion::{CompletionContext, Completions}; - -pub(super) fn complete_struct_pattern(acc: &mut Completions, ctx: &CompletionContext) { - let (ty, variant) = match ctx.struct_lit_pat.as_ref().and_then(|it| { - Some(( - ctx.analyzer.type_of_pat(ctx.db, &it.clone().into())?, - ctx.analyzer.resolve_struct_pattern(it)?, - )) - }) { - Some(it) => it, - _ => return, - }; - let substs = &ty.substs().unwrap_or_else(Substs::empty); - - for field in variant.fields(ctx.db) { - acc.add_field(ctx, field, substs); - } -} - -#[cfg(test)] -mod tests { - use crate::completion::{do_completion, CompletionItem, CompletionKind}; - use insta::assert_debug_snapshot_matches; - - fn complete(code: &str) -> Vec { - do_completion(code, CompletionKind::Reference) - } - - #[test] - fn test_struct_pattern_field() { - let completions = complete( - r" - struct S { foo: u32 } - - fn process(f: S) { - match f { - S { f<|>: 92 } => (), - } - } - ", - ); - assert_debug_snapshot_matches!(completions, @r###" - ⋮[ - ⋮ CompletionItem { - ⋮ label: "foo", - ⋮ source_range: [117; 118), - ⋮ delete: [117; 118), - ⋮ insert: "foo", - ⋮ kind: Field, - ⋮ detail: "u32", - ⋮ }, - ⋮] - "###); - } - - #[test] - fn test_struct_pattern_enum_variant() { - let completions = complete( - r" - enum E { - S { foo: u32, bar: () } - } - - fn process(e: E) { - match e { - E::S { <|> } => (), - } - } - ", - ); - assert_debug_snapshot_matches!(completions, @r###" - ⋮[ - ⋮ CompletionItem { - ⋮ label: "bar", - ⋮ source_range: [161; 161), - ⋮ delete: [161; 161), - ⋮ insert: "bar", - ⋮ kind: Field, - ⋮ detail: "()", - ⋮ }, - ⋮ CompletionItem { - ⋮ label: "foo", - ⋮ source_range: [161; 161), - ⋮ delete: [161; 161), - ⋮ insert: "foo", - ⋮ kind: Field, - ⋮ detail: "u32", - ⋮ }, - ⋮] - "###); - } -} diff --git a/crates/ra_ide_api/src/completion/completion_context.rs b/crates/ra_ide_api/src/completion/completion_context.rs index dfaa9ce69..7139947b3 100644 --- a/crates/ra_ide_api/src/completion/completion_context.rs +++ b/crates/ra_ide_api/src/completion/completion_context.rs @@ -20,8 +20,8 @@ pub(crate) struct CompletionContext<'a> { pub(super) module: Option, pub(super) function_syntax: Option, pub(super) use_item_syntax: Option, - pub(super) struct_lit_syntax: Option, - pub(super) struct_lit_pat: Option, + pub(super) record_lit_syntax: Option, + pub(super) record_lit_pat: Option, pub(super) is_param: bool, /// If a name-binding or reference to a const in a pattern. /// Irrefutable patterns (like let) are excluded. @@ -60,8 +60,8 @@ impl<'a> CompletionContext<'a> { module, function_syntax: None, use_item_syntax: None, - struct_lit_syntax: None, - struct_lit_pat: None, + record_lit_syntax: None, + record_lit_pat: None, is_param: false, is_pat_binding: false, is_trivial_path: false, @@ -120,8 +120,8 @@ impl<'a> CompletionContext<'a> { self.is_param = true; return; } - if name.syntax().ancestors().find_map(ast::FieldPatList::cast).is_some() { - self.struct_lit_pat = + if name.syntax().ancestors().find_map(ast::RecordFieldPatList::cast).is_some() { + self.record_lit_pat = find_node_at_offset(original_parse.tree().syntax(), self.offset); } } @@ -129,8 +129,8 @@ impl<'a> CompletionContext<'a> { fn classify_name_ref(&mut self, original_file: SourceFile, name_ref: ast::NameRef) { let name_range = name_ref.syntax().text_range(); - if name_ref.syntax().parent().and_then(ast::NamedField::cast).is_some() { - self.struct_lit_syntax = find_node_at_offset(original_file.syntax(), self.offset); + if name_ref.syntax().parent().and_then(ast::RecordField::cast).is_some() { + self.record_lit_syntax = find_node_at_offset(original_file.syntax(), self.offset); } let top_node = name_ref diff --git a/crates/ra_ide_api/src/completion/presentation.rs b/crates/ra_ide_api/src/completion/presentation.rs index 2b3f98482..147ceda0c 100644 --- a/crates/ra_ide_api/src/completion/presentation.rs +++ b/crates/ra_ide_api/src/completion/presentation.rs @@ -28,7 +28,7 @@ impl Completions { .add_to(self); } - pub(crate) fn add_pos_field(&mut self, ctx: &CompletionContext, field: usize, ty: &hir::Ty) { + pub(crate) fn add_tuple_field(&mut self, ctx: &CompletionContext, field: usize, ty: &hir::Ty) { CompletionItem::new(CompletionKind::Reference, ctx.source_range(), field.to_string()) .kind(CompletionItemKind::Field) .detail(ty.display(ctx.db).to_string()) diff --git a/crates/ra_ide_api/src/diagnostics.rs b/crates/ra_ide_api/src/diagnostics.rs index 98b840b26..c2b959cb3 100644 --- a/crates/ra_ide_api/src/diagnostics.rs +++ b/crates/ra_ide_api/src/diagnostics.rs @@ -9,7 +9,7 @@ use ra_assists::ast_editor::{AstBuilder, AstEditor}; use ra_db::SourceDatabase; use ra_prof::profile; use ra_syntax::{ - ast::{self, AstNode, NamedField}, + ast::{self, AstNode, RecordField}, Location, SyntaxNode, TextRange, T, }; use ra_text_edit::{TextEdit, TextEditBuilder}; @@ -62,7 +62,7 @@ pub(crate) fn diagnostics(db: &RootDatabase, file_id: FileId) -> Vec let node = d.ast(db); let mut ast_editor = AstEditor::new(node); for f in d.missed_fields.iter() { - ast_editor.append_field(&AstBuilder::::from_name(f)); + ast_editor.append_field(&AstBuilder::::from_name(f)); } let mut builder = TextEditBuilder::default(); @@ -141,20 +141,20 @@ fn check_struct_shorthand_initialization( file_id: FileId, node: &SyntaxNode, ) -> Option<()> { - let struct_lit = ast::StructLit::cast(node.clone())?; - let named_field_list = struct_lit.named_field_list()?; - for named_field in named_field_list.fields() { - if let (Some(name_ref), Some(expr)) = (named_field.name_ref(), named_field.expr()) { + let record_lit = ast::RecordLit::cast(node.clone())?; + let record_field_list = record_lit.record_field_list()?; + for record_field in record_field_list.fields() { + if let (Some(name_ref), Some(expr)) = (record_field.name_ref(), record_field.expr()) { let field_name = name_ref.syntax().text().to_string(); let field_expr = expr.syntax().text().to_string(); if field_name == field_expr { let mut edit_builder = TextEditBuilder::default(); - edit_builder.delete(named_field.syntax().text_range()); - edit_builder.insert(named_field.syntax().text_range().start(), field_name); + edit_builder.delete(record_field.syntax().text_range()); + edit_builder.insert(record_field.syntax().text_range().start(), field_name); let edit = edit_builder.finish(); acc.push(Diagnostic { - range: named_field.syntax().text_range(), + range: record_field.syntax().text_range(), message: "Shorthand struct initialization".to_string(), severity: Severity::WeakWarning, fix: Some(SourceChange::source_file_edit( diff --git a/crates/ra_ide_api/src/display/navigation_target.rs b/crates/ra_ide_api/src/display/navigation_target.rs index 84fabdb9e..c85214bb3 100644 --- a/crates/ra_ide_api/src/display/navigation_target.rs +++ b/crates/ra_ide_api/src/display/navigation_target.rs @@ -314,7 +314,7 @@ pub(crate) fn docs_from_symbol(db: &RootDatabase, symbol: &FileSymbol) -> Option .visit(|it: ast::TypeAliasDef| it.doc_comment_text()) .visit(|it: ast::ConstDef| it.doc_comment_text()) .visit(|it: ast::StaticDef| it.doc_comment_text()) - .visit(|it: ast::NamedFieldDef| it.doc_comment_text()) + .visit(|it: ast::RecordFieldDef| it.doc_comment_text()) .visit(|it: ast::EnumVariant| it.doc_comment_text()) .visit(|it: ast::MacroCall| it.doc_comment_text()) .accept(&node)? @@ -336,7 +336,7 @@ pub(crate) fn description_from_symbol(db: &RootDatabase, symbol: &FileSymbol) -> .visit(|node: ast::TypeAliasDef| node.short_label()) .visit(|node: ast::ConstDef| node.short_label()) .visit(|node: ast::StaticDef| node.short_label()) - .visit(|node: ast::NamedFieldDef| node.short_label()) + .visit(|node: ast::RecordFieldDef| node.short_label()) .visit(|node: ast::EnumVariant| node.short_label()) .accept(&node)? } diff --git a/crates/ra_ide_api/src/display/short_label.rs b/crates/ra_ide_api/src/display/short_label.rs index 825a033ee..b16d504e1 100644 --- a/crates/ra_ide_api/src/display/short_label.rs +++ b/crates/ra_ide_api/src/display/short_label.rs @@ -53,7 +53,7 @@ impl ShortLabel for ast::StaticDef { } } -impl ShortLabel for ast::NamedFieldDef { +impl ShortLabel for ast::RecordFieldDef { fn short_label(&self) -> Option { short_label_from_ascribed_node(self, "") } diff --git a/crates/ra_ide_api/src/display/structure.rs b/crates/ra_ide_api/src/display/structure.rs index b026dfa59..a2025ed59 100644 --- a/crates/ra_ide_api/src/display/structure.rs +++ b/crates/ra_ide_api/src/display/structure.rs @@ -124,7 +124,7 @@ fn structure_node(node: &SyntaxNode) -> Option { let ty = td.type_ref(); decl_with_type_ref(td, ty) }) - .visit(decl_with_ascription::) + .visit(decl_with_ascription::) .visit(decl_with_ascription::) .visit(decl_with_ascription::) .visit(|im: ast::ImplBlock| { @@ -222,7 +222,7 @@ fn very_obsolete() {} label: "x", navigation_range: [18; 19), node_range: [18; 24), - kind: NAMED_FIELD_DEF, + kind: RECORD_FIELD_DEF, detail: Some( "i32", ), diff --git a/crates/ra_ide_api/src/extend_selection.rs b/crates/ra_ide_api/src/extend_selection.rs index edbf622c1..e990eb0d1 100644 --- a/crates/ra_ide_api/src/extend_selection.rs +++ b/crates/ra_ide_api/src/extend_selection.rs @@ -18,11 +18,11 @@ pub(crate) fn extend_selection(db: &RootDatabase, frange: FileRange) -> TextRang fn try_extend_selection(root: &SyntaxNode, range: TextRange) -> Option { let string_kinds = [COMMENT, STRING, RAW_STRING, BYTE_STRING, RAW_BYTE_STRING]; let list_kinds = [ - FIELD_PAT_LIST, + RECORD_FIELD_PAT_LIST, MATCH_ARM_LIST, - NAMED_FIELD_DEF_LIST, - POS_FIELD_DEF_LIST, - NAMED_FIELD_LIST, + RECORD_FIELD_DEF_LIST, + TUPLE_FIELD_DEF_LIST, + RECORD_FIELD_LIST, ENUM_VARIANT_LIST, USE_TREE_LIST, TYPE_PARAM_LIST, diff --git a/crates/ra_ide_api/src/folding_ranges.rs b/crates/ra_ide_api/src/folding_ranges.rs index e60ae8cf6..3ab6c195e 100644 --- a/crates/ra_ide_api/src/folding_ranges.rs +++ b/crates/ra_ide_api/src/folding_ranges.rs @@ -81,8 +81,14 @@ fn fold_kind(kind: SyntaxKind) -> Option { match kind { COMMENT => Some(FoldKind::Comment), USE_ITEM => Some(FoldKind::Imports), - NAMED_FIELD_DEF_LIST | FIELD_PAT_LIST | ITEM_LIST | EXTERN_ITEM_LIST | USE_TREE_LIST - | BLOCK | ENUM_VARIANT_LIST | TOKEN_TREE => Some(FoldKind::Block), + RECORD_FIELD_DEF_LIST + | RECORD_FIELD_PAT_LIST + | ITEM_LIST + | EXTERN_ITEM_LIST + | USE_TREE_LIST + | BLOCK + | ENUM_VARIANT_LIST + | TOKEN_TREE => Some(FoldKind::Block), _ => None, } } diff --git a/crates/ra_ide_api/src/goto_definition.rs b/crates/ra_ide_api/src/goto_definition.rs index ddd55a9c1..28529a2de 100644 --- a/crates/ra_ide_api/src/goto_definition.rs +++ b/crates/ra_ide_api/src/goto_definition.rs @@ -178,7 +178,7 @@ fn named_target(file_id: FileId, node: &SyntaxNode) -> Option node.short_label(), ) }) - .visit(|node: ast::NamedFieldDef| { + .visit(|node: ast::RecordFieldDef| { NavigationTarget::from_named( file_id, &node, @@ -344,13 +344,13 @@ mod tests { foo.spam<|>; } ", - "spam NAMED_FIELD_DEF FileId(1) [17; 26) [17; 21)", + "spam RECORD_FIELD_DEF FileId(1) [17; 26) [17; 21)", ); } #[test] - fn goto_definition_works_for_named_fields() { - covers!(goto_definition_works_for_named_fields); + fn goto_definition_works_for_record_fields() { + covers!(goto_definition_works_for_record_fields); check_goto( " //- /lib.rs @@ -364,7 +364,7 @@ mod tests { } } ", - "spam NAMED_FIELD_DEF FileId(1) [17; 26) [17; 21)", + "spam RECORD_FIELD_DEF FileId(1) [17; 26) [17; 21)", ); } #[test] @@ -473,7 +473,7 @@ mod tests { field<|>: string, } "#, - "field NAMED_FIELD_DEF FileId(1) [17; 30) [17; 22)", + "field RECORD_FIELD_DEF FileId(1) [17; 30) [17; 22)", ); check_goto( diff --git a/crates/ra_ide_api/src/hover.rs b/crates/ra_ide_api/src/hover.rs index 2a5ac7821..1981e62d3 100644 --- a/crates/ra_ide_api/src/hover.rs +++ b/crates/ra_ide_api/src/hover.rs @@ -197,7 +197,7 @@ pub(crate) fn hover(db: &RootDatabase, position: FilePosition) -> Option Vec { pats_to_process.push_back(arg_pat); } } - ast::Pat::StructPat(struct_pat) => { - if let Some(pat_list) = struct_pat.field_pat_list() { + ast::Pat::RecordPat(record_pat) => { + if let Some(pat_list) = record_pat.record_field_pat_list() { pats_to_process.extend( pat_list - .field_pats() - .filter_map(|field_pat| { - field_pat + .record_field_pats() + .filter_map(|record_field_pat| { + record_field_pat .pat() .filter(|pat| pat.syntax().kind() != SyntaxKind::BIND_PAT) }) diff --git a/crates/ra_ide_api/src/marks.rs b/crates/ra_ide_api/src/marks.rs index 9cb991de5..c3752cc54 100644 --- a/crates/ra_ide_api/src/marks.rs +++ b/crates/ra_ide_api/src/marks.rs @@ -3,7 +3,7 @@ test_utils::marks!( goto_definition_works_for_macros goto_definition_works_for_methods goto_definition_works_for_fields - goto_definition_works_for_named_fields + goto_definition_works_for_record_fields call_info_bad_offset dont_complete_current_use dont_complete_primitive_in_use diff --git a/crates/ra_ide_api/src/name_ref_kind.rs b/crates/ra_ide_api/src/name_ref_kind.rs index f7db6c826..34a8bcc36 100644 --- a/crates/ra_ide_api/src/name_ref_kind.rs +++ b/crates/ra_ide_api/src/name_ref_kind.rs @@ -54,12 +54,12 @@ pub(crate) fn classify_name_ref( } // It could also be a named field - if let Some(field_expr) = name_ref.syntax().parent().and_then(ast::NamedField::cast) { - tested_by!(goto_definition_works_for_named_fields); + if let Some(field_expr) = name_ref.syntax().parent().and_then(ast::RecordField::cast) { + tested_by!(goto_definition_works_for_record_fields); - let struct_lit = field_expr.syntax().ancestors().find_map(ast::StructLit::cast); + let record_lit = field_expr.syntax().ancestors().find_map(ast::RecordLit::cast); - if let Some(ty) = struct_lit.and_then(|lit| analyzer.type_of(db, &lit.into())) { + if let Some(ty) = record_lit.and_then(|lit| analyzer.type_of(db, &lit.into())) { if let Some((hir::AdtDef::Struct(s), _)) = ty.as_adt() { let hir_path = hir::Path::from_name_ref(name_ref); let hir_name = hir_path.as_ident().unwrap(); diff --git a/crates/ra_ide_api/src/syntax_highlighting.rs b/crates/ra_ide_api/src/syntax_highlighting.rs index 448acffc8..06ccf0728 100644 --- a/crates/ra_ide_api/src/syntax_highlighting.rs +++ b/crates/ra_ide_api/src/syntax_highlighting.rs @@ -165,7 +165,7 @@ pub(crate) fn highlight(db: &RootDatabase, file_id: FileId) -> Vec { "type" } - NAMED_FIELD_DEF => "field", + RECORD_FIELD_DEF => "field", _ => "function", }) .unwrap_or("function") -- cgit v1.2.3