@@ -62,38 +62,24 @@ pub(crate) fn inlay_hints(
6262 let _p = profile:: span ( "inlay_hints" ) ;
6363 let sema = Semantics :: new ( db) ;
6464 let file = sema. parse ( file_id) ;
65+ let file = file. syntax ( ) ;
6566
6667 let mut res = Vec :: new ( ) ;
67- let mut queue = vec ! [ file. syntax( ) . preorder( ) ] ;
6868
69- while let Some ( mut preorder) = queue. pop ( ) {
70- while let Some ( event) = preorder. next ( ) {
71- let node = match event {
72- syntax:: WalkEvent :: Enter ( node) => node,
73- syntax:: WalkEvent :: Leave ( _) => continue ,
74- } ;
75- if let Some ( node) =
76- ast:: Item :: cast ( node. clone ( ) ) . and_then ( |item| sema. expand_attr_macro ( & item) )
77- {
78- preorder. skip_subtree ( ) ;
79- queue. push ( node. preorder ( ) ) ;
80- continue ;
81- }
82-
83- if let Some ( expr) = ast:: Expr :: cast ( node. clone ( ) ) {
84- get_chaining_hints ( & mut res, & sema, config, & expr) ;
85- match expr {
86- ast:: Expr :: CallExpr ( it) => {
87- get_param_name_hints ( & mut res, & sema, config, ast:: Expr :: from ( it) ) ;
88- }
89- ast:: Expr :: MethodCallExpr ( it) => {
90- get_param_name_hints ( & mut res, & sema, config, ast:: Expr :: from ( it) ) ;
91- }
92- _ => ( ) ,
69+ for node in file. descendants ( ) {
70+ if let Some ( expr) = ast:: Expr :: cast ( node. clone ( ) ) {
71+ get_chaining_hints ( & mut res, & sema, config, & expr) ;
72+ match expr {
73+ ast:: Expr :: CallExpr ( it) => {
74+ get_param_name_hints ( & mut res, & sema, config, ast:: Expr :: from ( it) ) ;
75+ }
76+ ast:: Expr :: MethodCallExpr ( it) => {
77+ get_param_name_hints ( & mut res, & sema, config, ast:: Expr :: from ( it) ) ;
9378 }
94- } else if let Some ( it) = ast:: IdentPat :: cast ( node. clone ( ) ) {
95- get_bind_pat_hints ( & mut res, & sema, config, it) ;
79+ _ => ( ) ,
9680 }
81+ } else if let Some ( it) = ast:: IdentPat :: cast ( node. clone ( ) ) {
82+ get_bind_pat_hints ( & mut res, & sema, config, it) ;
9783 }
9884 }
9985 res
@@ -1485,67 +1471,4 @@ fn main() {
14851471 "# ] ] ,
14861472 ) ;
14871473 }
1488-
1489- #[ test]
1490- fn hints_in_attr_call ( ) {
1491- // chaining hints do not currently work as macros lose all whitespace information
1492- check_expect (
1493- TEST_CONFIG ,
1494- r#"
1495- //- proc_macros: identity, input_replace
1496- struct Struct;
1497- impl Struct {
1498- fn chain(self) -> Self {
1499- self
1500- }
1501- }
1502-
1503- #[proc_macros::identity]
1504- fn main() {
1505- let strukt = Struct;
1506- strukt
1507- .chain()
1508- .chain()
1509- .chain();
1510- Struct::chain(strukt);
1511- }
1512-
1513- #[proc_macros::input_replace(
1514- fn not_main() {
1515- let strukt = Struct;
1516- strukt
1517- .chain()
1518- .chain()
1519- .chain();
1520- Struct::chain(strukt);
1521- }
1522- )]
1523- fn main() {}
1524- "# ,
1525- expect ! [ [ r#"
1526- [
1527- InlayHint {
1528- range: 297..303,
1529- kind: TypeHint,
1530- label: "Struct",
1531- },
1532- InlayHint {
1533- range: 415..421,
1534- kind: ParameterHint,
1535- label: "self",
1536- },
1537- InlayHint {
1538- range: 125..131,
1539- kind: TypeHint,
1540- label: "Struct",
1541- },
1542- InlayHint {
1543- range: 223..229,
1544- kind: ParameterHint,
1545- label: "self",
1546- },
1547- ]
1548- "# ] ] ,
1549- ) ;
1550- }
15511474}
0 commit comments