|
1 | 1 | //! Builtin macro |
| 2 | +use std::ops::Deref; |
| 3 | + |
2 | 4 | use crate::{ |
3 | 5 | db::AstDatabase, name, quote, AstId, CrateId, EagerMacroId, LazyMacroId, MacroCallId, |
4 | 6 | MacroDefId, MacroDefKind, TextSize, |
@@ -99,6 +101,7 @@ register_builtin! { |
99 | 101 | EAGER: |
100 | 102 | (concat, Concat) => concat_expand, |
101 | 103 | (include, Include) => include_expand, |
| 104 | + (include_str, IncludeStr) => include_str_expand, |
102 | 105 | (env, Env) => env_expand, |
103 | 106 | (option_env, OptionEnv) => option_env_expand |
104 | 107 | } |
@@ -331,6 +334,20 @@ fn include_expand( |
331 | 334 | Ok((res, FragmentKind::Items)) |
332 | 335 | } |
333 | 336 |
|
| 337 | +fn include_str_expand( |
| 338 | + db: &dyn AstDatabase, |
| 339 | + arg_id: EagerMacroId, |
| 340 | + tt: &tt::Subtree, |
| 341 | +) -> Result<(tt::Subtree, FragmentKind), mbe::ExpandError> { |
| 342 | + let path = parse_string(tt)?; |
| 343 | + let file_id = |
| 344 | + relative_file(db, arg_id.into(), &path).ok_or_else(|| mbe::ExpandError::ConversionError)?; |
| 345 | + let text = db.file_text(file_id); |
| 346 | + let text = text.deref(); |
| 347 | + |
| 348 | + Ok((quote!(#text), FragmentKind::Expr)) |
| 349 | +} |
| 350 | + |
334 | 351 | fn get_env_inner(db: &dyn AstDatabase, arg_id: EagerMacroId, key: &str) -> Option<String> { |
335 | 352 | let krate = db.lookup_intern_eager_expansion(arg_id).krate; |
336 | 353 | db.crate_graph()[krate].env.get(key) |
|
0 commit comments