Skip to content

Commit

Permalink
CM-35345 - Fix Quick Fix duplication (#81)
Browse files Browse the repository at this point in the history
  • Loading branch information
MarshalX authored Apr 26, 2024
1 parent ad4b93f commit 6483168
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion src/providers/code-actions/CodeActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export class CycodeActions implements vscode.CodeActionProvider {
codeActions.push(...this.createCodeActions(diagnosticCode, diagnostics, document, range));
}

return codeActions;
return this.getUniqueCodeActions(codeActions);
}

private createCodeActions(
Expand All @@ -47,4 +47,29 @@ export class CycodeActions implements vscode.CodeActionProvider {
return [];
}
}

private getUniqueCodeActions(actions: vscode.CodeAction[]): vscode.CodeAction[] {
/*
* The idea behind this function is to remove duplicate code actions using display name as a key.
* The aggregation of diagnostics by code is not enough for "ignore path" action.
* One range could have multiple diagnostics with different codes, *ignore path* action is the same for all of them.
*
* We don't have this problem in Intellij Plugin because, I assume, they have this deduplication logic in place.
*
* Note: display name must be unique for each action, for example, "Ignore rule: UUID"
*/
const codeActions: vscode.CodeAction[] = [];
const visitedActions = new Set<string>();

for (const action of actions) {
if (visitedActions.has(action.title)) {
continue;
}

visitedActions.add(action.title);
codeActions.push(action);
}

return codeActions;
}
}

0 comments on commit 6483168

Please sign in to comment.