Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test: editor.codeActionsOnSave #48303

Closed
2 tasks done
mjbvz opened this issue Apr 20, 2018 · 4 comments
Closed
2 tasks done

Test: editor.codeActionsOnSave #48303

mjbvz opened this issue Apr 20, 2018 · 4 comments

Comments

@mjbvz
Copy link
Collaborator

mjbvz commented Apr 20, 2018

Complexity: 2

Test for #42092 and #46678

Background

The new editor.codeActionsOnSave setting lets you configure a set of source code actions to be run when you save file. For example, the setting:

"editor.codeActionsOnSave": {
    "source.organizeImports": true
}

enables organize imports on save.

Testing

Basic

  1. In a ts project, set:

    "editor.codeActionsOnSave": {
        "source.organizeImports": true
    }
  2. In a ts file with un-ordered imports, save

    • Confirm that the imports are correctly organized
  3. Now make the file unformatted as well and save again

    • Confirm that the imports are organized and that the file is formatted

Disable

  1. Now set

    "editor.codeActionsOnSave": {
        "source.organizeImports": false
    }
  2. Confirm that organize imports is no longer run

Other settings

  1. Try other forms such as

    "editor.codeActionsOnSave": {
        "source.organizeImports.unicorn": true
    }
    "editor.codeActionsOnSave": {
        "source": true
    }
    "editor.codeActionsOnSave": {
        "source.org": true
    }
  2. Confirm that only examples like 2 actually enable this setting. The specific rule is: apply all code actions whose kind (source.organizeImports) is equal to or a subpart of the setting kind (source or source.organizeImports).

Language specific overrides

  1. Now try using this as a language specific setting:

    "[typescript]": {
    	"editor.codeActionsOnSave": {
    		"source.organizeImports": true
    	}
    }
  2. Confirm that you can enable this setting for just ts and not for js

  3. Confirm that the language specific setting overrides a global seting

  4. Confirm that for settings such as:

    "editor.codeActionsOnSave": {
       "source.organizeImports": true
    },
    "[typescript]": {
       "editor.codeActionsOnSave": {
       	"source.unicorn": true
       }
    }

That the settings are properly merged and organize imports is run

Timeouts

  1. With organizeImports on save enabled, open the vscode workspace
  2. Try immediatly saving a ts file in src/ before the ts server has fully loaded
  3. Confirm that this operation timesout
  4. Confirm that once ts is inited, that organize imports on save works again
@weinand
Copy link
Contributor

weinand commented Apr 24, 2018

@mjbvz sorry, but I have no clue what you are talking about under "Other settings" and what is the "unicorn" thing?
The only code action suggested is "source.organizeImports". Are there others?

@sandy081
Copy link
Member

If I understand correctly, properties are scoped. It means

source: true implies source.*: true which means source.organizeImports: true

@mjbvz
Copy link
Collaborator Author

mjbvz commented Apr 24, 2018

Yes, sorry about the confusion. The intent of that test is that no code actions of kind source.organizeImports.unicorn should exist, so nothing should happen.

Let's say an extension returns three code actions with kinds:

  • source.cleanup
  • source.organizeImports
  • source.organizeImports.foo

With "editor.codeActionsOnSave": { "source": true }, all three should be fired since they are all under the source scope.

With "editor.codeActionsOnSave": { "source.organizeImports": true }, only the two organize imports should be fired.

With "editor.codeActionsOnSave": { "source.organizeImports.foo": true }, only the last code action should be fired

And with "editor.codeActionsOnSave": { "source.foo": true }, none of the code actions should be fired

@weinand weinand removed their assignment Apr 25, 2018
@weinand
Copy link
Contributor

weinand commented Apr 25, 2018

@sandy081 @mjbvz thanks for the clarification.

A simple sentence in the "Background" section like "properties under editor.codeActionsOnSave are similar to glob patterns" would have made things clearer.

Is this a new wildcard scheme in settings or are we using this scheme already somewhere?
Why are you not using real glob patterns or wildcards?
I'm always a bit reluctant when adding another meta-language on top of JSON...

/cc @bpasero @jrieken

@vscodebot vscodebot bot locked and limited conversation to collaborators Jun 10, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants