diff options
Diffstat (limited to 'crates/ra_syntax')
-rw-r--r-- | crates/ra_syntax/Cargo.toml | 2 | ||||
-rw-r--r-- | crates/ra_syntax/src/ast/generated.rs | 1 | ||||
-rw-r--r-- | crates/ra_syntax/src/grammar.ron | 1 | ||||
-rw-r--r-- | crates/ra_syntax/src/ptr.rs | 5 | ||||
-rw-r--r-- | crates/ra_syntax/test_data/parser/err/0002_duplicate_shebang.txt | 2 | ||||
-rw-r--r-- | crates/ra_syntax/test_data/parser/err/0035_use_recover.rs | 5 | ||||
-rw-r--r-- | crates/ra_syntax/test_data/parser/err/0035_use_recover.txt | 54 |
7 files changed, 66 insertions, 4 deletions
diff --git a/crates/ra_syntax/Cargo.toml b/crates/ra_syntax/Cargo.toml index 0ead277b2..d3a8b516a 100644 --- a/crates/ra_syntax/Cargo.toml +++ b/crates/ra_syntax/Cargo.toml | |||
@@ -10,7 +10,7 @@ repository = "https://github.com/rust-analyzer/rust-analyzer" | |||
10 | [dependencies] | 10 | [dependencies] |
11 | itertools = "0.8.0" | 11 | itertools = "0.8.0" |
12 | rowan = "0.6.1" | 12 | rowan = "0.6.1" |
13 | ra_rustc_lexer = { version = "0.1.0-pre.3", features = ["unicode-xid"] } | 13 | rustc_lexer = "0.1.0" |
14 | 14 | ||
15 | # ideally, `serde` should be enabled by `ra_lsp_server`, but we enable it here | 15 | # ideally, `serde` should be enabled by `ra_lsp_server`, but we enable it here |
16 | # to reduce number of compilations | 16 | # to reduce number of compilations |
diff --git a/crates/ra_syntax/src/ast/generated.rs b/crates/ra_syntax/src/ast/generated.rs index e2a92ae60..bcf753f78 100644 --- a/crates/ra_syntax/src/ast/generated.rs +++ b/crates/ra_syntax/src/ast/generated.rs | |||
@@ -934,6 +934,7 @@ impl AstNode for ExternCrateItem { | |||
934 | &self.syntax | 934 | &self.syntax |
935 | } | 935 | } |
936 | } | 936 | } |
937 | impl ast::AttrsOwner for ExternCrateItem {} | ||
937 | impl ExternCrateItem { | 938 | impl ExternCrateItem { |
938 | pub fn name_ref(&self) -> Option<NameRef> { | 939 | pub fn name_ref(&self) -> Option<NameRef> { |
939 | AstChildren::new(&self.syntax).next() | 940 | AstChildren::new(&self.syntax).next() |
diff --git a/crates/ra_syntax/src/grammar.ron b/crates/ra_syntax/src/grammar.ron index c14ee0e85..3e6c2d3f3 100644 --- a/crates/ra_syntax/src/grammar.ron +++ b/crates/ra_syntax/src/grammar.ron | |||
@@ -669,6 +669,7 @@ Grammar( | |||
669 | collections: [("use_trees", "UseTree")] | 669 | collections: [("use_trees", "UseTree")] |
670 | ), | 670 | ), |
671 | "ExternCrateItem": ( | 671 | "ExternCrateItem": ( |
672 | traits: ["AttrsOwner"], | ||
672 | options: ["NameRef", "Alias"], | 673 | options: ["NameRef", "Alias"], |
673 | ), | 674 | ), |
674 | "ArgList": ( | 675 | "ArgList": ( |
diff --git a/crates/ra_syntax/src/ptr.rs b/crates/ra_syntax/src/ptr.rs index 80e55d2aa..992034ef0 100644 --- a/crates/ra_syntax/src/ptr.rs +++ b/crates/ra_syntax/src/ptr.rs | |||
@@ -15,8 +15,9 @@ impl SyntaxNodePtr { | |||
15 | SyntaxNodePtr { range: node.text_range(), kind: node.kind() } | 15 | SyntaxNodePtr { range: node.text_range(), kind: node.kind() } |
16 | } | 16 | } |
17 | 17 | ||
18 | pub fn to_node(self, parent: &SyntaxNode) -> SyntaxNode { | 18 | pub fn to_node(self, root: &SyntaxNode) -> SyntaxNode { |
19 | successors(Some(parent.clone()), |node| { | 19 | assert!(root.parent().is_none()); |
20 | successors(Some(root.clone()), |node| { | ||
20 | node.children().find(|it| self.range.is_subrange(&it.text_range())) | 21 | node.children().find(|it| self.range.is_subrange(&it.text_range())) |
21 | }) | 22 | }) |
22 | .find(|it| it.text_range() == self.range && it.kind() == self.kind) | 23 | .find(|it| it.text_range() == self.range && it.kind() == self.kind) |
diff --git a/crates/ra_syntax/test_data/parser/err/0002_duplicate_shebang.txt b/crates/ra_syntax/test_data/parser/err/0002_duplicate_shebang.txt index 84867026f..bdb5fa6c5 100644 --- a/crates/ra_syntax/test_data/parser/err/0002_duplicate_shebang.txt +++ b/crates/ra_syntax/test_data/parser/err/0002_duplicate_shebang.txt | |||
@@ -28,7 +28,7 @@ SOURCE_FILE@[0; 42) | |||
28 | WHITESPACE@[41; 42) "\n" | 28 | WHITESPACE@[41; 42) "\n" |
29 | error 23: expected `[` | 29 | error 23: expected `[` |
30 | error 23: expected an item | 30 | error 23: expected an item |
31 | error 27: expected one of `*`, `::`, `{`, `self`, `super` or an indentifier | 31 | error 27: expected one of `*`, `::`, `{`, `self`, `super` or an identifier |
32 | error 28: expected SEMI | 32 | error 28: expected SEMI |
33 | error 31: expected EXCL | 33 | error 31: expected EXCL |
34 | error 31: expected `{`, `[`, `(` | 34 | error 31: expected `{`, `[`, `(` |
diff --git a/crates/ra_syntax/test_data/parser/err/0035_use_recover.rs b/crates/ra_syntax/test_data/parser/err/0035_use_recover.rs new file mode 100644 index 000000000..4a2668126 --- /dev/null +++ b/crates/ra_syntax/test_data/parser/err/0035_use_recover.rs | |||
@@ -0,0 +1,5 @@ | |||
1 | use foo::bar; | ||
2 | use | ||
3 | use crate::baz; | ||
4 | use | ||
5 | fn f() {} | ||
diff --git a/crates/ra_syntax/test_data/parser/err/0035_use_recover.txt b/crates/ra_syntax/test_data/parser/err/0035_use_recover.txt new file mode 100644 index 000000000..636840828 --- /dev/null +++ b/crates/ra_syntax/test_data/parser/err/0035_use_recover.txt | |||
@@ -0,0 +1,54 @@ | |||
1 | SOURCE_FILE@[0; 48) | ||
2 | USE_ITEM@[0; 13) | ||
3 | USE_KW@[0; 3) "use" | ||
4 | WHITESPACE@[3; 4) " " | ||
5 | USE_TREE@[4; 12) | ||
6 | PATH@[4; 12) | ||
7 | PATH@[4; 7) | ||
8 | PATH_SEGMENT@[4; 7) | ||
9 | NAME_REF@[4; 7) | ||
10 | IDENT@[4; 7) "foo" | ||
11 | COLONCOLON@[7; 9) "::" | ||
12 | PATH_SEGMENT@[9; 12) | ||
13 | NAME_REF@[9; 12) | ||
14 | IDENT@[9; 12) "bar" | ||
15 | SEMI@[12; 13) ";" | ||
16 | WHITESPACE@[13; 14) "\n" | ||
17 | USE_ITEM@[14; 17) | ||
18 | USE_KW@[14; 17) "use" | ||
19 | WHITESPACE@[17; 18) "\n" | ||
20 | USE_ITEM@[18; 33) | ||
21 | USE_KW@[18; 21) "use" | ||
22 | WHITESPACE@[21; 22) " " | ||
23 | USE_TREE@[22; 32) | ||
24 | PATH@[22; 32) | ||
25 | PATH@[22; 27) | ||
26 | PATH_SEGMENT@[22; 27) | ||
27 | CRATE_KW@[22; 27) "crate" | ||
28 | COLONCOLON@[27; 29) "::" | ||
29 | PATH_SEGMENT@[29; 32) | ||
30 | NAME_REF@[29; 32) | ||
31 | IDENT@[29; 32) "baz" | ||
32 | SEMI@[32; 33) ";" | ||
33 | WHITESPACE@[33; 34) "\n" | ||
34 | USE_ITEM@[34; 37) | ||
35 | USE_KW@[34; 37) "use" | ||
36 | WHITESPACE@[37; 38) "\n" | ||
37 | FN_DEF@[38; 47) | ||
38 | FN_KW@[38; 40) "fn" | ||
39 | WHITESPACE@[40; 41) " " | ||
40 | NAME@[41; 42) | ||
41 | IDENT@[41; 42) "f" | ||
42 | PARAM_LIST@[42; 44) | ||
43 | L_PAREN@[42; 43) "(" | ||
44 | R_PAREN@[43; 44) ")" | ||
45 | WHITESPACE@[44; 45) " " | ||
46 | BLOCK_EXPR@[45; 47) | ||
47 | BLOCK@[45; 47) | ||
48 | L_CURLY@[45; 46) "{" | ||
49 | R_CURLY@[46; 47) "}" | ||
50 | WHITESPACE@[47; 48) "\n" | ||
51 | error 17: expected one of `*`, `::`, `{`, `self`, `super` or an identifier | ||
52 | error 17: expected SEMI | ||
53 | error 37: expected one of `*`, `::`, `{`, `self`, `super` or an identifier | ||
54 | error 37: expected SEMI | ||