diff options
Diffstat (limited to 'crates')
-rw-r--r-- | crates/completion/src/completions/keyword.rs | 8 | ||||
-rw-r--r-- | crates/hir_ty/Cargo.toml | 6 | ||||
-rw-r--r-- | crates/hir_ty/src/method_resolution.rs | 27 | ||||
-rw-r--r-- | crates/hir_ty/src/tests/method_resolution.rs | 22 | ||||
-rw-r--r-- | crates/hir_ty/src/traits/chalk/interner.rs | 5 | ||||
-rw-r--r-- | crates/ide/src/join_lines.rs | 41 | ||||
-rw-r--r-- | crates/ide/src/syntax_tree.rs | 366 | ||||
-rw-r--r-- | crates/rust-analyzer/src/cli/analysis_bench.rs | 14 | ||||
-rw-r--r-- | crates/rust-analyzer/src/cli/analysis_stats.rs | 13 | ||||
-rw-r--r-- | crates/rust-analyzer/src/cli/diagnostics.rs | 18 | ||||
-rw-r--r-- | crates/rust-analyzer/src/cli/load_cargo.rs | 26 | ||||
-rw-r--r-- | crates/rust-analyzer/src/cli/ssr.rs | 19 | ||||
-rw-r--r-- | crates/syntax/Cargo.toml | 2 |
13 files changed, 313 insertions, 254 deletions
diff --git a/crates/completion/src/completions/keyword.rs b/crates/completion/src/completions/keyword.rs index 47e146128..eb81f9765 100644 --- a/crates/completion/src/completions/keyword.rs +++ b/crates/completion/src/completions/keyword.rs | |||
@@ -88,6 +88,7 @@ pub(crate) fn complete_expr_keyword(acc: &mut Completions, ctx: &CompletionConte | |||
88 | add_keyword(ctx, acc, "loop", "loop {$0}"); | 88 | add_keyword(ctx, acc, "loop", "loop {$0}"); |
89 | add_keyword(ctx, acc, "if", "if $0 {}"); | 89 | add_keyword(ctx, acc, "if", "if $0 {}"); |
90 | add_keyword(ctx, acc, "if let", "if let $1 = $0 {}"); | 90 | add_keyword(ctx, acc, "if let", "if let $1 = $0 {}"); |
91 | add_keyword(ctx, acc, "for", "for $1 in $0 {}"); | ||
91 | } | 92 | } |
92 | 93 | ||
93 | if ctx.if_is_prev || ctx.block_expr_parent { | 94 | if ctx.if_is_prev || ctx.block_expr_parent { |
@@ -258,6 +259,7 @@ mod tests { | |||
258 | kw loop | 259 | kw loop |
259 | kw if | 260 | kw if |
260 | kw if let | 261 | kw if let |
262 | kw for | ||
261 | kw let | 263 | kw let |
262 | kw mod | 264 | kw mod |
263 | kw const | 265 | kw const |
@@ -284,6 +286,7 @@ mod tests { | |||
284 | kw loop | 286 | kw loop |
285 | kw if | 287 | kw if |
286 | kw if let | 288 | kw if let |
289 | kw for | ||
287 | kw let | 290 | kw let |
288 | kw mod | 291 | kw mod |
289 | kw const | 292 | kw const |
@@ -310,6 +313,7 @@ mod tests { | |||
310 | kw loop | 313 | kw loop |
311 | kw if | 314 | kw if |
312 | kw if let | 315 | kw if let |
316 | kw for | ||
313 | kw let | 317 | kw let |
314 | kw else | 318 | kw else |
315 | kw else if | 319 | kw else if |
@@ -343,6 +347,7 @@ fn quux() -> i32 { | |||
343 | kw loop | 347 | kw loop |
344 | kw if | 348 | kw if |
345 | kw if let | 349 | kw if let |
350 | kw for | ||
346 | kw unsafe | 351 | kw unsafe |
347 | kw return | 352 | kw return |
348 | "#]], | 353 | "#]], |
@@ -391,6 +396,7 @@ fn quux() -> i32 { | |||
391 | kw loop | 396 | kw loop |
392 | kw if | 397 | kw if |
393 | kw if let | 398 | kw if let |
399 | kw for | ||
394 | kw let | 400 | kw let |
395 | kw mod | 401 | kw mod |
396 | kw const | 402 | kw const |
@@ -549,6 +555,7 @@ pub mod future { | |||
549 | kw loop | 555 | kw loop |
550 | kw if | 556 | kw if |
551 | kw if let | 557 | kw if let |
558 | kw for | ||
552 | kw return | 559 | kw return |
553 | "#]], | 560 | "#]], |
554 | ) | 561 | ) |
@@ -607,6 +614,7 @@ fn foo() { | |||
607 | kw loop | 614 | kw loop |
608 | kw if | 615 | kw if |
609 | kw if let | 616 | kw if let |
617 | kw for | ||
610 | kw return | 618 | kw return |
611 | "#]], | 619 | "#]], |
612 | ); | 620 | ); |
diff --git a/crates/hir_ty/Cargo.toml b/crates/hir_ty/Cargo.toml index f6bf49546..418ac8cbb 100644 --- a/crates/hir_ty/Cargo.toml +++ b/crates/hir_ty/Cargo.toml | |||
@@ -17,9 +17,9 @@ ena = "0.14.0" | |||
17 | log = "0.4.8" | 17 | log = "0.4.8" |
18 | rustc-hash = "1.1.0" | 18 | rustc-hash = "1.1.0" |
19 | scoped-tls = "1" | 19 | scoped-tls = "1" |
20 | chalk-solve = { version = "0.55", default-features = false } | 20 | chalk-solve = { version = "0.56", default-features = false } |
21 | chalk-ir = "0.55" | 21 | chalk-ir = "0.56" |
22 | chalk-recursive = "0.55" | 22 | chalk-recursive = "0.56" |
23 | la-arena = { version = "0.2.0", path = "../../lib/arena" } | 23 | la-arena = { version = "0.2.0", path = "../../lib/arena" } |
24 | 24 | ||
25 | stdx = { path = "../stdx", version = "0.0.0" } | 25 | stdx = { path = "../stdx", version = "0.0.0" } |
diff --git a/crates/hir_ty/src/method_resolution.rs b/crates/hir_ty/src/method_resolution.rs index a302456b0..b3d1fe9a4 100644 --- a/crates/hir_ty/src/method_resolution.rs +++ b/crates/hir_ty/src/method_resolution.rs | |||
@@ -10,25 +10,26 @@ use hir_def::{ | |||
10 | builtin_type::{IntBitness, Signedness}, | 10 | builtin_type::{IntBitness, Signedness}, |
11 | lang_item::LangItemTarget, | 11 | lang_item::LangItemTarget, |
12 | type_ref::Mutability, | 12 | type_ref::Mutability, |
13 | AssocContainerId, AssocItemId, FunctionId, HasModule, ImplId, Lookup, TraitId, | 13 | AssocContainerId, AssocItemId, FunctionId, GenericDefId, HasModule, ImplId, Lookup, ModuleId, |
14 | TraitId, | ||
14 | }; | 15 | }; |
15 | use hir_expand::name::Name; | 16 | use hir_expand::name::Name; |
16 | use rustc_hash::{FxHashMap, FxHashSet}; | 17 | use rustc_hash::{FxHashMap, FxHashSet}; |
17 | 18 | ||
18 | use super::Substs; | ||
19 | use crate::{ | 19 | use crate::{ |
20 | autoderef, | 20 | autoderef, |
21 | db::HirDatabase, | 21 | db::HirDatabase, |
22 | primitive::{FloatBitness, FloatTy, IntTy}, | 22 | primitive::{FloatBitness, FloatTy, IntTy}, |
23 | utils::all_super_traits, | 23 | utils::all_super_traits, |
24 | ApplicationTy, Canonical, DebruijnIndex, InEnvironment, TraitEnvironment, TraitRef, Ty, TyKind, | 24 | ApplicationTy, Canonical, DebruijnIndex, InEnvironment, Substs, TraitEnvironment, TraitRef, Ty, |
25 | TypeCtor, TypeWalk, | 25 | TyKind, TypeCtor, TypeWalk, |
26 | }; | 26 | }; |
27 | 27 | ||
28 | /// This is used as a key for indexing impls. | 28 | /// This is used as a key for indexing impls. |
29 | #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] | 29 | #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] |
30 | pub enum TyFingerprint { | 30 | pub enum TyFingerprint { |
31 | Apply(TypeCtor), | 31 | Apply(TypeCtor), |
32 | Dyn(TraitId), | ||
32 | } | 33 | } |
33 | 34 | ||
34 | impl TyFingerprint { | 35 | impl TyFingerprint { |
@@ -38,6 +39,7 @@ impl TyFingerprint { | |||
38 | pub(crate) fn for_impl(ty: &Ty) -> Option<TyFingerprint> { | 39 | pub(crate) fn for_impl(ty: &Ty) -> Option<TyFingerprint> { |
39 | match ty { | 40 | match ty { |
40 | Ty::Apply(a_ty) => Some(TyFingerprint::Apply(a_ty.ctor)), | 41 | Ty::Apply(a_ty) => Some(TyFingerprint::Apply(a_ty.ctor)), |
42 | Ty::Dyn(_) => ty.dyn_trait().map(|trait_| TyFingerprint::Dyn(trait_)), | ||
41 | _ => None, | 43 | _ => None, |
42 | } | 44 | } |
43 | } | 45 | } |
@@ -245,18 +247,15 @@ impl Ty { | |||
245 | }}; | 247 | }}; |
246 | } | 248 | } |
247 | 249 | ||
250 | let mod_to_crate_ids = |module: ModuleId| Some(std::iter::once(module.krate()).collect()); | ||
251 | |||
248 | let lang_item_targets = match self { | 252 | let lang_item_targets = match self { |
249 | Ty::Apply(a_ty) => match a_ty.ctor { | 253 | Ty::Apply(a_ty) => match a_ty.ctor { |
250 | TypeCtor::Adt(def_id) => { | 254 | TypeCtor::Adt(def_id) => { |
251 | return Some(std::iter::once(def_id.module(db.upcast()).krate()).collect()) | 255 | return mod_to_crate_ids(def_id.module(db.upcast())); |
252 | } | 256 | } |
253 | TypeCtor::ForeignType(type_alias_id) => { | 257 | TypeCtor::ForeignType(type_alias_id) => { |
254 | return Some( | 258 | return mod_to_crate_ids(type_alias_id.lookup(db.upcast()).module(db.upcast())); |
255 | std::iter::once( | ||
256 | type_alias_id.lookup(db.upcast()).module(db.upcast()).krate(), | ||
257 | ) | ||
258 | .collect(), | ||
259 | ) | ||
260 | } | 259 | } |
261 | TypeCtor::Bool => lang_item_crate!("bool"), | 260 | TypeCtor::Bool => lang_item_crate!("bool"), |
262 | TypeCtor::Char => lang_item_crate!("char"), | 261 | TypeCtor::Char => lang_item_crate!("char"), |
@@ -272,6 +271,11 @@ impl Ty { | |||
272 | TypeCtor::RawPtr(Mutability::Mut) => lang_item_crate!("mut_ptr"), | 271 | TypeCtor::RawPtr(Mutability::Mut) => lang_item_crate!("mut_ptr"), |
273 | _ => return None, | 272 | _ => return None, |
274 | }, | 273 | }, |
274 | Ty::Dyn(_) => { | ||
275 | return self.dyn_trait().and_then(|trait_| { | ||
276 | mod_to_crate_ids(GenericDefId::TraitId(trait_).module(db.upcast())) | ||
277 | }); | ||
278 | } | ||
275 | _ => return None, | 279 | _ => return None, |
276 | }; | 280 | }; |
277 | let res = lang_item_targets | 281 | let res = lang_item_targets |
@@ -285,6 +289,7 @@ impl Ty { | |||
285 | Some(res) | 289 | Some(res) |
286 | } | 290 | } |
287 | } | 291 | } |
292 | |||
288 | /// Look up the method with the given name, returning the actual autoderefed | 293 | /// Look up the method with the given name, returning the actual autoderefed |
289 | /// receiver type (but without autoref applied yet). | 294 | /// receiver type (but without autoref applied yet). |
290 | pub(crate) fn lookup_method( | 295 | pub(crate) fn lookup_method( |
diff --git a/crates/hir_ty/src/tests/method_resolution.rs b/crates/hir_ty/src/tests/method_resolution.rs index a6a54e542..80e795fbf 100644 --- a/crates/hir_ty/src/tests/method_resolution.rs +++ b/crates/hir_ty/src/tests/method_resolution.rs | |||
@@ -1106,3 +1106,25 @@ fn main() { | |||
1106 | "#, | 1106 | "#, |
1107 | ); | 1107 | ); |
1108 | } | 1108 | } |
1109 | |||
1110 | #[test] | ||
1111 | fn method_on_dyn_impl() { | ||
1112 | check_types( | ||
1113 | r#" | ||
1114 | trait Foo {} | ||
1115 | |||
1116 | impl Foo for u32 {} | ||
1117 | impl dyn Foo { | ||
1118 | pub fn dyn_foo(&self) -> u32 { | ||
1119 | 0 | ||
1120 | } | ||
1121 | } | ||
1122 | |||
1123 | fn main() { | ||
1124 | let f = &42u32 as &dyn Foo<u32>; | ||
1125 | f.dyn_foo(); | ||
1126 | // ^u32 | ||
1127 | } | ||
1128 | "#, | ||
1129 | ); | ||
1130 | } | ||
diff --git a/crates/hir_ty/src/traits/chalk/interner.rs b/crates/hir_ty/src/traits/chalk/interner.rs index 6a4aa8333..54bd1c724 100644 --- a/crates/hir_ty/src/traits/chalk/interner.rs +++ b/crates/hir_ty/src/traits/chalk/interner.rs | |||
@@ -193,8 +193,9 @@ impl chalk_ir::interner::Interner for Interner { | |||
193 | tls::with_current_program(|prog| Some(prog?.debug_quantified_where_clauses(clauses, fmt))) | 193 | tls::with_current_program(|prog| Some(prog?.debug_quantified_where_clauses(clauses, fmt))) |
194 | } | 194 | } |
195 | 195 | ||
196 | fn intern_ty(&self, ty: chalk_ir::TyData<Self>) -> Arc<chalk_ir::TyData<Self>> { | 196 | fn intern_ty(&self, kind: chalk_ir::TyKind<Self>) -> Arc<chalk_ir::TyData<Self>> { |
197 | Arc::new(ty) | 197 | let flags = kind.compute_flags(self); |
198 | Arc::new(chalk_ir::TyData { kind, flags }) | ||
198 | } | 199 | } |
199 | 200 | ||
200 | fn ty_data<'a>(&self, ty: &'a Arc<chalk_ir::TyData<Self>>) -> &'a chalk_ir::TyData<Self> { | 201 | fn ty_data<'a>(&self, ty: &'a Arc<chalk_ir::TyData<Self>>) -> &'a chalk_ir::TyData<Self> { |
diff --git a/crates/ide/src/join_lines.rs b/crates/ide/src/join_lines.rs index 631bde0f1..e3f3985d1 100644 --- a/crates/ide/src/join_lines.rs +++ b/crates/ide/src/join_lines.rs | |||
@@ -270,27 +270,28 @@ fn foo() { | |||
270 | 270 | ||
271 | #[test] | 271 | #[test] |
272 | fn test_join_lines_diverging_block() { | 272 | fn test_join_lines_diverging_block() { |
273 | let before = r" | 273 | check_join_lines( |
274 | fn foo() { | 274 | r" |
275 | loop { | 275 | fn foo() { |
276 | match x { | 276 | loop { |
277 | 92 => $0{ | 277 | match x { |
278 | continue; | 278 | 92 => $0{ |
279 | } | 279 | continue; |
280 | } | ||
281 | } | ||
282 | } | ||
283 | "; | ||
284 | let after = r" | ||
285 | fn foo() { | ||
286 | loop { | ||
287 | match x { | ||
288 | 92 => $0continue, | ||
289 | } | ||
290 | } | ||
291 | } | 280 | } |
292 | "; | 281 | } |
293 | check_join_lines(before, after); | 282 | } |
283 | } | ||
284 | ", | ||
285 | r" | ||
286 | fn foo() { | ||
287 | loop { | ||
288 | match x { | ||
289 | 92 => $0continue, | ||
290 | } | ||
291 | } | ||
292 | } | ||
293 | ", | ||
294 | ); | ||
294 | } | 295 | } |
295 | 296 | ||
296 | #[test] | 297 | #[test] |
diff --git a/crates/ide/src/syntax_tree.rs b/crates/ide/src/syntax_tree.rs index 4c63d3023..f979ba434 100644 --- a/crates/ide/src/syntax_tree.rs +++ b/crates/ide/src/syntax_tree.rs | |||
@@ -100,147 +100,137 @@ fn syntax_tree_for_token(node: &SyntaxToken, text_range: TextRange) -> Option<St | |||
100 | 100 | ||
101 | #[cfg(test)] | 101 | #[cfg(test)] |
102 | mod tests { | 102 | mod tests { |
103 | use test_utils::assert_eq_text; | 103 | use expect_test::expect; |
104 | 104 | ||
105 | use crate::fixture; | 105 | use crate::fixture; |
106 | 106 | ||
107 | fn check(ra_fixture: &str, expect: expect_test::Expect) { | ||
108 | let (analysis, file_id) = fixture::file(ra_fixture); | ||
109 | let syn = analysis.syntax_tree(file_id, None).unwrap(); | ||
110 | expect.assert_eq(&syn) | ||
111 | } | ||
112 | fn check_range(ra_fixture: &str, expect: expect_test::Expect) { | ||
113 | let (analysis, frange) = fixture::range(ra_fixture); | ||
114 | let syn = analysis.syntax_tree(frange.file_id, Some(frange.range)).unwrap(); | ||
115 | expect.assert_eq(&syn) | ||
116 | } | ||
117 | |||
107 | #[test] | 118 | #[test] |
108 | fn test_syntax_tree_without_range() { | 119 | fn test_syntax_tree_without_range() { |
109 | // Basic syntax | 120 | // Basic syntax |
110 | let (analysis, file_id) = fixture::file(r#"fn foo() {}"#); | 121 | check( |
111 | let syn = analysis.syntax_tree(file_id, None).unwrap(); | 122 | r#"fn foo() {}"#, |
112 | 123 | expect![[r#" | |
113 | assert_eq_text!( | 124 | [email protected] |
114 | r#" | 125 | [email protected] |
115 | [email protected] | 126 | [email protected] "fn" |
116 | [email protected] | 127 | [email protected] " " |
117 | [email protected] "fn" | 128 | [email protected] |
118 | [email protected] " " | 129 | [email protected] "foo" |
119 | [email protected] | 130 | [email protected] |
120 | [email protected] "foo" | 131 | [email protected] "(" |
121 | [email protected] | 132 | [email protected] ")" |
122 | [email protected] "(" | 133 | [email protected] " " |
123 | [email protected] ")" | 134 | [email protected] |
124 | [email protected] " " | 135 | [email protected] "{" |
125 | [email protected] | 136 | [email protected] "}" |
126 | [email protected] "{" | 137 | "#]], |
127 | [email protected] "}" | ||
128 | "# | ||
129 | .trim(), | ||
130 | syn.trim() | ||
131 | ); | 138 | ); |
132 | 139 | ||
133 | let (analysis, file_id) = fixture::file( | 140 | check( |
134 | r#" | 141 | r#" |
135 | fn test() { | 142 | fn test() { |
136 | assert!(" | 143 | assert!(" |
137 | fn foo() { | 144 | fn foo() { |
138 | } | 145 | } |
139 | ", ""); | 146 | ", ""); |
140 | }"# | 147 | }"#, |
141 | .trim(), | 148 | expect![[r#" |
142 | ); | 149 | [email protected] |
143 | let syn = analysis.syntax_tree(file_id, None).unwrap(); | 150 | [email protected] |
144 | 151 | [email protected] "fn" | |
145 | assert_eq_text!( | 152 | [email protected] " " |
146 | r#" | 153 | [email protected] |
147 | [email protected] | 154 | [email protected] "test" |
148 | [email protected] | 155 | [email protected] |
149 | [email protected] "fn" | 156 | [email protected] "(" |
150 | [email protected] " " | 157 | [email protected] ")" |
151 | [email protected] | 158 | [email protected] " " |
152 | [email protected] "test" | 159 | [email protected] |
153 | [email protected] | 160 | [email protected] "{" |
154 | [email protected] "(" | 161 | [email protected] "\n " |
155 | [email protected] ")" | 162 | [email protected] |
156 | [email protected] " " | 163 | [email protected] |
157 | [email protected] | 164 | [email protected] |
158 | [email protected] "{" | 165 | [email protected] |
159 | [email protected] "\n " | 166 | [email protected] |
160 | [email protected] | 167 | [email protected] "assert" |
161 | [email protected] | 168 | [email protected] "!" |
162 | [email protected] | 169 | [email protected] |
163 | [email protected] | 170 | [email protected] "(" |
164 | [email protected] | 171 | [email protected] "\"\n fn foo() {\n ..." |
165 | [email protected] "assert" | 172 | [email protected] "," |
166 | [email protected] "!" | 173 | [email protected] " " |
167 | [email protected] | 174 | [email protected] "\"\"" |
168 | [email protected] "(" | 175 | [email protected] ")" |
169 | [email protected] "\"\n fn foo() {\n ..." | 176 | [email protected] ";" |
170 | [email protected] "," | 177 | [email protected] "\n" |
171 | [email protected] " " | 178 | [email protected] "}" |
172 | [email protected] "\"\"" | 179 | "#]], |
173 | [email protected] ")" | 180 | ) |
174 | [email protected] ";" | ||
175 | [email protected] "\n" | ||
176 | [email protected] "}" | ||
177 | "# | ||
178 | .trim(), | ||
179 | syn.trim() | ||
180 | ); | ||
181 | } | 181 | } |
182 | 182 | ||
183 | #[test] | 183 | #[test] |
184 | fn test_syntax_tree_with_range() { | 184 | fn test_syntax_tree_with_range() { |
185 | let (analysis, range) = fixture::range(r#"$0fn foo() {}$0"#.trim()); | 185 | check_range( |
186 | let syn = analysis.syntax_tree(range.file_id, Some(range.range)).unwrap(); | 186 | r#"$0fn foo() {}$0"#, |
187 | 187 | expect![[r#" | |
188 | assert_eq_text!( | 188 | [email protected] |
189 | r#" | 189 | [email protected] "fn" |
190 | [email protected] | 190 | [email protected] " " |
191 | [email protected] "fn" | 191 | [email protected] |
192 | [email protected] " " | 192 | [email protected] "foo" |
193 | [email protected] | 193 | [email protected] |
194 | [email protected] "foo" | 194 | [email protected] "(" |
195 | [email protected] | 195 | [email protected] ")" |
196 | [email protected] "(" | 196 | [email protected] " " |
197 | [email protected] ")" | 197 | [email protected] |
198 | [email protected] " " | 198 | [email protected] "{" |
199 | [email protected] | 199 | [email protected] "}" |
200 | [email protected] "{" | 200 | "#]], |
201 | [email protected] "}" | ||
202 | "# | ||
203 | .trim(), | ||
204 | syn.trim() | ||
205 | ); | 201 | ); |
206 | 202 | ||
207 | let (analysis, range) = fixture::range( | 203 | check_range( |
208 | r#"fn test() { | 204 | r#" |
205 | fn test() { | ||
209 | $0assert!(" | 206 | $0assert!(" |
210 | fn foo() { | 207 | fn foo() { |
211 | } | 208 | } |
212 | ", "");$0 | 209 | ", "");$0 |
213 | }"# | 210 | }"#, |
214 | .trim(), | 211 | expect![[r#" |
215 | ); | 212 | [email protected] |
216 | let syn = analysis.syntax_tree(range.file_id, Some(range.range)).unwrap(); | 213 | [email protected] |
217 | 214 | [email protected] | |
218 | assert_eq_text!( | 215 | [email protected] |
219 | r#" | 216 | [email protected] |
220 | [email protected] | 217 | [email protected] "assert" |
221 | [email protected] | 218 | [email protected] "!" |
222 | [email protected] | 219 | [email protected] |
223 | [email protected] | 220 | [email protected] "(" |
224 | [email protected] | 221 | [email protected] "\"\n fn foo() {\n ..." |
225 | [email protected] "assert" | 222 | [email protected] "," |
226 | [email protected] "!" | 223 | [email protected] " " |
227 | [email protected] | 224 | [email protected] "\"\"" |
228 | [email protected] "(" | 225 | [email protected] ")" |
229 | [email protected] "\"\n fn foo() {\n ..." | 226 | [email protected] ";" |
230 | [email protected] "," | 227 | "#]], |
231 | [email protected] " " | ||
232 | [email protected] "\"\"" | ||
233 | [email protected] ")" | ||
234 | [email protected] ";" | ||
235 | "# | ||
236 | .trim(), | ||
237 | syn.trim() | ||
238 | ); | 228 | ); |
239 | } | 229 | } |
240 | 230 | ||
241 | #[test] | 231 | #[test] |
242 | fn test_syntax_tree_inside_string() { | 232 | fn test_syntax_tree_inside_string() { |
243 | let (analysis, range) = fixture::range( | 233 | check_range( |
244 | r#"fn test() { | 234 | r#"fn test() { |
245 | assert!(" | 235 | assert!(" |
246 | $0fn foo() { | 236 | $0fn foo() { |
@@ -248,33 +238,27 @@ $0fn foo() { | |||
248 | fn bar() { | 238 | fn bar() { |
249 | } | 239 | } |
250 | ", ""); | 240 | ", ""); |
251 | }"# | 241 | }"#, |
252 | .trim(), | 242 | expect![[r#" |
253 | ); | 243 | [email protected] |
254 | let syn = analysis.syntax_tree(range.file_id, Some(range.range)).unwrap(); | 244 | [email protected] |
255 | assert_eq_text!( | 245 | [email protected] "fn" |
256 | r#" | 246 | [email protected] " " |
257 | [email protected] | 247 | [email protected] |
258 | [email protected] | 248 | [email protected] "foo" |
259 | [email protected] "fn" | 249 | [email protected] |
260 | [email protected] " " | 250 | [email protected] "(" |
261 | [email protected] | 251 | [email protected] ")" |
262 | [email protected] "foo" | 252 | [email protected] " " |
263 | [email protected] | 253 | [email protected] |
264 | [email protected] "(" | 254 | [email protected] "{" |
265 | [email protected] ")" | 255 | [email protected] "\n" |
266 | [email protected] " " | 256 | [email protected] "}" |
267 | [email protected] | 257 | "#]], |
268 | [email protected] "{" | ||
269 | [email protected] "\n" | ||
270 | [email protected] "}" | ||
271 | "# | ||
272 | .trim(), | ||
273 | syn.trim() | ||
274 | ); | 258 | ); |
275 | 259 | ||
276 | // With a raw string | 260 | // With a raw string |
277 | let (analysis, range) = fixture::range( | 261 | check_range( |
278 | r###"fn test() { | 262 | r###"fn test() { |
279 | assert!(r#" | 263 | assert!(r#" |
280 | $0fn foo() { | 264 | $0fn foo() { |
@@ -282,76 +266,64 @@ $0fn foo() { | |||
282 | fn bar() { | 266 | fn bar() { |
283 | } | 267 | } |
284 | "#, ""); | 268 | "#, ""); |
285 | }"### | 269 | }"###, |
286 | .trim(), | 270 | expect![[r#" |
287 | ); | 271 | [email protected] |
288 | let syn = analysis.syntax_tree(range.file_id, Some(range.range)).unwrap(); | 272 | [email protected] |
289 | assert_eq_text!( | 273 | [email protected] "fn" |
290 | r#" | 274 | [email protected] " " |
291 | [email protected] | 275 | [email protected] |
292 | [email protected] | 276 | [email protected] "foo" |
293 | [email protected] "fn" | 277 | [email protected] |
294 | [email protected] " " | 278 | [email protected] "(" |
295 | [email protected] | 279 | [email protected] ")" |
296 | [email protected] "foo" | 280 | [email protected] " " |
297 | [email protected] | 281 | [email protected] |
298 | [email protected] "(" | 282 | [email protected] "{" |
299 | [email protected] ")" | 283 | [email protected] "\n" |
300 | [email protected] " " | 284 | [email protected] "}" |
301 | [email protected] | 285 | "#]], |
302 | [email protected] "{" | ||
303 | [email protected] "\n" | ||
304 | [email protected] "}" | ||
305 | "# | ||
306 | .trim(), | ||
307 | syn.trim() | ||
308 | ); | 286 | ); |
309 | 287 | ||
310 | // With a raw string | 288 | // With a raw string |
311 | let (analysis, range) = fixture::range( | 289 | check_range( |
312 | r###"fn test() { | 290 | r###"fn test() { |
313 | assert!(r$0#" | 291 | assert!(r$0#" |
314 | fn foo() { | 292 | fn foo() { |
315 | } | 293 | } |
316 | fn bar() { | 294 | fn bar() { |
317 | }"$0#, ""); | 295 | }"$0#, ""); |
318 | }"### | 296 | }"###, |
319 | .trim(), | 297 | expect![[r#" |
320 | ); | 298 | [email protected] |
321 | let syn = analysis.syntax_tree(range.file_id, Some(range.range)).unwrap(); | 299 | [email protected] |
322 | assert_eq_text!( | 300 | [email protected] "fn" |
323 | r#" | 301 | [email protected] " " |
324 | [email protected] | 302 | [email protected] |
325 | [email protected] | 303 | [email protected] "foo" |
326 | [email protected] "fn" | 304 | [email protected] |
327 | [email protected] " " | 305 | [email protected] "(" |
328 | [email protected] | 306 | [email protected] ")" |
329 | [email protected] "foo" | 307 | [email protected] " " |
330 | [email protected] | 308 | [email protected] |
331 | [email protected] "(" | 309 | [email protected] "{" |
332 | [email protected] ")" | 310 | [email protected] "\n" |
333 | [email protected] " " | 311 | [email protected] "}" |
334 | [email protected] | 312 | [email protected] "\n" |
335 | [email protected] "{" | 313 | [email protected] |
336 | [email protected] "\n" | 314 | [email protected] "fn" |
337 | [email protected] "}" | 315 | [email protected] " " |
338 | [email protected] "\n" | 316 | [email protected] |
339 | [email protected] | 317 | [email protected] "bar" |
340 | [email protected] "fn" | 318 | [email protected] |
341 | [email protected] " " | 319 | [email protected] "(" |
342 | [email protected] | 320 | [email protected] ")" |
343 | [email protected] "bar" | 321 | [email protected] " " |
344 | [email protected] | 322 | [email protected] |
345 | [email protected] "(" | 323 | [email protected] "{" |
346 | [email protected] ")" | 324 | [email protected] "\n" |
347 | [email protected] " " | 325 | [email protected] "}" |
348 | [email protected] | 326 | "#]], |
349 | [email protected] "{" | ||
350 | [email protected] "\n" | ||
351 | [email protected] "}" | ||
352 | "# | ||
353 | .trim(), | ||
354 | syn.trim() | ||
355 | ); | 327 | ); |
356 | } | 328 | } |
357 | } | 329 | } |
diff --git a/crates/rust-analyzer/src/cli/analysis_bench.rs b/crates/rust-analyzer/src/cli/analysis_bench.rs index a01b49822..6735b6388 100644 --- a/crates/rust-analyzer/src/cli/analysis_bench.rs +++ b/crates/rust-analyzer/src/cli/analysis_bench.rs | |||
@@ -16,7 +16,10 @@ use ide_db::{ | |||
16 | }; | 16 | }; |
17 | use vfs::AbsPathBuf; | 17 | use vfs::AbsPathBuf; |
18 | 18 | ||
19 | use crate::cli::{load_cargo::load_cargo, print_memory_usage, Verbosity}; | 19 | use crate::cli::{ |
20 | load_cargo::{load_cargo, LoadCargoConfig}, | ||
21 | print_memory_usage, Verbosity, | ||
22 | }; | ||
20 | 23 | ||
21 | pub struct BenchCmd { | 24 | pub struct BenchCmd { |
22 | pub path: PathBuf, | 25 | pub path: PathBuf, |
@@ -59,7 +62,14 @@ impl BenchCmd { | |||
59 | 62 | ||
60 | let start = Instant::now(); | 63 | let start = Instant::now(); |
61 | eprint!("loading: "); | 64 | eprint!("loading: "); |
62 | let (mut host, vfs) = load_cargo(&self.path, self.load_output_dirs, self.with_proc_macro)?; | 65 | |
66 | let load_cargo_config = LoadCargoConfig { | ||
67 | cargo_config: Default::default(), | ||
68 | load_out_dirs_from_check: self.load_output_dirs, | ||
69 | with_proc_macro: self.with_proc_macro, | ||
70 | }; | ||
71 | |||
72 | let (mut host, vfs) = load_cargo(&self.path, &load_cargo_config)?; | ||
63 | eprintln!("{:?}\n", start.elapsed()); | 73 | eprintln!("{:?}\n", start.elapsed()); |
64 | 74 | ||
65 | let file_id = { | 75 | let file_id = { |
diff --git a/crates/rust-analyzer/src/cli/analysis_stats.rs b/crates/rust-analyzer/src/cli/analysis_stats.rs index 66416f709..3417af687 100644 --- a/crates/rust-analyzer/src/cli/analysis_stats.rs +++ b/crates/rust-analyzer/src/cli/analysis_stats.rs | |||
@@ -25,8 +25,10 @@ use stdx::format_to; | |||
25 | use syntax::AstNode; | 25 | use syntax::AstNode; |
26 | 26 | ||
27 | use crate::cli::{ | 27 | use crate::cli::{ |
28 | load_cargo::load_cargo, print_memory_usage, progress_report::ProgressReport, report_metric, | 28 | load_cargo::{load_cargo, LoadCargoConfig}, |
29 | Result, Verbosity, | 29 | print_memory_usage, |
30 | progress_report::ProgressReport, | ||
31 | report_metric, Result, Verbosity, | ||
30 | }; | 32 | }; |
31 | use profile::StopWatch; | 33 | use profile::StopWatch; |
32 | 34 | ||
@@ -57,7 +59,12 @@ impl AnalysisStatsCmd { | |||
57 | }; | 59 | }; |
58 | 60 | ||
59 | let mut db_load_sw = self.stop_watch(); | 61 | let mut db_load_sw = self.stop_watch(); |
60 | let (host, vfs) = load_cargo(&self.path, self.load_output_dirs, self.with_proc_macro)?; | 62 | let load_cargo_config = LoadCargoConfig { |
63 | cargo_config: Default::default(), | ||
64 | load_out_dirs_from_check: self.load_output_dirs, | ||
65 | with_proc_macro: self.with_proc_macro, | ||
66 | }; | ||
67 | let (host, vfs) = load_cargo(&self.path, &load_cargo_config)?; | ||
61 | let db = host.raw_database(); | 68 | let db = host.raw_database(); |
62 | eprintln!("{:<20} {}", "Database loaded:", db_load_sw.elapsed()); | 69 | eprintln!("{:<20} {}", "Database loaded:", db_load_sw.elapsed()); |
63 | 70 | ||
diff --git a/crates/rust-analyzer/src/cli/diagnostics.rs b/crates/rust-analyzer/src/cli/diagnostics.rs index 0090fd2c2..c60374c24 100644 --- a/crates/rust-analyzer/src/cli/diagnostics.rs +++ b/crates/rust-analyzer/src/cli/diagnostics.rs | |||
@@ -10,7 +10,10 @@ use hir::{db::HirDatabase, Crate, Module}; | |||
10 | use ide::{DiagnosticsConfig, Severity}; | 10 | use ide::{DiagnosticsConfig, Severity}; |
11 | use ide_db::base_db::SourceDatabaseExt; | 11 | use ide_db::base_db::SourceDatabaseExt; |
12 | 12 | ||
13 | use crate::cli::{load_cargo::load_cargo, Result}; | 13 | use crate::cli::{ |
14 | load_cargo::{load_cargo, LoadCargoConfig}, | ||
15 | Result, | ||
16 | }; | ||
14 | 17 | ||
15 | fn all_modules(db: &dyn HirDatabase) -> Vec<Module> { | 18 | fn all_modules(db: &dyn HirDatabase) -> Vec<Module> { |
16 | let mut worklist: Vec<_> = | 19 | let mut worklist: Vec<_> = |
@@ -25,8 +28,17 @@ fn all_modules(db: &dyn HirDatabase) -> Vec<Module> { | |||
25 | modules | 28 | modules |
26 | } | 29 | } |
27 | 30 | ||
28 | pub fn diagnostics(path: &Path, load_output_dirs: bool, with_proc_macro: bool) -> Result<()> { | 31 | pub fn diagnostics( |
29 | let (host, _vfs) = load_cargo(path, load_output_dirs, with_proc_macro)?; | 32 | path: &Path, |
33 | load_out_dirs_from_check: bool, | ||
34 | with_proc_macro: bool, | ||
35 | ) -> Result<()> { | ||
36 | let load_cargo_config = LoadCargoConfig { | ||
37 | cargo_config: Default::default(), | ||
38 | load_out_dirs_from_check, | ||
39 | with_proc_macro, | ||
40 | }; | ||
41 | let (host, _vfs) = load_cargo(path, &load_cargo_config)?; | ||
30 | let db = host.raw_database(); | 42 | let db = host.raw_database(); |
31 | let analysis = host.analysis(); | 43 | let analysis = host.analysis(); |
32 | 44 | ||
diff --git a/crates/rust-analyzer/src/cli/load_cargo.rs b/crates/rust-analyzer/src/cli/load_cargo.rs index e12e87180..cc63c6cc2 100644 --- a/crates/rust-analyzer/src/cli/load_cargo.rs +++ b/crates/rust-analyzer/src/cli/load_cargo.rs | |||
@@ -13,14 +13,16 @@ use vfs::{loader::Handle, AbsPath, AbsPathBuf}; | |||
13 | 13 | ||
14 | use crate::reload::{ProjectFolders, SourceRootConfig}; | 14 | use crate::reload::{ProjectFolders, SourceRootConfig}; |
15 | 15 | ||
16 | pub fn load_cargo( | 16 | pub struct LoadCargoConfig { |
17 | root: &Path, | 17 | pub cargo_config: CargoConfig, |
18 | load_out_dirs_from_check: bool, | 18 | pub load_out_dirs_from_check: bool, |
19 | with_proc_macro: bool, | 19 | pub with_proc_macro: bool, |
20 | ) -> Result<(AnalysisHost, vfs::Vfs)> { | 20 | } |
21 | |||
22 | pub fn load_cargo(root: &Path, config: &LoadCargoConfig) -> Result<(AnalysisHost, vfs::Vfs)> { | ||
21 | let root = AbsPathBuf::assert(std::env::current_dir()?.join(root)); | 23 | let root = AbsPathBuf::assert(std::env::current_dir()?.join(root)); |
22 | let root = ProjectManifest::discover_single(&root)?; | 24 | let root = ProjectManifest::discover_single(&root)?; |
23 | let ws = ProjectWorkspace::load(root, &CargoConfig::default(), &|_| {})?; | 25 | let ws = ProjectWorkspace::load(root, &config.cargo_config, &|_| {})?; |
24 | 26 | ||
25 | let (sender, receiver) = unbounded(); | 27 | let (sender, receiver) = unbounded(); |
26 | let mut vfs = vfs::Vfs::default(); | 28 | let mut vfs = vfs::Vfs::default(); |
@@ -30,14 +32,14 @@ pub fn load_cargo( | |||
30 | Box::new(loader) | 32 | Box::new(loader) |
31 | }; | 33 | }; |
32 | 34 | ||
33 | let proc_macro_client = if with_proc_macro { | 35 | let proc_macro_client = if config.with_proc_macro { |
34 | let path = std::env::current_exe()?; | 36 | let path = std::env::current_exe()?; |
35 | Some(ProcMacroClient::extern_process(path, &["proc-macro"]).unwrap()) | 37 | Some(ProcMacroClient::extern_process(path, &["proc-macro"]).unwrap()) |
36 | } else { | 38 | } else { |
37 | None | 39 | None |
38 | }; | 40 | }; |
39 | 41 | ||
40 | let build_data = if load_out_dirs_from_check { | 42 | let build_data = if config.load_out_dirs_from_check { |
41 | let mut collector = BuildDataCollector::default(); | 43 | let mut collector = BuildDataCollector::default(); |
42 | ws.collect_build_data_configs(&mut collector); | 44 | ws.collect_build_data_configs(&mut collector); |
43 | Some(collector.collect(&|_| {})?) | 45 | Some(collector.collect(&|_| {})?) |
@@ -116,7 +118,13 @@ mod tests { | |||
116 | #[test] | 118 | #[test] |
117 | fn test_loading_rust_analyzer() { | 119 | fn test_loading_rust_analyzer() { |
118 | let path = Path::new(env!("CARGO_MANIFEST_DIR")).parent().unwrap().parent().unwrap(); | 120 | let path = Path::new(env!("CARGO_MANIFEST_DIR")).parent().unwrap().parent().unwrap(); |
119 | let (host, _vfs) = load_cargo(path, false, false).unwrap(); | 121 | let load_cargo_config = LoadCargoConfig { |
122 | cargo_config: Default::default(), | ||
123 | load_out_dirs_from_check: false, | ||
124 | with_proc_macro: false, | ||
125 | }; | ||
126 | |||
127 | let (host, _vfs) = load_cargo(path, &load_cargo_config).unwrap(); | ||
120 | let n_crates = Crate::all(host.raw_database()).len(); | 128 | let n_crates = Crate::all(host.raw_database()).len(); |
121 | // RA has quite a few crates, but the exact count doesn't matter | 129 | // RA has quite a few crates, but the exact count doesn't matter |
122 | assert!(n_crates > 20); | 130 | assert!(n_crates > 20); |
diff --git a/crates/rust-analyzer/src/cli/ssr.rs b/crates/rust-analyzer/src/cli/ssr.rs index bbb550ec9..8729ff0d9 100644 --- a/crates/rust-analyzer/src/cli/ssr.rs +++ b/crates/rust-analyzer/src/cli/ssr.rs | |||
@@ -1,11 +1,19 @@ | |||
1 | //! Applies structured search replace rules from the command line. | 1 | //! Applies structured search replace rules from the command line. |
2 | 2 | ||
3 | use crate::cli::{load_cargo::load_cargo, Result}; | 3 | use crate::cli::{ |
4 | load_cargo::{load_cargo, LoadCargoConfig}, | ||
5 | Result, | ||
6 | }; | ||
4 | use ssr::{MatchFinder, SsrPattern, SsrRule}; | 7 | use ssr::{MatchFinder, SsrPattern, SsrRule}; |
5 | 8 | ||
6 | pub fn apply_ssr_rules(rules: Vec<SsrRule>) -> Result<()> { | 9 | pub fn apply_ssr_rules(rules: Vec<SsrRule>) -> Result<()> { |
7 | use ide_db::base_db::SourceDatabaseExt; | 10 | use ide_db::base_db::SourceDatabaseExt; |
8 | let (host, vfs) = load_cargo(&std::env::current_dir()?, true, true)?; | 11 | let load_cargo_config = LoadCargoConfig { |
12 | cargo_config: Default::default(), | ||
13 | load_out_dirs_from_check: true, | ||
14 | with_proc_macro: true, | ||
15 | }; | ||
16 | let (host, vfs) = load_cargo(&std::env::current_dir()?, &load_cargo_config)?; | ||
9 | let db = host.raw_database(); | 17 | let db = host.raw_database(); |
10 | let mut match_finder = MatchFinder::at_first_file(db)?; | 18 | let mut match_finder = MatchFinder::at_first_file(db)?; |
11 | for rule in rules { | 19 | for rule in rules { |
@@ -28,7 +36,12 @@ pub fn apply_ssr_rules(rules: Vec<SsrRule>) -> Result<()> { | |||
28 | pub fn search_for_patterns(patterns: Vec<SsrPattern>, debug_snippet: Option<String>) -> Result<()> { | 36 | pub fn search_for_patterns(patterns: Vec<SsrPattern>, debug_snippet: Option<String>) -> Result<()> { |
29 | use ide_db::base_db::SourceDatabaseExt; | 37 | use ide_db::base_db::SourceDatabaseExt; |
30 | use ide_db::symbol_index::SymbolsDatabase; | 38 | use ide_db::symbol_index::SymbolsDatabase; |
31 | let (host, _vfs) = load_cargo(&std::env::current_dir()?, true, true)?; | 39 | let load_cargo_config = LoadCargoConfig { |
40 | cargo_config: Default::default(), | ||
41 | load_out_dirs_from_check: true, | ||
42 | with_proc_macro: true, | ||
43 | }; | ||
44 | let (host, _vfs) = load_cargo(&std::env::current_dir()?, &load_cargo_config)?; | ||
32 | let db = host.raw_database(); | 45 | let db = host.raw_database(); |
33 | let mut match_finder = MatchFinder::at_first_file(db)?; | 46 | let mut match_finder = MatchFinder::at_first_file(db)?; |
34 | for pattern in patterns { | 47 | for pattern in patterns { |
diff --git a/crates/syntax/Cargo.toml b/crates/syntax/Cargo.toml index aa6f6e0b6..e3ef71650 100644 --- a/crates/syntax/Cargo.toml +++ b/crates/syntax/Cargo.toml | |||
@@ -13,7 +13,7 @@ doctest = false | |||
13 | [dependencies] | 13 | [dependencies] |
14 | itertools = "0.10.0" | 14 | itertools = "0.10.0" |
15 | rowan = "0.12.2" | 15 | rowan = "0.12.2" |
16 | rustc_lexer = { version = "702.0.0", package = "rustc-ap-rustc_lexer" } | 16 | rustc_lexer = { version = "705.0.0", package = "rustc-ap-rustc_lexer" } |
17 | rustc-hash = "1.1.0" | 17 | rustc-hash = "1.1.0" |
18 | arrayvec = "0.5.1" | 18 | arrayvec = "0.5.1" |
19 | once_cell = "1.3.1" | 19 | once_cell = "1.3.1" |