aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_assists/src/test_db.rs2
-rw-r--r--crates/ra_hir/src/code_model.rs8
-rw-r--r--crates/ra_hir/src/debug.rs94
-rw-r--r--crates/ra_hir/src/has_source.rs (renamed from crates/ra_hir/src/code_model/src.rs)0
-rw-r--r--crates/ra_hir/src/lib.rs14
-rw-r--r--crates/ra_hir/src/source_binder.rs4
-rw-r--r--crates/ra_hir_def/src/body/lower.rs7
-rw-r--r--crates/ra_hir_expand/src/builtin_macro.rs19
-rw-r--r--crates/ra_hir_expand/src/db.rs4
-rw-r--r--crates/ra_ide/src/completion/complete_dot.rs2
-rw-r--r--crates/ra_ide/src/db.rs14
-rw-r--r--crates/ra_ide/src/goto_definition.rs3
12 files changed, 31 insertions, 140 deletions
diff --git a/crates/ra_assists/src/test_db.rs b/crates/ra_assists/src/test_db.rs
index 523259fd4..d5249f308 100644
--- a/crates/ra_assists/src/test_db.rs
+++ b/crates/ra_assists/src/test_db.rs
@@ -43,5 +43,3 @@ impl FileLoader for TestDB {
43 FileLoaderDelegate(self).relevant_crates(file_id) 43 FileLoaderDelegate(self).relevant_crates(file_id)
44 } 44 }
45} 45}
46
47impl hir::debug::HirDebugHelper for TestDB {}
diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs
index 7ac1bf461..c013ff99b 100644
--- a/crates/ra_hir/src/code_model.rs
+++ b/crates/ra_hir/src/code_model.rs
@@ -1,7 +1,4 @@
1//! FIXME: write short doc here 1//! FIXME: write short doc here
2
3pub(crate) mod src;
4
5use std::sync::Arc; 2use std::sync::Arc;
6 3
7use either::Either; 4use either::Either;
@@ -989,11 +986,6 @@ impl Type {
989 None 986 None
990 } 987 }
991 988
992 // FIXME: remove
993 pub fn into_ty(self) -> Ty {
994 self.ty.value
995 }
996
997 pub fn as_adt(&self) -> Option<Adt> { 989 pub fn as_adt(&self) -> Option<Adt> {
998 let (adt, _subst) = self.ty.value.as_adt()?; 990 let (adt, _subst) = self.ty.value.as_adt()?;
999 Some(adt.into()) 991 Some(adt.into())
diff --git a/crates/ra_hir/src/debug.rs b/crates/ra_hir/src/debug.rs
deleted file mode 100644
index 6cd5c8cb9..000000000
--- a/crates/ra_hir/src/debug.rs
+++ /dev/null
@@ -1,94 +0,0 @@
1//! XXX: This does not work at the moment.
2//!
3//! printf debugging infrastructure for rust-analyzer.
4//!
5//! When you print a hir type, like a module, using `eprintln!("{:?}", module)`,
6//! you usually get back a numeric ID, which doesn't tell you much:
7//! `Module(92)`.
8//!
9//! This module adds convenience `debug` methods to various types, which resolve
10//! the id to a human-readable location info:
11//!
12//! ```not_rust
13//! eprintln!("{:?}", module.debug(db));
14//! =>
15//! Module { name: collections, path: "liballoc/collections/mod.rs" }
16//! ```
17//!
18//! Note that to get this info, we might need to execute queries! So
19//!
20//! * don't use the `debug` methods for logging
21//! * when debugging, be aware that interference is possible.
22
23use std::fmt;
24
25use hir_expand::HirFileId;
26use ra_db::{CrateId, FileId};
27
28use crate::{db::HirDatabase, Crate, Module, Name};
29
30impl Crate {
31 pub fn debug(self, db: &impl HirDebugDatabase) -> impl fmt::Debug + '_ {
32 debug_fn(move |fmt| db.debug_crate(self, fmt))
33 }
34}
35
36impl Module {
37 pub fn debug(self, db: &impl HirDebugDatabase) -> impl fmt::Debug + '_ {
38 debug_fn(move |fmt| db.debug_module(self, fmt))
39 }
40}
41
42pub trait HirDebugHelper: HirDatabase {
43 fn crate_name(&self, _krate: CrateId) -> Option<String> {
44 None
45 }
46 fn file_path(&self, _file_id: FileId) -> Option<String> {
47 None
48 }
49}
50
51pub trait HirDebugDatabase {
52 fn debug_crate(&self, krate: Crate, fmt: &mut fmt::Formatter<'_>) -> fmt::Result;
53 fn debug_module(&self, module: Module, fmt: &mut fmt::Formatter<'_>) -> fmt::Result;
54 fn debug_hir_file_id(&self, file_id: HirFileId, fmt: &mut fmt::Formatter<'_>) -> fmt::Result;
55}
56
57impl<DB: HirDebugHelper> HirDebugDatabase for DB {
58 fn debug_crate(&self, krate: Crate, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
59 let mut builder = fmt.debug_tuple("Crate");
60 match self.crate_name(krate.id) {
61 Some(name) => builder.field(&name),
62 None => builder.field(&krate.id),
63 }
64 .finish()
65 }
66
67 fn debug_module(&self, module: Module, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
68 let file_id = module.definition_source(self).file_id.original_file(self);
69 let path = self.file_path(file_id).unwrap_or_else(|| "N/A".to_string());
70 fmt.debug_struct("Module")
71 .field("name", &module.name(self).unwrap_or_else(Name::missing))
72 .field("path", &path)
73 .finish()
74 }
75
76 fn debug_hir_file_id(&self, file_id: HirFileId, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
77 let original = file_id.original_file(self);
78 let path = self.file_path(original).unwrap_or_else(|| "N/A".to_string());
79 let is_macro = file_id != original.into();
80 fmt.debug_struct("HirFileId").field("path", &path).field("macro", &is_macro).finish()
81 }
82}
83
84fn debug_fn(f: impl Fn(&mut fmt::Formatter<'_>) -> fmt::Result) -> impl fmt::Debug {
85 struct DebugFn<F>(F);
86
87 impl<F: Fn(&mut fmt::Formatter<'_>) -> fmt::Result> fmt::Debug for DebugFn<F> {
88 fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
89 (&self.0)(fmt)
90 }
91 }
92
93 DebugFn(f)
94}
diff --git a/crates/ra_hir/src/code_model/src.rs b/crates/ra_hir/src/has_source.rs
index b09582f93..b09582f93 100644
--- a/crates/ra_hir/src/code_model/src.rs
+++ b/crates/ra_hir/src/has_source.rs
diff --git a/crates/ra_hir/src/lib.rs b/crates/ra_hir/src/lib.rs
index bb22882b1..e7602ee30 100644
--- a/crates/ra_hir/src/lib.rs
+++ b/crates/ra_hir/src/lib.rs
@@ -26,8 +26,6 @@ macro_rules! impl_froms {
26 } 26 }
27} 27}
28 28
29pub mod debug;
30
31pub mod db; 29pub mod db;
32pub mod source_binder; 30pub mod source_binder;
33 31
@@ -36,16 +34,18 @@ pub mod diagnostics;
36mod from_id; 34mod from_id;
37mod code_model; 35mod code_model;
38 36
39pub mod from_source; 37mod has_source;
38mod from_source;
40 39
41pub use crate::{ 40pub use crate::{
42 code_model::{ 41 code_model::{
43 src::HasSource, Adt, AssocItem, AttrDef, Const, Container, Crate, CrateDependency, 42 Adt, AssocItem, AttrDef, Const, Container, Crate, CrateDependency, DefWithBody, Docs, Enum,
44 DefWithBody, Docs, Enum, EnumVariant, FieldSource, Function, GenericDef, HasAttrs, 43 EnumVariant, FieldSource, Function, GenericDef, HasAttrs, ImplBlock, Import, Local,
45 ImplBlock, Import, Local, MacroDef, Module, ModuleDef, ScopeDef, Static, Struct, 44 MacroDef, Module, ModuleDef, ScopeDef, Static, Struct, StructField, Trait, Type, TypeAlias,
46 StructField, Trait, Type, TypeAlias, TypeParam, Union, VariantDef, 45 TypeParam, Union, VariantDef,
47 }, 46 },
48 from_source::FromSource, 47 from_source::FromSource,
48 has_source::HasSource,
49 source_binder::{PathResolution, ScopeEntryWithSyntax, SourceAnalyzer}, 49 source_binder::{PathResolution, ScopeEntryWithSyntax, SourceAnalyzer},
50}; 50};
51 51
diff --git a/crates/ra_hir/src/source_binder.rs b/crates/ra_hir/src/source_binder.rs
index 9efd0477c..44d185003 100644
--- a/crates/ra_hir/src/source_binder.rs
+++ b/crates/ra_hir/src/source_binder.rs
@@ -427,7 +427,7 @@ impl SourceAnalyzer {
427 427
428 /// Checks that particular type `ty` implements `std::future::Future`. 428 /// Checks that particular type `ty` implements `std::future::Future`.
429 /// This function is used in `.await` syntax completion. 429 /// This function is used in `.await` syntax completion.
430 pub fn impls_future(&self, db: &impl HirDatabase, ty: Ty) -> bool { 430 pub fn impls_future(&self, db: &impl HirDatabase, ty: Type) -> bool {
431 let std_future_path = known::std_future_future(); 431 let std_future_path = known::std_future_future();
432 432
433 let std_future_trait = match self.resolver.resolve_known_trait(db, &std_future_path) { 433 let std_future_trait = match self.resolver.resolve_known_trait(db, &std_future_path) {
@@ -440,7 +440,7 @@ impl SourceAnalyzer {
440 _ => return false, 440 _ => return false,
441 }; 441 };
442 442
443 let canonical_ty = Canonical { value: ty, num_vars: 0 }; 443 let canonical_ty = Canonical { value: ty.ty.value, num_vars: 0 };
444 implements_trait(&canonical_ty, db, &self.resolver, krate.into(), std_future_trait) 444 implements_trait(&canonical_ty, db, &self.resolver, krate.into(), std_future_trait)
445 } 445 }
446 446
diff --git a/crates/ra_hir_def/src/body/lower.rs b/crates/ra_hir_def/src/body/lower.rs
index 71c08f024..cc068ff94 100644
--- a/crates/ra_hir_def/src/body/lower.rs
+++ b/crates/ra_hir_def/src/body/lower.rs
@@ -437,9 +437,7 @@ where
437 None => self.alloc_expr(Expr::Missing, syntax_ptr), 437 None => self.alloc_expr(Expr::Missing, syntax_ptr),
438 } 438 }
439 } 439 }
440 440 // FIXME expand to statements in statement position
441 // FIXME implement HIR for these:
442 ast::Expr::Label(_e) => self.alloc_expr(Expr::Missing, syntax_ptr),
443 ast::Expr::MacroCall(e) => match self.expander.enter_expand(self.db, e) { 441 ast::Expr::MacroCall(e) => match self.expander.enter_expand(self.db, e) {
444 Some((mark, expansion)) => { 442 Some((mark, expansion)) => {
445 let id = self.collect_expr(expansion); 443 let id = self.collect_expr(expansion);
@@ -448,6 +446,9 @@ where
448 } 446 }
449 None => self.alloc_expr(Expr::Missing, syntax_ptr), 447 None => self.alloc_expr(Expr::Missing, syntax_ptr),
450 }, 448 },
449
450 // FIXME implement HIR for these:
451 ast::Expr::Label(_e) => self.alloc_expr(Expr::Missing, syntax_ptr),
451 } 452 }
452 } 453 }
453 454
diff --git a/crates/ra_hir_expand/src/builtin_macro.rs b/crates/ra_hir_expand/src/builtin_macro.rs
index c7071fe85..ec5ace757 100644
--- a/crates/ra_hir_expand/src/builtin_macro.rs
+++ b/crates/ra_hir_expand/src/builtin_macro.rs
@@ -208,15 +208,20 @@ fn format_args_expand(
208 _id: MacroCallId, 208 _id: MacroCallId,
209 tt: &tt::Subtree, 209 tt: &tt::Subtree,
210) -> Result<tt::Subtree, mbe::ExpandError> { 210) -> Result<tt::Subtree, mbe::ExpandError> {
211 // We expand `format_args!("", arg1, arg2)` to 211 // We expand `format_args!("", a1, a2)` to
212 // `std::fmt::Arguments::new_v1(&[], &[&arg1, &arg2])`, 212 // ```
213 // std::fmt::Arguments::new_v1(&[], &[
214 // std::fmt::ArgumentV1::new(&arg1,std::fmt::Display::fmt),
215 // std::fmt::ArgumentV1::new(&arg2,std::fmt::Display::fmt),
216 // ])
217 // ```,
213 // which is still not really correct, but close enough for now 218 // which is still not really correct, but close enough for now
214 let mut args = Vec::new(); 219 let mut args = Vec::new();
215 let mut current = Vec::new(); 220 let mut current = Vec::new();
216 for tt in tt.token_trees.iter().cloned() { 221 for tt in tt.token_trees.iter().cloned() {
217 match tt { 222 match tt {
218 tt::TokenTree::Leaf(tt::Leaf::Punct(p)) if p.char == ',' => { 223 tt::TokenTree::Leaf(tt::Leaf::Punct(p)) if p.char == ',' => {
219 args.push(tt::Subtree { delimiter: tt::Delimiter::None, token_trees: current }); 224 args.push(current);
220 current = Vec::new(); 225 current = Vec::new();
221 } 226 }
222 _ => { 227 _ => {
@@ -225,13 +230,15 @@ fn format_args_expand(
225 } 230 }
226 } 231 }
227 if !current.is_empty() { 232 if !current.is_empty() {
228 args.push(tt::Subtree { delimiter: tt::Delimiter::None, token_trees: current }); 233 args.push(current);
229 } 234 }
230 if args.is_empty() { 235 if args.is_empty() {
231 return Err(mbe::ExpandError::NoMatchingRule); 236 return Err(mbe::ExpandError::NoMatchingRule);
232 } 237 }
233 let _format_string = args.remove(0); 238 let _format_string = args.remove(0);
234 let arg_tts = args.into_iter().flat_map(|arg| (quote! { & #arg , }).token_trees); 239 let arg_tts = args.into_iter().flat_map(|arg| {
240 quote! { std::fmt::ArgumentV1::new(&(##arg), std::fmt::Display::fmt), }
241 }.token_trees).collect::<Vec<_>>();
235 let expanded = quote! { 242 let expanded = quote! {
236 std::fmt::Arguments::new_v1(&[], &[##arg_tts]) 243 std::fmt::Arguments::new_v1(&[], &[##arg_tts])
237 }; 244 };
@@ -360,6 +367,6 @@ mod tests {
360 BuiltinFnLikeExpander::FormatArgs, 367 BuiltinFnLikeExpander::FormatArgs,
361 ); 368 );
362 369
363 assert_eq!(expanded, r#"std::fmt::Arguments::new_v1(&[] ,&[&arg1(a,b,c),&arg2,])"#); 370 assert_eq!(expanded, r#"std::fmt::Arguments::new_v1(&[] ,&[std::fmt::ArgumentV1::new(&(arg1(a,b,c)),std::fmt::Display::fmt),std::fmt::ArgumentV1::new(&(arg2),std::fmt::Display::fmt),])"#);
364 } 371 }
365} 372}
diff --git a/crates/ra_hir_expand/src/db.rs b/crates/ra_hir_expand/src/db.rs
index 4bdb41619..f68aca789 100644
--- a/crates/ra_hir_expand/src/db.rs
+++ b/crates/ra_hir_expand/src/db.rs
@@ -183,8 +183,8 @@ fn to_fragment_kind(db: &dyn AstDatabase, macro_call_id: MacroCallId) -> Fragmen
183 // FIXME: Handle Pattern 183 // FIXME: Handle Pattern
184 FragmentKind::Expr 184 FragmentKind::Expr
185 } 185 }
186 EXPR_STMT => FragmentKind::Statements, 186 // FIXME: Expand to statements in appropriate positions; HIR lowering needs to handle that
187 BLOCK => FragmentKind::Statements, 187 EXPR_STMT | BLOCK => FragmentKind::Expr,
188 ARG_LIST => FragmentKind::Expr, 188 ARG_LIST => FragmentKind::Expr,
189 TRY_EXPR => FragmentKind::Expr, 189 TRY_EXPR => FragmentKind::Expr,
190 TUPLE_EXPR => FragmentKind::Expr, 190 TUPLE_EXPR => FragmentKind::Expr,
diff --git a/crates/ra_ide/src/completion/complete_dot.rs b/crates/ra_ide/src/completion/complete_dot.rs
index a52eb0ee4..294964887 100644
--- a/crates/ra_ide/src/completion/complete_dot.rs
+++ b/crates/ra_ide/src/completion/complete_dot.rs
@@ -27,7 +27,7 @@ pub(super) fn complete_dot(acc: &mut Completions, ctx: &CompletionContext) {
27 complete_methods(acc, ctx, &receiver_ty); 27 complete_methods(acc, ctx, &receiver_ty);
28 28
29 // Suggest .await syntax for types that implement Future trait 29 // Suggest .await syntax for types that implement Future trait
30 if ctx.analyzer.impls_future(ctx.db, receiver_ty.into_ty()) { 30 if ctx.analyzer.impls_future(ctx.db, receiver_ty) {
31 CompletionItem::new(CompletionKind::Keyword, ctx.source_range(), "await") 31 CompletionItem::new(CompletionKind::Keyword, ctx.source_range(), "await")
32 .detail("expr.await") 32 .detail("expr.await")
33 .insert_text("await") 33 .insert_text("await")
diff --git a/crates/ra_ide/src/db.rs b/crates/ra_ide/src/db.rs
index f739ebecd..47d0aed6f 100644
--- a/crates/ra_ide/src/db.rs
+++ b/crates/ra_ide/src/db.rs
@@ -5,7 +5,7 @@ use std::sync::Arc;
5use ra_db::{ 5use ra_db::{
6 salsa::{self, Database, Durability}, 6 salsa::{self, Database, Durability},
7 Canceled, CheckCanceled, CrateId, FileId, FileLoader, FileLoaderDelegate, RelativePath, 7 Canceled, CheckCanceled, CrateId, FileId, FileLoader, FileLoaderDelegate, RelativePath,
8 SourceDatabase, SourceDatabaseExt, SourceRootId, 8 SourceDatabase, SourceRootId,
9}; 9};
10use rustc_hash::FxHashMap; 10use rustc_hash::FxHashMap;
11 11
@@ -49,18 +49,6 @@ impl FileLoader for RootDatabase {
49 } 49 }
50} 50}
51 51
52impl hir::debug::HirDebugHelper for RootDatabase {
53 fn crate_name(&self, krate: CrateId) -> Option<String> {
54 self.debug_data.crate_names.get(&krate).cloned()
55 }
56 fn file_path(&self, file_id: FileId) -> Option<String> {
57 let source_root_id = self.file_source_root(file_id);
58 let source_root_path = self.debug_data.root_paths.get(&source_root_id)?;
59 let file_path = self.file_relative_path(file_id);
60 Some(format!("{}/{}", source_root_path, file_path))
61 }
62}
63
64impl salsa::Database for RootDatabase { 52impl salsa::Database for RootDatabase {
65 fn salsa_runtime(&self) -> &salsa::Runtime<RootDatabase> { 53 fn salsa_runtime(&self) -> &salsa::Runtime<RootDatabase> {
66 &self.runtime 54 &self.runtime
diff --git a/crates/ra_ide/src/goto_definition.rs b/crates/ra_ide/src/goto_definition.rs
index 1b968134d..b93d6a931 100644
--- a/crates/ra_ide/src/goto_definition.rs
+++ b/crates/ra_ide/src/goto_definition.rs
@@ -693,7 +693,6 @@ mod tests {
693 ); 693 );
694 } 694 }
695 695
696 #[should_panic] // currently failing because of expr mapping problems
697 #[test] 696 #[test]
698 fn goto_through_format() { 697 fn goto_through_format() {
699 check_goto( 698 check_goto(
@@ -718,7 +717,7 @@ mod tests {
718 format!(\"{}\", fo<|>o()) 717 format!(\"{}\", fo<|>o())
719 } 718 }
720 ", 719 ",
721 "foo FN_DEF FileId(1) [359; 376) [362; 365)", 720 "foo FN_DEF FileId(1) [398; 415) [401; 404)",
722 ); 721 );
723 } 722 }
724 723