diff --git a/src/harness/fourslash.ts b/src/harness/fourslash.ts index 411f6762ba31d..01caa3d70efa6 100644 --- a/src/harness/fourslash.ts +++ b/src/harness/fourslash.ts @@ -2336,29 +2336,19 @@ namespace FourSlash { * @param fileName Path to file where error should be retrieved from. */ private getCodeFixActions(fileName: string, errorCode?: number): ts.CodeAction[] { - const diagnosticsForCodeFix = this.getDiagnostics(fileName).map(diagnostic => { - return { - start: diagnostic.start, - length: diagnostic.length, - code: diagnostic.code - }; - }); - const dedupedDiagnositcs = ts.deduplicate(diagnosticsForCodeFix, ts.equalOwnProperties); - - let actions: ts.CodeAction[] = undefined; - - for (const diagnostic of dedupedDiagnositcs) { + const diagnosticsForCodeFix = this.getDiagnostics(fileName).map(diagnostic => ({ + start: diagnostic.start, + length: diagnostic.length, + code: diagnostic.code + })); + return ts.flatMap(ts.deduplicate(diagnosticsForCodeFix, ts.equalOwnProperties), diagnostic => { if (errorCode && errorCode !== diagnostic.code) { - continue; + return; } - const newActions = this.languageService.getCodeFixesAtPosition(fileName, diagnostic.start, diagnostic.start + diagnostic.length, [diagnostic.code], this.formatCodeSettings); - if (newActions && newActions.length) { - actions = actions ? actions.concat(newActions) : newActions; - } - } - return actions; + return this.languageService.getCodeFixesAtPosition(fileName, diagnostic.start, diagnostic.start + diagnostic.length, [diagnostic.code], this.formatCodeSettings); + }); } private applyCodeActions(actions: ts.CodeAction[], index?: number): void { @@ -2389,7 +2379,7 @@ namespace FourSlash { const codeFixes = this.getCodeFixActions(this.activeFile.fileName, errorCode); - if (!codeFixes || codeFixes.length === 0) { + if (codeFixes.length === 0) { if (expectedTextArray.length !== 0) { this.raiseError("No codefixes returned."); } @@ -2718,11 +2708,11 @@ namespace FourSlash { public verifyCodeFixAvailable(negative: boolean) { const codeFix = this.getCodeFixActions(this.activeFile.fileName); - if (negative && codeFix) { + if (negative && codeFix.length) { this.raiseError(`verifyCodeFixAvailable failed - expected no fixes but found one.`); } - if (!(negative || codeFix)) { + if (!(negative || codeFix.length)) { this.raiseError(`verifyCodeFixAvailable failed - expected code fixes but none found.`); } } diff --git a/src/services/pathCompletions.ts b/src/services/pathCompletions.ts index bc94fb7dbc5ed..8addcf494bf3f 100644 --- a/src/services/pathCompletions.ts +++ b/src/services/pathCompletions.ts @@ -40,13 +40,8 @@ namespace ts.Completions.PathCompletions { rootDirs = map(rootDirs, rootDirectory => normalizePath(isRootedDiskPath(rootDirectory) ? rootDirectory : combinePaths(basePath, rootDirectory))); // Determine the path to the directory containing the script relative to the root directory it is contained within - let relativeDirectory: string; - for (const rootDirectory of rootDirs) { - if (containsPath(rootDirectory, scriptPath, basePath, ignoreCase)) { - relativeDirectory = scriptPath.substr(rootDirectory.length); - break; - } - } + const relativeDirectory = forEach(rootDirs, rootDirectory => + containsPath(rootDirectory, scriptPath, basePath, ignoreCase) ? scriptPath.substr(rootDirectory.length) : undefined); // Now find a path for each potential directory that is to be merged with the one containing the script return deduplicate(map(rootDirs, rootDirectory => combinePaths(rootDirectory, relativeDirectory))); diff --git a/src/services/services.ts b/src/services/services.ts index d89051ee666c2..5b2cf949d2a9a 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -1770,19 +1770,12 @@ namespace ts { const sourceFile = getValidSourceFile(fileName); const span = createTextSpanFromBounds(start, end); const newLineCharacter = getNewLineOrDefaultFromHost(host); + const rulesProvider = getRuleProvider(formatOptions); - let allFixes: CodeAction[] = []; - - forEach(deduplicate(errorCodes), errorCode => { + return flatMap(deduplicate(errorCodes), errorCode => { cancellationToken.throwIfCancellationRequested(); - const rulesProvider = getRuleProvider(formatOptions); - const fixes = codefix.getFixes({ errorCode, sourceFile, span, program, newLineCharacter, host, cancellationToken, rulesProvider }); - if (fixes) { - allFixes = allFixes.concat(fixes); - } + return codefix.getFixes({ errorCode, sourceFile, span, program, newLineCharacter, host, cancellationToken, rulesProvider }); }); - - return allFixes; } function getDocCommentTemplateAtPosition(fileName: string, position: number): TextInsertion {