After some searching, I think the possible approach is to use a Language Server. For example: the "Find References" in VSCode is implemented through TypeScript Language Server.
I skimmed some LSP extensions (Vue, TS), the codes are quite complex, but you only need to interact with those language servers, not re-implement them, so that's still possible