diff options
20 files changed, 412 insertions, 1320 deletions
diff --git a/crates/assists/src/handlers/invert_if.rs b/crates/assists/src/handlers/invert_if.rs index 91e2f5c8c..f9c33b3f7 100644 --- a/crates/assists/src/handlers/invert_if.rs +++ b/crates/assists/src/handlers/invert_if.rs | |||
@@ -78,6 +78,15 @@ mod tests { | |||
78 | } | 78 | } |
79 | 79 | ||
80 | #[test] | 80 | #[test] |
81 | fn invert_if_remove_not_parentheses() { | ||
82 | check_assist( | ||
83 | invert_if, | ||
84 | "fn f() { i<|>f !(x == 3 || x == 4 || x == 5) { 3 * 2 } else { 1 } }", | ||
85 | "fn f() { if x == 3 || x == 4 || x == 5 { 1 } else { 3 * 2 } }", | ||
86 | ) | ||
87 | } | ||
88 | |||
89 | #[test] | ||
81 | fn invert_if_remove_inequality() { | 90 | fn invert_if_remove_inequality() { |
82 | check_assist( | 91 | check_assist( |
83 | invert_if, | 92 | invert_if, |
diff --git a/crates/assists/src/handlers/remove_unused_param.rs b/crates/assists/src/handlers/remove_unused_param.rs index 1ff5e92b0..f72dd49ed 100644 --- a/crates/assists/src/handlers/remove_unused_param.rs +++ b/crates/assists/src/handlers/remove_unused_param.rs | |||
@@ -2,9 +2,10 @@ use ide_db::{defs::Definition, search::Reference}; | |||
2 | use syntax::{ | 2 | use syntax::{ |
3 | algo::find_node_at_range, | 3 | algo::find_node_at_range, |
4 | ast::{self, ArgListOwner}, | 4 | ast::{self, ArgListOwner}, |
5 | AstNode, SyntaxNode, TextRange, T, | 5 | AstNode, SyntaxKind, SyntaxNode, TextRange, T, |
6 | }; | 6 | }; |
7 | use test_utils::mark; | 7 | use test_utils::mark; |
8 | use SyntaxKind::WHITESPACE; | ||
8 | 9 | ||
9 | use crate::{ | 10 | use crate::{ |
10 | assist_context::AssistBuilder, utils::next_prev, AssistContext, AssistId, AssistKind, Assists, | 11 | assist_context::AssistBuilder, utils::next_prev, AssistContext, AssistId, AssistKind, Assists, |
@@ -56,7 +57,7 @@ pub(crate) fn remove_unused_param(acc: &mut Assists, ctx: &AssistContext) -> Opt | |||
56 | "Remove unused parameter", | 57 | "Remove unused parameter", |
57 | param.syntax().text_range(), | 58 | param.syntax().text_range(), |
58 | |builder| { | 59 | |builder| { |
59 | builder.delete(range_with_coma(param.syntax())); | 60 | builder.delete(range_to_remove(param.syntax())); |
60 | for usage in fn_def.usages(&ctx.sema).all() { | 61 | for usage in fn_def.usages(&ctx.sema).all() { |
61 | process_usage(ctx, builder, usage, param_position); | 62 | process_usage(ctx, builder, usage, param_position); |
62 | } | 63 | } |
@@ -80,19 +81,34 @@ fn process_usage( | |||
80 | let arg = call_expr.arg_list()?.args().nth(arg_to_remove)?; | 81 | let arg = call_expr.arg_list()?.args().nth(arg_to_remove)?; |
81 | 82 | ||
82 | builder.edit_file(usage.file_range.file_id); | 83 | builder.edit_file(usage.file_range.file_id); |
83 | builder.delete(range_with_coma(arg.syntax())); | 84 | builder.delete(range_to_remove(arg.syntax())); |
84 | 85 | ||
85 | Some(()) | 86 | Some(()) |
86 | } | 87 | } |
87 | 88 | ||
88 | fn range_with_coma(node: &SyntaxNode) -> TextRange { | 89 | fn range_to_remove(node: &SyntaxNode) -> TextRange { |
89 | let up_to = next_prev().find_map(|dir| { | 90 | let up_to_comma = next_prev().find_map(|dir| { |
90 | node.siblings_with_tokens(dir) | 91 | node.siblings_with_tokens(dir) |
91 | .filter_map(|it| it.into_token()) | 92 | .filter_map(|it| it.into_token()) |
92 | .find(|it| it.kind() == T![,]) | 93 | .find(|it| it.kind() == T![,]) |
94 | .map(|it| (dir, it)) | ||
93 | }); | 95 | }); |
94 | let up_to = up_to.map_or(node.text_range(), |it| it.text_range()); | 96 | if let Some((dir, token)) = up_to_comma { |
95 | node.text_range().cover(up_to) | 97 | if node.next_sibling().is_some() { |
98 | let up_to_space = token | ||
99 | .siblings_with_tokens(dir) | ||
100 | .skip(1) | ||
101 | .take_while(|it| it.kind() == WHITESPACE) | ||
102 | .last() | ||
103 | .and_then(|it| it.into_token()); | ||
104 | return node | ||
105 | .text_range() | ||
106 | .cover(up_to_space.map_or(token.text_range(), |it| it.text_range())); | ||
107 | } | ||
108 | node.text_range().cover(token.text_range()) | ||
109 | } else { | ||
110 | node.text_range() | ||
111 | } | ||
96 | } | 112 | } |
97 | 113 | ||
98 | #[cfg(test)] | 114 | #[cfg(test)] |
@@ -119,6 +135,57 @@ fn b() { foo(9, ) } | |||
119 | } | 135 | } |
120 | 136 | ||
121 | #[test] | 137 | #[test] |
138 | fn remove_unused_first_param() { | ||
139 | check_assist( | ||
140 | remove_unused_param, | ||
141 | r#" | ||
142 | fn foo(<|>x: i32, y: i32) { y; } | ||
143 | fn a() { foo(1, 2) } | ||
144 | fn b() { foo(1, 2,) } | ||
145 | "#, | ||
146 | r#" | ||
147 | fn foo(y: i32) { y; } | ||
148 | fn a() { foo(2) } | ||
149 | fn b() { foo(2,) } | ||
150 | "#, | ||
151 | ); | ||
152 | } | ||
153 | |||
154 | #[test] | ||
155 | fn remove_unused_single_param() { | ||
156 | check_assist( | ||
157 | remove_unused_param, | ||
158 | r#" | ||
159 | fn foo(<|>x: i32) { 0; } | ||
160 | fn a() { foo(1) } | ||
161 | fn b() { foo(1, ) } | ||
162 | "#, | ||
163 | r#" | ||
164 | fn foo() { 0; } | ||
165 | fn a() { foo() } | ||
166 | fn b() { foo( ) } | ||
167 | "#, | ||
168 | ); | ||
169 | } | ||
170 | |||
171 | #[test] | ||
172 | fn remove_unused_surrounded_by_parms() { | ||
173 | check_assist( | ||
174 | remove_unused_param, | ||
175 | r#" | ||
176 | fn foo(x: i32, <|>y: i32, z: i32) { x; } | ||
177 | fn a() { foo(1, 2, 3) } | ||
178 | fn b() { foo(1, 2, 3,) } | ||
179 | "#, | ||
180 | r#" | ||
181 | fn foo(x: i32, z: i32) { x; } | ||
182 | fn a() { foo(1, 3) } | ||
183 | fn b() { foo(1, 3,) } | ||
184 | "#, | ||
185 | ); | ||
186 | } | ||
187 | |||
188 | #[test] | ||
122 | fn remove_unused_qualified_call() { | 189 | fn remove_unused_qualified_call() { |
123 | check_assist( | 190 | check_assist( |
124 | remove_unused_param, | 191 | remove_unused_param, |
diff --git a/crates/assists/src/utils.rs b/crates/assists/src/utils.rs index f2cacf7c8..d41084b59 100644 --- a/crates/assists/src/utils.rs +++ b/crates/assists/src/utils.rs | |||
@@ -232,7 +232,13 @@ fn invert_special_case(expr: &ast::Expr) -> Option<ast::Expr> { | |||
232 | }; | 232 | }; |
233 | Some(make::expr_method_call(receiver, method, arg_list)) | 233 | Some(make::expr_method_call(receiver, method, arg_list)) |
234 | } | 234 | } |
235 | ast::Expr::PrefixExpr(pe) if pe.op_kind()? == ast::PrefixOp::Not => pe.expr(), | 235 | ast::Expr::PrefixExpr(pe) if pe.op_kind()? == ast::PrefixOp::Not => { |
236 | if let ast::Expr::ParenExpr(parexpr) = pe.expr()? { | ||
237 | parexpr.expr() | ||
238 | } else { | ||
239 | pe.expr() | ||
240 | } | ||
241 | } | ||
236 | // FIXME: | 242 | // FIXME: |
237 | // ast::Expr::Literal(true | false ) | 243 | // ast::Expr::Literal(true | false ) |
238 | _ => None, | 244 | _ => None, |
diff --git a/crates/ide/src/references.rs b/crates/ide/src/references.rs index 18ea19305..33b7358f7 100644 --- a/crates/ide/src/references.rs +++ b/crates/ide/src/references.rs | |||
@@ -147,20 +147,20 @@ fn find_name( | |||
147 | ) -> Option<RangeInfo<Definition>> { | 147 | ) -> Option<RangeInfo<Definition>> { |
148 | if let Some(name) = opt_name { | 148 | if let Some(name) = opt_name { |
149 | let def = NameClass::classify(sema, &name)?.referenced_or_defined(sema.db); | 149 | let def = NameClass::classify(sema, &name)?.referenced_or_defined(sema.db); |
150 | let range = name.syntax().text_range(); | 150 | let FileRange { range, .. } = sema.original_range(name.syntax()); |
151 | return Some(RangeInfo::new(range, def)); | 151 | return Some(RangeInfo::new(range, def)); |
152 | } | 152 | } |
153 | 153 | ||
154 | let (text_range, def) = if let Some(lifetime) = | 154 | let (FileRange { range, .. }, def) = if let Some(lifetime) = |
155 | sema.find_node_at_offset_with_descend::<ast::Lifetime>(&syntax, position.offset) | 155 | sema.find_node_at_offset_with_descend::<ast::Lifetime>(&syntax, position.offset) |
156 | { | 156 | { |
157 | if let Some(def) = NameRefClass::classify_lifetime(sema, &lifetime) | 157 | if let Some(def) = NameRefClass::classify_lifetime(sema, &lifetime) |
158 | .map(|class| NameRefClass::referenced(class, sema.db)) | 158 | .map(|class| NameRefClass::referenced(class, sema.db)) |
159 | { | 159 | { |
160 | (lifetime.syntax().text_range(), def) | 160 | (sema.original_range(lifetime.syntax()), def) |
161 | } else { | 161 | } else { |
162 | ( | 162 | ( |
163 | lifetime.syntax().text_range(), | 163 | sema.original_range(lifetime.syntax()), |
164 | NameClass::classify_lifetime(sema, &lifetime)?.referenced_or_defined(sema.db), | 164 | NameClass::classify_lifetime(sema, &lifetime)?.referenced_or_defined(sema.db), |
165 | ) | 165 | ) |
166 | } | 166 | } |
@@ -168,11 +168,11 @@ fn find_name( | |||
168 | let name_ref = | 168 | let name_ref = |
169 | sema.find_node_at_offset_with_descend::<ast::NameRef>(&syntax, position.offset)?; | 169 | sema.find_node_at_offset_with_descend::<ast::NameRef>(&syntax, position.offset)?; |
170 | ( | 170 | ( |
171 | name_ref.syntax().text_range(), | 171 | sema.original_range(name_ref.syntax()), |
172 | NameRefClass::classify(sema, &name_ref)?.referenced(sema.db), | 172 | NameRefClass::classify(sema, &name_ref)?.referenced(sema.db), |
173 | ) | 173 | ) |
174 | }; | 174 | }; |
175 | Some(RangeInfo::new(text_range, def)) | 175 | Some(RangeInfo::new(range, def)) |
176 | } | 176 | } |
177 | 177 | ||
178 | fn decl_access(def: &Definition, syntax: &SyntaxNode, range: TextRange) -> Option<ReferenceAccess> { | 178 | fn decl_access(def: &Definition, syntax: &SyntaxNode, range: TextRange) -> Option<ReferenceAccess> { |
@@ -1086,4 +1086,40 @@ impl<'a> Foo<'a> for &'a () { | |||
1086 | "#]], | 1086 | "#]], |
1087 | ); | 1087 | ); |
1088 | } | 1088 | } |
1089 | |||
1090 | #[test] | ||
1091 | fn test_map_range_to_original() { | ||
1092 | check( | ||
1093 | r#" | ||
1094 | macro_rules! foo {($i:ident) => {$i} } | ||
1095 | fn main() { | ||
1096 | let a<|> = "test"; | ||
1097 | foo!(a); | ||
1098 | } | ||
1099 | "#, | ||
1100 | expect![[r#" | ||
1101 | a Local FileId(0) 59..60 Other | ||
1102 | |||
1103 | FileId(0) 80..81 Other Read | ||
1104 | "#]], | ||
1105 | ); | ||
1106 | } | ||
1107 | |||
1108 | #[test] | ||
1109 | fn test_map_range_to_original_ref() { | ||
1110 | check( | ||
1111 | r#" | ||
1112 | macro_rules! foo {($i:ident) => {$i} } | ||
1113 | fn main() { | ||
1114 | let a = "test"; | ||
1115 | foo!(a<|>); | ||
1116 | } | ||
1117 | "#, | ||
1118 | expect![[r#" | ||
1119 | a Local FileId(0) 59..60 Other | ||
1120 | |||
1121 | FileId(0) 80..81 Other Read | ||
1122 | "#]], | ||
1123 | ); | ||
1124 | } | ||
1089 | } | 1125 | } |
diff --git a/crates/parser/src/grammar/expressions/atom.rs b/crates/parser/src/grammar/expressions/atom.rs index 18b63feb7..e897d5a52 100644 --- a/crates/parser/src/grammar/expressions/atom.rs +++ b/crates/parser/src/grammar/expressions/atom.rs | |||
@@ -156,11 +156,13 @@ fn tuple_expr(p: &mut Parser) -> CompletedMarker { | |||
156 | let mut saw_expr = false; | 156 | let mut saw_expr = false; |
157 | while !p.at(EOF) && !p.at(T![')']) { | 157 | while !p.at(EOF) && !p.at(T![')']) { |
158 | saw_expr = true; | 158 | saw_expr = true; |
159 | if !p.at_ts(EXPR_FIRST) { | 159 | |
160 | p.error("expected expression"); | 160 | // test tuple_attrs |
161 | // const A: (i64, i64) = (1, #[cfg(test)] 2); | ||
162 | if !expr_with_attrs(p) { | ||
161 | break; | 163 | break; |
162 | } | 164 | } |
163 | expr(p); | 165 | |
164 | if !p.at(T![')']) { | 166 | if !p.at(T![')']) { |
165 | saw_comma = true; | 167 | saw_comma = true; |
166 | p.expect(T![,]); | 168 | p.expect(T![,]); |
diff --git a/crates/parser/src/grammar/params.rs b/crates/parser/src/grammar/params.rs index 3ee4e4fca..2d006a1d5 100644 --- a/crates/parser/src/grammar/params.rs +++ b/crates/parser/src/grammar/params.rs | |||
@@ -47,20 +47,23 @@ fn list_(p: &mut Parser, flavor: Flavor) { | |||
47 | if let FnDef = flavor { | 47 | if let FnDef = flavor { |
48 | // test self_param_outer_attr | 48 | // test self_param_outer_attr |
49 | // fn f(#[must_use] self) {} | 49 | // fn f(#[must_use] self) {} |
50 | let m = p.start(); | ||
50 | attributes::outer_attrs(p); | 51 | attributes::outer_attrs(p); |
51 | opt_self_param(p); | 52 | opt_self_param(p, m); |
52 | } | 53 | } |
53 | 54 | ||
54 | while !p.at(EOF) && !p.at(ket) { | 55 | while !p.at(EOF) && !p.at(ket) { |
55 | // test param_outer_arg | 56 | // test param_outer_arg |
56 | // fn f(#[attr1] pat: Type) {} | 57 | // fn f(#[attr1] pat: Type) {} |
58 | let m = p.start(); | ||
57 | attributes::outer_attrs(p); | 59 | attributes::outer_attrs(p); |
58 | 60 | ||
59 | if !p.at_ts(PARAM_FIRST) { | 61 | if !p.at_ts(PARAM_FIRST) { |
60 | p.error("expected value parameter"); | 62 | p.error("expected value parameter"); |
63 | m.abandon(p); | ||
61 | break; | 64 | break; |
62 | } | 65 | } |
63 | let param = param(p, flavor); | 66 | let param = param(p, m, flavor); |
64 | if !p.at(ket) { | 67 | if !p.at(ket) { |
65 | p.expect(T![,]); | 68 | p.expect(T![,]); |
66 | } | 69 | } |
@@ -77,9 +80,8 @@ const PARAM_FIRST: TokenSet = patterns::PATTERN_FIRST.union(types::TYPE_FIRST); | |||
77 | 80 | ||
78 | struct Variadic(bool); | 81 | struct Variadic(bool); |
79 | 82 | ||
80 | fn param(p: &mut Parser, flavor: Flavor) -> Variadic { | 83 | fn param(p: &mut Parser, m: Marker, flavor: Flavor) -> Variadic { |
81 | let mut res = Variadic(false); | 84 | let mut res = Variadic(false); |
82 | let m = p.start(); | ||
83 | match flavor { | 85 | match flavor { |
84 | // test param_list_vararg | 86 | // test param_list_vararg |
85 | // extern "C" { fn printf(format: *const i8, ...) -> i32; } | 87 | // extern "C" { fn printf(format: *const i8, ...) -> i32; } |
@@ -151,10 +153,8 @@ fn variadic_param(p: &mut Parser) -> bool { | |||
151 | // fn d(&'a mut self, x: i32) {} | 153 | // fn d(&'a mut self, x: i32) {} |
152 | // fn e(mut self) {} | 154 | // fn e(mut self) {} |
153 | // } | 155 | // } |
154 | fn opt_self_param(p: &mut Parser) { | 156 | fn opt_self_param(p: &mut Parser, m: Marker) { |
155 | let m; | ||
156 | if p.at(T![self]) || p.at(T![mut]) && p.nth(1) == T![self] { | 157 | if p.at(T![self]) || p.at(T![mut]) && p.nth(1) == T![self] { |
157 | m = p.start(); | ||
158 | p.eat(T![mut]); | 158 | p.eat(T![mut]); |
159 | p.eat(T![self]); | 159 | p.eat(T![self]); |
160 | // test arb_self_types | 160 | // test arb_self_types |
@@ -174,9 +174,8 @@ fn opt_self_param(p: &mut Parser) { | |||
174 | (T![&], T![mut], T![self], _) => 3, | 174 | (T![&], T![mut], T![self], _) => 3, |
175 | (T![&], LIFETIME_IDENT, T![self], _) => 3, | 175 | (T![&], LIFETIME_IDENT, T![self], _) => 3, |
176 | (T![&], LIFETIME_IDENT, T![mut], T![self]) => 4, | 176 | (T![&], LIFETIME_IDENT, T![mut], T![self]) => 4, |
177 | _ => return, | 177 | _ => return m.abandon(p), |
178 | }; | 178 | }; |
179 | m = p.start(); | ||
180 | p.bump_any(); | 179 | p.bump_any(); |
181 | if p.at(LIFETIME_IDENT) { | 180 | if p.at(LIFETIME_IDENT) { |
182 | lifetime(p); | 181 | lifetime(p); |
diff --git a/crates/parser/src/grammar/type_params.rs b/crates/parser/src/grammar/type_params.rs index 9c3f7c28a..4aeccd193 100644 --- a/crates/parser/src/grammar/type_params.rs +++ b/crates/parser/src/grammar/type_params.rs | |||
@@ -113,7 +113,7 @@ fn type_bound(p: &mut Parser) -> bool { | |||
113 | p.eat(T![?]); | 113 | p.eat(T![?]); |
114 | match p.current() { | 114 | match p.current() { |
115 | LIFETIME_IDENT => lifetime(p), | 115 | LIFETIME_IDENT => lifetime(p), |
116 | T![for] => types::for_type(p), | 116 | T![for] => types::for_type(p, false), |
117 | _ if paths::is_use_path_start(p) => types::path_type_(p, false), | 117 | _ if paths::is_use_path_start(p) => types::path_type_(p, false), |
118 | _ => { | 118 | _ => { |
119 | m.abandon(p); | 119 | m.abandon(p); |
diff --git a/crates/parser/src/grammar/types.rs b/crates/parser/src/grammar/types.rs index 36a15eace..94cbf7d85 100644 --- a/crates/parser/src/grammar/types.rs +++ b/crates/parser/src/grammar/types.rs | |||
@@ -44,7 +44,7 @@ fn type_with_bounds_cond(p: &mut Parser, allow_bounds: bool) { | |||
44 | T![&] => ref_type(p), | 44 | T![&] => ref_type(p), |
45 | T![_] => infer_type(p), | 45 | T![_] => infer_type(p), |
46 | T![fn] | T![unsafe] | T![extern] => fn_ptr_type(p), | 46 | T![fn] | T![unsafe] | T![extern] => fn_ptr_type(p), |
47 | T![for] => for_type(p), | 47 | T![for] => for_type(p, allow_bounds), |
48 | T![impl] => impl_trait_type(p), | 48 | T![impl] => impl_trait_type(p), |
49 | T![dyn] => dyn_trait_type(p), | 49 | T![dyn] => dyn_trait_type(p), |
50 | // Some path types are not allowed to have bounds (no plus) | 50 | // Some path types are not allowed to have bounds (no plus) |
@@ -227,7 +227,7 @@ pub(super) fn for_binder(p: &mut Parser) { | |||
227 | // type A = for<'a> fn() -> (); | 227 | // type A = for<'a> fn() -> (); |
228 | // type B = for<'a> unsafe extern "C" fn(&'a ()) -> (); | 228 | // type B = for<'a> unsafe extern "C" fn(&'a ()) -> (); |
229 | // type Obj = for<'a> PartialEq<&'a i32>; | 229 | // type Obj = for<'a> PartialEq<&'a i32>; |
230 | pub(super) fn for_type(p: &mut Parser) { | 230 | pub(super) fn for_type(p: &mut Parser, allow_bounds: bool) { |
231 | assert!(p.at(T![for])); | 231 | assert!(p.at(T![for])); |
232 | let m = p.start(); | 232 | let m = p.start(); |
233 | for_binder(p); | 233 | for_binder(p); |
@@ -240,7 +240,13 @@ pub(super) fn for_type(p: &mut Parser) { | |||
240 | } | 240 | } |
241 | } | 241 | } |
242 | type_no_bounds(p); | 242 | type_no_bounds(p); |
243 | m.complete(p, FOR_TYPE); | 243 | let completed = m.complete(p, FOR_TYPE); |
244 | |||
245 | // test no_dyn_trait_leading_for | ||
246 | // type A = for<'a> Test<'a> + Send; | ||
247 | if allow_bounds { | ||
248 | opt_type_bounds_as_dyn_trait_type(p, completed); | ||
249 | } | ||
244 | } | 250 | } |
245 | 251 | ||
246 | // test impl_trait_type | 252 | // test impl_trait_type |
@@ -290,7 +296,7 @@ fn path_or_macro_type_(p: &mut Parser, allow_bounds: bool) { | |||
290 | let path = m.complete(p, kind); | 296 | let path = m.complete(p, kind); |
291 | 297 | ||
292 | if allow_bounds { | 298 | if allow_bounds { |
293 | opt_path_type_bounds_as_dyn_trait_type(p, path); | 299 | opt_type_bounds_as_dyn_trait_type(p, path); |
294 | } | 300 | } |
295 | } | 301 | } |
296 | 302 | ||
@@ -304,19 +310,23 @@ pub(super) fn path_type_(p: &mut Parser, allow_bounds: bool) { | |||
304 | // fn foo() -> Box<dyn T + 'f> {} | 310 | // fn foo() -> Box<dyn T + 'f> {} |
305 | let path = m.complete(p, PATH_TYPE); | 311 | let path = m.complete(p, PATH_TYPE); |
306 | if allow_bounds { | 312 | if allow_bounds { |
307 | opt_path_type_bounds_as_dyn_trait_type(p, path); | 313 | opt_type_bounds_as_dyn_trait_type(p, path); |
308 | } | 314 | } |
309 | } | 315 | } |
310 | 316 | ||
311 | /// This turns a parsed PATH_TYPE optionally into a DYN_TRAIT_TYPE | 317 | /// This turns a parsed PATH_TYPE or FOR_TYPE optionally into a DYN_TRAIT_TYPE |
312 | /// with a TYPE_BOUND_LIST | 318 | /// with a TYPE_BOUND_LIST |
313 | fn opt_path_type_bounds_as_dyn_trait_type(p: &mut Parser, path_type_marker: CompletedMarker) { | 319 | fn opt_type_bounds_as_dyn_trait_type(p: &mut Parser, type_marker: CompletedMarker) { |
320 | assert!(matches!( | ||
321 | type_marker.kind(), | ||
322 | SyntaxKind::PATH_TYPE | SyntaxKind::FOR_TYPE | SyntaxKind::MACRO_CALL | ||
323 | )); | ||
314 | if !p.at(T![+]) { | 324 | if !p.at(T![+]) { |
315 | return; | 325 | return; |
316 | } | 326 | } |
317 | 327 | ||
318 | // First create a TYPE_BOUND from the completed PATH_TYPE | 328 | // First create a TYPE_BOUND from the completed PATH_TYPE |
319 | let m = path_type_marker.precede(p).complete(p, TYPE_BOUND); | 329 | let m = type_marker.precede(p).complete(p, TYPE_BOUND); |
320 | 330 | ||
321 | // Next setup a marker for the TYPE_BOUND_LIST | 331 | // Next setup a marker for the TYPE_BOUND_LIST |
322 | let m = m.precede(p); | 332 | let m = m.precede(p); |
diff --git a/crates/rust-analyzer/src/diagnostics/to_proto.rs b/crates/rust-analyzer/src/diagnostics/to_proto.rs index f16f97131..540759198 100644 --- a/crates/rust-analyzer/src/diagnostics/to_proto.rs +++ b/crates/rust-analyzer/src/diagnostics/to_proto.rs | |||
@@ -319,6 +319,10 @@ pub(crate) fn map_rust_diagnostic_to_lsp( | |||
319 | message: "original diagnostic".to_string(), | 319 | message: "original diagnostic".to_string(), |
320 | }; | 320 | }; |
321 | for info in &related_information { | 321 | for info in &related_information { |
322 | // Filter out empty/non-existent messages, as they greatly confuse VS Code. | ||
323 | if info.message.is_empty() { | ||
324 | continue; | ||
325 | } | ||
322 | diagnostics.push(MappedRustDiagnostic { | 326 | diagnostics.push(MappedRustDiagnostic { |
323 | url: info.location.uri.clone(), | 327 | url: info.location.uri.clone(), |
324 | fixes: fixes.clone(), // share fixes to make them easier to apply | 328 | fixes: fixes.clone(), // share fixes to make them easier to apply |
diff --git a/crates/syntax/test_data/parser/inline/ok/0138_self_param_outer_attr.rast b/crates/syntax/test_data/parser/inline/ok/0138_self_param_outer_attr.rast index 6403ff8d5..d3219f0b2 100644 --- a/crates/syntax/test_data/parser/inline/ok/0138_self_param_outer_attr.rast +++ b/crates/syntax/test_data/parser/inline/ok/0138_self_param_outer_attr.rast | |||
@@ -6,16 +6,16 @@ [email protected] | |||
6 | [email protected] "f" | 6 | [email protected] "f" |
7 | [email protected] | 7 | [email protected] |
8 | [email protected] "(" | 8 | [email protected] "(" |
9 | ATT[email protected]6 | 9 | SELF_PARAM@5..21 |
10 | POUND@5..6 "#" | 10 | ATTR@5..16 |
11 | L_BRACK@6..7 "[" | 11 | POUND@5..6 "#" |
12 | PATH@7..15 | 12 | L_BRACK@6..7 "[" |
13 | PATH_SEGMENT@7..15 | 13 | [email protected] |
14 | NAME_REF@7..15 | 14 | PATH_SEGMENT@7..15 |
15 | IDENT@7..15 "must_use" | 15 | NAME_REF@7..15 |
16 | R_BRACK@15..16 "]" | 16 | IDENT@7..15 "must_use" |
17 | WHITESPACE@16..17 " " | 17 | R_BRACK@15..16 "]" |
18 | SELF_PARAM@17..21 | 18 | WHITESPACE@16..17 " " |
19 | [email protected] "self" | 19 | [email protected] "self" |
20 | [email protected] ")" | 20 | [email protected] ")" |
21 | [email protected] " " | 21 | [email protected] " " |
diff --git a/crates/syntax/test_data/parser/inline/ok/0154_no_dyn_trait_leading_for.rast b/crates/syntax/test_data/parser/inline/ok/0154_no_dyn_trait_leading_for.rast new file mode 100644 index 000000000..edfcb288c --- /dev/null +++ b/crates/syntax/test_data/parser/inline/ok/0154_no_dyn_trait_leading_for.rast | |||
@@ -0,0 +1,43 @@ | |||
1 | [email protected] | ||
2 | [email protected] | ||
3 | [email protected] "type" | ||
4 | [email protected] " " | ||
5 | [email protected] | ||
6 | [email protected] "A" | ||
7 | [email protected] " " | ||
8 | [email protected] "=" | ||
9 | [email protected] " " | ||
10 | [email protected] | ||
11 | [email protected] | ||
12 | [email protected] | ||
13 | [email protected] | ||
14 | [email protected] "for" | ||
15 | [email protected] | ||
16 | [email protected] "<" | ||
17 | [email protected] | ||
18 | [email protected] | ||
19 | [email protected] "\'a" | ||
20 | [email protected] ">" | ||
21 | [email protected] " " | ||
22 | [email protected] | ||
23 | [email protected] | ||
24 | [email protected] | ||
25 | [email protected] | ||
26 | [email protected] "Test" | ||
27 | [email protected] | ||
28 | [email protected] "<" | ||
29 | [email protected] | ||
30 | [email protected] | ||
31 | [email protected] "\'a" | ||
32 | [email protected] ">" | ||
33 | [email protected] " " | ||
34 | [email protected] "+" | ||
35 | [email protected] " " | ||
36 | [email protected] | ||
37 | [email protected] | ||
38 | [email protected] | ||
39 | [email protected] | ||
40 | [email protected] | ||
41 | [email protected] "Send" | ||
42 | [email protected] ";" | ||
43 | [email protected] "\n" | ||
diff --git a/crates/syntax/test_data/parser/inline/ok/0154_no_dyn_trait_leading_for.rs b/crates/syntax/test_data/parser/inline/ok/0154_no_dyn_trait_leading_for.rs new file mode 100644 index 000000000..47a71fd19 --- /dev/null +++ b/crates/syntax/test_data/parser/inline/ok/0154_no_dyn_trait_leading_for.rs | |||
@@ -0,0 +1 @@ | |||
type A = for<'a> Test<'a> + Send; | |||
diff --git a/crates/syntax/test_data/parser/inline/ok/0154_tuple_attrs.rast b/crates/syntax/test_data/parser/inline/ok/0154_tuple_attrs.rast new file mode 100644 index 000000000..d34b21abe --- /dev/null +++ b/crates/syntax/test_data/parser/inline/ok/0154_tuple_attrs.rast | |||
@@ -0,0 +1,50 @@ | |||
1 | [email protected] | ||
2 | [email protected] | ||
3 | [email protected] "const" | ||
4 | [email protected] " " | ||
5 | [email protected] | ||
6 | [email protected] "A" | ||
7 | [email protected] ":" | ||
8 | [email protected] " " | ||
9 | [email protected] | ||
10 | [email protected] "(" | ||
11 | [email protected] | ||
12 | [email protected] | ||
13 | [email protected] | ||
14 | [email protected] | ||
15 | [email protected] "i64" | ||
16 | [email protected] "," | ||
17 | [email protected] " " | ||
18 | [email protected] | ||
19 | [email protected] | ||
20 | [email protected] | ||
21 | [email protected] | ||
22 | [email protected] "i64" | ||
23 | [email protected] ")" | ||
24 | [email protected] " " | ||
25 | [email protected] "=" | ||
26 | [email protected] " " | ||
27 | [email protected] | ||
28 | [email protected] "(" | ||
29 | [email protected] | ||
30 | [email protected] "1" | ||
31 | [email protected] "," | ||
32 | [email protected] " " | ||
33 | [email protected] | ||
34 | [email protected] | ||
35 | [email protected] "#" | ||
36 | [email protected] "[" | ||
37 | [email protected] | ||
38 | [email protected] | ||
39 | [email protected] | ||
40 | [email protected] "cfg" | ||
41 | [email protected] | ||
42 | [email protected] "(" | ||
43 | [email protected] "test" | ||
44 | [email protected] ")" | ||
45 | [email protected] "]" | ||
46 | [email protected] " " | ||
47 | [email protected] "2" | ||
48 | [email protected] ")" | ||
49 | [email protected] ";" | ||
50 | [email protected] "\n" | ||
diff --git a/crates/syntax/test_data/parser/inline/ok/0154_tuple_attrs.rs b/crates/syntax/test_data/parser/inline/ok/0154_tuple_attrs.rs new file mode 100644 index 000000000..f84b7ab31 --- /dev/null +++ b/crates/syntax/test_data/parser/inline/ok/0154_tuple_attrs.rs | |||
@@ -0,0 +1 @@ | |||
const A: (i64, i64) = (1, #[cfg(test)] 2); | |||
diff --git a/crates/syntax/test_data/parser/ok/0051_parameter_attrs.rast b/crates/syntax/test_data/parser/ok/0051_parameter_attrs.rast index 8974f9e40..3fed11838 100644 --- a/crates/syntax/test_data/parser/ok/0051_parameter_attrs.rast +++ b/crates/syntax/test_data/parser/ok/0051_parameter_attrs.rast | |||
@@ -107,16 +107,16 @@ [email protected] | |||
107 | [email protected] "i8" | 107 | [email protected] "i8" |
108 | [email protected] "," | 108 | [email protected] "," |
109 | [email protected] " " | 109 | [email protected] " " |
110 | ATT[email protected]3 | 110 | PARAM@106..117 |
111 | POUND@106..107 "#" | 111 | ATTR@106..113 |
112 | L_BRACK@107..108 "[" | 112 | POUND@106..107 "#" |
113 | PATH@108..112 | 113 | L_BRACK@107..108 "[" |
114 | PATH_SEGMENT@108..112 | 114 | [email protected] |
115 | NAME_REF@108..112 | 115 | PATH_SEGMENT@108..112 |
116 | IDENT@108..112 "attr" | 116 | NAME_REF@108..112 |
117 | R_BRACK@112..113 "]" | 117 | IDENT@108..112 "attr" |
118 | WHITESPACE@113..114 " " | 118 | R_BRACK@112..113 "]" |
119 | PARAM@114..117 | 119 | WHITESPACE@113..114 " " |
120 | [email protected] "..." | 120 | [email protected] "..." |
121 | [email protected] ")" | 121 | [email protected] ")" |
122 | [email protected] " " | 122 | [email protected] " " |
@@ -153,16 +153,16 @@ [email protected] | |||
153 | [email protected] "FnMut" | 153 | [email protected] "FnMut" |
154 | [email protected] | 154 | [email protected] |
155 | [email protected] "(" | 155 | [email protected] "(" |
156 | ATT[email protected]53 | 156 | PARAM@146..166 |
157 | POUND@146..147 "#" | 157 | ATTR@146..153 |
158 | L_BRACK@147..148 "[" | 158 | POUND@146..147 "#" |
159 | PATH@148..152 | 159 | L_BRACK@147..148 "[" |
160 | PATH_SEGMENT@148..152 | 160 | [email protected] |
161 | NAME_REF@148..152 | 161 | PATH_SEGMENT@148..152 |
162 | IDENT@148..152 "attr" | 162 | NAME_REF@148..152 |
163 | R_BRACK@152..153 "]" | 163 | IDENT@148..152 "attr" |
164 | WHITESPACE@153..154 " " | 164 | R_BRACK@152..153 "]" |
165 | PARAM@154..166 | 165 | WHITESPACE@153..154 " " |
166 | [email protected] | 166 | [email protected] |
167 | [email protected] "&" | 167 | [email protected] "&" |
168 | [email protected] "mut" | 168 | [email protected] "mut" |
@@ -224,17 +224,17 @@ [email protected] | |||
224 | [email protected] "u64" | 224 | [email protected] "u64" |
225 | [email protected] "," | 225 | [email protected] "," |
226 | [email protected] " " | 226 | [email protected] " " |
227 | ATT[email protected]1 | 227 | PARAM@213..232 |
228 | POUND@213..214 "#" | 228 | ATTR@213..221 |
229 | WHITESPACE@214..215 " " | 229 | POUND@213..214 "#" |
230 | L_BRACK@215..216 "[" | 230 | WHITESPACE@214..215 " " |
231 | PATH@216..220 | 231 | L_BRACK@215..216 "[" |
232 | PATH_SEGMENT@216..220 | 232 | [email protected] |
233 | NAME_REF@216..220 | 233 | PATH_SEGMENT@216..220 |
234 | IDENT@216..220 "attr" | 234 | NAME_REF@216..220 |
235 | R_BRACK@220..221 "]" | 235 | IDENT@216..220 "attr" |
236 | WHITESPACE@221..222 " " | 236 | R_BRACK@220..221 "]" |
237 | PARAM@222..232 | 237 | WHITESPACE@221..222 " " |
238 | [email protected] | 238 | [email protected] |
239 | [email protected] "mut" | 239 | [email protected] "mut" |
240 | [email protected] " " | 240 | [email protected] " " |
@@ -271,16 +271,16 @@ [email protected] | |||
271 | [email protected] "f" | 271 | [email protected] "f" |
272 | [email protected] | 272 | [email protected] |
273 | [email protected] "(" | 273 | [email protected] "(" |
274 | ATT[email protected]68 | 274 | SELF_PARAM@257..273 |
275 | POUND@257..258 "#" | 275 | ATTR@257..268 |
276 | L_BRACK@258..259 "[" | 276 | POUND@257..258 "#" |
277 | PATH@259..267 | 277 | L_BRACK@258..259 "[" |
278 | PATH_SEGMENT@259..267 | 278 | [email protected] |
279 | NAME_REF@259..267 | 279 | PATH_SEGMENT@259..267 |
280 | IDENT@259..267 "must_use" | 280 | NAME_REF@259..267 |
281 | R_BRACK@267..268 "]" | 281 | IDENT@259..267 "must_use" |
282 | WHITESPACE@268..269 " " | 282 | R_BRACK@267..268 "]" |
283 | SELF_PARAM@269..273 | 283 | WHITESPACE@268..269 " " |
284 | [email protected] "self" | 284 | [email protected] "self" |
285 | [email protected] ")" | 285 | [email protected] ")" |
286 | [email protected] " " | 286 | [email protected] " " |
@@ -295,16 +295,16 @@ [email protected] | |||
295 | [email protected] "g1" | 295 | [email protected] "g1" |
296 | [email protected] | 296 | [email protected] |
297 | [email protected] "(" | 297 | [email protected] "(" |
298 | ATTR@289..296 | 298 | SELF_PARAM@289..301 |
299 | POUND@289..290 "#" | 299 | ATTR@289..296 |
300 | L_BRACK@290..291 "[" | 300 | POUND@289..290 "#" |
301 | PATH@291..295 | 301 | L_BRACK@290..291 "[" |
302 | PATH_SEGMENT@291..295 | 302 | [email protected] |
303 | NAME_REF@291..295 | 303 | PATH_SEGMENT@291..295 |
304 | IDENT@291..295 "attr" | 304 | NAME_REF@291..295 |
305 | R_BRACK@295..296 "]" | 305 | IDENT@291..295 "attr" |
306 | WHITESPACE@296..297 " " | 306 | R_BRACK@295..296 "]" |
307 | SELF_PARAM@297..301 | 307 | WHITESPACE@296..297 " " |
308 | [email protected] "self" | 308 | [email protected] "self" |
309 | [email protected] ")" | 309 | [email protected] ")" |
310 | [email protected] " " | 310 | [email protected] " " |
@@ -319,16 +319,16 @@ [email protected] | |||
319 | [email protected] "g2" | 319 | [email protected] "g2" |
320 | [email protected] | 320 | [email protected] |
321 | [email protected] "(" | 321 | [email protected] "(" |
322 | ATT[email protected]24 | 322 | SELF_PARAM@317..330 |
323 | POUND@317..318 "#" | 323 | ATTR@317..324 |
324 | L_BRACK@318..319 "[" | 324 | POUND@317..318 "#" |
325 | PATH@319..323 | 325 | L_BRACK@318..319 "[" |
326 | PATH_SEGMENT@319..323 | 326 | [email protected] |
327 | NAME_REF@319..323 | 327 | PATH_SEGMENT@319..323 |
328 | IDENT@319..323 "attr" | 328 | NAME_REF@319..323 |
329 | R_BRACK@323..324 "]" | 329 | IDENT@319..323 "attr" |
330 | WHITESPACE@324..325 " " | 330 | R_BRACK@323..324 "]" |
331 | SELF_PARAM@325..330 | 331 | WHITESPACE@324..325 " " |
332 | [email protected] "&" | 332 | [email protected] "&" |
333 | [email protected] "self" | 333 | [email protected] "self" |
334 | [email protected] ")" | 334 | [email protected] ")" |
@@ -350,16 +350,16 @@ [email protected] | |||
350 | [email protected] ">" | 350 | [email protected] ">" |
351 | [email protected] | 351 | [email protected] |
352 | [email protected] "(" | 352 | [email protected] "(" |
353 | ATT[email protected]57 | 353 | SELF_PARAM@350..367 |
354 | POUND@350..351 "#" | 354 | ATTR@350..357 |
355 | L_BRACK@351..352 "[" | 355 | POUND@350..351 "#" |
356 | PATH@352..356 | 356 | L_BRACK@351..352 "[" |
357 | PATH_SEGMENT@352..356 | 357 | [email protected] |
358 | NAME_REF@352..356 | 358 | PATH_SEGMENT@352..356 |
359 | IDENT@352..356 "attr" | 359 | NAME_REF@352..356 |
360 | R_BRACK@356..357 "]" | 360 | IDENT@352..356 "attr" |
361 | WHITESPACE@357..358 " " | 361 | R_BRACK@356..357 "]" |
362 | SELF_PARAM@358..367 | 362 | WHITESPACE@357..358 " " |
363 | [email protected] "&" | 363 | [email protected] "&" |
364 | [email protected] "mut" | 364 | [email protected] "mut" |
365 | [email protected] " " | 365 | [email protected] " " |
@@ -383,16 +383,16 @@ [email protected] | |||
383 | [email protected] ">" | 383 | [email protected] ">" |
384 | [email protected] | 384 | [email protected] |
385 | [email protected] "(" | 385 | [email protected] "(" |
386 | ATTR@387..394 | 386 | SELF_PARAM@387..403 |
387 | POUND@387..388 "#" | 387 | ATTR@387..394 |
388 | L_BRACK@388..389 "[" | 388 | POUND@387..388 "#" |
389 | PATH@389..393 | 389 | L_BRACK@388..389 "[" |
390 | PATH_SEGMENT@389..393 | 390 | [email protected] |
391 | NAME_REF@389..393 | 391 | PATH_SEGMENT@389..393 |
392 | IDENT@389..393 "attr" | 392 | NAME_REF@389..393 |
393 | R_BRACK@393..394 "]" | 393 | IDENT@389..393 "attr" |
394 | WHITESPACE@394..395 " " | 394 | R_BRACK@393..394 "]" |
395 | SELF_PARAM@395..403 | 395 | WHITESPACE@394..395 " " |
396 | [email protected] "&" | 396 | [email protected] "&" |
397 | [email protected] | 397 | [email protected] |
398 | [email protected] "\'a" | 398 | [email protected] "\'a" |
@@ -417,16 +417,16 @@ [email protected] | |||
417 | [email protected] ">" | 417 | [email protected] ">" |
418 | [email protected] | 418 | [email protected] |
419 | [email protected] "(" | 419 | [email protected] "(" |
420 | ATT[email protected]0 | 420 | SELF_PARAM@423..443 |
421 | POUND@423..424 "#" | 421 | ATTR@423..430 |
422 | L_BRACK@424..425 "[" | 422 | POUND@423..424 "#" |
423 | PATH@425..429 | 423 | L_BRACK@424..425 "[" |
424 | PATH_SEGMENT@425..429 | 424 | [email protected] |
425 | NAME_REF@425..429 | 425 | PATH_SEGMENT@425..429 |
426 | IDENT@425..429 "attr" | 426 | NAME_REF@425..429 |
427 | R_BRACK@429..430 "]" | 427 | IDENT@425..429 "attr" |
428 | WHITESPACE@430..431 " " | 428 | R_BRACK@429..430 "]" |
429 | SELF_PARAM@431..443 | 429 | WHITESPACE@430..431 " " |
430 | [email protected] "&" | 430 | [email protected] "&" |
431 | [email protected] | 431 | [email protected] |
432 | [email protected] "\'a" | 432 | [email protected] "\'a" |
@@ -447,16 +447,16 @@ [email protected] | |||
447 | [email protected] "c" | 447 | [email protected] "c" |
448 | [email protected] | 448 | [email protected] |
449 | [email protected] "(" | 449 | [email protected] "(" |
450 | ATT[email protected]5 | 450 | SELF_PARAM@458..476 |
451 | POUND@458..459 "#" | 451 | ATTR@458..465 |
452 | L_BRACK@459..460 "[" | 452 | POUND@458..459 "#" |
453 | PATH@460..464 | 453 | L_BRACK@459..460 "[" |
454 | PATH_SEGMENT@460..464 | 454 | [email protected] |
455 | NAME_REF@460..464 | 455 | PATH_SEGMENT@460..464 |
456 | IDENT@460..464 "attr" | 456 | NAME_REF@460..464 |
457 | R_BRACK@464..465 "]" | 457 | IDENT@460..464 "attr" |
458 | WHITESPACE@465..466 " " | 458 | R_BRACK@464..465 "]" |
459 | SELF_PARAM@466..476 | 459 | WHITESPACE@465..466 " " |
460 | [email protected] "self" | 460 | [email protected] "self" |
461 | [email protected] ":" | 461 | [email protected] ":" |
462 | [email protected] " " | 462 | [email protected] " " |
@@ -478,16 +478,16 @@ [email protected] | |||
478 | [email protected] "d" | 478 | [email protected] "d" |
479 | [email protected] | 479 | [email protected] |
480 | [email protected] "(" | 480 | [email protected] "(" |
481 | ATTR@491..498 | 481 | SELF_PARAM@491..513 |
482 | POUND@491..492 "#" | 482 | ATTR@491..498 |
483 | L_BRACK@492..493 "[" | 483 | POUND@491..492 "#" |
484 | PATH@493..497 | 484 | L_BRACK@492..493 "[" |
485 | PATH_SEGMENT@493..497 | 485 | [email protected] |
486 | NAME_REF@493..497 | 486 | PATH_SEGMENT@493..497 |
487 | IDENT@493..497 "attr" | 487 | NAME_REF@493..497 |
488 | R_BRACK@497..498 "]" | 488 | IDENT@493..497 "attr" |
489 | WHITESPACE@498..499 " " | 489 | R_BRACK@497..498 "]" |
490 | SELF_PARAM@499..513 | 490 | WHITESPACE@498..499 " " |
491 | [email protected] "self" | 491 | [email protected] "self" |
492 | [email protected] ":" | 492 | [email protected] ":" |
493 | [email protected] " " | 493 | [email protected] " " |
diff --git a/crates/syntax/test_data/parser/ok/0063_variadic_fun.rast b/crates/syntax/test_data/parser/ok/0063_variadic_fun.rast index 4009b3ff8..f7c094898 100644 --- a/crates/syntax/test_data/parser/ok/0063_variadic_fun.rast +++ b/crates/syntax/test_data/parser/ok/0063_variadic_fun.rast | |||
@@ -92,20 +92,20 @@ [email protected] | |||
92 | [email protected] "u8" | 92 | [email protected] "u8" |
93 | [email protected] "," | 93 | [email protected] "," |
94 | [email protected] " " | 94 | [email protected] " " |
95 | ATT[email protected]5 | 95 | PARAM@92..120 |
96 | POUND@92..93 "#" | 96 | ATTR@92..105 |
97 | L_BRACK@93..94 "[" | 97 | POUND@92..93 "#" |
98 | PATH@94..97 | 98 | L_BRACK@93..94 "[" |
99 | PATH_SEGMENT@94..97 | 99 | [email protected] |
100 | NAME_REF@94..97 | 100 | PATH_SEGMENT@94..97 |
101 | IDENT@94..97 "cfg" | 101 | NAME_REF@94..97 |
102 | TOKEN_TREE@97..104 | 102 | IDENT@94..97 "cfg" |
103 | L_PAREN@97..98 "(" | 103 | TOKEN_TREE@97..104 |
104 | IDENT@98..103 "never" | 104 | L_PAREN@97..98 "(" |
105 | R_PAREN@103..104 ")" | 105 | IDENT@98..103 "never" |
106 | R_BRACK@104..105 "]" | 106 | R_PAREN@103..104 ")" |
107 | WHITESPACE@105..106 " " | 107 | R_BRACK@104..105 "]" |
108 | PARAM@106..120 | 108 | WHITESPACE@105..106 " " |
109 | [email protected] | 109 | [email protected] |
110 | [email protected] "[" | 110 | [email protected] "[" |
111 | [email protected] | 111 | [email protected] |
diff --git a/editors/code/.vscodeignore b/editors/code/.vscodeignore index 5096ce4da..c1cf00fa0 100644 --- a/editors/code/.vscodeignore +++ b/editors/code/.vscodeignore | |||
@@ -4,6 +4,5 @@ | |||
4 | !package.json | 4 | !package.json |
5 | !package-lock.json | 5 | !package-lock.json |
6 | !ra_syntax_tree.tmGrammar.json | 6 | !ra_syntax_tree.tmGrammar.json |
7 | !rust.tmGrammar.json | ||
8 | !icon.png | 7 | !icon.png |
9 | !README.md | 8 | !README.md |
diff --git a/editors/code/package.json b/editors/code/package.json index ad01fea7b..abcc84eda 100644 --- a/editors/code/package.json +++ b/editors/code/package.json | |||
@@ -749,11 +749,6 @@ | |||
749 | ], | 749 | ], |
750 | "grammars": [ | 750 | "grammars": [ |
751 | { | 751 | { |
752 | "language": "rust", | ||
753 | "scopeName": "source.rust", | ||
754 | "path": "rust.tmGrammar.json" | ||
755 | }, | ||
756 | { | ||
757 | "language": "ra_syntax_tree", | 752 | "language": "ra_syntax_tree", |
758 | "scopeName": "source.ra_syntax_tree", | 753 | "scopeName": "source.ra_syntax_tree", |
759 | "path": "ra_syntax_tree.tmGrammar.json" | 754 | "path": "ra_syntax_tree.tmGrammar.json" |
diff --git a/editors/code/rust.tmGrammar.json b/editors/code/rust.tmGrammar.json deleted file mode 100644 index 4759bb116..000000000 --- a/editors/code/rust.tmGrammar.json +++ /dev/null | |||
@@ -1,1140 +0,0 @@ | |||
1 | { | ||
2 | "$schema": "https://raw.githubusercontent.com/martinring/tmlanguage/master/tmlanguage.json", | ||
3 | "name": "Rust", | ||
4 | "fileTypes": [ | ||
5 | "rs" | ||
6 | ], | ||
7 | "scopeName": "source.rust", | ||
8 | "patterns": [ | ||
9 | { | ||
10 | "comment": "boxed slice literal", | ||
11 | "begin": "(<)(\\[)", | ||
12 | "beginCaptures": { | ||
13 | "1": { | ||
14 | "name": "punctuation.brackets.angle.rust" | ||
15 | }, | ||
16 | "2": { | ||
17 | "name": "punctuation.brackets.square.rust" | ||
18 | } | ||
19 | }, | ||
20 | "end": ">", | ||
21 | "endCaptures": { | ||
22 | "0": { | ||
23 | "name": "punctuation.brackets.angle.rust" | ||
24 | } | ||
25 | }, | ||
26 | "patterns": [ | ||
27 | { | ||
28 | "include": "#block-comments" | ||
29 | }, | ||
30 | { | ||
31 | "include": "#comments" | ||
32 | }, | ||
33 | { | ||
34 | "include": "#gtypes" | ||
35 | }, | ||
36 | { | ||
37 | "include": "#lvariables" | ||
38 | }, | ||
39 | { | ||
40 | "include": "#lifetimes" | ||
41 | }, | ||
42 | { | ||
43 | "include": "#punctuation" | ||
44 | }, | ||
45 | { | ||
46 | "include": "#types" | ||
47 | } | ||
48 | ] | ||
49 | }, | ||
50 | { | ||
51 | "comment": "macro type metavariables", | ||
52 | "name": "meta.macro.metavariable.type.rust", | ||
53 | "match": "(\\$)((crate)|([A-Z][A-Za-z0-9_]*))((:)(block|expr|ident|item|lifetime|literal|meta|path?|stmt|tt|ty|vis))?", | ||
54 | "captures": { | ||
55 | "1": { | ||
56 | "name": "keyword.operator.macro.dollar.rust" | ||
57 | }, | ||
58 | "3": { | ||
59 | "name": "keyword.other.crate.rust" | ||
60 | }, | ||
61 | "4": { | ||
62 | "name": "entity.name.type.metavariable.rust" | ||
63 | }, | ||
64 | "6": { | ||
65 | "name": "keyword.operator.key-value.rust" | ||
66 | }, | ||
67 | "7": { | ||
68 | "name": "variable.other.metavariable.specifier.rust" | ||
69 | } | ||
70 | }, | ||
71 | "patterns": [ | ||
72 | { | ||
73 | "include": "#keywords" | ||
74 | } | ||
75 | ] | ||
76 | }, | ||
77 | { | ||
78 | "comment": "macro metavariables", | ||
79 | "name": "meta.macro.metavariable.rust", | ||
80 | "match": "(\\$)([a-z][A-Za-z0-9_]*)((:)(block|expr|ident|item|lifetime|literal|meta|path?|stmt|tt|ty|vis))?", | ||
81 | "captures": { | ||
82 | "1": { | ||
83 | "name": "keyword.operator.macro.dollar.rust" | ||
84 | }, | ||
85 | "2": { | ||
86 | "name": "variable.other.metavariable.name.rust" | ||
87 | }, | ||
88 | "4": { | ||
89 | "name": "keyword.operator.key-value.rust" | ||
90 | }, | ||
91 | "5": { | ||
92 | "name": "variable.other.metavariable.specifier.rust" | ||
93 | } | ||
94 | }, | ||
95 | "patterns": [ | ||
96 | { | ||
97 | "include": "#keywords" | ||
98 | } | ||
99 | ] | ||
100 | }, | ||
101 | { | ||
102 | "comment": "macro rules", | ||
103 | "name": "meta.macro.rules.rust", | ||
104 | "match": "\\b(macro_rules!)\\s+(([a-z0-9_]+)|([A-Z][a-z0-9_]*))\\s+(\\{)", | ||
105 | "captures": { | ||
106 | "1": { | ||
107 | "name": "entity.name.function.macro.rules.rust" | ||
108 | }, | ||
109 | "3": { | ||
110 | "name": "entity.name.function.macro.rust" | ||
111 | }, | ||
112 | "4": { | ||
113 | "name": "entity.name.type.macro.rust" | ||
114 | }, | ||
115 | "5": { | ||
116 | "name": "punctuation.brackets.curly.rust" | ||
117 | } | ||
118 | } | ||
119 | }, | ||
120 | { | ||
121 | "comment": "attributes", | ||
122 | "name": "meta.attribute.rust", | ||
123 | "begin": "(#)(\\!?)(\\[)", | ||
124 | "beginCaptures": { | ||
125 | "1": { | ||
126 | "name": "punctuation.definition.attribute.rust" | ||
127 | }, | ||
128 | "2": { | ||
129 | "name": "keyword.operator.attribute.inner.rust" | ||
130 | }, | ||
131 | "3": { | ||
132 | "name": "punctuation.brackets.attribute.rust" | ||
133 | } | ||
134 | }, | ||
135 | "end": "\\]", | ||
136 | "endCaptures": { | ||
137 | "0": { | ||
138 | "name": "punctuation.brackets.attribute.rust" | ||
139 | } | ||
140 | }, | ||
141 | "patterns": [ | ||
142 | { | ||
143 | "include": "#block-comments" | ||
144 | }, | ||
145 | { | ||
146 | "include": "#comments" | ||
147 | }, | ||
148 | { | ||
149 | "include": "#keywords" | ||
150 | }, | ||
151 | { | ||
152 | "include": "#punctuation" | ||
153 | }, | ||
154 | { | ||
155 | "include": "#strings" | ||
156 | }, | ||
157 | { | ||
158 | "include": "#gtypes" | ||
159 | }, | ||
160 | { | ||
161 | "include": "#types" | ||
162 | } | ||
163 | ] | ||
164 | }, | ||
165 | { | ||
166 | "comment": "modules", | ||
167 | "match": "(mod)\\s+((?:r#(?!crate|[Ss]elf|super))?[a-z][A-Za-z0-9_]*)", | ||
168 | "captures": { | ||
169 | "1": { | ||
170 | "name": "storage.type.rust" | ||
171 | }, | ||
172 | "2": { | ||
173 | "name": "entity.name.module.rust" | ||
174 | } | ||
175 | } | ||
176 | }, | ||
177 | { | ||
178 | "comment": "external crate imports", | ||
179 | "name": "meta.import.rust", | ||
180 | "begin": "\\b(extern)\\s+(crate)", | ||
181 | "beginCaptures": { | ||
182 | "1": { | ||
183 | "name": "storage.type.rust" | ||
184 | }, | ||
185 | "2": { | ||
186 | "name": "keyword.other.crate.rust" | ||
187 | } | ||
188 | }, | ||
189 | "end": ";", | ||
190 | "endCaptures": { | ||
191 | "0": { | ||
192 | "name": "punctuation.semi.rust" | ||
193 | } | ||
194 | }, | ||
195 | "patterns": [ | ||
196 | { | ||
197 | "include": "#block-comments" | ||
198 | }, | ||
199 | { | ||
200 | "include": "#comments" | ||
201 | }, | ||
202 | { | ||
203 | "include": "#keywords" | ||
204 | }, | ||
205 | { | ||
206 | "include": "#punctuation" | ||
207 | } | ||
208 | ] | ||
209 | }, | ||
210 | { | ||
211 | "comment": "use statements", | ||
212 | "name": "meta.use.rust", | ||
213 | "begin": "\\b(use)\\s", | ||
214 | "beginCaptures": { | ||
215 | "1": { | ||
216 | "name": "keyword.other.rust" | ||
217 | } | ||
218 | }, | ||
219 | "end": ";", | ||
220 | "endCaptures": { | ||
221 | "0": { | ||
222 | "name": "punctuation.semi.rust" | ||
223 | } | ||
224 | }, | ||
225 | "patterns": [ | ||
226 | { | ||
227 | "include": "#block-comments" | ||
228 | }, | ||
229 | { | ||
230 | "include": "#comments" | ||
231 | }, | ||
232 | { | ||
233 | "include": "#keywords" | ||
234 | }, | ||
235 | { | ||
236 | "include": "#namespaces" | ||
237 | }, | ||
238 | { | ||
239 | "include": "#punctuation" | ||
240 | }, | ||
241 | { | ||
242 | "include": "#types" | ||
243 | }, | ||
244 | { | ||
245 | "include": "#lvariables" | ||
246 | } | ||
247 | ] | ||
248 | }, | ||
249 | { | ||
250 | "include": "#block-comments" | ||
251 | }, | ||
252 | { | ||
253 | "include": "#comments" | ||
254 | }, | ||
255 | { | ||
256 | "include": "#lvariables" | ||
257 | }, | ||
258 | { | ||
259 | "include": "#constants" | ||
260 | }, | ||
261 | { | ||
262 | "include": "#gtypes" | ||
263 | }, | ||
264 | { | ||
265 | "include": "#functions" | ||
266 | }, | ||
267 | { | ||
268 | "include": "#types" | ||
269 | }, | ||
270 | { | ||
271 | "include": "#keywords" | ||
272 | }, | ||
273 | { | ||
274 | "include": "#lifetimes" | ||
275 | }, | ||
276 | { | ||
277 | "include": "#macros" | ||
278 | }, | ||
279 | { | ||
280 | "include": "#namespaces" | ||
281 | }, | ||
282 | { | ||
283 | "include": "#punctuation" | ||
284 | }, | ||
285 | { | ||
286 | "include": "#strings" | ||
287 | }, | ||
288 | { | ||
289 | "include": "#variables" | ||
290 | } | ||
291 | ], | ||
292 | "repository": { | ||
293 | "comments": { | ||
294 | "patterns": [ | ||
295 | { | ||
296 | "comment": "documentation comments", | ||
297 | "name": "comment.line.documentation.rust", | ||
298 | "match": "^\\s*///.*" | ||
299 | }, | ||
300 | { | ||
301 | "comment": "line comments", | ||
302 | "name": "comment.line.double-slash.rust", | ||
303 | "match": "\\s*//.*" | ||
304 | } | ||
305 | ] | ||
306 | }, | ||
307 | "block-comments": { | ||
308 | "patterns": [ | ||
309 | { | ||
310 | "comment": "empty block comments", | ||
311 | "name": "comment.block.rust", | ||
312 | "match": "/\\*\\*/" | ||
313 | }, | ||
314 | { | ||
315 | "comment": "block documentation comments", | ||
316 | "name": "comment.block.documentation.rust", | ||
317 | "begin": "/\\*\\*", | ||
318 | "end": "\\*/", | ||
319 | "patterns": [ | ||
320 | { | ||
321 | "include": "#block-comments" | ||
322 | } | ||
323 | ] | ||
324 | }, | ||
325 | { | ||
326 | "comment": "block comments", | ||
327 | "name": "comment.block.rust", | ||
328 | "begin": "/\\*(?!\\*)", | ||
329 | "end": "\\*/", | ||
330 | "patterns": [ | ||
331 | { | ||
332 | "include": "#block-comments" | ||
333 | } | ||
334 | ] | ||
335 | } | ||
336 | ] | ||
337 | }, | ||
338 | "constants": { | ||
339 | "patterns": [ | ||
340 | { | ||
341 | "comment": "ALL CAPS constants", | ||
342 | "name": "constant.other.caps.rust", | ||
343 | "match": "\\b[A-Z]{2}[A-Z0-9_]*\\b" | ||
344 | }, | ||
345 | { | ||
346 | "comment": "constant declarations", | ||
347 | "match": "\\b(const)\\s+([A-Z][A-Za-z0-9_]*)\\b", | ||
348 | "captures": { | ||
349 | "1": { | ||
350 | "name": "storage.type.rust" | ||
351 | }, | ||
352 | "2": { | ||
353 | "name": "constant.other.caps.rust" | ||
354 | } | ||
355 | } | ||
356 | }, | ||
357 | { | ||
358 | "comment": "decimal integers and floats", | ||
359 | "name": "constant.numeric.decimal.rust", | ||
360 | "match": "\\b\\d[\\d_]*(\\.?)[\\d_]*(?:(E)([+-])([\\d_]+))?(f32|f64|i128|i16|i32|i64|i8|isize|u128|u16|u32|u64|u8|usize)?\\b", | ||
361 | "captures": { | ||
362 | "1": { | ||
363 | "name": "punctuation.separator.dot.decimal.rust" | ||
364 | }, | ||
365 | "2": { | ||
366 | "name": "keyword.operator.exponent.rust" | ||
367 | }, | ||
368 | "3": { | ||
369 | "name": "keyword.operator.exponent.sign.rust" | ||
370 | }, | ||
371 | "4": { | ||
372 | "name": "constant.numeric.decimal.exponent.mantissa.rust" | ||
373 | }, | ||
374 | "5": { | ||
375 | "name": "entity.name.type.numeric.rust" | ||
376 | } | ||
377 | } | ||
378 | }, | ||
379 | { | ||
380 | "comment": "hexadecimal integers", | ||
381 | "name": "constant.numeric.hex.rust", | ||
382 | "match": "\\b0x[\\da-fA-F_]+(i128|i16|i32|i64|i8|isize|u128|u16|u32|u64|u8|usize)?\\b", | ||
383 | "captures": { | ||
384 | "1": { | ||
385 | "name": "entity.name.type.numeric.rust" | ||
386 | } | ||
387 | } | ||
388 | }, | ||
389 | { | ||
390 | "comment": "octal integers", | ||
391 | "name": "constant.numeric.oct.rust", | ||
392 | "match": "\\b0o[0-7_]+(i128|i16|i32|i64|i8|isize|u128|u16|u32|u64|u8|usize)?\\b", | ||
393 | "captures": { | ||
394 | "1": { | ||
395 | "name": "entity.name.type.numeric.rust" | ||
396 | } | ||
397 | } | ||
398 | }, | ||
399 | { | ||
400 | "comment": "binary integers", | ||
401 | "name": "constant.numeric.bin.rust", | ||
402 | "match": "\\b0b[01_]+(i128|i16|i32|i64|i8|isize|u128|u16|u32|u64|u8|usize)?\\b", | ||
403 | "captures": { | ||
404 | "1": { | ||
405 | "name": "entity.name.type.numeric.rust" | ||
406 | } | ||
407 | } | ||
408 | }, | ||
409 | { | ||
410 | "comment": "booleans", | ||
411 | "name": "constant.language.bool.rust", | ||
412 | "match": "\\b(true|false)\\b" | ||
413 | } | ||
414 | ] | ||
415 | }, | ||
416 | "escapes": { | ||
417 | "comment": "escapes: ASCII, byte, Unicode, quote, regex", | ||
418 | "name": "constant.character.escape.rust", | ||
419 | "match": "(\\\\)(?:(?:(x[0-7][0-7a-fA-F])|(u(\\{)[\\da-fA-F]{4,6}(\\}))|.))", | ||
420 | "captures": { | ||
421 | "1": { | ||
422 | "name": "constant.character.escape.backslash.rust" | ||
423 | }, | ||
424 | "2": { | ||
425 | "name": "constant.character.escape.bit.rust" | ||
426 | }, | ||
427 | "3": { | ||
428 | "name": "constant.character.escape.unicode.rust" | ||
429 | }, | ||
430 | "4": { | ||
431 | "name": "constant.character.escape.unicode.punctuation.rust" | ||
432 | }, | ||
433 | "5": { | ||
434 | "name": "constant.character.escape.unicode.punctuation.rust" | ||
435 | } | ||
436 | } | ||
437 | }, | ||
438 | "functions": { | ||
439 | "patterns": [ | ||
440 | { | ||
441 | "comment": "pub as a function", | ||
442 | "match": "\\b(pub)(\\()", | ||
443 | "captures": { | ||
444 | "1": { | ||
445 | "name": "keyword.other.rust" | ||
446 | }, | ||
447 | "2": { | ||
448 | "name": "punctuation.brackets.round.rust" | ||
449 | } | ||
450 | } | ||
451 | }, | ||
452 | { | ||
453 | "comment": "function definition", | ||
454 | "name": "meta.function.definition.rust", | ||
455 | "begin": "\\b(fn)\\s+((?:r#(?!crate|[Ss]elf|super))?[A-Za-z0-9_]+)((\\()|(<))", | ||
456 | "beginCaptures": { | ||
457 | "1": { | ||
458 | "name": "keyword.other.fn.rust" | ||
459 | }, | ||
460 | "2": { | ||
461 | "name": "entity.name.function.rust" | ||
462 | }, | ||
463 | "4": { | ||
464 | "name": "punctuation.brackets.round.rust" | ||
465 | }, | ||
466 | "5": { | ||
467 | "name": "punctuation.brackets.angle.rust" | ||
468 | } | ||
469 | }, | ||
470 | "end": "\\{|;", | ||
471 | "endCaptures": { | ||
472 | "0": { | ||
473 | "name": "punctuation.brackets.curly.rust" | ||
474 | } | ||
475 | }, | ||
476 | "patterns": [ | ||
477 | { | ||
478 | "include": "#block-comments" | ||
479 | }, | ||
480 | { | ||
481 | "include": "#comments" | ||
482 | }, | ||
483 | { | ||
484 | "include": "#keywords" | ||
485 | }, | ||
486 | { | ||
487 | "include": "#lvariables" | ||
488 | }, | ||
489 | { | ||
490 | "include": "#constants" | ||
491 | }, | ||
492 | { | ||
493 | "include": "#gtypes" | ||
494 | }, | ||
495 | { | ||
496 | "include": "#functions" | ||
497 | }, | ||
498 | { | ||
499 | "include": "#lifetimes" | ||
500 | }, | ||
501 | { | ||
502 | "include": "#macros" | ||
503 | }, | ||
504 | { | ||
505 | "include": "#namespaces" | ||
506 | }, | ||
507 | { | ||
508 | "include": "#punctuation" | ||
509 | }, | ||
510 | { | ||
511 | "include": "#strings" | ||
512 | }, | ||
513 | { | ||
514 | "include": "#types" | ||
515 | }, | ||
516 | { | ||
517 | "include": "#variables" | ||
518 | } | ||
519 | ] | ||
520 | }, | ||
521 | { | ||
522 | "comment": "function/method calls, chaining", | ||
523 | "name": "meta.function.call.rust", | ||
524 | "begin": "((?:r#(?!crate|[Ss]elf|super))?[A-Za-z0-9_]+)(\\()", | ||
525 | "beginCaptures": { | ||
526 | "1": { | ||
527 | "name": "entity.name.function.rust" | ||
528 | }, | ||
529 | "2": { | ||
530 | "name": "punctuation.brackets.round.rust" | ||
531 | } | ||
532 | }, | ||
533 | "end": "\\)", | ||
534 | "endCaptures": { | ||
535 | "0": { | ||
536 | "name": "punctuation.brackets.round.rust" | ||
537 | } | ||
538 | }, | ||
539 | "patterns": [ | ||
540 | { | ||
541 | "include": "#block-comments" | ||
542 | }, | ||
543 | { | ||
544 | "include": "#comments" | ||
545 | }, | ||
546 | { | ||
547 | "include": "#keywords" | ||
548 | }, | ||
549 | { | ||
550 | "include": "#lvariables" | ||
551 | }, | ||
552 | { | ||
553 | "include": "#constants" | ||
554 | }, | ||
555 | { | ||
556 | "include": "#gtypes" | ||
557 | }, | ||
558 | { | ||
559 | "include": "#functions" | ||
560 | }, | ||
561 | { | ||
562 | "include": "#lifetimes" | ||
563 | }, | ||
564 | { | ||
565 | "include": "#macros" | ||
566 | }, | ||
567 | { | ||
568 | "include": "#namespaces" | ||
569 | }, | ||
570 | { | ||
571 | "include": "#punctuation" | ||
572 | }, | ||
573 | { | ||
574 | "include": "#strings" | ||
575 | }, | ||
576 | { | ||
577 | "include": "#types" | ||
578 | }, | ||
579 | { | ||
580 | "include": "#variables" | ||
581 | } | ||
582 | ] | ||
583 | }, | ||
584 | { | ||
585 | "comment": "function/method calls with turbofish", | ||
586 | "name": "meta.function.call.rust", | ||
587 | "begin": "((?:r#(?!crate|[Ss]elf|super))?[A-Za-z0-9_]+)(?=::<.*>\\()", | ||
588 | "beginCaptures": { | ||
589 | "1": { | ||
590 | "name": "entity.name.function.rust" | ||
591 | } | ||
592 | }, | ||
593 | "end": "\\)", | ||
594 | "endCaptures": { | ||
595 | "0": { | ||
596 | "name": "punctuation.brackets.round.rust" | ||
597 | } | ||
598 | }, | ||
599 | "patterns": [ | ||
600 | { | ||
601 | "include": "#block-comments" | ||
602 | }, | ||
603 | { | ||
604 | "include": "#comments" | ||
605 | }, | ||
606 | { | ||
607 | "include": "#keywords" | ||
608 | }, | ||
609 | { | ||
610 | "include": "#lvariables" | ||
611 | }, | ||
612 | { | ||
613 | "include": "#constants" | ||
614 | }, | ||
615 | { | ||
616 | "include": "#gtypes" | ||
617 | }, | ||
618 | { | ||
619 | "include": "#functions" | ||
620 | }, | ||
621 | { | ||
622 | "include": "#lifetimes" | ||
623 | }, | ||
624 | { | ||
625 | "include": "#macros" | ||
626 | }, | ||
627 | { | ||
628 | "include": "#namespaces" | ||
629 | }, | ||
630 | { | ||
631 | "include": "#punctuation" | ||
632 | }, | ||
633 | { | ||
634 | "include": "#strings" | ||
635 | }, | ||
636 | { | ||
637 | "include": "#types" | ||
638 | }, | ||
639 | { | ||
640 | "include": "#variables" | ||
641 | } | ||
642 | ] | ||
643 | } | ||
644 | ] | ||
645 | }, | ||
646 | "keywords": { | ||
647 | "patterns": [ | ||
648 | { | ||
649 | "comment": "control flow keywords", | ||
650 | "name": "keyword.control.rust", | ||
651 | "match": "\\b(await|break|continue|do|else|for|if|loop|match|return|try|while|yield)\\b" | ||
652 | }, | ||
653 | { | ||
654 | "comment": "storage keywords", | ||
655 | "name": "storage.type.rust", | ||
656 | "match": "\\b(const|enum|extern|let|macro|mod|struct|trait|type)\\b" | ||
657 | }, | ||
658 | { | ||
659 | "comment": "storage modifiers", | ||
660 | "name": "storage.modifier.rust", | ||
661 | "match": "\\b(abstract|static)\\b" | ||
662 | }, | ||
663 | { | ||
664 | "comment": "other keywords", | ||
665 | "name": "keyword.other.rust", | ||
666 | "match": "\\b(as|async|become|box|dyn|move|final|impl|in|override|priv|pub|ref|typeof|union|unsafe|unsized|use|virtual|where)\\b" | ||
667 | }, | ||
668 | { | ||
669 | "comment": "fn", | ||
670 | "name": "keyword.other.fn.rust", | ||
671 | "match": "\\bfn\\b" | ||
672 | }, | ||
673 | { | ||
674 | "comment": "crate", | ||
675 | "name": "keyword.other.crate.rust", | ||
676 | "match": "\\bcrate\\b" | ||
677 | }, | ||
678 | { | ||
679 | "comment": "mut", | ||
680 | "name": "storage.modifier.mut.rust", | ||
681 | "match": "\\bmut\\b" | ||
682 | }, | ||
683 | { | ||
684 | "comment": "logical operators", | ||
685 | "name": "keyword.operator.logical.rust", | ||
686 | "match": "(\\^|\\||\\|\\||&&|<<|>>|!)(?!=)" | ||
687 | }, | ||
688 | { | ||
689 | "comment": "logical AND, borrow references", | ||
690 | "name": "keyword.operator.borrow.and.rust", | ||
691 | "match": "&(?![&=])" | ||
692 | }, | ||
693 | { | ||
694 | "comment": "assignment operators", | ||
695 | "name": "keyword.operator.assignment.rust", | ||
696 | "match": "(\\+=|-=|\\*=|/=|%=|\\^=|&=|\\|=|<<=|>>=)" | ||
697 | }, | ||
698 | { | ||
699 | "comment": "single equal", | ||
700 | "name": "keyword.operator.assignment.equal.rust", | ||
701 | "match": "(?<![<>])=(?!=|>)" | ||
702 | }, | ||
703 | { | ||
704 | "comment": "comparison operators", | ||
705 | "name": "keyword.operator.comparison.rust", | ||
706 | "match": "(=(=)?(?!>)|!=|<=|(?<!=)>=)" | ||
707 | }, | ||
708 | { | ||
709 | "comment": "math operators", | ||
710 | "name": "keyword.operator.math.rust", | ||
711 | "match": "(([+%]|(\\*(?!\\w)))(?!=))|(-(?!>))|(/(?!/))" | ||
712 | }, | ||
713 | { | ||
714 | "comment": "less than, greater than (special case)", | ||
715 | "match": "(?:\\b|(?:(\\))|(\\])|(\\})))[ \\t]+([<>])[ \\t]+(?:\\b|(?:(\\()|(\\[)|(\\{)))", | ||
716 | "captures": { | ||
717 | "1": { | ||
718 | "name": "punctuation.brackets.round.rust" | ||
719 | }, | ||
720 | "2": { | ||
721 | "name": "punctuation.brackets.square.rust" | ||
722 | }, | ||
723 | "3": { | ||
724 | "name": "punctuation.brackets.curly.rust" | ||
725 | }, | ||
726 | "4": { | ||
727 | "name": "keyword.operator.comparison.rust" | ||
728 | }, | ||
729 | "5": { | ||
730 | "name": "punctuation.brackets.round.rust" | ||
731 | }, | ||
732 | "6": { | ||
733 | "name": "punctuation.brackets.square.rust" | ||
734 | }, | ||
735 | "7": { | ||
736 | "name": "punctuation.brackets.curly.rust" | ||
737 | } | ||
738 | } | ||
739 | }, | ||
740 | { | ||
741 | "comment": "namespace operator", | ||
742 | "name": "keyword.operator.namespace.rust", | ||
743 | "match": "::" | ||
744 | }, | ||
745 | { | ||
746 | "comment": "dereference asterisk", | ||
747 | "match": "(\\*)(?=\\w+)", | ||
748 | "captures": { | ||
749 | "1": { | ||
750 | "name": "keyword.operator.dereference.rust" | ||
751 | } | ||
752 | } | ||
753 | }, | ||
754 | { | ||
755 | "comment": "subpattern binding", | ||
756 | "name": "keyword.operator.subpattern.rust", | ||
757 | "match": "@" | ||
758 | }, | ||
759 | { | ||
760 | "comment": "dot access", | ||
761 | "name": "keyword.operator.access.dot.rust", | ||
762 | "match": "\\.(?!\\.)" | ||
763 | }, | ||
764 | { | ||
765 | "comment": "ranges, range patterns", | ||
766 | "name": "keyword.operator.range.rust", | ||
767 | "match": "\\.{2}(=|\\.)?" | ||
768 | }, | ||
769 | { | ||
770 | "comment": "colon", | ||
771 | "name": "keyword.operator.key-value.rust", | ||
772 | "match": ":(?!:)" | ||
773 | }, | ||
774 | { | ||
775 | "comment": "dashrocket, skinny arrow", | ||
776 | "name": "keyword.operator.arrow.skinny.rust", | ||
777 | "match": "->" | ||
778 | }, | ||
779 | { | ||
780 | "comment": "hashrocket, fat arrow", | ||
781 | "name": "keyword.operator.arrow.fat.rust", | ||
782 | "match": "=>" | ||
783 | }, | ||
784 | { | ||
785 | "comment": "dollar macros", | ||
786 | "name": "keyword.operator.macro.dollar.rust", | ||
787 | "match": "\\$" | ||
788 | }, | ||
789 | { | ||
790 | "comment": "question mark operator, questionably sized, macro kleene matcher", | ||
791 | "name": "keyword.operator.question.rust", | ||
792 | "match": "\\?" | ||
793 | } | ||
794 | ] | ||
795 | }, | ||
796 | "interpolations": { | ||
797 | "comment": "curly brace interpolations", | ||
798 | "name": "meta.interpolation.rust", | ||
799 | "match": "({)[^\"{}]*(})", | ||
800 | "captures": { | ||
801 | "1": { | ||
802 | "name": "punctuation.definition.interpolation.rust" | ||
803 | }, | ||
804 | "2": { | ||
805 | "name": "punctuation.definition.interpolation.rust" | ||
806 | } | ||
807 | } | ||
808 | }, | ||
809 | "lifetimes": { | ||
810 | "patterns": [ | ||
811 | { | ||
812 | "comment": "named lifetime parameters", | ||
813 | "match": "(['])([a-zA-Z_][0-9a-zA-Z_]*)(?!['])\\b", | ||
814 | "captures": { | ||
815 | "1": { | ||
816 | "name": "punctuation.definition.lifetime.rust" | ||
817 | }, | ||
818 | "2": { | ||
819 | "name": "entity.name.type.lifetime.rust" | ||
820 | } | ||
821 | } | ||
822 | }, | ||
823 | { | ||
824 | "comment": "borrowing references to named lifetimes", | ||
825 | "match": "(\\&)(['])([a-zA-Z_][0-9a-zA-Z_]*)(?!['])\\b", | ||
826 | "captures": { | ||
827 | "1": { | ||
828 | "name": "keyword.operator.borrow.rust" | ||
829 | }, | ||
830 | "2": { | ||
831 | "name": "punctuation.definition.lifetime.rust" | ||
832 | }, | ||
833 | "3": { | ||
834 | "name": "entity.name.type.lifetime.rust" | ||
835 | } | ||
836 | } | ||
837 | } | ||
838 | ] | ||
839 | }, | ||
840 | "macros": { | ||
841 | "patterns": [ | ||
842 | { | ||
843 | "comment": "macros", | ||
844 | "name": "meta.macro.rust", | ||
845 | "match": "(([a-z_][A-Za-z0-9_]*!)|([A-Z_][A-Za-z0-9_]*!))", | ||
846 | "captures": { | ||
847 | "2": { | ||
848 | "name": "entity.name.function.macro.rust" | ||
849 | }, | ||
850 | "3": { | ||
851 | "name": "entity.name.type.macro.rust" | ||
852 | } | ||
853 | } | ||
854 | } | ||
855 | ] | ||
856 | }, | ||
857 | "namespaces": { | ||
858 | "patterns": [ | ||
859 | { | ||
860 | "comment": "namespace (non-type, non-function path segment)", | ||
861 | "match": "(?<![A-Za-z0-9_])([a-z0-9_]+)((?<!super|self)::)", | ||
862 | "captures": { | ||
863 | "1": { | ||
864 | "name": "entity.name.namespace.rust" | ||
865 | }, | ||
866 | "2": { | ||
867 | "name": "keyword.operator.namespace.rust" | ||
868 | } | ||
869 | } | ||
870 | } | ||
871 | ] | ||
872 | }, | ||
873 | "types": { | ||
874 | "patterns": [ | ||
875 | { | ||
876 | "comment": "numeric types", | ||
877 | "match": "(?<![A-Za-z])(f32|f64|i128|i16|i32|i64|i8|isize|u128|u16|u32|u64|u8|usize)\\b", | ||
878 | "captures": { | ||
879 | "1": { | ||
880 | "name": "entity.name.type.numeric.rust" | ||
881 | } | ||
882 | } | ||
883 | }, | ||
884 | { | ||
885 | "comment": "parameterized types", | ||
886 | "begin": "\\b([A-Z][A-Za-z0-9]*)(<)", | ||
887 | "beginCaptures": { | ||
888 | "1": { | ||
889 | "name": "entity.name.type.rust" | ||
890 | }, | ||
891 | "2": { | ||
892 | "name": "punctuation.brackets.angle.rust" | ||
893 | } | ||
894 | }, | ||
895 | "end": ">", | ||
896 | "endCaptures": { | ||
897 | "0": { | ||
898 | "name": "punctuation.brackets.angle.rust" | ||
899 | } | ||
900 | }, | ||
901 | "patterns": [ | ||
902 | { | ||
903 | "include": "#block-comments" | ||
904 | }, | ||
905 | { | ||
906 | "include": "#comments" | ||
907 | }, | ||
908 | { | ||
909 | "include": "#keywords" | ||
910 | }, | ||
911 | { | ||
912 | "include": "#lvariables" | ||
913 | }, | ||
914 | { | ||
915 | "include": "#lifetimes" | ||
916 | }, | ||
917 | { | ||
918 | "include": "#punctuation" | ||
919 | }, | ||
920 | { | ||
921 | "include": "#types" | ||
922 | }, | ||
923 | { | ||
924 | "include": "#variables" | ||
925 | } | ||
926 | ] | ||
927 | }, | ||
928 | { | ||
929 | "comment": "primitive types", | ||
930 | "name": "entity.name.type.primitive.rust", | ||
931 | "match": "\\b(bool|char|str)\\b" | ||
932 | }, | ||
933 | { | ||
934 | "comment": "trait declarations", | ||
935 | "match": "\\b(trait)\\s+([A-Z][A-Za-z0-9]*)\\b", | ||
936 | "captures": { | ||
937 | "1": { | ||
938 | "name": "storage.type.rust" | ||
939 | }, | ||
940 | "2": { | ||
941 | "name": "entity.name.type.trait.rust" | ||
942 | } | ||
943 | } | ||
944 | }, | ||
945 | { | ||
946 | "comment": "struct declarations", | ||
947 | "match": "\\b(struct)\\s+([A-Z][A-Za-z0-9]*)\\b", | ||
948 | "captures": { | ||
949 | "1": { | ||
950 | "name": "storage.type.rust" | ||
951 | }, | ||
952 | "2": { | ||
953 | "name": "entity.name.type.struct.rust" | ||
954 | } | ||
955 | } | ||
956 | }, | ||
957 | { | ||
958 | "comment": "enum declarations", | ||
959 | "match": "\\b(enum)\\s+([A-Z][A-Za-z0-9_]*)\\b", | ||
960 | "captures": { | ||
961 | "1": { | ||
962 | "name": "storage.type.rust" | ||
963 | }, | ||
964 | "2": { | ||
965 | "name": "entity.name.type.enum.rust" | ||
966 | } | ||
967 | } | ||
968 | }, | ||
969 | { | ||
970 | "comment": "type declarations", | ||
971 | "match": "\\b(type)\\s+([A-Z][A-Za-z0-9_]*)\\b", | ||
972 | "captures": { | ||
973 | "1": { | ||
974 | "name": "storage.type.rust" | ||
975 | }, | ||
976 | "2": { | ||
977 | "name": "entity.name.type.declaration.rust" | ||
978 | } | ||
979 | } | ||
980 | }, | ||
981 | { | ||
982 | "comment": "types", | ||
983 | "name": "entity.name.type.rust", | ||
984 | "match": "\\b[A-Z][A-Za-z0-9]*\\b(?!!)" | ||
985 | } | ||
986 | ] | ||
987 | }, | ||
988 | "gtypes": { | ||
989 | "patterns": [ | ||
990 | { | ||
991 | "comment": "option types", | ||
992 | "name": "entity.name.type.option.rust", | ||
993 | "match": "\\b(Some|None)\\b" | ||
994 | }, | ||
995 | { | ||
996 | "comment": "result types", | ||
997 | "name": "entity.name.type.result.rust", | ||
998 | "match": "\\b(Ok|Err)\\b" | ||
999 | } | ||
1000 | ] | ||
1001 | }, | ||
1002 | "punctuation": { | ||
1003 | "patterns": [ | ||
1004 | { | ||
1005 | "comment": "comma", | ||
1006 | "name": "punctuation.comma.rust", | ||
1007 | "match": "," | ||
1008 | }, | ||
1009 | { | ||
1010 | "comment": "curly braces", | ||
1011 | "name": "punctuation.brackets.curly.rust", | ||
1012 | "match": "[{}]" | ||
1013 | }, | ||
1014 | { | ||
1015 | "comment": "parentheses, round brackets", | ||
1016 | "name": "punctuation.brackets.round.rust", | ||
1017 | "match": "[()]" | ||
1018 | }, | ||
1019 | { | ||
1020 | "comment": "semicolon", | ||
1021 | "name": "punctuation.semi.rust", | ||
1022 | "match": ";" | ||
1023 | }, | ||
1024 | { | ||
1025 | "comment": "square brackets", | ||
1026 | "name": "punctuation.brackets.square.rust", | ||
1027 | "match": "[\\[\\]]" | ||
1028 | }, | ||
1029 | { | ||
1030 | "comment": "angle brackets", | ||
1031 | "name": "punctuation.brackets.angle.rust", | ||
1032 | "match": "(?<!=)[<>]" | ||
1033 | } | ||
1034 | ] | ||
1035 | }, | ||
1036 | "strings": { | ||
1037 | "patterns": [ | ||
1038 | { | ||
1039 | "comment": "double-quoted strings and byte strings", | ||
1040 | "name": "string.quoted.double.rust", | ||
1041 | "begin": "(b?)(\")", | ||
1042 | "beginCaptures": { | ||
1043 | "1": { | ||
1044 | "name": "string.quoted.byte.raw.rust" | ||
1045 | }, | ||
1046 | "2": { | ||
1047 | "name": "punctuation.definition.string.rust" | ||
1048 | } | ||
1049 | }, | ||
1050 | "end": "\"", | ||
1051 | "endCaptures": { | ||
1052 | "0": { | ||
1053 | "name": "punctuation.definition.string.rust" | ||
1054 | } | ||
1055 | }, | ||
1056 | "patterns": [ | ||
1057 | { | ||
1058 | "include": "#escapes" | ||
1059 | }, | ||
1060 | { | ||
1061 | "include": "#interpolations" | ||
1062 | } | ||
1063 | ] | ||
1064 | }, | ||
1065 | { | ||
1066 | "comment": "double-quoted raw strings and raw byte strings", | ||
1067 | "name": "string.quoted.double.rust", | ||
1068 | "begin": "(b?r)(#*)(\")", | ||
1069 | "beginCaptures": { | ||
1070 | "1": { | ||
1071 | "name": "string.quoted.byte.raw.rust" | ||
1072 | }, | ||
1073 | "2": { | ||
1074 | "name": "punctuation.definition.string.raw.rust" | ||
1075 | }, | ||
1076 | "3": { | ||
1077 | "name": "punctuation.definition.string.rust" | ||
1078 | } | ||
1079 | }, | ||
1080 | "end": "(\")(\\2)", | ||
1081 | "endCaptures": { | ||
1082 | "1": { | ||
1083 | "name": "punctuation.definition.string.rust" | ||
1084 | }, | ||
1085 | "2": { | ||
1086 | "name": "punctuation.definition.string.raw.rust" | ||
1087 | } | ||
1088 | } | ||
1089 | }, | ||
1090 | { | ||
1091 | "comment": "characters and bytes", | ||
1092 | "name": "string.quoted.single.char.rust", | ||
1093 | "begin": "(b)?(')", | ||
1094 | "beginCaptures": { | ||
1095 | "1": { | ||
1096 | "name": "string.quoted.byte.raw.rust" | ||
1097 | }, | ||
1098 | "2": { | ||
1099 | "name": "punctuation.definition.char.rust" | ||
1100 | } | ||
1101 | }, | ||
1102 | "end": "'", | ||
1103 | "endCaptures": { | ||
1104 | "0": { | ||
1105 | "name": "punctuation.definition.char.rust" | ||
1106 | } | ||
1107 | }, | ||
1108 | "patterns": [ | ||
1109 | { | ||
1110 | "include": "#escapes" | ||
1111 | } | ||
1112 | ] | ||
1113 | } | ||
1114 | ] | ||
1115 | }, | ||
1116 | "lvariables": { | ||
1117 | "patterns": [ | ||
1118 | { | ||
1119 | "comment": "self", | ||
1120 | "name": "variable.language.self.rust", | ||
1121 | "match": "\\b[Ss]elf\\b" | ||
1122 | }, | ||
1123 | { | ||
1124 | "comment": "super", | ||
1125 | "name": "variable.language.super.rust", | ||
1126 | "match": "\\bsuper\\b" | ||
1127 | } | ||
1128 | ] | ||
1129 | }, | ||
1130 | "variables": { | ||
1131 | "patterns": [ | ||
1132 | { | ||
1133 | "comment": "variables", | ||
1134 | "name": "variable.other.rust", | ||
1135 | "match": "\\b(?<!(?<!\\.)\\.)(?:r#(?!(crate|[Ss]elf|super)))?[a-z0-9_]+\\b" | ||
1136 | } | ||
1137 | ] | ||
1138 | } | ||
1139 | } | ||
1140 | } | ||
diff --git a/editors/code/src/main.ts b/editors/code/src/main.ts index 191960960..4b2d3c8a5 100644 --- a/editors/code/src/main.ts +++ b/editors/code/src/main.ts | |||
@@ -19,9 +19,8 @@ let ctx: Ctx | undefined; | |||
19 | const RUST_PROJECT_CONTEXT_NAME = "inRustProject"; | 19 | const RUST_PROJECT_CONTEXT_NAME = "inRustProject"; |
20 | 20 | ||
21 | export async function activate(context: vscode.ExtensionContext) { | 21 | export async function activate(context: vscode.ExtensionContext) { |
22 | // For some reason vscode not always shows pop-up error notifications | 22 | // VS Code doesn't show a notification when an extension fails to activate |
23 | // when an extension fails to activate, so we do it explicitly by ourselves. | 23 | // so we do it ourselves. |
24 | // FIXME: remove this bit of code once vscode fixes this issue: https://github.com/microsoft/vscode/issues/101242 | ||
25 | await tryActivate(context).catch(err => { | 24 | await tryActivate(context).catch(err => { |
26 | void vscode.window.showErrorMessage(`Cannot activate rust-analyzer: ${err.message}`); | 25 | void vscode.window.showErrorMessage(`Cannot activate rust-analyzer: ${err.message}`); |
27 | throw err; | 26 | throw err; |
@@ -292,6 +291,8 @@ async function getServer(config: Config, state: PersistentState): Promise<string | |||
292 | if (process.platform === "linux") platform = "linux"; | 291 | if (process.platform === "linux") platform = "linux"; |
293 | if (process.platform === "darwin") platform = "mac"; | 292 | if (process.platform === "darwin") platform = "mac"; |
294 | if (process.platform === "win32") platform = "windows"; | 293 | if (process.platform === "win32") platform = "windows"; |
294 | } else if (process.arch === "arm64" && process.platform === "darwin") { | ||
295 | platform = "mac"; | ||
295 | } | 296 | } |
296 | if (platform === undefined) { | 297 | if (platform === undefined) { |
297 | vscode.window.showErrorMessage( | 298 | vscode.window.showErrorMessage( |
@@ -340,7 +341,7 @@ async function getServer(config: Config, state: PersistentState): Promise<string | |||
340 | }); | 341 | }); |
341 | 342 | ||
342 | // Patching executable if that's NixOS. | 343 | // Patching executable if that's NixOS. |
343 | if (await fs.stat("/etc/nixos").then(_ => true).catch(_ => false)) { | 344 | if (await isNixOs()) { |
344 | await patchelf(dest); | 345 | await patchelf(dest); |
345 | } | 346 | } |
346 | 347 | ||
@@ -348,6 +349,15 @@ async function getServer(config: Config, state: PersistentState): Promise<string | |||
348 | return dest; | 349 | return dest; |
349 | } | 350 | } |
350 | 351 | ||
352 | async function isNixOs(): Promise<boolean> { | ||
353 | try { | ||
354 | const contents = await fs.readFile("/etc/os-release"); | ||
355 | return contents.indexOf("ID=nixos") !== -1; | ||
356 | } catch (e) { | ||
357 | return false; | ||
358 | } | ||
359 | } | ||
360 | |||
351 | async function downloadWithRetryDialog<T>(state: PersistentState, downloadFunc: () => Promise<T>): Promise<T> { | 361 | async function downloadWithRetryDialog<T>(state: PersistentState, downloadFunc: () => Promise<T>): Promise<T> { |
352 | while (true) { | 362 | while (true) { |
353 | try { | 363 | try { |