-1

is there any quick way in vs code to search for method1 referenced inside method2?

I am trying to see if using remote-redux-devtools is useful for my project, and we are using next js which does server side calls via getInitialProps so I am trying to find all references to dispatch inside getInitialProps

rather than search for either term (dispatch or getInitialProps) via command + shift + F individually, i need a more specific search. in this case I need to search for references to dispatch inside getInitialProps

devdropper87
  • 4,025
  • 11
  • 44
  • 70

1 Answers1

0

If we can assume that your getInitialProps functions are of a form similar to this:

  static async getInitialProps(ctx) {
    const res = await fetch('https://api.github.com/repos/zeit/next.js')
    const json = await res.json()
    dispatchEvent(event)
    return { stars: json.stargazers_count }
  }

particularly with respect to the return statement on the final line, then this regex works to distinguish those getInitialProps functions with the sequence dispatch somewhere in that function.

^.*getInitialProps[\s\S]*?\bdispatch[\s\S]*?(return).*\n.*

If you want only dispatch as opposed to dispatchEvent you could use word boundaries around it like \bdispatch\b unless it is used as dispatch( then use \bdispatch( or similar.

See regex101 demo

Mark
  • 143,421
  • 24
  • 428
  • 436