首页 > 解决方案 > VS code - search for function reference within specific function- macOS

问题描述

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

标签: reduxvisual-studio-codenext.jsredux-devtools

解决方案


如果我们可以假设您的getInitialProps函数的形式类似于:

  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 }
  }

特别是关于return最后一行的语句,那么这个正则表达式可以将这些getInitialProps函数与该函数中dispatch某处的序列区分开来。

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

如果你只想要dispatch而不是dispatchEvent你可以在它周围使用单词边界,\bdispatch\b除非它被用作dispatch(然后使用\bdispatch(或类似的。

regex101 演示


推荐阅读