@@ -8,7 +8,10 @@ use intern::sym;
8
8
use mbe:: { parse_exprs_with_sep, parse_to_token_tree} ;
9
9
use span:: { Edition , Span , SpanAnchor , SyntaxContextId , ROOT_ERASED_FILE_AST_ID } ;
10
10
use stdx:: format_to;
11
- use syntax:: unescape:: { unescape_byte, unescape_char, unescape_unicode, Mode } ;
11
+ use syntax:: {
12
+ format_smolstr,
13
+ unescape:: { unescape_byte, unescape_char, unescape_unicode, Mode } ,
14
+ } ;
12
15
13
16
use crate :: {
14
17
db:: ExpandDatabase ,
@@ -265,7 +268,7 @@ fn file_expand(
265
268
) -> ExpandResult < tt:: Subtree > {
266
269
// FIXME: RA purposefully lacks knowledge of absolute file names
267
270
// so just return "".
268
- let file_name = "" ;
271
+ let file_name = "file " ;
269
272
270
273
let expanded = quote ! { span =>
271
274
#file_name
@@ -275,34 +278,36 @@ fn file_expand(
275
278
}
276
279
277
280
fn format_args_expand (
278
- db : & dyn ExpandDatabase ,
279
- id : MacroCallId ,
281
+ _db : & dyn ExpandDatabase ,
282
+ _id : MacroCallId ,
280
283
tt : & tt:: Subtree ,
281
284
span : Span ,
282
285
) -> ExpandResult < tt:: Subtree > {
283
- format_args_expand_general ( db, id, tt, "" , span)
286
+ let pound = mk_pound ( span) ;
287
+ let mut tt = tt. clone ( ) ;
288
+ tt. delimiter . kind = tt:: DelimiterKind :: Parenthesis ;
289
+ ExpandResult :: ok ( quote ! { span =>
290
+ builtin #pound format_args #tt
291
+ } )
284
292
}
285
293
286
294
fn format_args_nl_expand (
287
- db : & dyn ExpandDatabase ,
288
- id : MacroCallId ,
289
- tt : & tt:: Subtree ,
290
- span : Span ,
291
- ) -> ExpandResult < tt:: Subtree > {
292
- format_args_expand_general ( db, id, tt, "\\ n" , span)
293
- }
294
-
295
- fn format_args_expand_general (
296
295
_db : & dyn ExpandDatabase ,
297
296
_id : MacroCallId ,
298
297
tt : & tt:: Subtree ,
299
- // FIXME: Make use of this so that mir interpretation works properly
300
- _end_string : & str ,
301
298
span : Span ,
302
299
) -> ExpandResult < tt:: Subtree > {
303
300
let pound = mk_pound ( span) ;
304
301
let mut tt = tt. clone ( ) ;
305
302
tt. delimiter . kind = tt:: DelimiterKind :: Parenthesis ;
303
+ if let Some ( tt:: TokenTree :: Leaf ( tt:: Leaf :: Literal ( tt:: Literal {
304
+ text,
305
+ kind : tt:: LitKind :: Str ,
306
+ ..
307
+ } ) ) ) = tt. token_trees . first_mut ( )
308
+ {
309
+ * text = format_smolstr ! ( "{text}\\ n" ) ;
310
+ }
306
311
ExpandResult :: ok ( quote ! { span =>
307
312
builtin #pound format_args #tt
308
313
} )
@@ -788,7 +793,7 @@ fn include_str_expand(
788
793
789
794
fn get_env_inner ( db : & dyn ExpandDatabase , arg_id : MacroCallId , key : & str ) -> Option < String > {
790
795
let krate = db. lookup_intern_macro_call ( arg_id) . krate ;
791
- db. crate_graph ( ) [ krate] . env . get ( key)
796
+ db. crate_graph ( ) [ krate] . env . get ( key) . map ( |it| it . escape_debug ( ) . to_string ( ) )
792
797
}
793
798
794
799
fn env_expand (
0 commit comments