From 029b1f25e442f0982cb103f47a03881bb0176019 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Wed, 12 Jul 2017 12:50:52 -0700 Subject: [PATCH] Fixes the fourslash runner tests by handling hosts that cannot support read directory or getDirectories --- src/server/lsHost.ts | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/src/server/lsHost.ts b/src/server/lsHost.ts index b050a7d26d9..133db8cac2c 100644 --- a/src/server/lsHost.ts +++ b/src/server/lsHost.ts @@ -47,6 +47,20 @@ namespace ts.server { return resultFromHost; } + private canWorkWithCacheForDir(rootDir: string) { + // Some of the hosts might not be able to handle read directory or getDirectories + const path = ts.toPath(rootDir, this.currentDirectory, this.getCanonicalFileName); + if (this.cachedReadDirectoryResult.get(path)) { + return true; + } + try { + return this.getFileSystemEntries(rootDir); + } + catch (_e) { + return false; + } + } + write(s: string) { return this.host.write(s); } @@ -86,12 +100,18 @@ namespace ts.server { return this.host.getEnvironmentVariable(name); } - getDirectories(path: string) { - return this.getFileSystemEntries(path).directories; + getDirectories(rootDir: string) { + if (this.canWorkWithCacheForDir(rootDir)) { + return this.getFileSystemEntries(rootDir).directories; + } + return this.host.getDirectories(rootDir); } readDirectory(rootDir: string, extensions: string[], excludes: string[], includes: string[], depth: number): string[] { - return matchFiles(rootDir, extensions, excludes, includes, this.useCaseSensitiveFileNames, this.currentDirectory, depth, path => this.getFileSystemEntries(path)); + if (this.canWorkWithCacheForDir(rootDir)) { + return matchFiles(rootDir, extensions, excludes, includes, this.useCaseSensitiveFileNames, this.currentDirectory, depth, path => this.getFileSystemEntries(path)); + } + return this.host.readDirectory(rootDir, extensions, excludes, includes, depth); } fileExists(fileName: string): boolean {