diff options
Diffstat (limited to 'crates')
19 files changed, 126 insertions, 65 deletions
diff --git a/crates/assists/src/handlers/add_lifetime_to_type.rs b/crates/assists/src/handlers/add_lifetime_to_type.rs index c1603e972..2edf7b204 100644 --- a/crates/assists/src/handlers/add_lifetime_to_type.rs +++ b/crates/assists/src/handlers/add_lifetime_to_type.rs | |||
@@ -26,7 +26,7 @@ pub(crate) fn add_lifetime_to_type(acc: &mut Assists, ctx: &AssistContext) -> Op | |||
26 | return None; | 26 | return None; |
27 | } | 27 | } |
28 | 28 | ||
29 | let node = ctx.find_node_at_offset::<ast::AdtDef>()?; | 29 | let node = ctx.find_node_at_offset::<ast::Adt>()?; |
30 | let has_lifetime = node | 30 | let has_lifetime = node |
31 | .generic_param_list() | 31 | .generic_param_list() |
32 | .map(|gen_list| gen_list.lifetime_params().count() > 0) | 32 | .map(|gen_list| gen_list.lifetime_params().count() > 0) |
@@ -66,9 +66,9 @@ pub(crate) fn add_lifetime_to_type(acc: &mut Assists, ctx: &AssistContext) -> Op | |||
66 | ) | 66 | ) |
67 | } | 67 | } |
68 | 68 | ||
69 | fn fetch_borrowed_types(node: &ast::AdtDef) -> Option<Vec<RefType>> { | 69 | fn fetch_borrowed_types(node: &ast::Adt) -> Option<Vec<RefType>> { |
70 | let ref_types: Vec<RefType> = match node { | 70 | let ref_types: Vec<RefType> = match node { |
71 | ast::AdtDef::Enum(enum_) => { | 71 | ast::Adt::Enum(enum_) => { |
72 | let variant_list = enum_.variant_list()?; | 72 | let variant_list = enum_.variant_list()?; |
73 | variant_list | 73 | variant_list |
74 | .variants() | 74 | .variants() |
@@ -80,11 +80,11 @@ fn fetch_borrowed_types(node: &ast::AdtDef) -> Option<Vec<RefType>> { | |||
80 | .flatten() | 80 | .flatten() |
81 | .collect() | 81 | .collect() |
82 | } | 82 | } |
83 | ast::AdtDef::Struct(strukt) => { | 83 | ast::Adt::Struct(strukt) => { |
84 | let field_list = strukt.field_list()?; | 84 | let field_list = strukt.field_list()?; |
85 | find_ref_types_from_field_list(&field_list)? | 85 | find_ref_types_from_field_list(&field_list)? |
86 | } | 86 | } |
87 | ast::AdtDef::Union(un) => { | 87 | ast::Adt::Union(un) => { |
88 | let record_field_list = un.record_field_list()?; | 88 | let record_field_list = un.record_field_list()?; |
89 | record_field_list | 89 | record_field_list |
90 | .fields() | 90 | .fields() |
diff --git a/crates/assists/src/handlers/generate_derive.rs b/crates/assists/src/handlers/generate_derive.rs index f876b7684..adae8ab7e 100644 --- a/crates/assists/src/handlers/generate_derive.rs +++ b/crates/assists/src/handlers/generate_derive.rs | |||
@@ -26,7 +26,7 @@ use crate::{AssistContext, AssistId, AssistKind, Assists}; | |||
26 | // ``` | 26 | // ``` |
27 | pub(crate) fn generate_derive(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { | 27 | pub(crate) fn generate_derive(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { |
28 | let cap = ctx.config.snippet_cap?; | 28 | let cap = ctx.config.snippet_cap?; |
29 | let nominal = ctx.find_node_at_offset::<ast::AdtDef>()?; | 29 | let nominal = ctx.find_node_at_offset::<ast::Adt>()?; |
30 | let node_start = derive_insertion_offset(&nominal)?; | 30 | let node_start = derive_insertion_offset(&nominal)?; |
31 | let target = nominal.syntax().text_range(); | 31 | let target = nominal.syntax().text_range(); |
32 | acc.add( | 32 | acc.add( |
@@ -58,7 +58,7 @@ pub(crate) fn generate_derive(acc: &mut Assists, ctx: &AssistContext) -> Option< | |||
58 | } | 58 | } |
59 | 59 | ||
60 | // Insert `derive` after doc comments. | 60 | // Insert `derive` after doc comments. |
61 | fn derive_insertion_offset(nominal: &ast::AdtDef) -> Option<TextSize> { | 61 | fn derive_insertion_offset(nominal: &ast::Adt) -> Option<TextSize> { |
62 | let non_ws_child = nominal | 62 | let non_ws_child = nominal |
63 | .syntax() | 63 | .syntax() |
64 | .children_with_tokens() | 64 | .children_with_tokens() |
diff --git a/crates/assists/src/handlers/generate_enum_match_method.rs b/crates/assists/src/handlers/generate_enum_match_method.rs index 4cf66b5d5..9d6b161c9 100644 --- a/crates/assists/src/handlers/generate_enum_match_method.rs +++ b/crates/assists/src/handlers/generate_enum_match_method.rs | |||
@@ -49,7 +49,7 @@ pub(crate) fn generate_enum_match_method(acc: &mut Assists, ctx: &AssistContext) | |||
49 | // Return early if we've found an existing new fn | 49 | // Return early if we've found an existing new fn |
50 | let impl_def = find_struct_impl( | 50 | let impl_def = find_struct_impl( |
51 | &ctx, | 51 | &ctx, |
52 | &ast::AdtDef::Enum(parent_enum.clone()), | 52 | &ast::Adt::Enum(parent_enum.clone()), |
53 | format!("is_{}", fn_name).as_str(), | 53 | format!("is_{}", fn_name).as_str(), |
54 | )?; | 54 | )?; |
55 | 55 | ||
diff --git a/crates/assists/src/handlers/generate_impl.rs b/crates/assists/src/handlers/generate_impl.rs index 827477272..61d1bd25c 100644 --- a/crates/assists/src/handlers/generate_impl.rs +++ b/crates/assists/src/handlers/generate_impl.rs | |||
@@ -27,7 +27,7 @@ use crate::{AssistContext, AssistId, AssistKind, Assists}; | |||
27 | // } | 27 | // } |
28 | // ``` | 28 | // ``` |
29 | pub(crate) fn generate_impl(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { | 29 | pub(crate) fn generate_impl(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { |
30 | let nominal = ctx.find_node_at_offset::<ast::AdtDef>()?; | 30 | let nominal = ctx.find_node_at_offset::<ast::Adt>()?; |
31 | let name = nominal.name()?; | 31 | let name = nominal.name()?; |
32 | let target = nominal.syntax().text_range(); | 32 | let target = nominal.syntax().text_range(); |
33 | 33 | ||
diff --git a/crates/assists/src/handlers/generate_new.rs b/crates/assists/src/handlers/generate_new.rs index 307f2e228..a9203d33f 100644 --- a/crates/assists/src/handlers/generate_new.rs +++ b/crates/assists/src/handlers/generate_new.rs | |||
@@ -40,7 +40,7 @@ pub(crate) fn generate_new(acc: &mut Assists, ctx: &AssistContext) -> Option<()> | |||
40 | }; | 40 | }; |
41 | 41 | ||
42 | // Return early if we've found an existing new fn | 42 | // Return early if we've found an existing new fn |
43 | let impl_def = find_struct_impl(&ctx, &ast::AdtDef::Struct(strukt.clone()), "new")?; | 43 | let impl_def = find_struct_impl(&ctx, &ast::Adt::Struct(strukt.clone()), "new")?; |
44 | 44 | ||
45 | let target = strukt.syntax().text_range(); | 45 | let target = strukt.syntax().text_range(); |
46 | acc.add(AssistId("generate_new", AssistKind::Generate), "Generate `new`", target, |builder| { | 46 | acc.add(AssistId("generate_new", AssistKind::Generate), "Generate `new`", target, |builder| { |
diff --git a/crates/assists/src/utils.rs b/crates/assists/src/utils.rs index 8045aac40..cd80c2958 100644 --- a/crates/assists/src/utils.rs +++ b/crates/assists/src/utils.rs | |||
@@ -281,7 +281,7 @@ pub(crate) fn does_pat_match_variant(pat: &ast::Pat, var: &ast::Pat) -> bool { | |||
281 | // FIXME: this partially overlaps with `find_impl_block` | 281 | // FIXME: this partially overlaps with `find_impl_block` |
282 | pub(crate) fn find_struct_impl( | 282 | pub(crate) fn find_struct_impl( |
283 | ctx: &AssistContext, | 283 | ctx: &AssistContext, |
284 | strukt: &ast::AdtDef, | 284 | strukt: &ast::Adt, |
285 | name: &str, | 285 | name: &str, |
286 | ) -> Option<Option<ast::Impl>> { | 286 | ) -> Option<Option<ast::Impl>> { |
287 | let db = ctx.db(); | 287 | let db = ctx.db(); |
@@ -290,9 +290,9 @@ pub(crate) fn find_struct_impl( | |||
290 | })?; | 290 | })?; |
291 | 291 | ||
292 | let struct_def = match strukt { | 292 | let struct_def = match strukt { |
293 | ast::AdtDef::Enum(e) => Adt::Enum(ctx.sema.to_def(e)?), | 293 | ast::Adt::Enum(e) => Adt::Enum(ctx.sema.to_def(e)?), |
294 | ast::AdtDef::Struct(s) => Adt::Struct(ctx.sema.to_def(s)?), | 294 | ast::Adt::Struct(s) => Adt::Struct(ctx.sema.to_def(s)?), |
295 | ast::AdtDef::Union(u) => Adt::Union(ctx.sema.to_def(u)?), | 295 | ast::Adt::Union(u) => Adt::Union(ctx.sema.to_def(u)?), |
296 | }; | 296 | }; |
297 | 297 | ||
298 | let block = module.descendants().filter_map(ast::Impl::cast).find_map(|impl_blk| { | 298 | let block = module.descendants().filter_map(ast::Impl::cast).find_map(|impl_blk| { |
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/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/goto_implementation.rs b/crates/ide/src/goto_implementation.rs index 761a98b2c..3990305fc 100644 --- a/crates/ide/src/goto_implementation.rs +++ b/crates/ide/src/goto_implementation.rs | |||
@@ -23,7 +23,7 @@ pub(crate) fn goto_implementation( | |||
23 | 23 | ||
24 | let krate = sema.to_module_def(position.file_id)?.krate(); | 24 | let krate = sema.to_module_def(position.file_id)?.krate(); |
25 | 25 | ||
26 | if let Some(nominal_def) = find_node_at_offset::<ast::AdtDef>(&syntax, position.offset) { | 26 | if let Some(nominal_def) = find_node_at_offset::<ast::Adt>(&syntax, position.offset) { |
27 | return Some(RangeInfo::new( | 27 | return Some(RangeInfo::new( |
28 | nominal_def.syntax().text_range(), | 28 | nominal_def.syntax().text_range(), |
29 | impls_for_def(&sema, &nominal_def, krate)?, | 29 | impls_for_def(&sema, &nominal_def, krate)?, |
@@ -40,13 +40,13 @@ pub(crate) fn goto_implementation( | |||
40 | 40 | ||
41 | fn impls_for_def( | 41 | fn impls_for_def( |
42 | sema: &Semantics<RootDatabase>, | 42 | sema: &Semantics<RootDatabase>, |
43 | node: &ast::AdtDef, | 43 | node: &ast::Adt, |
44 | krate: Crate, | 44 | krate: Crate, |
45 | ) -> Option<Vec<NavigationTarget>> { | 45 | ) -> Option<Vec<NavigationTarget>> { |
46 | let ty = match node { | 46 | let ty = match node { |
47 | ast::AdtDef::Struct(def) => sema.to_def(def)?.ty(sema.db), | 47 | ast::Adt::Struct(def) => sema.to_def(def)?.ty(sema.db), |
48 | ast::AdtDef::Enum(def) => sema.to_def(def)?.ty(sema.db), | 48 | ast::Adt::Enum(def) => sema.to_def(def)?.ty(sema.db), |
49 | ast::AdtDef::Union(def) => sema.to_def(def)?.ty(sema.db), | 49 | ast::Adt::Union(def) => sema.to_def(def)?.ty(sema.db), |
50 | }; | 50 | }; |
51 | 51 | ||
52 | let impls = Impl::all_in_crate(sema.db, krate); | 52 | let impls = Impl::all_in_crate(sema.db, krate); |
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/rust-analyzer/src/semantic_tokens.rs b/crates/rust-analyzer/src/semantic_tokens.rs index 7ce9a4ab6..be0bea00b 100644 --- a/crates/rust-analyzer/src/semantic_tokens.rs +++ b/crates/rust-analyzer/src/semantic_tokens.rs | |||
@@ -44,6 +44,7 @@ define_semantic_token_types![ | |||
44 | (BRACE, "brace"), | 44 | (BRACE, "brace"), |
45 | (BRACKET, "bracket"), | 45 | (BRACKET, "bracket"), |
46 | (BUILTIN_TYPE, "builtinType"), | 46 | (BUILTIN_TYPE, "builtinType"), |
47 | (CHAR_LITERAL, "characterLiteral"), | ||
47 | (COMMA, "comma"), | 48 | (COMMA, "comma"), |
48 | (COLON, "colon"), | 49 | (COLON, "colon"), |
49 | (DOT, "dot"), | 50 | (DOT, "dot"), |
diff --git a/crates/rust-analyzer/src/to_proto.rs b/crates/rust-analyzer/src/to_proto.rs index 96f915f1c..5236932e8 100644 --- a/crates/rust-analyzer/src/to_proto.rs +++ b/crates/rust-analyzer/src/to_proto.rs | |||
@@ -426,7 +426,8 @@ fn semantic_token_type_and_modifiers( | |||
426 | HlTag::None => semantic_tokens::GENERIC, | 426 | HlTag::None => semantic_tokens::GENERIC, |
427 | HlTag::ByteLiteral | HlTag::NumericLiteral => lsp_types::SemanticTokenType::NUMBER, | 427 | HlTag::ByteLiteral | HlTag::NumericLiteral => lsp_types::SemanticTokenType::NUMBER, |
428 | HlTag::BoolLiteral => semantic_tokens::BOOLEAN, | 428 | HlTag::BoolLiteral => semantic_tokens::BOOLEAN, |
429 | HlTag::CharLiteral | HlTag::StringLiteral => lsp_types::SemanticTokenType::STRING, | 429 | HlTag::StringLiteral => lsp_types::SemanticTokenType::STRING, |
430 | HlTag::CharLiteral => semantic_tokens::CHAR_LITERAL, | ||
430 | HlTag::Comment => lsp_types::SemanticTokenType::COMMENT, | 431 | HlTag::Comment => lsp_types::SemanticTokenType::COMMENT, |
431 | HlTag::Attribute => semantic_tokens::ATTRIBUTE, | 432 | HlTag::Attribute => semantic_tokens::ATTRIBUTE, |
432 | HlTag::Keyword => lsp_types::SemanticTokenType::KEYWORD, | 433 | HlTag::Keyword => lsp_types::SemanticTokenType::KEYWORD, |
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" |
diff --git a/crates/syntax/src/ast/generated/nodes.rs b/crates/syntax/src/ast/generated/nodes.rs index 5baa54a3f..064931aec 100644 --- a/crates/syntax/src/ast/generated/nodes.rs +++ b/crates/syntax/src/ast/generated/nodes.rs | |||
@@ -1401,15 +1401,15 @@ pub enum FieldList { | |||
1401 | TupleFieldList(TupleFieldList), | 1401 | TupleFieldList(TupleFieldList), |
1402 | } | 1402 | } |
1403 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1403 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1404 | pub enum AdtDef { | 1404 | pub enum Adt { |
1405 | Enum(Enum), | 1405 | Enum(Enum), |
1406 | Struct(Struct), | 1406 | Struct(Struct), |
1407 | Union(Union), | 1407 | Union(Union), |
1408 | } | 1408 | } |
1409 | impl ast::AttrsOwner for AdtDef {} | 1409 | impl ast::AttrsOwner for Adt {} |
1410 | impl ast::GenericParamsOwner for AdtDef {} | 1410 | impl ast::GenericParamsOwner for Adt {} |
1411 | impl ast::NameOwner for AdtDef {} | 1411 | impl ast::NameOwner for Adt {} |
1412 | impl ast::VisibilityOwner for AdtDef {} | 1412 | impl ast::VisibilityOwner for Adt {} |
1413 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1413 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1414 | pub enum AssocItem { | 1414 | pub enum AssocItem { |
1415 | Const(Const), | 1415 | Const(Const), |
@@ -3394,16 +3394,16 @@ impl AstNode for FieldList { | |||
3394 | } | 3394 | } |
3395 | } | 3395 | } |
3396 | } | 3396 | } |
3397 | impl From<Enum> for AdtDef { | 3397 | impl From<Enum> for Adt { |
3398 | fn from(node: Enum) -> AdtDef { AdtDef::Enum(node) } | 3398 | fn from(node: Enum) -> Adt { Adt::Enum(node) } |
3399 | } | 3399 | } |
3400 | impl From<Struct> for AdtDef { | 3400 | impl From<Struct> for Adt { |
3401 | fn from(node: Struct) -> AdtDef { AdtDef::Struct(node) } | 3401 | fn from(node: Struct) -> Adt { Adt::Struct(node) } |
3402 | } | 3402 | } |
3403 | impl From<Union> for AdtDef { | 3403 | impl From<Union> for Adt { |
3404 | fn from(node: Union) -> AdtDef { AdtDef::Union(node) } | 3404 | fn from(node: Union) -> Adt { Adt::Union(node) } |
3405 | } | 3405 | } |
3406 | impl AstNode for AdtDef { | 3406 | impl AstNode for Adt { |
3407 | fn can_cast(kind: SyntaxKind) -> bool { | 3407 | fn can_cast(kind: SyntaxKind) -> bool { |
3408 | match kind { | 3408 | match kind { |
3409 | ENUM | STRUCT | UNION => true, | 3409 | ENUM | STRUCT | UNION => true, |
@@ -3412,18 +3412,18 @@ impl AstNode for AdtDef { | |||
3412 | } | 3412 | } |
3413 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 3413 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
3414 | let res = match syntax.kind() { | 3414 | let res = match syntax.kind() { |
3415 | ENUM => AdtDef::Enum(Enum { syntax }), | 3415 | ENUM => Adt::Enum(Enum { syntax }), |
3416 | STRUCT => AdtDef::Struct(Struct { syntax }), | 3416 | STRUCT => Adt::Struct(Struct { syntax }), |
3417 | UNION => AdtDef::Union(Union { syntax }), | 3417 | UNION => Adt::Union(Union { syntax }), |
3418 | _ => return None, | 3418 | _ => return None, |
3419 | }; | 3419 | }; |
3420 | Some(res) | 3420 | Some(res) |
3421 | } | 3421 | } |
3422 | fn syntax(&self) -> &SyntaxNode { | 3422 | fn syntax(&self) -> &SyntaxNode { |
3423 | match self { | 3423 | match self { |
3424 | AdtDef::Enum(it) => &it.syntax, | 3424 | Adt::Enum(it) => &it.syntax, |
3425 | AdtDef::Struct(it) => &it.syntax, | 3425 | Adt::Struct(it) => &it.syntax, |
3426 | AdtDef::Union(it) => &it.syntax, | 3426 | Adt::Union(it) => &it.syntax, |
3427 | } | 3427 | } |
3428 | } | 3428 | } |
3429 | } | 3429 | } |
@@ -3571,7 +3571,7 @@ impl std::fmt::Display for FieldList { | |||
3571 | std::fmt::Display::fmt(self.syntax(), f) | 3571 | std::fmt::Display::fmt(self.syntax(), f) |
3572 | } | 3572 | } |
3573 | } | 3573 | } |
3574 | impl std::fmt::Display for AdtDef { | 3574 | impl std::fmt::Display for Adt { |
3575 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | 3575 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
3576 | std::fmt::Display::fmt(self.syntax(), f) | 3576 | std::fmt::Display::fmt(self.syntax(), f) |
3577 | } | 3577 | } |