aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_expand
diff options
context:
space:
mode:
authorkjeremy <[email protected]>2019-11-22 15:05:04 +0000
committerkjeremy <[email protected]>2019-11-22 15:05:04 +0000
commit786544f022418ed7813e401aded31e4bd5451391 (patch)
tree9e9dfe41c3ae8ea5fe7d10544212cb91fb30a64f /crates/ra_hir_expand
parenta132cc715ed05cab83fd058156eb152f0be96982 (diff)
Expand file! to dummy ""
Diffstat (limited to 'crates/ra_hir_expand')
-rw-r--r--crates/ra_hir_expand/src/builtin_macro.rs26
-rw-r--r--crates/ra_hir_expand/src/name.rs1
2 files changed, 26 insertions, 1 deletions
diff --git a/crates/ra_hir_expand/src/builtin_macro.rs b/crates/ra_hir_expand/src/builtin_macro.rs
index 9628666d4..d7057e005 100644
--- a/crates/ra_hir_expand/src/builtin_macro.rs
+++ b/crates/ra_hir_expand/src/builtin_macro.rs
@@ -10,6 +10,7 @@ use crate::quote;
10 10
11#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] 11#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
12pub enum BuiltinExpander { 12pub enum BuiltinExpander {
13 File,
13 Line, 14 Line,
14 Stringify, 15 Stringify,
15} 16}
@@ -22,6 +23,7 @@ impl BuiltinExpander {
22 tt: &tt::Subtree, 23 tt: &tt::Subtree,
23 ) -> Result<tt::Subtree, mbe::ExpandError> { 24 ) -> Result<tt::Subtree, mbe::ExpandError> {
24 match self { 25 match self {
26 BuiltinExpander::File => file_expand(db, id, tt),
25 BuiltinExpander::Line => line_expand(db, id, tt), 27 BuiltinExpander::Line => line_expand(db, id, tt),
26 BuiltinExpander::Stringify => stringify_expand(db, id, tt), 28 BuiltinExpander::Stringify => stringify_expand(db, id, tt),
27 } 29 }
@@ -34,7 +36,9 @@ pub fn find_builtin_macro(
34 ast_id: AstId<ast::MacroCall>, 36 ast_id: AstId<ast::MacroCall>,
35) -> Option<MacroDefId> { 37) -> Option<MacroDefId> {
36 // FIXME: Better registering method 38 // FIXME: Better registering method
37 if ident == &name::LINE_MACRO { 39 if ident == &name::FILE_MACRO {
40 Some(MacroDefId { krate, ast_id, kind: MacroDefKind::BuiltIn(BuiltinExpander::File) })
41 } else if ident == &name::LINE_MACRO {
38 Some(MacroDefId { krate, ast_id, kind: MacroDefKind::BuiltIn(BuiltinExpander::Line) }) 42 Some(MacroDefId { krate, ast_id, kind: MacroDefKind::BuiltIn(BuiltinExpander::Line) })
39 } else if ident == &name::STRINGIFY_MACRO { 43 } else if ident == &name::STRINGIFY_MACRO {
40 Some(MacroDefId { krate, ast_id, kind: MacroDefKind::BuiltIn(BuiltinExpander::Stringify) }) 44 Some(MacroDefId { krate, ast_id, kind: MacroDefKind::BuiltIn(BuiltinExpander::Stringify) })
@@ -105,3 +109,23 @@ fn stringify_expand(
105 109
106 Ok(expanded) 110 Ok(expanded)
107} 111}
112
113fn file_expand(
114 db: &dyn AstDatabase,
115 id: MacroCallId,
116 _tt: &tt::Subtree,
117) -> Result<tt::Subtree, mbe::ExpandError> {
118 let loc = db.lookup_intern_macro(id);
119 let macro_call = loc.ast_id.to_node(db);
120 let _ = macro_call.token_tree().ok_or_else(|| mbe::ExpandError::UnexpectedToken)?;
121
122 // FIXME: RA purposefully lacks knowledge of absolute file names
123 // so just return "".
124 let file_name = "";
125
126 let expanded = quote! {
127 #file_name
128 };
129
130 Ok(expanded)
131}
diff --git a/crates/ra_hir_expand/src/name.rs b/crates/ra_hir_expand/src/name.rs
index c3f7e77a5..05fe6afd9 100644
--- a/crates/ra_hir_expand/src/name.rs
+++ b/crates/ra_hir_expand/src/name.rs
@@ -142,5 +142,6 @@ pub const TARGET_TYPE: Name = Name::new_inline_ascii(6, b"Target");
142pub const BOX_TYPE: Name = Name::new_inline_ascii(3, b"Box"); 142pub const BOX_TYPE: Name = Name::new_inline_ascii(3, b"Box");
143 143
144// Builtin Macros 144// Builtin Macros
145pub const FILE_MACRO: Name = Name::new_inline_ascii(4, b"file");
145pub const LINE_MACRO: Name = Name::new_inline_ascii(4, b"line"); 146pub const LINE_MACRO: Name = Name::new_inline_ascii(4, b"line");
146pub const STRINGIFY_MACRO: Name = Name::new_inline_ascii(9, b"stringify"); 147pub const STRINGIFY_MACRO: Name = Name::new_inline_ascii(9, b"stringify");