Skip to content

Commit 284b0ac

Browse files
committed
Add server baseline test to confirm searches are not repeated
1 parent 430e24f commit 284b0ac

File tree

2 files changed

+428
-0
lines changed

2 files changed

+428
-0
lines changed

src/testRunner/unittests/tsserver/projectReferences.ts

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,126 @@ testCompositeFunction('why hello there', 42);`
581581
baselineTsserverLogs("projectReferences", `finding local reference doesnt load ancestor/sibling projects`, session);
582582
});
583583

584+
it("when finding references in overlapping projects", () => {
585+
const solutionLocation = "/user/username/projects/solution";
586+
const solutionConfig: File = {
587+
path: `${solutionLocation}/tsconfig.json`,
588+
content: JSON.stringify({
589+
files: [],
590+
include: [],
591+
references: [
592+
{ path: "./a" },
593+
{ path: "./b" },
594+
{ path: "./c" },
595+
{ path: "./d" },
596+
]
597+
})
598+
};
599+
const aConfig: File = {
600+
path: `${solutionLocation}/a/tsconfig.json`,
601+
content: JSON.stringify({
602+
compilerOptions: {
603+
composite: true,
604+
module: "none"
605+
},
606+
files: ["./index.ts"]
607+
})
608+
};
609+
const aFile: File = {
610+
path: `${solutionLocation}/a/index.ts`,
611+
content: `
612+
export interface I {
613+
M(): void;
614+
}`
615+
};
616+
617+
const bConfig: File = {
618+
path: `${solutionLocation}/b/tsconfig.json`,
619+
content: JSON.stringify({
620+
compilerOptions: {
621+
composite: true
622+
},
623+
files: ["./index.ts"],
624+
references: [
625+
{ path: "../a" }
626+
]
627+
})
628+
};
629+
const bFile: File = {
630+
path: `${solutionLocation}/b/index.ts`,
631+
content: `
632+
import { I } from "../a";
633+
634+
export class B implements I {
635+
M() {}
636+
}`
637+
};
638+
639+
const cConfig: File = {
640+
path: `${solutionLocation}/c/tsconfig.json`,
641+
content: JSON.stringify({
642+
compilerOptions: {
643+
composite: true
644+
},
645+
files: ["./index.ts"],
646+
references: [
647+
{ path: "../b" }
648+
]
649+
})
650+
};
651+
const cFile: File = {
652+
path: `${solutionLocation}/c/index.ts`,
653+
content: `
654+
import { I } from "../a";
655+
import { B } from "../b";
656+
657+
export const C: I = new B();
658+
`
659+
};
660+
661+
const dConfig: File = {
662+
path: `${solutionLocation}/d/tsconfig.json`,
663+
content: JSON.stringify({
664+
compilerOptions: {
665+
composite: true
666+
},
667+
files: ["./index.ts"],
668+
references: [
669+
{ path: "../c" }
670+
]
671+
})
672+
};
673+
const dFile: File = {
674+
path: `${solutionLocation}/d/index.ts`,
675+
content: `
676+
import { I } from "../a";
677+
import { C } from "../c";
678+
679+
export const D: I = C;
680+
`
681+
};
682+
683+
const files = [libFile, solutionConfig, aConfig, aFile, bConfig, bFile, cConfig, cFile, dConfig, dFile, libFile];
684+
const host = createServerHost(files);
685+
const session = createSession(host, { logger: createLoggerWithInMemoryLogs() });
686+
openFilesForSession([bFile], session);
687+
688+
// The first search will trigger project loads
689+
session.executeCommandSeq<protocol.ReferencesRequest>({
690+
command: protocol.CommandTypes.References,
691+
arguments: protocolFileLocationFromSubstring(bFile, "I", { index: 1 })
692+
});
693+
694+
// The second search starts with the projects already loaded
695+
// Formerly, this would search some projects multiple times
696+
session.executeCommandSeq<protocol.ReferencesRequest>({
697+
command: protocol.CommandTypes.References,
698+
arguments: protocolFileLocationFromSubstring(bFile, "I", { index: 1 })
699+
});
700+
701+
baselineTsserverLogs("projectReferences", `finding references in overlapping projects`, session);
702+
});
703+
584704
describe("special handling of localness of the definitions for findAllRefs", () => {
585705
function verify(scenario: string, definition: string, usage: string, referenceTerm: string) {
586706
it(scenario, () => {

0 commit comments

Comments
 (0)