Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 12 additions & 22 deletions src/harness/fourslash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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.");
}
Expand Down Expand Up @@ -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.`);
}
}
Expand Down
9 changes: 2 additions & 7 deletions src/services/pathCompletions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
Expand Down
13 changes: 3 additions & 10 deletions src/services/services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down