Skip to content

Update CodeActionOnSaveParticipant#108193

Merged
mjbvz merged 2 commits intomicrosoft:masterfrom
turara:fix-106924
Nov 20, 2020
Merged

Update CodeActionOnSaveParticipant#108193
mjbvz merged 2 commits intomicrosoft:masterfrom
turara:fix-106924

Conversation

@turara
Copy link
Contributor

@turara turara commented Oct 6, 2020

This PR fixes #106924.

I updated CodeActionOnSaveParticipant#participate method to filter out CodeActionKind with 'source.fixAll.eslint' from codeActionsOnSave when "source.fixAll" is true.


The reason why the eslint code action provider is called twice with the settings:

{
    "editor.codeActionsOnSave": {
        "source.fixAll": true,
        "source.fixAll.eslint": true,
    }
}

is as follows.

  1. codeActionsOnSave array has two CodeActionKinds with values of 'source.fixAll' and 'source.fixAll.eslint'

    const codeActionsOnSave = settingItems
    .map(x => new CodeActionKind(x));

  2. getActionsToRun method returns CodeActionSet with provider from eslint for both of them.

    for (const codeActionKind of codeActionsOnSave) {
    const actionsToRun = await this.getActionsToRun(model, codeActionKind, excludes, getActionProgress, token);


Should I add filtering code for other CodeActionKind such as SourceOrganizeImports, Refactor, etc...?

Please let me know, in the first place, if there are better approaches.

Add filtering CodeActionKind.SourceFixAll derivatives for codeActionsOnSave
let codeActionsOnSave = settingItems
.map(x => new CodeActionKind(x));

if (!excludedActions.some(a => a.equals(CodeActionKind.SourceFixAll))) {
Copy link
Collaborator

@mjbvz mjbvz Oct 20, 2020

Choose a reason for hiding this comment

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

I don't think we should hardcode FixAll here. Instead, the logic should be:

  • If there are multiple code actions on save
  • Remove any of them that are strict subsets of the other ones (such as source.fixAll.eslint being a subset of source.fixall)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@mjbvz Thank you for the comment. I've updated the code to remove subsets from settingItems.

@mjbvz mjbvz added this to the November 2020 milestone Oct 27, 2020
const actionSeeds = new Set<string>();

// Remove subsets
const len = settingItems.length;
Copy link
Collaborator

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

@mjbvz mjbvz merged commit f1cfe2d into microsoft:master Nov 20, 2020
@mjbvz
Copy link
Collaborator

mjbvz commented Nov 20, 2020

Merging and will look at using array.filter

mjbvz added a commit that referenced this pull request Nov 21, 2020
@turara
Copy link
Contributor Author

turara commented Nov 21, 2020

@mjbvz Sorry that I missed your comment. Thank you for your commit and merging!

chenjigeng pushed a commit to chenjigeng/vscode that referenced this pull request Nov 22, 2020
* Update CodeActionOnSaveParticipant

Add filtering CodeActionKind.SourceFixAll derivatives for codeActionsOnSave

* Add CodeActionOnSaveParticipant#createCodeActionsOnSave method to remove subsets.

Fixes microsoft#106924.
chenjigeng pushed a commit to chenjigeng/vscode that referenced this pull request Nov 22, 2020
@github-actions github-actions bot locked and limited conversation to collaborators Jan 5, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Code action provider called twice on save

2 participants