Include type reference directives in symlink cache, wait until program is present to create it (#44259)

* Fix discovery of more pnpm symlinks

* Add some tests

* Never show pnpm paths in auto imports, even if there’s no other path

* Import statement completions can return none

* Fix tests

* Add failing test showing poor symlink cache reuse

* Fix test, fails for right reasons now

* Preserve cache built up during program creation, then fill in with program resolutions

* Remove obsolete comment

* Remove obsolete type assertion

* Revert fully filtering out ignored paths
This commit is contained in:
Andrew Branch
2021-06-08 12:06:55 -05:00
committed by GitHub
parent bf4642f089
commit 703c1bc69d
22 changed files with 197 additions and 43 deletions

View File

@@ -213,6 +213,7 @@
"unittests/tsserver/session.ts",
"unittests/tsserver/skipLibCheck.ts",
"unittests/tsserver/smartSelection.ts",
"unittests/tsserver/symlinkCache.ts",
"unittests/tsserver/symLinks.ts",
"unittests/tsserver/syntacticServer.ts",
"unittests/tsserver/syntaxOperations.ts",

View File

@@ -0,0 +1,80 @@
namespace ts.projectSystem {
const appTsconfigJson: File = {
path: "/packages/app/tsconfig.json",
content: `
{
"compilerOptions": {
"module": "commonjs",
"outDir": "dist",
"rootDir": "src",
"baseUrl": "."
}
"references": [{ "path": "../dep" }]
}`
};
const appSrcIndexTs: File = {
path: "/packages/app/src/index.ts",
content: `import "dep/does/not/exist";`
};
const depPackageJson: File = {
path: "/packages/dep/package.json",
content: `{ "name": "dep", "main": "dist/index.js", "types": "dist/index.d.ts" }`
};
const depTsconfigJson: File = {
path: "/packages/dep/tsconfig.json",
content: `
{
"compilerOptions": { "outDir": "dist", "rootDir": "src", "module": "commonjs" }
}`
};
const depSrcIndexTs: File = {
path: "/packages/dep/src/index.ts",
content: `
import "./sub/folder";`
};
const depSrcSubFolderIndexTs: File = {
path: "/packages/dep/src/sub/folder/index.ts",
content: `export const dep = 0;`
};
const link: SymLink = {
path: "/packages/app/node_modules/dep",
symLink: "../../dep",
};
describe("unittests:: tsserver:: symlinkCache", () => {
it("contains symlinks discovered by project references resolution after program creation", () => {
const { session, projectService } = setup();
openFilesForSession([appSrcIndexTs], session);
const project = projectService.configuredProjects.get(appTsconfigJson.path)!;
assert.deepEqual(
project.getSymlinkCache()?.getSymlinkedDirectories()?.get(link.path + "/" as Path),
{ real: "/packages/dep/", realPath: "/packages/dep/" as Path }
);
});
});
function setup() {
const host = createServerHost([
appTsconfigJson,
appSrcIndexTs,
depPackageJson,
depTsconfigJson,
depSrcIndexTs,
depSrcSubFolderIndexTs,
link,
]);
const session = createSession(host);
const projectService = session.getProjectService();
return {
host,
projectService,
session,
};
}
}