Skip to content

Commit 009dd48

Browse files
authored
Update symlink cache from AutoImportProvider resolution even if host project already contains the file via its realpath (#46830)
1 parent 0bf9729 commit 009dd48

File tree

2 files changed

+71
-3
lines changed

2 files changed

+71
-3
lines changed

src/server/project.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1944,15 +1944,15 @@ namespace ts.server {
19441944
for (const resolution of resolutions) {
19451945
if (!resolution.resolvedFileName) continue;
19461946
const { resolvedFileName, originalPath } = resolution;
1947+
if (originalPath) {
1948+
symlinkCache.setSymlinkedDirectoryFromSymlinkedFile(originalPath, resolvedFileName);
1949+
}
19471950
if (!program.getSourceFile(resolvedFileName) && (!originalPath || !program.getSourceFile(originalPath))) {
19481951
rootNames = append(rootNames, resolvedFileName);
19491952
// Avoid creating a large project that would significantly slow down time to editor interactivity
19501953
if (dependencySelection === PackageJsonAutoImportPreference.Auto && rootNames.length > this.maxDependencies) {
19511954
return ts.emptyArray;
19521955
}
1953-
if (originalPath) {
1954-
symlinkCache.setSymlinkedDirectoryFromSymlinkedFile(originalPath, resolvedFileName);
1955-
}
19561956
}
19571957
}
19581958
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/// <reference path="../fourslash.ts" />
2+
3+
// @Filename: /tsconfig.json
4+
//// { "compilerOptions": { "module": "commonjs" } }
5+
6+
// @Filename: /package.json
7+
//// { "dependencies": { "mylib": "file:packages/mylib" } }
8+
9+
// @Filename: /packages/mylib/package.json
10+
//// { "name": "mylib", "version": "1.0.0", "main": "index.js", "types": "index" }
11+
12+
// @Filename: /packages/mylib/index.ts
13+
//// export * from "./mySubDir";
14+
15+
// @Filename: /packages/mylib/mySubDir/index.ts
16+
//// export * from "./myClass";
17+
//// export * from "./myClass2";
18+
19+
// @Filename: /packages/mylib/mySubDir/myClass.ts
20+
//// export class MyClass {}
21+
22+
// @Filename: /packages/mylib/mySubDir/myClass2.ts
23+
//// export class MyClass2 {}
24+
25+
// @link: /packages/mylib -> /node_modules/mylib
26+
27+
// @Filename: /src/index.ts
28+
////
29+
//// const a = new MyClass/*1*/();
30+
//// const b = new MyClass2/*2*/();
31+
32+
goTo.marker("1");
33+
format.setOption("newLineCharacter", "\n");
34+
35+
verify.completions({
36+
marker: "1",
37+
includes: [{
38+
name: "MyClass",
39+
source: "mylib",
40+
sourceDisplay: "mylib",
41+
hasAction: true,
42+
sortText: completion.SortText.AutoImportSuggestions,
43+
}],
44+
preferences: {
45+
includeCompletionsForModuleExports: true,
46+
includeInsertTextCompletions: true,
47+
allowIncompleteCompletions: true,
48+
}
49+
});
50+
51+
verify.applyCodeActionFromCompletion("1", {
52+
name: "MyClass",
53+
source: "mylib",
54+
description: `Import 'MyClass' from module "mylib"`,
55+
data: {
56+
exportName: "MyClass",
57+
fileName: "/packages/mylib/index.ts",
58+
},
59+
preferences: {
60+
includeCompletionsForModuleExports: true,
61+
includeCompletionsWithInsertText: true,
62+
allowIncompleteCompletions: true,
63+
},
64+
newFileContent: `import { MyClass } from "mylib";
65+
66+
const a = new MyClass();
67+
const b = new MyClass2();`,
68+
});

0 commit comments

Comments
 (0)