From f1cfe2d3a6392ccd2fae26a19d33da417ab8fd49 Mon Sep 17 00:00:00 2001 From: turara Date: Sat, 21 Nov 2020 08:58:23 +0900 Subject: [PATCH] Update CodeActionOnSaveParticipant (#108193) * Update CodeActionOnSaveParticipant Add filtering CodeActionKind.SourceFixAll derivatives for codeActionsOnSave * Add CodeActionOnSaveParticipant#createCodeActionsOnSave method to remove subsets. Fixes #106924. --- .../codeEditor/browser/saveParticipants.ts | 25 +++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/src/vs/workbench/contrib/codeEditor/browser/saveParticipants.ts b/src/vs/workbench/contrib/codeEditor/browser/saveParticipants.ts index f2770354531..d540af4e095 100644 --- a/src/vs/workbench/contrib/codeEditor/browser/saveParticipants.ts +++ b/src/vs/workbench/contrib/codeEditor/browser/saveParticipants.ts @@ -287,8 +287,7 @@ class CodeActionOnSaveParticipant implements ITextFileSaveParticipant { ? setting : Object.keys(setting).filter(x => setting[x]); - const codeActionsOnSave = settingItems - .map(x => new CodeActionKind(x)); + const codeActionsOnSave = this.createCodeActionsOnSave(settingItems); if (!Array.isArray(setting)) { codeActionsOnSave.sort((a, b) => { @@ -319,6 +318,28 @@ class CodeActionOnSaveParticipant implements ITextFileSaveParticipant { await this.applyOnSaveActions(textEditorModel, codeActionsOnSave, excludedActions, progress, token); } + private createCodeActionsOnSave(settingItems: string[]): CodeActionKind[] { + const actionSeeds = new Set(); + + // Remove subsets + const len = settingItems.length; + outer: for (let i = 0; i < len; i++) { + const s1 = settingItems[i]; + for (let j = 0; j < len; j++) { + if (j === i) { + continue; + } + const s2 = settingItems[j]; + if (s1.startsWith(s2) && s1.length > s2.length) { + continue outer; + } + } + actionSeeds.add(s1); + } + + return Array.from(actionSeeds).map(x => new CodeActionKind(x)); + } + private async applyOnSaveActions(model: ITextModel, codeActionsOnSave: readonly CodeActionKind[], excludes: readonly CodeActionKind[], progress: IProgress, token: CancellationToken): Promise { const getActionProgress = new class implements IProgress { -- GitLab