Skip to content

Commit b1eaf3e

Browse files
authored
Ensure AutoImportProviderProject can share source files with main program (#44274)
* Ensure AutoImportProviderProject can share source files with main program * Revert package-lock change * Add back reclassified options
1 parent 2ffd35d commit b1eaf3e

File tree

4 files changed

+64
-18
lines changed

4 files changed

+64
-18
lines changed

src/harness/fourslashImpl.ts

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -879,7 +879,13 @@ namespace FourSlash {
879879
nameToEntries.set(entry.name, [entry]);
880880
}
881881
else {
882-
if (entries.some(e => e.source === entry.source && this.deepEqual(e.data, entry.data))) {
882+
if (entries.some(e =>
883+
e.source === entry.source &&
884+
e.data?.exportName === entry.data?.exportName &&
885+
e.data?.fileName === entry.data?.fileName &&
886+
e.data?.moduleSpecifier === entry.data?.moduleSpecifier &&
887+
e.data?.ambientModuleName === entry.data?.ambientModuleName
888+
)) {
883889
this.raiseError(`Duplicate completions for ${entry.name}`);
884890
}
885891
entries.push(entry);
@@ -1280,16 +1286,6 @@ namespace FourSlash {
12801286

12811287
}
12821288

1283-
private deepEqual(a: unknown, b: unknown) {
1284-
try {
1285-
this.assertObjectsEqual(a, b);
1286-
return true;
1287-
}
1288-
catch {
1289-
return false;
1290-
}
1291-
}
1292-
12931289
public verifyDisplayPartsOfReferencedSymbol(expected: ts.SymbolDisplayPart[]) {
12941290
const referencedSymbols = this.findReferencesAtCaret()!;
12951291

src/server/project.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1928,20 +1928,25 @@ namespace ts.server {
19281928
}
19291929
}
19301930

1931+
/*@internal*/
1932+
static readonly compilerOptionsOverrides: CompilerOptions = {
1933+
diagnostics: false,
1934+
skipLibCheck: true,
1935+
sourceMap: false,
1936+
types: ts.emptyArray,
1937+
lib: ts.emptyArray,
1938+
noLib: true,
1939+
};
1940+
19311941
/*@internal*/
19321942
static create(dependencySelection: PackageJsonAutoImportPreference, hostProject: Project, moduleResolutionHost: ModuleResolutionHost, documentRegistry: DocumentRegistry): AutoImportProviderProject | undefined {
19331943
if (dependencySelection === PackageJsonAutoImportPreference.Off) {
19341944
return undefined;
19351945
}
19361946

1937-
const compilerOptions: CompilerOptions = {
1947+
const compilerOptions = {
19381948
...hostProject.getCompilerOptions(),
1939-
noLib: true,
1940-
diagnostics: false,
1941-
skipLibCheck: true,
1942-
types: ts.emptyArray,
1943-
lib: ts.emptyArray,
1944-
sourceMap: false,
1949+
...this.compilerOptionsOverrides,
19451950
};
19461951

19471952
const rootNames = this.getRootFileNames(dependencySelection, hostProject, moduleResolutionHost, compilerOptions);

src/testRunner/unittests/tsserver/autoImportProvider.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,15 @@ namespace ts.projectSystem {
302302
assert.isDefined(projectService.configuredProjects.get("/packages/a/tsconfig.json")!.getPackageJsonAutoImportProvider());
303303
assert.isDefined(projectService.configuredProjects.get("/packages/a/tsconfig.json")!.getPackageJsonAutoImportProvider());
304304
});
305+
306+
it("Can use the same document registry bucket key as main program", () => {
307+
for (const option of sourceFileAffectingCompilerOptions) {
308+
assert(
309+
!hasProperty(server.AutoImportProviderProject.compilerOptionsOverrides, option.name),
310+
`'${option.name}' may cause AutoImportProviderProject not to share source files with main program`
311+
);
312+
}
313+
});
305314
});
306315

307316
function setup(files: File[]) {
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/// <reference path="../fourslash.ts" />
2+
3+
// @Filename: /tsconfig.json
4+
//// { "compilerOptions": { "module": "commonjs", "lib": ["es2019"] } }
5+
6+
// @Filename: /package.json
7+
//// { "dependencies": { "antd": "*", "react": "*" } }
8+
9+
// @Filename: /node_modules/@types/react/index.d.ts
10+
//// export declare function Component(): void;
11+
12+
// @Filename: /node_modules/antd/index.d.ts
13+
//// import "react";
14+
15+
// @Filename: /index.ts
16+
//// Component/**/
17+
18+
// react/index.d.ts will be in both the auto import provider program
19+
// and the main program, and will result in duplicate completions
20+
// unless the two programs successfully share the same source file.
21+
// This tests the configuration of the AutoImportProviderProject.
22+
// See also the 'Can use the same document registry bucket key as main program'
23+
// unit test in autoImportProvider.ts.
24+
goTo.marker("");
25+
verify.completions({
26+
marker: "",
27+
includes: [{
28+
name: "Component",
29+
hasAction: true,
30+
source: "/node_modules/@types/react/index",
31+
sortText: completion.SortText.AutoImportSuggestions,
32+
}],
33+
preferences: {
34+
includeCompletionsForModuleExports: true,
35+
},
36+
});

0 commit comments

Comments
 (0)