aboutsummaryrefslogtreecommitdiff
path: root/crates/syntax
diff options
context:
space:
mode:
Diffstat (limited to 'crates/syntax')
-rw-r--r--crates/syntax/Cargo.toml6
-rw-r--r--crates/syntax/src/algo.rs2
-rw-r--r--crates/syntax/src/ast/generated/nodes.rs8
-rw-r--r--crates/syntax/src/ast/make.rs8
4 files changed, 18 insertions, 6 deletions
diff --git a/crates/syntax/Cargo.toml b/crates/syntax/Cargo.toml
index 6818f3ad8..2c1bdb295 100644
--- a/crates/syntax/Cargo.toml
+++ b/crates/syntax/Cargo.toml
@@ -23,9 +23,9 @@ once_cell = "1.3.1"
23smol_str = { version = "0.1.15", features = ["serde"] } 23smol_str = { version = "0.1.15", features = ["serde"] }
24serde = { version = "1.0.106", features = ["derive"] } 24serde = { version = "1.0.106", features = ["derive"] }
25 25
26stdx = { path = "../stdx" } 26stdx = { path = "../stdx", version = "0.0.0" }
27text_edit = { path = "../text_edit" } 27text_edit = { path = "../text_edit", version = "0.0.0" }
28parser = { path = "../parser" } 28parser = { path = "../parser", version = "0.0.0" }
29 29
30[dev-dependencies] 30[dev-dependencies]
31walkdir = "2.3.1" 31walkdir = "2.3.1"
diff --git a/crates/syntax/src/algo.rs b/crates/syntax/src/algo.rs
index 6254b38ba..ea199f9b8 100644
--- a/crates/syntax/src/algo.rs
+++ b/crates/syntax/src/algo.rs
@@ -32,7 +32,7 @@ pub fn ancestors_at_offset(
32/// imprecise: if the cursor is strictly between two nodes of the desired type, 32/// imprecise: if the cursor is strictly between two nodes of the desired type,
33/// as in 33/// as in
34/// 34///
35/// ```no-run 35/// ```no_run
36/// struct Foo {}|struct Bar; 36/// struct Foo {}|struct Bar;
37/// ``` 37/// ```
38/// 38///
diff --git a/crates/syntax/src/ast/generated/nodes.rs b/crates/syntax/src/ast/generated/nodes.rs
index 6317407c6..d6af5755c 100644
--- a/crates/syntax/src/ast/generated/nodes.rs
+++ b/crates/syntax/src/ast/generated/nodes.rs
@@ -1380,6 +1380,7 @@ pub enum ExternItem {
1380 Fn(Fn), 1380 Fn(Fn),
1381 MacroCall(MacroCall), 1381 MacroCall(MacroCall),
1382 Static(Static), 1382 Static(Static),
1383 TypeAlias(TypeAlias),
1383} 1384}
1384impl ast::AttrsOwner for ExternItem {} 1385impl ast::AttrsOwner for ExternItem {}
1385impl ast::NameOwner for ExternItem {} 1386impl ast::NameOwner for ExternItem {}
@@ -3339,10 +3340,13 @@ impl From<MacroCall> for ExternItem {
3339impl From<Static> for ExternItem { 3340impl From<Static> for ExternItem {
3340 fn from(node: Static) -> ExternItem { ExternItem::Static(node) } 3341 fn from(node: Static) -> ExternItem { ExternItem::Static(node) }
3341} 3342}
3343impl From<TypeAlias> for ExternItem {
3344 fn from(node: TypeAlias) -> ExternItem { ExternItem::TypeAlias(node) }
3345}
3342impl AstNode for ExternItem { 3346impl AstNode for ExternItem {
3343 fn can_cast(kind: SyntaxKind) -> bool { 3347 fn can_cast(kind: SyntaxKind) -> bool {
3344 match kind { 3348 match kind {
3345 FN | MACRO_CALL | STATIC => true, 3349 FN | MACRO_CALL | STATIC | TYPE_ALIAS => true,
3346 _ => false, 3350 _ => false,
3347 } 3351 }
3348 } 3352 }
@@ -3351,6 +3355,7 @@ impl AstNode for ExternItem {
3351 FN => ExternItem::Fn(Fn { syntax }), 3355 FN => ExternItem::Fn(Fn { syntax }),
3352 MACRO_CALL => ExternItem::MacroCall(MacroCall { syntax }), 3356 MACRO_CALL => ExternItem::MacroCall(MacroCall { syntax }),
3353 STATIC => ExternItem::Static(Static { syntax }), 3357 STATIC => ExternItem::Static(Static { syntax }),
3358 TYPE_ALIAS => ExternItem::TypeAlias(TypeAlias { syntax }),
3354 _ => return None, 3359 _ => return None,
3355 }; 3360 };
3356 Some(res) 3361 Some(res)
@@ -3360,6 +3365,7 @@ impl AstNode for ExternItem {
3360 ExternItem::Fn(it) => &it.syntax, 3365 ExternItem::Fn(it) => &it.syntax,
3361 ExternItem::MacroCall(it) => &it.syntax, 3366 ExternItem::MacroCall(it) => &it.syntax,
3362 ExternItem::Static(it) => &it.syntax, 3367 ExternItem::Static(it) => &it.syntax,
3368 ExternItem::TypeAlias(it) => &it.syntax,
3363 } 3369 }
3364 } 3370 }
3365} 3371}
diff --git a/crates/syntax/src/ast/make.rs b/crates/syntax/src/ast/make.rs
index d20c085aa..7958721e2 100644
--- a/crates/syntax/src/ast/make.rs
+++ b/crates/syntax/src/ast/make.rs
@@ -7,7 +7,7 @@
7use itertools::Itertools; 7use itertools::Itertools;
8use stdx::format_to; 8use stdx::format_to;
9 9
10use crate::{ast, AstNode, SourceFile, SyntaxKind, SyntaxNode, SyntaxToken}; 10use crate::{ast, AstNode, SourceFile, SyntaxKind, SyntaxNode, SyntaxText, SyntaxToken};
11 11
12pub fn name(text: &str) -> ast::Name { 12pub fn name(text: &str) -> ast::Name {
13 ast_from_text(&format!("mod {};", text)) 13 ast_from_text(&format!("mod {};", text))
@@ -137,6 +137,12 @@ pub fn expr_prefix(op: SyntaxKind, expr: ast::Expr) -> ast::Expr {
137pub fn expr_call(f: ast::Expr, arg_list: ast::ArgList) -> ast::Expr { 137pub fn expr_call(f: ast::Expr, arg_list: ast::ArgList) -> ast::Expr {
138 expr_from_text(&format!("{}{}", f, arg_list)) 138 expr_from_text(&format!("{}{}", f, arg_list))
139} 139}
140pub fn expr_method_call<F>(text: &str, caller: F) -> Option<ast::Expr>
141where
142 F: FnOnce() -> Option<SyntaxText>,
143{
144 try_expr_from_text(&format!("{}.{}()", caller()?, text))
145}
140fn expr_from_text(text: &str) -> ast::Expr { 146fn expr_from_text(text: &str) -> ast::Expr {
141 ast_from_text(&format!("const C: () = {};", text)) 147 ast_from_text(&format!("const C: () = {};", text))
142} 148}