aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/ra_editor/src/lib.rs18
-rw-r--r--crates/ra_syntax/src/ast/generated.rs96
-rw-r--r--crates/ra_syntax/src/ast/generated.rs.tera3
-rw-r--r--editors/code/src/highlighting.ts7
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
110pub fn diagnostics(file: &File) -> Vec<Diagnostic> { 109pub 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
128pub fn syntax_tree(file: &File) -> String { 116pub 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
84impl<'a> Attr<'a> {pub fn value(self) -> Option<TokenTree<'a>> { 84impl<'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 }
146pub 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
167impl<'a> BlockExpr<'a> {pub fn block(self) -> Option<Block<'a>> { 169impl<'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
206impl<'a> ast::ArgListOwner<'a> for CallExpr<'a> {} 209impl<'a> ast::ArgListOwner<'a> for CallExpr<'a> {}
207impl<'a> CallExpr<'a> {pub fn expr(self) -> Option<Expr<'a>> { 210impl<'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
264impl<'a> Condition<'a> {pub fn pat(self) -> Option<Pat<'a>> { 268impl<'a> Condition<'a> {
269 pub fn pat(self) -> Option<Pat<'a>> {
265 super::child_opt(self) 270 super::child_opt(self)
266 } 271 }
267pub 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
481impl<'a> ExprStmt<'a> {pub fn expr(self) -> Option<Expr<'a>> { 487impl<'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> {
556impl<'a> ast::NameOwner<'a> for FnDef<'a> {} 563impl<'a> ast::NameOwner<'a> for FnDef<'a> {}
557impl<'a> ast::TypeParamsOwner<'a> for FnDef<'a> {} 564impl<'a> ast::TypeParamsOwner<'a> for FnDef<'a> {}
558impl<'a> ast::AttrsOwner<'a> for FnDef<'a> {} 565impl<'a> ast::AttrsOwner<'a> for FnDef<'a> {}
559impl<'a> FnDef<'a> {pub fn param_list(self) -> Option<ParamList<'a>> { 566impl<'a> FnDef<'a> {
567 pub fn param_list(self) -> Option<ParamList<'a>> {
560 super::child_opt(self) 568 super::child_opt(self)
561 } 569 }
562pub 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 }
565pub 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
604impl<'a> ast::LoopBodyOwner<'a> for ForExpr<'a> {} 614impl<'a> ast::LoopBodyOwner<'a> for ForExpr<'a> {}
605impl<'a> ForExpr<'a> {pub fn pat(self) -> Option<Pat<'a>> { 615impl<'a> ForExpr<'a> {
616 pub fn pat(self) -> Option<Pat<'a>> {
606 super::child_opt(self) 617 super::child_opt(self)
607 } 618 }
608pub 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
647impl<'a> IfExpr<'a> {pub fn condition(self) -> Option<Condition<'a>> { 659impl<'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
760impl<'a> LambdaExpr<'a> {pub fn param_list(self) -> Option<ParamList<'a>> { 773impl<'a> LambdaExpr<'a> {
774 pub fn param_list(self) -> Option<ParamList<'a>> {
761 super::child_opt(self) 775 super::child_opt(self)
762 } 776 }
763pub 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
784impl<'a> LetStmt<'a> {pub fn pat(self) -> Option<Pat<'a>> { 799impl<'a> LetStmt<'a> {
800 pub fn pat(self) -> Option<Pat<'a>> {
785 super::child_opt(self) 801 super::child_opt(self)
786 } 802 }
787pub 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
826impl<'a> LifetimeParam<'a> {pub fn lifetime(self) -> Option<Lifetime<'a>> { 843impl<'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 }
888pub 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 }
891pub 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
934impl<'a> MatchExpr<'a> {pub fn expr(self) -> Option<Expr<'a>> { 954impl<'a> MatchExpr<'a> {
955 pub fn expr(self) -> Option<Expr<'a>> {
935 super::child_opt(self) 956 super::child_opt(self)
936 } 957 }
937pub 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
976impl<'a> ast::ArgListOwner<'a> for MethodCallExpr<'a> {} 998impl<'a> ast::ArgListOwner<'a> for MethodCallExpr<'a> {}
977impl<'a> MethodCallExpr<'a> {pub fn expr(self) -> Option<Expr<'a>> { 999impl<'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
998impl<'a> ast::NameOwner<'a> for Module<'a> {} 1021impl<'a> ast::NameOwner<'a> for Module<'a> {}
999impl<'a> ast::AttrsOwner<'a> for Module<'a> {} 1022impl<'a> ast::AttrsOwner<'a> for Module<'a> {}
1000impl<'a> Module<'a> {pub fn item_list(self) -> Option<ItemList<'a>> { 1023impl<'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
1211impl<'a> Param<'a> {pub fn pat(self) -> Option<Pat<'a>> { 1235impl<'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 }
1236pub 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
1342impl<'a> Path<'a> {pub fn segment(self) -> Option<PathSegment<'a>> { 1368impl<'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
1399impl<'a> PathSegment<'a> {pub fn name_ref(self) -> Option<NameRef<'a>> { 1426impl<'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
2073impl<'a> UseItem<'a> {pub fn use_tree(self) -> Option<UseTree<'a>> { 2101impl<'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
2094impl<'a> UseTree<'a> {pub fn path(self) -> Option<Path<'a>> { 2123impl<'a> UseTree<'a> {
2124 pub fn path(self) -> Option<Path<'a>> {
2095 super::child_opt(self) 2125 super::child_opt(self)
2096 } 2126 }
2097pub 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
2158impl<'a> ast::LoopBodyOwner<'a> for WhileExpr<'a> {} 2189impl<'a> ast::LoopBodyOwner<'a> for WhileExpr<'a> {}
2159impl<'a> WhileExpr<'a> {pub fn condition(self) -> Option<Condition<'a>> { 2190impl<'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')],