diff options
-rw-r--r-- | crates/libeditor/src/completion.rs | 53 | ||||
-rw-r--r-- | crates/libsyntax2/src/grammar/patterns.rs | 11 | ||||
-rw-r--r-- | crates/libsyntax2/tests/data/parser/err/0018_incomplete_fn.rs | 8 | ||||
-rw-r--r-- | crates/libsyntax2/tests/data/parser/err/0018_incomplete_fn.txt | 179 |
4 files changed, 248 insertions, 3 deletions
diff --git a/crates/libeditor/src/completion.rs b/crates/libeditor/src/completion.rs index aeed19559..351781ec4 100644 --- a/crates/libeditor/src/completion.rs +++ b/crates/libeditor/src/completion.rs | |||
@@ -1,5 +1,7 @@ | |||
1 | use std::collections::HashMap; | ||
2 | |||
1 | use libsyntax2::{ | 3 | use libsyntax2::{ |
2 | File, TextUnit, AstNode, SyntaxNodeRef, | 4 | File, TextUnit, AstNode, SyntaxNodeRef, SyntaxNode, SmolStr, |
3 | ast::{self, NameOwner}, | 5 | ast::{self, NameOwner}, |
4 | algo::{ | 6 | algo::{ |
5 | ancestors, | 7 | ancestors, |
@@ -59,3 +61,52 @@ fn process_scope(node: SyntaxNodeRef, sink: &mut Vec<CompletionItem>) { | |||
59 | sink.extend(items); | 61 | sink.extend(items); |
60 | } | 62 | } |
61 | } | 63 | } |
64 | |||
65 | // fn compute_scopes(fn_def: ast::FnDef) -> FnScopes { | ||
66 | // let mut scopes = FnScopes::new(); | ||
67 | // } | ||
68 | |||
69 | // type ScopeId = usize; | ||
70 | |||
71 | // struct FnScopes { | ||
72 | // scopes: Vec<ScopeData>, | ||
73 | // scope_for_expr: HashMap<SyntaxNode, ScopeId>, | ||
74 | // } | ||
75 | |||
76 | // impl FnScopes { | ||
77 | // fn new() -> FnScopes { | ||
78 | // FnScopes { | ||
79 | // scopes: vec![], | ||
80 | // scope_for_expr: HashMap::new(), | ||
81 | // } | ||
82 | // } | ||
83 | |||
84 | // fn new_scope(&mut Self) -> ScopeId { | ||
85 | // let res = self.scopes.len(); | ||
86 | // self.scopes.push(ScopeData { parent: None, entries: vec![] }) | ||
87 | // } | ||
88 | |||
89 | // fn set_parent | ||
90 | // } | ||
91 | |||
92 | // struct ScopeData { | ||
93 | // parent: Option<ScopeId>, | ||
94 | // entries: Vec<ScopeEntry> | ||
95 | // } | ||
96 | |||
97 | // struct ScopeEntry { | ||
98 | // syntax: SyntaxNode | ||
99 | // } | ||
100 | |||
101 | // impl ScopeEntry { | ||
102 | // fn name(&self) -> SmolStr { | ||
103 | // self.ast().name() | ||
104 | // .unwrap() | ||
105 | // .text() | ||
106 | // } | ||
107 | |||
108 | // fn ast(&self) -> ast::BindPat { | ||
109 | // ast::BindPat::cast(self.syntax.borrowed()) | ||
110 | // .unwrap() | ||
111 | // } | ||
112 | // } | ||
diff --git a/crates/libsyntax2/src/grammar/patterns.rs b/crates/libsyntax2/src/grammar/patterns.rs index 11852e0d3..114964651 100644 --- a/crates/libsyntax2/src/grammar/patterns.rs +++ b/crates/libsyntax2/src/grammar/patterns.rs | |||
@@ -2,7 +2,7 @@ use super::*; | |||
2 | 2 | ||
3 | pub(super) const PATTERN_FIRST: TokenSet = | 3 | pub(super) const PATTERN_FIRST: TokenSet = |
4 | token_set_union![ | 4 | token_set_union![ |
5 | token_set![REF_KW, MUT_KW, L_PAREN, L_BRACK, AMP], | 5 | token_set![REF_KW, MUT_KW, L_PAREN, L_BRACK, AMP, UNDERSCORE], |
6 | expressions::LITERAL_FIRST, | 6 | expressions::LITERAL_FIRST, |
7 | paths::PATH_FIRST, | 7 | paths::PATH_FIRST, |
8 | ]; | 8 | ]; |
@@ -97,7 +97,13 @@ fn tuple_pat_fields(p: &mut Parser) { | |||
97 | while !p.at(EOF) && !p.at(R_PAREN) { | 97 | while !p.at(EOF) && !p.at(R_PAREN) { |
98 | match p.current() { | 98 | match p.current() { |
99 | DOTDOT => p.bump(), | 99 | DOTDOT => p.bump(), |
100 | _ => pattern(p), | 100 | _ => { |
101 | if !PATTERN_FIRST.contains(p.current()) { | ||
102 | p.error("expected a pattern"); | ||
103 | break; | ||
104 | } | ||
105 | pattern(p) | ||
106 | } | ||
101 | } | 107 | } |
102 | if !p.at(R_PAREN) { | 108 | if !p.at(R_PAREN) { |
103 | p.expect(COMMA); | 109 | p.expect(COMMA); |
@@ -125,6 +131,7 @@ fn field_pat_list(p: &mut Parser) { | |||
125 | p.bump(); | 131 | p.bump(); |
126 | pattern(p); | 132 | pattern(p); |
127 | } | 133 | } |
134 | L_CURLY => error_block(p, "expected ident"), | ||
128 | _ => { | 135 | _ => { |
129 | bind_pat(p, false); | 136 | bind_pat(p, false); |
130 | } | 137 | } |
diff --git a/crates/libsyntax2/tests/data/parser/err/0018_incomplete_fn.rs b/crates/libsyntax2/tests/data/parser/err/0018_incomplete_fn.rs new file mode 100644 index 000000000..fe604006c --- /dev/null +++ b/crates/libsyntax2/tests/data/parser/err/0018_incomplete_fn.rs | |||
@@ -0,0 +1,8 @@ | |||
1 | impl FnScopes { | ||
2 | fn new_scope(&) -> ScopeId { | ||
3 | let res = self.scopes.len(); | ||
4 | self.scopes.push(ScopeData { parent: None, entries: vec![] }) | ||
5 | } | ||
6 | |||
7 | fn set_parent | ||
8 | } | ||
diff --git a/crates/libsyntax2/tests/data/parser/err/0018_incomplete_fn.txt b/crates/libsyntax2/tests/data/parser/err/0018_incomplete_fn.txt new file mode 100644 index 000000000..3f3a7784b --- /dev/null +++ b/crates/libsyntax2/tests/data/parser/err/0018_incomplete_fn.txt | |||
@@ -0,0 +1,179 @@ | |||
1 | ROOT@[0; 183) | ||
2 | IMPL_ITEM@[0; 182) | ||
3 | IMPL_KW@[0; 4) | ||
4 | WHITESPACE@[4; 5) | ||
5 | PATH_TYPE@[5; 13) | ||
6 | PATH@[5; 13) | ||
7 | PATH_SEGMENT@[5; 13) | ||
8 | NAME_REF@[5; 13) | ||
9 | IDENT@[5; 13) "FnScopes" | ||
10 | WHITESPACE@[13; 14) | ||
11 | ITEM_LIST@[14; 182) | ||
12 | L_CURLY@[14; 15) | ||
13 | WHITESPACE@[15; 20) | ||
14 | FN_DEF@[20; 181) | ||
15 | FN_KW@[20; 22) | ||
16 | WHITESPACE@[22; 23) | ||
17 | NAME@[23; 32) | ||
18 | IDENT@[23; 32) "new_scope" | ||
19 | PARAM_LIST@[32; 181) | ||
20 | L_PAREN@[32; 33) | ||
21 | PARAM@[33; 38) | ||
22 | REF_PAT@[33; 35) | ||
23 | AMP@[33; 34) | ||
24 | err: `expected pattern` | ||
25 | ERROR@[34; 35) | ||
26 | R_PAREN@[34; 35) | ||
27 | err: `expected COLON` | ||
28 | WHITESPACE@[35; 36) | ||
29 | err: `expected type` | ||
30 | ERROR@[36; 38) | ||
31 | THIN_ARROW@[36; 38) | ||
32 | err: `expected COMMA` | ||
33 | WHITESPACE@[38; 39) | ||
34 | PARAM@[39; 169) | ||
35 | STRUCT_PAT@[39; 161) | ||
36 | PATH@[39; 46) | ||
37 | PATH_SEGMENT@[39; 46) | ||
38 | NAME_REF@[39; 46) | ||
39 | IDENT@[39; 46) "ScopeId" | ||
40 | WHITESPACE@[46; 47) | ||
41 | FIELD_PAT_LIST@[47; 161) | ||
42 | L_CURLY@[47; 48) | ||
43 | WHITESPACE@[48; 57) | ||
44 | err: `expected a name` | ||
45 | BIND_PAT@[57; 60) | ||
46 | ERROR@[57; 60) | ||
47 | LET_KW@[57; 60) | ||
48 | err: `expected COMMA` | ||
49 | WHITESPACE@[60; 61) | ||
50 | BIND_PAT@[61; 64) | ||
51 | NAME@[61; 64) | ||
52 | IDENT@[61; 64) "res" | ||
53 | err: `expected COMMA` | ||
54 | WHITESPACE@[64; 65) | ||
55 | err: `expected a name` | ||
56 | BIND_PAT@[65; 66) | ||
57 | ERROR@[65; 66) | ||
58 | EQ@[65; 66) | ||
59 | err: `expected COMMA` | ||
60 | WHITESPACE@[66; 67) | ||
61 | err: `expected a name` | ||
62 | BIND_PAT@[67; 71) | ||
63 | ERROR@[67; 71) | ||
64 | SELF_KW@[67; 71) | ||
65 | err: `expected COMMA` | ||
66 | err: `expected a name` | ||
67 | BIND_PAT@[71; 72) | ||
68 | ERROR@[71; 72) | ||
69 | DOT@[71; 72) | ||
70 | err: `expected COMMA` | ||
71 | BIND_PAT@[72; 78) | ||
72 | NAME@[72; 78) | ||
73 | IDENT@[72; 78) "scopes" | ||
74 | err: `expected COMMA` | ||
75 | err: `expected a name` | ||
76 | BIND_PAT@[78; 79) | ||
77 | ERROR@[78; 79) | ||
78 | DOT@[78; 79) | ||
79 | err: `expected COMMA` | ||
80 | BIND_PAT@[79; 82) | ||
81 | NAME@[79; 82) | ||
82 | IDENT@[79; 82) "len" | ||
83 | err: `expected COMMA` | ||
84 | err: `expected a name` | ||
85 | BIND_PAT@[82; 83) | ||
86 | ERROR@[82; 83) | ||
87 | L_PAREN@[82; 83) | ||
88 | err: `expected COMMA` | ||
89 | err: `expected a name` | ||
90 | BIND_PAT@[83; 84) | ||
91 | ERROR@[83; 84) | ||
92 | R_PAREN@[83; 84) | ||
93 | err: `expected COMMA` | ||
94 | err: `expected a name` | ||
95 | BIND_PAT@[84; 85) | ||
96 | ERROR@[84; 85) | ||
97 | SEMI@[84; 85) | ||
98 | err: `expected COMMA` | ||
99 | WHITESPACE@[85; 94) | ||
100 | err: `expected a name` | ||
101 | BIND_PAT@[94; 98) | ||
102 | ERROR@[94; 98) | ||
103 | SELF_KW@[94; 98) | ||
104 | err: `expected COMMA` | ||
105 | err: `expected a name` | ||
106 | BIND_PAT@[98; 99) | ||
107 | ERROR@[98; 99) | ||
108 | DOT@[98; 99) | ||
109 | err: `expected COMMA` | ||
110 | BIND_PAT@[99; 105) | ||
111 | NAME@[99; 105) | ||
112 | IDENT@[99; 105) "scopes" | ||
113 | err: `expected COMMA` | ||
114 | err: `expected a name` | ||
115 | BIND_PAT@[105; 106) | ||
116 | ERROR@[105; 106) | ||
117 | DOT@[105; 106) | ||
118 | err: `expected COMMA` | ||
119 | BIND_PAT@[106; 110) | ||
120 | NAME@[106; 110) | ||
121 | IDENT@[106; 110) "push" | ||
122 | err: `expected COMMA` | ||
123 | err: `expected a name` | ||
124 | BIND_PAT@[110; 111) | ||
125 | ERROR@[110; 111) | ||
126 | L_PAREN@[110; 111) | ||
127 | err: `expected COMMA` | ||
128 | BIND_PAT@[111; 120) | ||
129 | NAME@[111; 120) | ||
130 | IDENT@[111; 120) "ScopeData" | ||
131 | err: `expected COMMA` | ||
132 | WHITESPACE@[120; 121) | ||
133 | err: `expected ident` | ||
134 | ERROR@[121; 154) | ||
135 | L_CURLY@[121; 122) | ||
136 | WHITESPACE@[122; 123) | ||
137 | IDENT@[123; 129) "parent" | ||
138 | COLON@[129; 130) | ||
139 | WHITESPACE@[130; 131) | ||
140 | IDENT@[131; 135) "None" | ||
141 | COMMA@[135; 136) | ||
142 | WHITESPACE@[136; 137) | ||
143 | IDENT@[137; 144) "entries" | ||
144 | COLON@[144; 145) | ||
145 | WHITESPACE@[145; 146) | ||
146 | IDENT@[146; 149) "vec" | ||
147 | EXCL@[149; 150) | ||
148 | L_BRACK@[150; 151) | ||
149 | R_BRACK@[151; 152) | ||
150 | WHITESPACE@[152; 153) | ||
151 | R_CURLY@[153; 154) | ||
152 | err: `expected COMMA` | ||
153 | err: `expected a name` | ||
154 | BIND_PAT@[154; 155) | ||
155 | ERROR@[154; 155) | ||
156 | R_PAREN@[154; 155) | ||
157 | WHITESPACE@[155; 160) | ||
158 | R_CURLY@[160; 161) | ||
159 | err: `expected COLON` | ||
160 | WHITESPACE@[161; 167) | ||
161 | FN_POINTER_TYPE@[167; 169) | ||
162 | FN_KW@[167; 169) | ||
163 | err: `expected parameters` | ||
164 | err: `expected COMMA` | ||
165 | WHITESPACE@[169; 170) | ||
166 | PARAM@[170; 181) | ||
167 | BIND_PAT@[170; 180) | ||
168 | NAME@[170; 180) | ||
169 | IDENT@[170; 180) "set_parent" | ||
170 | err: `expected COLON` | ||
171 | WHITESPACE@[180; 181) | ||
172 | err: `expected type` | ||
173 | err: `expected COMMA` | ||
174 | err: `expected value parameter` | ||
175 | err: `expected R_PAREN` | ||
176 | err: `expected a block` | ||
177 | ERROR@[181; 181) | ||
178 | R_CURLY@[181; 182) | ||
179 | WHITESPACE@[182; 183) | ||