Skip to content
Merged
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
25 changes: 23 additions & 2 deletions src/vs/workbench/contrib/codeEditor/browser/saveParticipants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down Expand Up @@ -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<string>();

// Remove subsets
const len = settingItems.length;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of nested for loops, can you use array.filter? That should simplify the logic

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<IProgressStep>, token: CancellationToken): Promise<void> {

const getActionProgress = new class implements IProgress<CodeActionProvider> {
Expand Down