diff options
-rw-r--r-- | crates/ra_editor/src/lib.rs | 18 | ||||
-rw-r--r-- | crates/ra_syntax/src/ast/generated.rs | 96 | ||||
-rw-r--r-- | crates/ra_syntax/src/ast/generated.rs.tera | 3 | ||||
-rw-r--r-- | editors/code/src/highlighting.ts | 7 |
4 files changed, 68 insertions, 56 deletions
diff --git a/crates/ra_editor/src/lib.rs b/crates/ra_editor/src/lib.rs index fe0045378..906ee11fe 100644 --- a/crates/ra_editor/src/lib.rs +++ b/crates/ra_editor/src/lib.rs | |||
@@ -88,7 +88,6 @@ pub fn highlight(file: &File) -> Vec<HighlightedRange> { | |||
88 | let mut res = Vec::new(); | 88 | let mut res = Vec::new(); |
89 | for node in file.syntax().descendants() { | 89 | for node in file.syntax().descendants() { |
90 | let tag = match node.kind() { | 90 | let tag = match node.kind() { |
91 | ERROR => "error", | ||
92 | COMMENT | DOC_COMMENT => "comment", | 91 | COMMENT | DOC_COMMENT => "comment", |
93 | STRING | RAW_STRING | RAW_BYTE_STRING | BYTE_STRING => "string", | 92 | STRING | RAW_STRING | RAW_BYTE_STRING | BYTE_STRING => "string", |
94 | ATTR => "attribute", | 93 | ATTR => "attribute", |
@@ -108,21 +107,10 @@ pub fn highlight(file: &File) -> Vec<HighlightedRange> { | |||
108 | } | 107 | } |
109 | 108 | ||
110 | pub fn diagnostics(file: &File) -> Vec<Diagnostic> { | 109 | pub fn diagnostics(file: &File) -> Vec<Diagnostic> { |
111 | let mut res = Vec::new(); | 110 | file.errors().into_iter().map(|err| Diagnostic { |
112 | |||
113 | for node in file.syntax().descendants() { | ||
114 | if node.kind() == ERROR { | ||
115 | res.push(Diagnostic { | ||
116 | range: node.range(), | ||
117 | msg: "Syntax Error".to_string(), | ||
118 | }); | ||
119 | } | ||
120 | } | ||
121 | res.extend(file.errors().into_iter().map(|err| Diagnostic { | ||
122 | range: TextRange::offset_len(err.offset, 1.into()), | 111 | range: TextRange::offset_len(err.offset, 1.into()), |
123 | msg: err.msg, | 112 | msg: "Syntax Error: ".to_string() + &err.msg, |
124 | })); | 113 | }).collect() |
125 | res | ||
126 | } | 114 | } |
127 | 115 | ||
128 | pub fn syntax_tree(file: &File) -> String { | 116 | pub fn syntax_tree(file: &File) -> String { |
diff --git a/crates/ra_syntax/src/ast/generated.rs b/crates/ra_syntax/src/ast/generated.rs index b0b855eb4..ef7b5b1a1 100644 --- a/crates/ra_syntax/src/ast/generated.rs +++ b/crates/ra_syntax/src/ast/generated.rs | |||
@@ -81,7 +81,8 @@ impl<'a> AstNode<'a> for Attr<'a> { | |||
81 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 81 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } |
82 | } | 82 | } |
83 | 83 | ||
84 | impl<'a> Attr<'a> {pub fn value(self) -> Option<TokenTree<'a>> { | 84 | impl<'a> Attr<'a> { |
85 | pub fn value(self) -> Option<TokenTree<'a>> { | ||
85 | super::child_opt(self) | 86 | super::child_opt(self) |
86 | } | 87 | } |
87 | } | 88 | } |
@@ -143,7 +144,8 @@ impl<'a> Block<'a> { | |||
143 | pub fn statements(self) -> impl Iterator<Item = Stmt<'a>> + 'a { | 144 | pub fn statements(self) -> impl Iterator<Item = Stmt<'a>> + 'a { |
144 | super::children(self) | 145 | super::children(self) |
145 | } | 146 | } |
146 | pub fn expr(self) -> Option<Expr<'a>> { | 147 | |
148 | pub fn expr(self) -> Option<Expr<'a>> { | ||
147 | super::child_opt(self) | 149 | super::child_opt(self) |
148 | } | 150 | } |
149 | } | 151 | } |
@@ -164,7 +166,8 @@ impl<'a> AstNode<'a> for BlockExpr<'a> { | |||
164 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 166 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } |
165 | } | 167 | } |
166 | 168 | ||
167 | impl<'a> BlockExpr<'a> {pub fn block(self) -> Option<Block<'a>> { | 169 | impl<'a> BlockExpr<'a> { |
170 | pub fn block(self) -> Option<Block<'a>> { | ||
168 | super::child_opt(self) | 171 | super::child_opt(self) |
169 | } | 172 | } |
170 | } | 173 | } |
@@ -204,7 +207,8 @@ impl<'a> AstNode<'a> for CallExpr<'a> { | |||
204 | } | 207 | } |
205 | 208 | ||
206 | impl<'a> ast::ArgListOwner<'a> for CallExpr<'a> {} | 209 | impl<'a> ast::ArgListOwner<'a> for CallExpr<'a> {} |
207 | impl<'a> CallExpr<'a> {pub fn expr(self) -> Option<Expr<'a>> { | 210 | impl<'a> CallExpr<'a> { |
211 | pub fn expr(self) -> Option<Expr<'a>> { | ||
208 | super::child_opt(self) | 212 | super::child_opt(self) |
209 | } | 213 | } |
210 | } | 214 | } |
@@ -261,10 +265,12 @@ impl<'a> AstNode<'a> for Condition<'a> { | |||
261 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 265 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } |
262 | } | 266 | } |
263 | 267 | ||
264 | impl<'a> Condition<'a> {pub fn pat(self) -> Option<Pat<'a>> { | 268 | impl<'a> Condition<'a> { |
269 | pub fn pat(self) -> Option<Pat<'a>> { | ||
265 | super::child_opt(self) | 270 | super::child_opt(self) |
266 | } | 271 | } |
267 | pub fn expr(self) -> Option<Expr<'a>> { | 272 | |
273 | pub fn expr(self) -> Option<Expr<'a>> { | ||
268 | super::child_opt(self) | 274 | super::child_opt(self) |
269 | } | 275 | } |
270 | } | 276 | } |
@@ -478,7 +484,8 @@ impl<'a> AstNode<'a> for ExprStmt<'a> { | |||
478 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 484 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } |
479 | } | 485 | } |
480 | 486 | ||
481 | impl<'a> ExprStmt<'a> {pub fn expr(self) -> Option<Expr<'a>> { | 487 | impl<'a> ExprStmt<'a> { |
488 | pub fn expr(self) -> Option<Expr<'a>> { | ||
482 | super::child_opt(self) | 489 | super::child_opt(self) |
483 | } | 490 | } |
484 | } | 491 | } |
@@ -556,13 +563,16 @@ impl<'a> AstNode<'a> for FnDef<'a> { | |||
556 | impl<'a> ast::NameOwner<'a> for FnDef<'a> {} | 563 | impl<'a> ast::NameOwner<'a> for FnDef<'a> {} |
557 | impl<'a> ast::TypeParamsOwner<'a> for FnDef<'a> {} | 564 | impl<'a> ast::TypeParamsOwner<'a> for FnDef<'a> {} |
558 | impl<'a> ast::AttrsOwner<'a> for FnDef<'a> {} | 565 | impl<'a> ast::AttrsOwner<'a> for FnDef<'a> {} |
559 | impl<'a> FnDef<'a> {pub fn param_list(self) -> Option<ParamList<'a>> { | 566 | impl<'a> FnDef<'a> { |
567 | pub fn param_list(self) -> Option<ParamList<'a>> { | ||
560 | super::child_opt(self) | 568 | super::child_opt(self) |
561 | } | 569 | } |
562 | pub fn body(self) -> Option<Block<'a>> { | 570 | |
571 | pub fn body(self) -> Option<Block<'a>> { | ||
563 | super::child_opt(self) | 572 | super::child_opt(self) |
564 | } | 573 | } |
565 | pub fn ret_type(self) -> Option<RetType<'a>> { | 574 | |
575 | pub fn ret_type(self) -> Option<RetType<'a>> { | ||
566 | super::child_opt(self) | 576 | super::child_opt(self) |
567 | } | 577 | } |
568 | } | 578 | } |
@@ -602,10 +612,12 @@ impl<'a> AstNode<'a> for ForExpr<'a> { | |||
602 | } | 612 | } |
603 | 613 | ||
604 | impl<'a> ast::LoopBodyOwner<'a> for ForExpr<'a> {} | 614 | impl<'a> ast::LoopBodyOwner<'a> for ForExpr<'a> {} |
605 | impl<'a> ForExpr<'a> {pub fn pat(self) -> Option<Pat<'a>> { | 615 | impl<'a> ForExpr<'a> { |
616 | pub fn pat(self) -> Option<Pat<'a>> { | ||
606 | super::child_opt(self) | 617 | super::child_opt(self) |
607 | } | 618 | } |
608 | pub fn iterable(self) -> Option<Expr<'a>> { | 619 | |
620 | pub fn iterable(self) -> Option<Expr<'a>> { | ||
609 | super::child_opt(self) | 621 | super::child_opt(self) |
610 | } | 622 | } |
611 | } | 623 | } |
@@ -644,7 +656,8 @@ impl<'a> AstNode<'a> for IfExpr<'a> { | |||
644 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 656 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } |
645 | } | 657 | } |
646 | 658 | ||
647 | impl<'a> IfExpr<'a> {pub fn condition(self) -> Option<Condition<'a>> { | 659 | impl<'a> IfExpr<'a> { |
660 | pub fn condition(self) -> Option<Condition<'a>> { | ||
648 | super::child_opt(self) | 661 | super::child_opt(self) |
649 | } | 662 | } |
650 | } | 663 | } |
@@ -757,10 +770,12 @@ impl<'a> AstNode<'a> for LambdaExpr<'a> { | |||
757 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 770 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } |
758 | } | 771 | } |
759 | 772 | ||
760 | impl<'a> LambdaExpr<'a> {pub fn param_list(self) -> Option<ParamList<'a>> { | 773 | impl<'a> LambdaExpr<'a> { |
774 | pub fn param_list(self) -> Option<ParamList<'a>> { | ||
761 | super::child_opt(self) | 775 | super::child_opt(self) |
762 | } | 776 | } |
763 | pub fn body(self) -> Option<Expr<'a>> { | 777 | |
778 | pub fn body(self) -> Option<Expr<'a>> { | ||
764 | super::child_opt(self) | 779 | super::child_opt(self) |
765 | } | 780 | } |
766 | } | 781 | } |
@@ -781,10 +796,12 @@ impl<'a> AstNode<'a> for LetStmt<'a> { | |||
781 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 796 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } |
782 | } | 797 | } |
783 | 798 | ||
784 | impl<'a> LetStmt<'a> {pub fn pat(self) -> Option<Pat<'a>> { | 799 | impl<'a> LetStmt<'a> { |
800 | pub fn pat(self) -> Option<Pat<'a>> { | ||
785 | super::child_opt(self) | 801 | super::child_opt(self) |
786 | } | 802 | } |
787 | pub fn initializer(self) -> Option<Expr<'a>> { | 803 | |
804 | pub fn initializer(self) -> Option<Expr<'a>> { | ||
788 | super::child_opt(self) | 805 | super::child_opt(self) |
789 | } | 806 | } |
790 | } | 807 | } |
@@ -823,7 +840,8 @@ impl<'a> AstNode<'a> for LifetimeParam<'a> { | |||
823 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 840 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } |
824 | } | 841 | } |
825 | 842 | ||
826 | impl<'a> LifetimeParam<'a> {pub fn lifetime(self) -> Option<Lifetime<'a>> { | 843 | impl<'a> LifetimeParam<'a> { |
844 | pub fn lifetime(self) -> Option<Lifetime<'a>> { | ||
827 | super::child_opt(self) | 845 | super::child_opt(self) |
828 | } | 846 | } |
829 | } | 847 | } |
@@ -885,10 +903,12 @@ impl<'a> MatchArm<'a> { | |||
885 | pub fn pats(self) -> impl Iterator<Item = Pat<'a>> + 'a { | 903 | pub fn pats(self) -> impl Iterator<Item = Pat<'a>> + 'a { |
886 | super::children(self) | 904 | super::children(self) |
887 | } | 905 | } |
888 | pub fn guard(self) -> Option<MatchGuard<'a>> { | 906 | |
907 | pub fn guard(self) -> Option<MatchGuard<'a>> { | ||
889 | super::child_opt(self) | 908 | super::child_opt(self) |
890 | } | 909 | } |
891 | pub fn expr(self) -> Option<Expr<'a>> { | 910 | |
911 | pub fn expr(self) -> Option<Expr<'a>> { | ||
892 | super::child_opt(self) | 912 | super::child_opt(self) |
893 | } | 913 | } |
894 | } | 914 | } |
@@ -931,10 +951,12 @@ impl<'a> AstNode<'a> for MatchExpr<'a> { | |||
931 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 951 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } |
932 | } | 952 | } |
933 | 953 | ||
934 | impl<'a> MatchExpr<'a> {pub fn expr(self) -> Option<Expr<'a>> { | 954 | impl<'a> MatchExpr<'a> { |
955 | pub fn expr(self) -> Option<Expr<'a>> { | ||
935 | super::child_opt(self) | 956 | super::child_opt(self) |
936 | } | 957 | } |
937 | pub fn match_arm_list(self) -> Option<MatchArmList<'a>> { | 958 | |
959 | pub fn match_arm_list(self) -> Option<MatchArmList<'a>> { | ||
938 | super::child_opt(self) | 960 | super::child_opt(self) |
939 | } | 961 | } |
940 | } | 962 | } |
@@ -974,7 +996,8 @@ impl<'a> AstNode<'a> for MethodCallExpr<'a> { | |||
974 | } | 996 | } |
975 | 997 | ||
976 | impl<'a> ast::ArgListOwner<'a> for MethodCallExpr<'a> {} | 998 | impl<'a> ast::ArgListOwner<'a> for MethodCallExpr<'a> {} |
977 | impl<'a> MethodCallExpr<'a> {pub fn expr(self) -> Option<Expr<'a>> { | 999 | impl<'a> MethodCallExpr<'a> { |
1000 | pub fn expr(self) -> Option<Expr<'a>> { | ||
978 | super::child_opt(self) | 1001 | super::child_opt(self) |
979 | } | 1002 | } |
980 | } | 1003 | } |
@@ -997,7 +1020,8 @@ impl<'a> AstNode<'a> for Module<'a> { | |||
997 | 1020 | ||
998 | impl<'a> ast::NameOwner<'a> for Module<'a> {} | 1021 | impl<'a> ast::NameOwner<'a> for Module<'a> {} |
999 | impl<'a> ast::AttrsOwner<'a> for Module<'a> {} | 1022 | impl<'a> ast::AttrsOwner<'a> for Module<'a> {} |
1000 | impl<'a> Module<'a> {pub fn item_list(self) -> Option<ItemList<'a>> { | 1023 | impl<'a> Module<'a> { |
1024 | pub fn item_list(self) -> Option<ItemList<'a>> { | ||
1001 | super::child_opt(self) | 1025 | super::child_opt(self) |
1002 | } | 1026 | } |
1003 | } | 1027 | } |
@@ -1208,7 +1232,8 @@ impl<'a> AstNode<'a> for Param<'a> { | |||
1208 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 1232 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } |
1209 | } | 1233 | } |
1210 | 1234 | ||
1211 | impl<'a> Param<'a> {pub fn pat(self) -> Option<Pat<'a>> { | 1235 | impl<'a> Param<'a> { |
1236 | pub fn pat(self) -> Option<Pat<'a>> { | ||
1212 | super::child_opt(self) | 1237 | super::child_opt(self) |
1213 | } | 1238 | } |
1214 | } | 1239 | } |
@@ -1233,7 +1258,8 @@ impl<'a> ParamList<'a> { | |||
1233 | pub fn params(self) -> impl Iterator<Item = Param<'a>> + 'a { | 1258 | pub fn params(self) -> impl Iterator<Item = Param<'a>> + 'a { |
1234 | super::children(self) | 1259 | super::children(self) |
1235 | } | 1260 | } |
1236 | pub fn self_param(self) -> Option<SelfParam<'a>> { | 1261 | |
1262 | pub fn self_param(self) -> Option<SelfParam<'a>> { | ||
1237 | super::child_opt(self) | 1263 | super::child_opt(self) |
1238 | } | 1264 | } |
1239 | } | 1265 | } |
@@ -1339,7 +1365,8 @@ impl<'a> AstNode<'a> for Path<'a> { | |||
1339 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 1365 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } |
1340 | } | 1366 | } |
1341 | 1367 | ||
1342 | impl<'a> Path<'a> {pub fn segment(self) -> Option<PathSegment<'a>> { | 1368 | impl<'a> Path<'a> { |
1369 | pub fn segment(self) -> Option<PathSegment<'a>> { | ||
1343 | super::child_opt(self) | 1370 | super::child_opt(self) |
1344 | } | 1371 | } |
1345 | } | 1372 | } |
@@ -1396,7 +1423,8 @@ impl<'a> AstNode<'a> for PathSegment<'a> { | |||
1396 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 1423 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } |
1397 | } | 1424 | } |
1398 | 1425 | ||
1399 | impl<'a> PathSegment<'a> {pub fn name_ref(self) -> Option<NameRef<'a>> { | 1426 | impl<'a> PathSegment<'a> { |
1427 | pub fn name_ref(self) -> Option<NameRef<'a>> { | ||
1400 | super::child_opt(self) | 1428 | super::child_opt(self) |
1401 | } | 1429 | } |
1402 | } | 1430 | } |
@@ -2070,7 +2098,8 @@ impl<'a> AstNode<'a> for UseItem<'a> { | |||
2070 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 2098 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } |
2071 | } | 2099 | } |
2072 | 2100 | ||
2073 | impl<'a> UseItem<'a> {pub fn use_tree(self) -> Option<UseTree<'a>> { | 2101 | impl<'a> UseItem<'a> { |
2102 | pub fn use_tree(self) -> Option<UseTree<'a>> { | ||
2074 | super::child_opt(self) | 2103 | super::child_opt(self) |
2075 | } | 2104 | } |
2076 | } | 2105 | } |
@@ -2091,10 +2120,12 @@ impl<'a> AstNode<'a> for UseTree<'a> { | |||
2091 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 2120 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } |
2092 | } | 2121 | } |
2093 | 2122 | ||
2094 | impl<'a> UseTree<'a> {pub fn path(self) -> Option<Path<'a>> { | 2123 | impl<'a> UseTree<'a> { |
2124 | pub fn path(self) -> Option<Path<'a>> { | ||
2095 | super::child_opt(self) | 2125 | super::child_opt(self) |
2096 | } | 2126 | } |
2097 | pub fn use_tree_list(self) -> Option<UseTreeList<'a>> { | 2127 | |
2128 | pub fn use_tree_list(self) -> Option<UseTreeList<'a>> { | ||
2098 | super::child_opt(self) | 2129 | super::child_opt(self) |
2099 | } | 2130 | } |
2100 | } | 2131 | } |
@@ -2156,7 +2187,8 @@ impl<'a> AstNode<'a> for WhileExpr<'a> { | |||
2156 | } | 2187 | } |
2157 | 2188 | ||
2158 | impl<'a> ast::LoopBodyOwner<'a> for WhileExpr<'a> {} | 2189 | impl<'a> ast::LoopBodyOwner<'a> for WhileExpr<'a> {} |
2159 | impl<'a> WhileExpr<'a> {pub fn condition(self) -> Option<Condition<'a>> { | 2190 | impl<'a> WhileExpr<'a> { |
2191 | pub fn condition(self) -> Option<Condition<'a>> { | ||
2160 | super::child_opt(self) | 2192 | super::child_opt(self) |
2161 | } | 2193 | } |
2162 | } | 2194 | } |
diff --git a/crates/ra_syntax/src/ast/generated.rs.tera b/crates/ra_syntax/src/ast/generated.rs.tera index ceb2cd7e2..ffa9c4134 100644 --- a/crates/ra_syntax/src/ast/generated.rs.tera +++ b/crates/ra_syntax/src/ast/generated.rs.tera | |||
@@ -77,8 +77,7 @@ impl<'a> {{ node }}<'a> { | |||
77 | {%- else -%} | 77 | {%- else -%} |
78 | {%- set method_name = m.0 -%} | 78 | {%- set method_name = m.0 -%} |
79 | {%- set ChildName = m.1 %} | 79 | {%- set ChildName = m.1 %} |
80 | {%- endif -%} | 80 | {%- endif %} |
81 | |||
82 | pub fn {{ method_name }}(self) -> Option<{{ ChildName }}<'a>> { | 81 | pub fn {{ method_name }}(self) -> Option<{{ ChildName }}<'a>> { |
83 | super::child_opt(self) | 82 | super::child_opt(self) |
84 | } | 83 | } |
diff --git a/editors/code/src/highlighting.ts b/editors/code/src/highlighting.ts index ceddffe0e..d440e77c7 100644 --- a/editors/code/src/highlighting.ts +++ b/editors/code/src/highlighting.ts | |||
@@ -20,13 +20,6 @@ export class Highlighter { | |||
20 | [string, vscode.TextEditorDecorationType] | 20 | [string, vscode.TextEditorDecorationType] |
21 | > = [ | 21 | > = [ |
22 | ['background', decor('#3F3F3F')], | 22 | ['background', decor('#3F3F3F')], |
23 | [ | ||
24 | 'error', | ||
25 | vscode.window.createTextEditorDecorationType({ | ||
26 | borderColor: 'red', | ||
27 | borderStyle: 'none none dashed none' | ||
28 | }) | ||
29 | ], | ||
30 | ['comment', decor('#7F9F7F')], | 23 | ['comment', decor('#7F9F7F')], |
31 | ['string', decor('#CC9393')], | 24 | ['string', decor('#CC9393')], |
32 | ['keyword', decor('#F0DFAF')], | 25 | ['keyword', decor('#F0DFAF')], |