Skip to content

Commit

Permalink
Merge pull request #11 from tjx666/tj/fix/more-dynamic-cases
Browse files Browse the repository at this point in the history
fix: some dynamic import cases hover tooltip not work
  • Loading branch information
tjx666 authored Jul 13, 2024
2 parents 981d066 + 1b93301 commit 7d83746
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/hoverTooltips/modules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,19 @@ export class ModulesHoverProvider implements HoverProvider {

const stringBeforeLeftQuote = lineText.slice(0, leftQuotaIndex);
const stringAfterRightQuote = lineText.slice(rightQuotaIndex + 1);
const afterFnCallRegexp = /^\s*\)(?:;.*|\n?)$/;
const afterFnCallRegexp = /^\s*\)(?:;.*|\n?)/;
const afterStatementRegexp = /^\s*(?:;.*)?$/;
const isModule = // named imports/exports: import { pick } from 'lodash' or export * from 'antd'
(/(?:\b|\s+)from\s+$/.test(stringBeforeLeftQuote) &&
afterStatementRegexp.test(stringAfterRightQuote)) ||
// unnamed import
(/(?:\b|\s+)import\s+$/.test(stringBeforeLeftQuote) &&
afterStatementRegexp.test(stringAfterRightQuote)) ||
// dynamic imports: import( 'lodash' )
(/(?:\b|\s+)import\s*\(\s*$/.test(stringBeforeLeftQuote) &&
// dynamic imports:
// case1: import( 'lodash' )
// case2: import( 'lodash' ).then()
// case3: /** @type {import('next').NextConfig} */
(/(?:\b|\{|\s+)import\s*\(\s*$/.test(stringBeforeLeftQuote) &&
afterFnCallRegexp.test(stringAfterRightQuote)) ||
// require: require('lodash' )
(/require\s+\(\s*$/.test(stringBeforeLeftQuote) &&
Expand Down

0 comments on commit 7d83746

Please sign in to comment.