diff --git a/src/harness/harnessLanguageService.ts b/src/harness/harnessLanguageService.ts index 682496442e9..08c74e695be 100644 --- a/src/harness/harnessLanguageService.ts +++ b/src/harness/harnessLanguageService.ts @@ -135,7 +135,7 @@ namespace Harness.LanguageService { public getFilenames(): string[] { const fileNames: string[] = []; - this.virtualFileSystem.getAllFileEntries().forEach((virtualEntry) => { + ts.forEach(this.virtualFileSystem.getAllFileEntries(), (virtualEntry) => { const scriptInfo = virtualEntry.content; if (scriptInfo.isRootFile) { // only include root files here diff --git a/src/harness/virtualFileSystem.ts b/src/harness/virtualFileSystem.ts index 5a89efea7fa..2a46bf4c3fe 100644 --- a/src/harness/virtualFileSystem.ts +++ b/src/harness/virtualFileSystem.ts @@ -158,6 +158,11 @@ namespace Utils { return directory; } + /** + * Reads the directory at the given path and retrieves a list of file names and a list + * of directory names within it. Suitable for use with ts.matchFiles() + * @param path The path to the directory to be read + */ getAccessibleFileSystemEntries(path: string) { const entry = this.traversePath(path); if (entry && entry.isDirectory()) { @@ -176,8 +181,8 @@ namespace Utils { return fileEntries; function getFilesRecursive(dir: VirtualDirectory, result: VirtualFile[]) { - dir.getFiles().forEach((e) => result.push(e)); - dir.getDirectories().forEach((subDir) => getFilesRecursive(subDir, result)); + ts.forEach(dir.getFiles(), (e) => result.push(e)); + ts.forEach(dir.getDirectories(), (subDir) => getFilesRecursive(subDir, result)); } } diff --git a/src/services/services.ts b/src/services/services.ts index 04c435f1339..b7e79473fcd 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -1947,8 +1947,15 @@ namespace ts { sourceMapText?: string; } - + // Matches the beginning of a triple slash directive const tripleSlashDirectivePrefixRegex = /^\/\/\/\s* { + ts.forEach(files, (f) => { const fName = includeExtensions ? getBaseFileName(f) : removeFileExtension(getBaseFileName(f)); if (startsWith(fName, toComplete)) { @@ -4402,7 +4409,7 @@ namespace ts { // If possible, get folder completion as well if (host.getDirectories) { const directories = host.getDirectories(baseDir); - directories.forEach((d) => { + ts.forEach(directories, (d) => { const dName = getBaseFileName(removeTrailingDirectorySeparator(d)); if (startsWith(dName, toComplete)) { @@ -4471,7 +4478,7 @@ namespace ts { // Check for node_modules. We only offer completions for modules that are listed in the // package.json for a project for efficiency and to ensure that the completion list is // not polluted with sub-dependencies - findPackageJsons(scriptPath).forEach((packageJson) => { + ts.forEach(findPackageJsons(scriptPath), (packageJson) => { const package = tryReadingPackageJson(packageJson); if (!package) { return; @@ -4487,13 +4494,13 @@ namespace ts { addPotentialPackageNames(package.devDependencies, moduleNameFragment, foundModuleNames); } - foundModuleNames.forEach((moduleName) => { + ts.forEach(foundModuleNames, (moduleName) => { if (isNestedModule && moduleName === moduleNameFragment) { const moduleDir = combinePaths(nodeModulesDir, moduleName); if (directoryProbablyExists(moduleDir, host)) { const nestedFiles = host.readDirectory(moduleDir, supportedTypeScriptExtensions, /*exclude*/undefined, /*include*/["./*"]); - nestedFiles.forEach((f) => { + ts.forEach(nestedFiles, (f) => { const nestedModule = removeFileExtension(getBaseFileName(f)); nonRelativeModules.push(nestedModule); });