Update symlink cache from AutoImportProvider resolution even if host project already contains the file via its realpath (#46830)
This commit is contained in:
parent
0bf97296d6
commit
009dd487a6
|
@ -1944,15 +1944,15 @@ namespace ts.server {
|
|||
for (const resolution of resolutions) {
|
||||
if (!resolution.resolvedFileName) continue;
|
||||
const { resolvedFileName, originalPath } = resolution;
|
||||
if (originalPath) {
|
||||
symlinkCache.setSymlinkedDirectoryFromSymlinkedFile(originalPath, resolvedFileName);
|
||||
}
|
||||
if (!program.getSourceFile(resolvedFileName) && (!originalPath || !program.getSourceFile(originalPath))) {
|
||||
rootNames = append(rootNames, resolvedFileName);
|
||||
// Avoid creating a large project that would significantly slow down time to editor interactivity
|
||||
if (dependencySelection === PackageJsonAutoImportPreference.Auto && rootNames.length > this.maxDependencies) {
|
||||
return ts.emptyArray;
|
||||
}
|
||||
if (originalPath) {
|
||||
symlinkCache.setSymlinkedDirectoryFromSymlinkedFile(originalPath, resolvedFileName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
68
tests/cases/fourslash/server/autoImportProvider7.ts
Normal file
68
tests/cases/fourslash/server/autoImportProvider7.ts
Normal file
|
@ -0,0 +1,68 @@
|
|||
/// <reference path="../fourslash.ts" />
|
||||
|
||||
// @Filename: /tsconfig.json
|
||||
//// { "compilerOptions": { "module": "commonjs" } }
|
||||
|
||||
// @Filename: /package.json
|
||||
//// { "dependencies": { "mylib": "file:packages/mylib" } }
|
||||
|
||||
// @Filename: /packages/mylib/package.json
|
||||
//// { "name": "mylib", "version": "1.0.0", "main": "index.js", "types": "index" }
|
||||
|
||||
// @Filename: /packages/mylib/index.ts
|
||||
//// export * from "./mySubDir";
|
||||
|
||||
// @Filename: /packages/mylib/mySubDir/index.ts
|
||||
//// export * from "./myClass";
|
||||
//// export * from "./myClass2";
|
||||
|
||||
// @Filename: /packages/mylib/mySubDir/myClass.ts
|
||||
//// export class MyClass {}
|
||||
|
||||
// @Filename: /packages/mylib/mySubDir/myClass2.ts
|
||||
//// export class MyClass2 {}
|
||||
|
||||
// @link: /packages/mylib -> /node_modules/mylib
|
||||
|
||||
// @Filename: /src/index.ts
|
||||
////
|
||||
//// const a = new MyClass/*1*/();
|
||||
//// const b = new MyClass2/*2*/();
|
||||
|
||||
goTo.marker("1");
|
||||
format.setOption("newLineCharacter", "\n");
|
||||
|
||||
verify.completions({
|
||||
marker: "1",
|
||||
includes: [{
|
||||
name: "MyClass",
|
||||
source: "mylib",
|
||||
sourceDisplay: "mylib",
|
||||
hasAction: true,
|
||||
sortText: completion.SortText.AutoImportSuggestions,
|
||||
}],
|
||||
preferences: {
|
||||
includeCompletionsForModuleExports: true,
|
||||
includeInsertTextCompletions: true,
|
||||
allowIncompleteCompletions: true,
|
||||
}
|
||||
});
|
||||
|
||||
verify.applyCodeActionFromCompletion("1", {
|
||||
name: "MyClass",
|
||||
source: "mylib",
|
||||
description: `Import 'MyClass' from module "mylib"`,
|
||||
data: {
|
||||
exportName: "MyClass",
|
||||
fileName: "/packages/mylib/index.ts",
|
||||
},
|
||||
preferences: {
|
||||
includeCompletionsForModuleExports: true,
|
||||
includeCompletionsWithInsertText: true,
|
||||
allowIncompleteCompletions: true,
|
||||
},
|
||||
newFileContent: `import { MyClass } from "mylib";
|
||||
|
||||
const a = new MyClass();
|
||||
const b = new MyClass2();`,
|
||||
});
|
Loading…
Reference in a new issue