From 1b933016117617dce40d7e47e7e57ec49dc049aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BD=99=E8=85=BE=E9=9D=96?= Date: Sat, 13 Jul 2024 22:13:01 +0800 Subject: [PATCH] fix: some dynamic import cases hover tooltip not work --- src/hoverTooltips/modules.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/hoverTooltips/modules.ts b/src/hoverTooltips/modules.ts index a9bb121..feb3a11 100644 --- a/src/hoverTooltips/modules.ts +++ b/src/hoverTooltips/modules.ts @@ -67,7 +67,7 @@ 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) && @@ -75,8 +75,11 @@ export class ModulesHoverProvider implements HoverProvider { // 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) &&