diff --git a/src/harness/unittests/tsserverProjectSystem.ts b/src/harness/unittests/tsserverProjectSystem.ts index ee7b184b6d0..c4a641d5b13 100644 --- a/src/harness/unittests/tsserverProjectSystem.ts +++ b/src/harness/unittests/tsserverProjectSystem.ts @@ -31,6 +31,7 @@ namespace ts { protected projectService: server.ProjectService; constructor(private readonly host: server.ServerHost) { super(); + this.init(); } abstract cachePath: string; @@ -259,6 +260,8 @@ namespace ts { readonly watchedDirectories: MapLike<{ cb: DirectoryWatcherCallback, recursive: boolean }[]> = {}; readonly watchedFiles: MapLike = {}; + + private filesOrFolders: FileOrFolder[]; constructor(public useCaseSensitiveFileNames: boolean, private executingFilePath: string, private currentDirectory: string, fileOrFolderList: FileOrFolder[]) { this.getCanonicalFileName = createGetCanonicalFileName(useCaseSensitiveFileNames); @@ -268,6 +271,7 @@ namespace ts { } reloadFS(filesOrFolders: FileOrFolder[]) { + this.filesOrFolders = filesOrFolders; this.fs = createFileMap(); for (const fileOrFolder of filesOrFolders) { const path = this.toPath(fileOrFolder.path); @@ -419,15 +423,36 @@ namespace ts { this.immediateCallbacks.unregister(timeoutId); }; + createDirectory(directoryName: string): void { + this.createFileOrFolder({ path: directoryName }); + } + writeFile(path: string, content: string): void { + this.createFileOrFolder({ path, content, fileSize: content.length }) + } + + createFileOrFolder(f: FileOrFolder, createParentDirectory = false): void { + const base = getDirectoryPath(f.path); + if (base !== f.path && !this.directoryExists(base)) { + if (createParentDirectory) { + // TODO: avoid reloading FS on every creation + this.createFileOrFolder({ path: base }, createParentDirectory); + } + else { + throw new Error(`directory ${base} does not exist`); + } + } + const filesOrFolders = this.filesOrFolders.slice(0); + filesOrFolders.push(f); + this.reloadFS(filesOrFolders); + } + readonly readFile = (s: string) => (this.fs.get(this.toPath(s))).content; readonly resolvePath = (s: string) => s; readonly getExecutingFilePath = () => this.executingFilePath; readonly getCurrentDirectory = () => this.currentDirectory; - readonly writeFile = (path: string, content: string) => notImplemented(); readonly writeCompressedData = () => notImplemented(); readonly write = (s: string) => notImplemented(); - readonly createDirectory = (s: string) => notImplemented(); readonly exit = () => notImplemented(); } @@ -1496,7 +1521,7 @@ namespace ts { class TypingInstaller extends TestTypingsInstaller { cachePath = "/a/data/"; constructor(host: server.ServerHost) { - super(host) + super(host); } }; const installer = new TypingInstaller(host); @@ -1507,9 +1532,11 @@ namespace ts { const p = projectService.configuredProjects[0]; checkProjectActualFiles(p, [ file1.path ]); + assert(host.fileExists(combinePaths(installer.cachePath, "tsd.json"))); + installer.runPostInstallActions(t => { assert.deepEqual(t, ["jquery"]); - host.reloadFS([file1, tsconfig, packageJson, jquery]); + host.createFileOrFolder(jquery, /*createParentDirectory*/ true); return ["jquery/jquery.d.ts"]; }); checkNumberOfProjects(projectService, { configuredProjects: 1 }) diff --git a/src/server/editorServices.ts b/src/server/editorServices.ts index c24fac04dd3..1c177437e55 100644 --- a/src/server/editorServices.ts +++ b/src/server/editorServices.ts @@ -212,6 +212,7 @@ namespace ts.server { return; } this.typingsCache.updateTypingsForProject(response.projectName, response.compilerOptions, response.typingOptions, response.typings); + project.setTypings(response.typings); project.updateGraph(); }