Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/compiler/moduleNameResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -959,7 +959,7 @@ function compilerOptionValueToString(value: unknown): string {

/** @internal */
export function getKeyForCompilerOptions(options: CompilerOptions, affectingOptionDeclarations: readonly CommandLineOption[]): string {
return affectingOptionDeclarations.map(option => compilerOptionValueToString(getCompilerOptionValue(options, option))).join("|") + `|${options.pathsBasePath}`;
return affectingOptionDeclarations.map(option => compilerOptionValueToString(getCompilerOptionValue(options, option))).join("|");
}

/** @internal */
Expand Down Expand Up @@ -1042,7 +1042,7 @@ function createCacheWithRedirects<K, V>(ownOptions: CompilerOptions | undefined,
function getRedirectsCacheKey(options: CompilerOptions) {
let result = optionsToRedirectsKey.get(options);
if (!result) {
optionsToRedirectsKey.set(options, result = getKeyForCompilerOptions(options, moduleResolutionOptionDeclarations) as RedirectsCacheKey);
optionsToRedirectsKey.set(options, result = (getKeyForCompilerOptions(options, moduleResolutionOptionDeclarations) + `|${options.pathsBasePath}`) as RedirectsCacheKey);
}
return result;
}
Expand Down
57 changes: 57 additions & 0 deletions src/testRunner/unittests/tsserver/documentRegistry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,63 @@ describe("unittests:: tsserver:: documentRegistry:: document registry in project
});
});

describe("unittests:: tsserver:: documentRegistry:: projects with different pathsBasePath share the same document registry bucket", () => {
function getProject(session: TestSession, config: File) {
return session.getProjectService().configuredProjects.get(config.path.toLowerCase())!;
}

it("shares document registry bucket for projects with same compiler options but different pathsBasePath", () => {
const sharedFile: File = {
path: "/home/src/projects/shared/utils.d.ts",
content: "export const util: number;",
};

const configA: File = {
path: "/home/src/projects/projectA/tsconfig.json",
content: jsonToReadableText({
compilerOptions: { paths: { "@utils": ["../shared/utils.d.ts"] } },
files: ["index.ts"],
}),
};
const indexA: File = {
path: "/home/src/projects/projectA/index.ts",
content: `import { util } from "@utils";`,
};

const configB: File = {
path: "/home/src/projects/projectB/tsconfig.json",
content: jsonToReadableText({
compilerOptions: { paths: { "@utils": ["../shared/utils.d.ts"] } },
files: ["index.ts"],
}),
};
const indexB: File = {
path: "/home/src/projects/projectB/index.ts",
content: `import { util } from "@utils";`,
};

const host = TestServerHost.createServerHost([sharedFile, configA, indexA, configB, indexB]);
const session = new TestSession(host);
openFilesForSession([
{ file: indexA, projectRootPath: "/home/src/projects/projectA" },
{ file: indexB, projectRootPath: "/home/src/projects/projectB" },
], session);

const projectA = getProject(session, configA);
const projectB = getProject(session, configB);

// Both projects should reuse the same source file instance for the shared file
const sharedInfo = session.getProjectService().getScriptInfo(sharedFile.path)!;
const sourceFileA = projectA.getSourceFile(sharedInfo.path);
const sourceFileB = projectB.getSourceFile(sharedInfo.path);
assert.equal(sourceFileA, sourceFileB, "Both projects should share the same source file instance from the document registry");

session.logger.log("DocumentRegistry::");
session.logger.log(reportDocumentRegistryStats(session.getProjectService().documentRegistry).join("\n"));
baselineTsserverLogs("documentRegistry", "shares document registry bucket for projects with different pathsBasePath", session);
});
});

describe("unittests:: tsserver:: documentRegistry:: works when reusing orphan script info with different scriptKind", () => {
it("works when reusing orphan script info with different scriptKind", () => {
const host = TestServerHost.createServerHost({});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ ScriptInfos::
/user/username/projects/myproject/tsconfig.json

DocumentRegistry::
Key:: undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined
Key:: undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined
/user/username/projects/myproject/index.ts: TS 1
/user/username/projects/myproject/module1.d.ts: TS 1
/home/src/tslibs/ts/lib/lib.es2025.full.d.ts: TS 1
Expand Down Expand Up @@ -262,7 +262,7 @@ Info seq [hh:mm:ss:mss] Files (2)

Info seq [hh:mm:ss:mss] -----------------------------------------------
DocumentRegistry::
Key:: undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined
Key:: undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined
/user/username/projects/myproject/index.ts: TS 1
/home/src/tslibs/ts/lib/lib.es2025.full.d.ts: TS 1
Info seq [hh:mm:ss:mss] FileWatcher:: Triggered with /user/username/projects/myproject/module1.d.ts 1:: WatchInfo: /user/username/projects/myproject/module1.d.ts 500 undefined WatchType: Closed Script info
Expand Down Expand Up @@ -357,7 +357,7 @@ Info seq [hh:mm:ss:mss] Files (3)

Info seq [hh:mm:ss:mss] -----------------------------------------------
DocumentRegistry::
Key:: undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined
Key:: undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined
/user/username/projects/myproject/index.ts: TS 1
/home/src/tslibs/ts/lib/lib.es2025.full.d.ts: TS 1
/user/username/projects/myproject/module1.d.ts: TS 1
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ ScriptInfos::
/user/username/projects/myproject/tsconfig.json

DocumentRegistry::
Key:: undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined
Key:: undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined
/user/username/projects/myproject/index.ts: TS 1
/user/username/projects/myproject/module1.d.ts: TS 1
/home/src/tslibs/ts/lib/lib.es2025.full.d.ts: TS 1
Expand Down Expand Up @@ -262,7 +262,7 @@ Info seq [hh:mm:ss:mss] Files (2)

Info seq [hh:mm:ss:mss] -----------------------------------------------
DocumentRegistry::
Key:: undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined
Key:: undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined
/user/username/projects/myproject/index.ts: TS 1
/home/src/tslibs/ts/lib/lib.es2025.full.d.ts: TS 1
Before request
Expand Down Expand Up @@ -349,7 +349,7 @@ Info seq [hh:mm:ss:mss] Files (3)

Info seq [hh:mm:ss:mss] -----------------------------------------------
DocumentRegistry::
Key:: undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined
Key:: undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined
/user/username/projects/myproject/index.ts: TS 1
/home/src/tslibs/ts/lib/lib.es2025.full.d.ts: TS 1
/user/username/projects/myproject/module1.d.ts: TS 1
Loading