From ade9e84421dcd6677ca7f07116dfc0fb073e1cba Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 12 Jun 2025 19:35:09 +0000 Subject: [PATCH 1/3] Initial plan for issue From a7f0df5cb5e2c017a4f949e0889b1cbee5dc9d34 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 12 Jun 2025 23:34:43 +0000 Subject: [PATCH 2/3] Initial investigation into issue #61766 Co-authored-by: RyanCavanaugh <6685088+RyanCavanaugh@users.noreply.github.com> --- .../fourslash/findAllRefsWithDeclareModule.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 tests/cases/fourslash/findAllRefsWithDeclareModule.ts diff --git a/tests/cases/fourslash/findAllRefsWithDeclareModule.ts b/tests/cases/fourslash/findAllRefsWithDeclareModule.ts new file mode 100644 index 0000000000000..6b7c9ede307f2 --- /dev/null +++ b/tests/cases/fourslash/findAllRefsWithDeclareModule.ts @@ -0,0 +1,15 @@ +/// + +////declare module '@bug/api/index' { +//// export * from "@bug/api/miscFunctions"; +////} +////declare module '@bug/api/miscFunctions' { +//// export function /*1*/myFunction(testParam: string): Promise; +////} +//// +////declare namespace bug.v0 {const api: typeof import('@bug/api/index')} +//// +//////// test.ts +////bug.v0.api./*2*/myFunction('test') + +verify.baselineFindAllReferences('1', '2'); \ No newline at end of file From 8f480ef909f5053c1197f7dcb48c696a20b8f63b Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 12 Jun 2025 23:48:06 +0000 Subject: [PATCH 3/3] Fix Find References missing with declare module (#61766) Co-authored-by: RyanCavanaugh <6685088+RyanCavanaugh@users.noreply.github.com> --- src/services/findAllReferences.ts | 25 +++++++++++++------ .../findAllRefsWithDeclareModuleDuplicate.ts | 23 +++++++++++++++++ 2 files changed, 41 insertions(+), 7 deletions(-) create mode 100644 tests/cases/fourslash/findAllRefsWithDeclareModuleDuplicate.ts diff --git a/src/services/findAllReferences.ts b/src/services/findAllReferences.ts index a2ed0feb795a7..395afdadf096d 100644 --- a/src/services/findAllReferences.ts +++ b/src/services/findAllReferences.ts @@ -1687,13 +1687,24 @@ export namespace Core { scope = next; } } - } - - // If symbol.parent, this means we are in an export of an external module. (Otherwise we would have returned `undefined` above.) - // For an export of a module, we may be in a declaration file, and it may be accessed elsewhere. E.g.: - // declare module "a" { export type T = number; } - // declare module "b" { import { T } from "a"; export const x: T; } - // So we must search the whole source file. (Because we will mark the source file as seen, we we won't return to it when searching for imports.) + } + + // If symbol.parent, this means we are in an export of an external module. (Otherwise we would have returned `undefined` above.) + // For an export of a module, we may be in a declaration file, and it may be accessed elsewhere. E.g.: + // declare module "a" { export type T = number; } + // declare module "b" { import { T } from "a"; export const x: T; } + // So we must search the whole source file. (Because we will mark the source file as seen, we we won't return to it when searching for imports.) + // However, for declare modules, the exports are globally accessible and can be used from any file, so we should do a global search. + if (exposedByParent && parent && isExternalModuleSymbol(parent)) { + // Check if this is a declare module by examining the declarations + const isInDeclareModule = parent.declarations?.some(decl => + isModuleDeclaration(decl) && (decl.flags & NodeFlags.GlobalAugmentation) === 0 + ); + if (isInDeclareModule) { + // For declare modules, do a global search since their exports can be accessed from anywhere + return undefined; + } + } return exposedByParent ? scope!.getSourceFile() : scope; // TODO: GH#18217 } diff --git a/tests/cases/fourslash/findAllRefsWithDeclareModuleDuplicate.ts b/tests/cases/fourslash/findAllRefsWithDeclareModuleDuplicate.ts new file mode 100644 index 0000000000000..68edae355437e --- /dev/null +++ b/tests/cases/fourslash/findAllRefsWithDeclareModuleDuplicate.ts @@ -0,0 +1,23 @@ +/// + +////declare module '@bug/api/index' { +//// export * from "@bug/api/miscFunctions"; +////} +////declare module '@bug/api/miscFunctions' { +//// export function /*1*/myFunction(testParam: string): Promise; +////} +//// +////declare namespace bug.v0 {const api: typeof import('@bug/api/index')} + +////declare module '@bug/api/index' { +//// export * from "@bug/api/miscFunctions"; +////} +////declare module '@bug/api/miscFunctions' { +//// export function /*2*/myFunction(testParam: string): Promise; +////} +//// +////declare namespace bug.v0 {const api: typeof import('@bug/api/index')} + +////bug.v0.api./*3*/myFunction('test') + +verify.baselineFindAllReferences('1', '2', '3'); \ No newline at end of file