diff options
Diffstat (limited to 'crates/ra_syntax/src/ast')
-rw-r--r-- | crates/ra_syntax/src/ast/edit.rs | 12 | ||||
-rw-r--r-- | crates/ra_syntax/src/ast/expr_extensions.rs | 2 | ||||
-rw-r--r-- | crates/ra_syntax/src/ast/extensions.rs | 4 | ||||
-rw-r--r-- | crates/ra_syntax/src/ast/make.rs | 15 |
4 files changed, 27 insertions, 6 deletions
diff --git a/crates/ra_syntax/src/ast/edit.rs b/crates/ra_syntax/src/ast/edit.rs index 6f005a2d8..95bf9db14 100644 --- a/crates/ra_syntax/src/ast/edit.rs +++ b/crates/ra_syntax/src/ast/edit.rs | |||
@@ -13,11 +13,21 @@ use crate::{ | |||
13 | make::{self, tokens}, | 13 | make::{self, tokens}, |
14 | AstNode, TypeBoundsOwner, | 14 | AstNode, TypeBoundsOwner, |
15 | }, | 15 | }, |
16 | AstToken, Direction, InsertPosition, SmolStr, SyntaxElement, | 16 | AstToken, Direction, InsertPosition, SmolStr, SyntaxElement, SyntaxKind, |
17 | SyntaxKind::{ATTR, COMMENT, WHITESPACE}, | 17 | SyntaxKind::{ATTR, COMMENT, WHITESPACE}, |
18 | SyntaxNode, SyntaxToken, T, | 18 | SyntaxNode, SyntaxToken, T, |
19 | }; | 19 | }; |
20 | 20 | ||
21 | impl ast::BinExpr { | ||
22 | #[must_use] | ||
23 | pub fn replace_op(&self, op: SyntaxKind) -> Option<ast::BinExpr> { | ||
24 | let op_node: SyntaxElement = self.op_details()?.0.into(); | ||
25 | let to_insert: Option<SyntaxElement> = Some(tokens::op(op).into()); | ||
26 | let replace_range = RangeInclusive::new(op_node.clone(), op_node); | ||
27 | Some(replace_children(self, replace_range, to_insert.into_iter())) | ||
28 | } | ||
29 | } | ||
30 | |||
21 | impl ast::FnDef { | 31 | impl ast::FnDef { |
22 | #[must_use] | 32 | #[must_use] |
23 | pub fn with_body(&self, body: ast::Block) -> ast::FnDef { | 33 | pub fn with_body(&self, body: ast::Block) -> ast::FnDef { |
diff --git a/crates/ra_syntax/src/ast/expr_extensions.rs b/crates/ra_syntax/src/ast/expr_extensions.rs index 7c53aa934..2fd039837 100644 --- a/crates/ra_syntax/src/ast/expr_extensions.rs +++ b/crates/ra_syntax/src/ast/expr_extensions.rs | |||
@@ -127,7 +127,7 @@ pub enum BinOp { | |||
127 | } | 127 | } |
128 | 128 | ||
129 | impl ast::BinExpr { | 129 | impl ast::BinExpr { |
130 | fn op_details(&self) -> Option<(SyntaxToken, BinOp)> { | 130 | pub fn op_details(&self) -> Option<(SyntaxToken, BinOp)> { |
131 | self.syntax().children_with_tokens().filter_map(|it| it.into_token()).find_map(|c| { | 131 | self.syntax().children_with_tokens().filter_map(|it| it.into_token()).find_map(|c| { |
132 | let bin_op = match c.kind() { | 132 | let bin_op = match c.kind() { |
133 | T![||] => BinOp::BooleanOr, | 133 | T![||] => BinOp::BooleanOr, |
diff --git a/crates/ra_syntax/src/ast/extensions.rs b/crates/ra_syntax/src/ast/extensions.rs index 4851dacb2..513ed7920 100644 --- a/crates/ra_syntax/src/ast/extensions.rs +++ b/crates/ra_syntax/src/ast/extensions.rs | |||
@@ -178,15 +178,15 @@ impl ast::ImplBlock { | |||
178 | 178 | ||
179 | #[derive(Debug, Clone, PartialEq, Eq)] | 179 | #[derive(Debug, Clone, PartialEq, Eq)] |
180 | pub enum StructKind { | 180 | pub enum StructKind { |
181 | Record(ast::RecordFieldDefList), | ||
181 | Tuple(ast::TupleFieldDefList), | 182 | Tuple(ast::TupleFieldDefList), |
182 | Named(ast::RecordFieldDefList), | ||
183 | Unit, | 183 | Unit, |
184 | } | 184 | } |
185 | 185 | ||
186 | impl StructKind { | 186 | impl StructKind { |
187 | fn from_node<N: AstNode>(node: &N) -> StructKind { | 187 | fn from_node<N: AstNode>(node: &N) -> StructKind { |
188 | if let Some(nfdl) = child_opt::<_, ast::RecordFieldDefList>(node) { | 188 | if let Some(nfdl) = child_opt::<_, ast::RecordFieldDefList>(node) { |
189 | StructKind::Named(nfdl) | 189 | StructKind::Record(nfdl) |
190 | } else if let Some(pfl) = child_opt::<_, ast::TupleFieldDefList>(node) { | 190 | } else if let Some(pfl) = child_opt::<_, ast::TupleFieldDefList>(node) { |
191 | StructKind::Tuple(pfl) | 191 | StructKind::Tuple(pfl) |
192 | } else { | 192 | } else { |
diff --git a/crates/ra_syntax/src/ast/make.rs b/crates/ra_syntax/src/ast/make.rs index 9749327fa..40db570da 100644 --- a/crates/ra_syntax/src/ast/make.rs +++ b/crates/ra_syntax/src/ast/make.rs | |||
@@ -173,10 +173,21 @@ fn ast_from_text<N: AstNode>(text: &str) -> N { | |||
173 | } | 173 | } |
174 | 174 | ||
175 | pub mod tokens { | 175 | pub mod tokens { |
176 | use crate::{AstNode, Parse, SourceFile, SyntaxKind::*, SyntaxToken, T}; | 176 | use crate::{AstNode, Parse, SourceFile, SyntaxKind, SyntaxKind::*, SyntaxToken, T}; |
177 | use once_cell::sync::Lazy; | 177 | use once_cell::sync::Lazy; |
178 | 178 | ||
179 | static SOURCE_FILE: Lazy<Parse<SourceFile>> = Lazy::new(|| SourceFile::parse(",\n; ;")); | 179 | static SOURCE_FILE: Lazy<Parse<SourceFile>> = |
180 | Lazy::new(|| SourceFile::parse("const C: () = (1 != 1, 2 == 2)\n;")); | ||
181 | |||
182 | pub fn op(op: SyntaxKind) -> SyntaxToken { | ||
183 | SOURCE_FILE | ||
184 | .tree() | ||
185 | .syntax() | ||
186 | .descendants_with_tokens() | ||
187 | .filter_map(|it| it.into_token()) | ||
188 | .find(|it| it.kind() == op) | ||
189 | .unwrap() | ||
190 | } | ||
180 | 191 | ||
181 | pub fn comma() -> SyntaxToken { | 192 | pub fn comma() -> SyntaxToken { |
182 | SOURCE_FILE | 193 | SOURCE_FILE |