3
3
use std:: sync:: Arc ;
4
4
5
5
use base_db:: { salsa, SourceDatabase } ;
6
+ use itertools:: Itertools ;
6
7
use limit:: Limit ;
7
8
use mbe:: { ExpandError , ExpandResult } ;
8
9
use parser:: { FragmentKind , T } ;
9
10
use syntax:: {
10
11
algo:: diff,
11
- ast:: { self , NameOwner } ,
12
- AstNode , GreenNode , Parse , SyntaxNode , SyntaxToken ,
12
+ ast:: { self , AttrsOwner , NameOwner } ,
13
+ AstNode , GreenNode , Parse , SyntaxNode , SyntaxToken , TextRange ,
13
14
} ;
14
15
15
16
use crate :: {
16
- ast_id_map:: AstIdMap , hygiene:: HygieneFrame , input :: process_macro_input , BuiltinAttrExpander ,
17
- BuiltinDeriveExpander , BuiltinFnLikeExpander , HirFileId , HirFileIdRepr , MacroCallId ,
18
- MacroCallKind , MacroCallLoc , MacroDefId , MacroDefKind , MacroFile , ProcMacroExpander ,
17
+ ast_id_map:: AstIdMap , hygiene:: HygieneFrame , BuiltinAttrExpander , BuiltinDeriveExpander ,
18
+ BuiltinFnLikeExpander , HirFileId , HirFileIdRepr , MacroCallId , MacroCallKind , MacroCallLoc ,
19
+ MacroDefId , MacroDefKind , MacroFile , ProcMacroExpander ,
19
20
} ;
20
21
21
22
/// Total limit on the number of tokens produced by any macro invocation.
@@ -257,9 +258,28 @@ fn parse_macro_expansion(
257
258
258
259
fn macro_arg ( db : & dyn AstDatabase , id : MacroCallId ) -> Option < Arc < ( tt:: Subtree , mbe:: TokenMap ) > > {
259
260
let arg = db. macro_arg_text ( id) ?;
260
- let ( mut tt, tmap) = mbe:: syntax_node_to_token_tree ( & SyntaxNode :: new_root ( arg) ) ;
261
+ let loc = db. lookup_intern_macro ( id) ;
262
+
263
+ let node = SyntaxNode :: new_root ( arg) ;
264
+ let censor = match loc. kind {
265
+ MacroCallKind :: FnLike { .. } => None ,
266
+ MacroCallKind :: Derive { derive_attr_index, .. } => match ast:: Item :: cast ( node. clone ( ) ) {
267
+ Some ( item) => item
268
+ . attrs ( )
269
+ . map ( |attr| attr. syntax ( ) . text_range ( ) )
270
+ . take ( derive_attr_index as usize + 1 )
271
+ . fold1 ( TextRange :: cover) ,
272
+ None => None ,
273
+ } ,
274
+ MacroCallKind :: Attr { invoc_attr_index, .. } => match ast:: Item :: cast ( node. clone ( ) ) {
275
+ Some ( item) => {
276
+ item. attrs ( ) . nth ( invoc_attr_index as usize ) . map ( |attr| attr. syntax ( ) . text_range ( ) )
277
+ }
278
+ None => None ,
279
+ } ,
280
+ } ;
281
+ let ( mut tt, tmap) = mbe:: syntax_node_to_token_tree_censored ( & node, censor) ;
261
282
262
- let loc: MacroCallLoc = db. lookup_intern_macro ( id) ;
263
283
if loc. def . is_proc_macro ( ) {
264
284
// proc macros expect their inputs without parentheses, MBEs expect it with them included
265
285
tt. delimiter = None ;
@@ -271,7 +291,6 @@ fn macro_arg(db: &dyn AstDatabase, id: MacroCallId) -> Option<Arc<(tt::Subtree,
271
291
fn macro_arg_text ( db : & dyn AstDatabase , id : MacroCallId ) -> Option < GreenNode > {
272
292
let loc = db. lookup_intern_macro ( id) ;
273
293
let arg = loc. kind . arg ( db) ?;
274
- let arg = process_macro_input ( & loc. kind , arg) ;
275
294
if matches ! ( loc. kind, MacroCallKind :: FnLike { .. } ) {
276
295
let first = arg. first_child_or_token ( ) . map_or ( T ! [ . ] , |it| it. kind ( ) ) ;
277
296
let last = arg. last_child_or_token ( ) . map_or ( T ! [ . ] , |it| it. kind ( ) ) ;
0 commit comments