简体   繁体   中英

What is the best way to open an imported javascript source file using VS Code Extension API?

I'm attempting to write a VS Code extension for React. The basic gist is, I want to select a React Component and Open/goto the source of the component function/class and do some operations there.

In case the source is in another file, what is the best(and most reliable) way to open the file and do operations to it using the VS Code Extension API?

I have used the ast of the document to retrieve the relative import file source from a component and can access the required file that way, but what if the user is using import aliases or Import Path Resolver to import components like this.

import Header from 'components/Header';
import Grid from 'components/Grid';

instead of

import Header from '../../components/Header';
import Grid from '../../components/Grid';

I know VS code has a peek feature so it definitely has file source information somewhere. What is the best way to open an imported javascript source file using VS Code Extension API?

查看要在package.json文件中使用的"moduleNameMapper": {...}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM