From c8b4c36f8161d34c8145a49965efee4514275989 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 10 Apr 2020 10:11:05 +0200 Subject: Semicolon token --- .../ra_assists/src/handlers/introduce_variable.rs | 2 +- crates/ra_hir_def/src/nameres/raw.rs | 2 +- crates/ra_ide/src/typing.rs | 2 +- crates/ra_syntax/src/ast/edit.rs | 4 +- crates/ra_syntax/src/ast/generated/nodes.rs | 44 ++++++++++++++++------ 5 files changed, 38 insertions(+), 16 deletions(-) (limited to 'crates') diff --git a/crates/ra_assists/src/handlers/introduce_variable.rs b/crates/ra_assists/src/handlers/introduce_variable.rs index ab6bdf6bb..8d0f7e922 100644 --- a/crates/ra_assists/src/handlers/introduce_variable.rs +++ b/crates/ra_assists/src/handlers/introduce_variable.rs @@ -61,7 +61,7 @@ pub(crate) fn introduce_variable(ctx: AssistCtx) -> Option { }; if is_full_stmt { tested_by!(test_introduce_var_expr_stmt); - if full_stmt.unwrap().semi_token().is_none() { + if full_stmt.unwrap().semicolon_token().is_none() { buf.push_str(";"); } edit.replace(expr.syntax().text_range(), buf); diff --git a/crates/ra_hir_def/src/nameres/raw.rs b/crates/ra_hir_def/src/nameres/raw.rs index e72ba52cf..afd538e4a 100644 --- a/crates/ra_hir_def/src/nameres/raw.rs +++ b/crates/ra_hir_def/src/nameres/raw.rs @@ -287,7 +287,7 @@ impl RawItemsCollector { let visibility = RawVisibility::from_ast_with_hygiene(module.visibility(), &self.hygiene); let ast_id = self.source_ast_id_map.ast_id(&module); - if module.semi_token().is_some() { + if module.semicolon_token().is_some() { let item = self.raw_items.modules.alloc(ModuleData::Declaration { name, visibility, ast_id }); self.push_item(current_module, attrs, RawItemKind::Module(item)); diff --git a/crates/ra_ide/src/typing.rs b/crates/ra_ide/src/typing.rs index 71d2bcb04..f55cd3bf5 100644 --- a/crates/ra_ide/src/typing.rs +++ b/crates/ra_ide/src/typing.rs @@ -63,7 +63,7 @@ fn on_char_typed_inner( fn on_eq_typed(file: &SourceFile, offset: TextUnit) -> Option { assert_eq!(file.syntax().text().char_at(offset), Some('=')); let let_stmt: ast::LetStmt = find_node_at_offset(file.syntax(), offset)?; - if let_stmt.semi_token().is_some() { + if let_stmt.semicolon_token().is_some() { return None; } if let Some(expr) = let_stmt.initializer() { diff --git a/crates/ra_syntax/src/ast/edit.rs b/crates/ra_syntax/src/ast/edit.rs index 3d428fab3..a01f6487d 100644 --- a/crates/ra_syntax/src/ast/edit.rs +++ b/crates/ra_syntax/src/ast/edit.rs @@ -32,9 +32,9 @@ impl ast::FnDef { let mut to_insert: ArrayVec<[SyntaxElement; 2]> = ArrayVec::new(); let old_body_or_semi: SyntaxElement = if let Some(old_body) = self.body() { old_body.syntax().clone().into() - } else if let Some(semi) = self.semi_token() { + } else if let Some(semi) = self.semicolon_token() { to_insert.push(make::tokens::single_space().into()); - semi.syntax.clone().into() + semi.into() } else { to_insert.push(make::tokens::single_space().into()); to_insert.push(body.syntax().clone().into()); diff --git a/crates/ra_syntax/src/ast/generated/nodes.rs b/crates/ra_syntax/src/ast/generated/nodes.rs index 3b014e312..214e12918 100644 --- a/crates/ra_syntax/src/ast/generated/nodes.rs +++ b/crates/ra_syntax/src/ast/generated/nodes.rs @@ -58,7 +58,9 @@ impl FnDef { pub fn param_list(&self) -> Option { support::child(&self.syntax) } pub fn ret_type(&self) -> Option { support::child(&self.syntax) } pub fn body(&self) -> Option { support::child(&self.syntax) } - pub fn semi_token(&self) -> Option { support::token(&self.syntax) } + pub fn semicolon_token(&self) -> Option { + support::token2(&self.syntax, T ! [ ; ]) + } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct RetType { @@ -102,7 +104,9 @@ impl ast::DocCommentsOwner for StructDef {} impl StructDef { pub fn struct_token(&self) -> Option { support::token2(&self.syntax, T![struct]) } pub fn field_def_list(&self) -> Option { support::child(&self.syntax) } - pub fn semi_token(&self) -> Option { support::token(&self.syntax) } + pub fn semicolon_token(&self) -> Option { + support::token2(&self.syntax, T ! [ ; ]) + } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct UnionDef { @@ -328,7 +332,9 @@ impl ast::DocCommentsOwner for Module {} impl Module { pub fn mod_token(&self) -> Option { support::token2(&self.syntax, T![mod]) } pub fn item_list(&self) -> Option { support::child(&self.syntax) } - pub fn semi_token(&self) -> Option { support::token(&self.syntax) } + pub fn semicolon_token(&self) -> Option { + support::token2(&self.syntax, T ! [ ; ]) + } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct ItemList { @@ -379,7 +385,9 @@ impl ConstDef { pub fn const_token(&self) -> Option { support::token2(&self.syntax, T![const]) } pub fn eq_token(&self) -> Option { support::token(&self.syntax) } pub fn body(&self) -> Option { support::child(&self.syntax) } - pub fn semi_token(&self) -> Option { support::token(&self.syntax) } + pub fn semicolon_token(&self) -> Option { + support::token2(&self.syntax, T ! [ ; ]) + } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct StaticDef { @@ -407,7 +415,9 @@ impl StaticDef { pub fn mut_token(&self) -> Option { support::token2(&self.syntax, T![mut]) } pub fn eq_token(&self) -> Option { support::token(&self.syntax) } pub fn body(&self) -> Option { support::child(&self.syntax) } - pub fn semi_token(&self) -> Option { support::token(&self.syntax) } + pub fn semicolon_token(&self) -> Option { + support::token2(&self.syntax, T ! [ ; ]) + } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct TypeAliasDef { @@ -437,7 +447,9 @@ impl TypeAliasDef { pub fn type_token(&self) -> Option { support::token2(&self.syntax, T![type]) } pub fn eq_token(&self) -> Option { support::token(&self.syntax) } pub fn type_ref(&self) -> Option { support::child(&self.syntax) } - pub fn semi_token(&self) -> Option { support::token(&self.syntax) } + pub fn semicolon_token(&self) -> Option { + support::token2(&self.syntax, T ! [ ; ]) + } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct ImplDef { @@ -582,7 +594,9 @@ impl AstNode for ArrayType { impl ArrayType { pub fn l_brack_token(&self) -> Option { support::token(&self.syntax) } pub fn type_ref(&self) -> Option { support::child(&self.syntax) } - pub fn semi_token(&self) -> Option { support::token(&self.syntax) } + pub fn semicolon_token(&self) -> Option { + support::token2(&self.syntax, T ! [ ; ]) + } pub fn expr(&self) -> Option { support::child(&self.syntax) } pub fn r_brack_token(&self) -> Option { support::token(&self.syntax) } } @@ -765,7 +779,9 @@ impl ast::AttrsOwner for ArrayExpr {} impl ArrayExpr { pub fn l_brack_token(&self) -> Option { support::token(&self.syntax) } pub fn exprs(&self) -> AstChildren { support::children(&self.syntax) } - pub fn semi_token(&self) -> Option { support::token(&self.syntax) } + pub fn semicolon_token(&self) -> Option { + support::token2(&self.syntax, T ! [ ; ]) + } pub fn r_brack_token(&self) -> Option { support::token(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] @@ -1859,7 +1875,9 @@ impl MacroCall { pub fn path(&self) -> Option { support::child(&self.syntax) } pub fn excl_token(&self) -> Option { support::token(&self.syntax) } pub fn token_tree(&self) -> Option { support::child(&self.syntax) } - pub fn semi_token(&self) -> Option { support::token(&self.syntax) } + pub fn semicolon_token(&self) -> Option { + support::token2(&self.syntax, T ! [ ; ]) + } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct Attr { @@ -2100,7 +2118,9 @@ impl AstNode for ExprStmt { impl ast::AttrsOwner for ExprStmt {} impl ExprStmt { pub fn expr(&self) -> Option { support::child(&self.syntax) } - pub fn semi_token(&self) -> Option { support::token(&self.syntax) } + pub fn semicolon_token(&self) -> Option { + support::token2(&self.syntax, T ! [ ; ]) + } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct LetStmt { @@ -2124,7 +2144,9 @@ impl LetStmt { pub fn pat(&self) -> Option { support::child(&self.syntax) } pub fn eq_token(&self) -> Option { support::token(&self.syntax) } pub fn initializer(&self) -> Option { support::child(&self.syntax) } - pub fn semi_token(&self) -> Option { support::token(&self.syntax) } + pub fn semicolon_token(&self) -> Option { + support::token2(&self.syntax, T ! [ ; ]) + } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct Condition { -- cgit v1.2.3