diff options
Diffstat (limited to 'crates/ra_hir_expand/src')
-rw-r--r-- | crates/ra_hir_expand/src/builtin_macro.rs | 2 | ||||
-rw-r--r-- | crates/ra_hir_expand/src/lib.rs | 19 | ||||
-rw-r--r-- | crates/ra_hir_expand/src/test_db.rs | 24 |
3 files changed, 31 insertions, 14 deletions
diff --git a/crates/ra_hir_expand/src/builtin_macro.rs b/crates/ra_hir_expand/src/builtin_macro.rs index 626f9efd0..9f50569dc 100644 --- a/crates/ra_hir_expand/src/builtin_macro.rs +++ b/crates/ra_hir_expand/src/builtin_macro.rs | |||
@@ -272,7 +272,7 @@ fn format_args_expand( | |||
272 | fn unquote_str(lit: &tt::Literal) -> Option<String> { | 272 | fn unquote_str(lit: &tt::Literal) -> Option<String> { |
273 | let lit = ast::make::tokens::literal(&lit.to_string()); | 273 | let lit = ast::make::tokens::literal(&lit.to_string()); |
274 | let token = ast::String::cast(lit)?; | 274 | let token = ast::String::cast(lit)?; |
275 | token.value() | 275 | token.value().map(|it| it.into_owned()) |
276 | } | 276 | } |
277 | 277 | ||
278 | fn concat_expand( | 278 | fn concat_expand( |
diff --git a/crates/ra_hir_expand/src/lib.rs b/crates/ra_hir_expand/src/lib.rs index 5eac2605b..1cf6c1ba9 100644 --- a/crates/ra_hir_expand/src/lib.rs +++ b/crates/ra_hir_expand/src/lib.rs | |||
@@ -88,6 +88,25 @@ impl HirFileId { | |||
88 | } | 88 | } |
89 | } | 89 | } |
90 | 90 | ||
91 | pub fn expansion_level(self, db: &dyn db::AstDatabase) -> u32 { | ||
92 | let mut level = 0; | ||
93 | let mut curr = self; | ||
94 | while let HirFileIdRepr::MacroFile(macro_file) = curr.0 { | ||
95 | level += 1; | ||
96 | curr = match macro_file.macro_call_id { | ||
97 | MacroCallId::LazyMacro(id) => { | ||
98 | let loc = db.lookup_intern_macro(id); | ||
99 | loc.kind.file_id() | ||
100 | } | ||
101 | MacroCallId::EagerMacro(id) => { | ||
102 | let loc = db.lookup_intern_eager_expansion(id); | ||
103 | loc.file_id | ||
104 | } | ||
105 | }; | ||
106 | } | ||
107 | level | ||
108 | } | ||
109 | |||
91 | /// If this is a macro call, returns the syntax node of the call. | 110 | /// If this is a macro call, returns the syntax node of the call. |
92 | pub fn call_node(self, db: &dyn db::AstDatabase) -> Option<InFile<SyntaxNode>> { | 111 | pub fn call_node(self, db: &dyn db::AstDatabase) -> Option<InFile<SyntaxNode>> { |
93 | match self.0 { | 112 | match self.0 { |
diff --git a/crates/ra_hir_expand/src/test_db.rs b/crates/ra_hir_expand/src/test_db.rs index 09fc18c36..332fa556f 100644 --- a/crates/ra_hir_expand/src/test_db.rs +++ b/crates/ra_hir_expand/src/test_db.rs | |||
@@ -1,7 +1,7 @@ | |||
1 | //! Database used for testing `hir_expand`. | 1 | //! Database used for testing `hir_expand`. |
2 | 2 | ||
3 | use std::{ | 3 | use std::{ |
4 | panic, | 4 | fmt, panic, |
5 | sync::{Arc, Mutex}, | 5 | sync::{Arc, Mutex}, |
6 | }; | 6 | }; |
7 | 7 | ||
@@ -13,25 +13,23 @@ use rustc_hash::FxHashSet; | |||
13 | ra_db::SourceDatabaseStorage, | 13 | ra_db::SourceDatabaseStorage, |
14 | crate::db::AstDatabaseStorage | 14 | crate::db::AstDatabaseStorage |
15 | )] | 15 | )] |
16 | #[derive(Debug, Default)] | 16 | #[derive(Default)] |
17 | pub struct TestDB { | 17 | pub struct TestDB { |
18 | runtime: salsa::Runtime<TestDB>, | 18 | storage: salsa::Storage<TestDB>, |
19 | events: Mutex<Option<Vec<salsa::Event<TestDB>>>>, | 19 | events: Mutex<Option<Vec<salsa::Event>>>, |
20 | } | 20 | } |
21 | 21 | ||
22 | impl salsa::Database for TestDB { | 22 | impl fmt::Debug for TestDB { |
23 | fn salsa_runtime(&self) -> &salsa::Runtime<Self> { | 23 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
24 | &self.runtime | 24 | f.debug_struct("TestDB").finish() |
25 | } | ||
26 | |||
27 | fn salsa_runtime_mut(&mut self) -> &mut salsa::Runtime<Self> { | ||
28 | &mut self.runtime | ||
29 | } | 25 | } |
26 | } | ||
30 | 27 | ||
31 | fn salsa_event(&self, event: impl Fn() -> salsa::Event<TestDB>) { | 28 | impl salsa::Database for TestDB { |
29 | fn salsa_event(&self, event: salsa::Event) { | ||
32 | let mut events = self.events.lock().unwrap(); | 30 | let mut events = self.events.lock().unwrap(); |
33 | if let Some(events) = &mut *events { | 31 | if let Some(events) = &mut *events { |
34 | events.push(event()); | 32 | events.push(event); |
35 | } | 33 | } |
36 | } | 34 | } |
37 | } | 35 | } |