Skip to content

CrendKing/code-action-from-commands

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Create Code Action that executes sequence of commands, customizable via configuration.

Unlike the general, ubiquitous commands, Code Action is a different kind of function that are more contextual to the specific content and language of the document.

While you can't execute a Code Action from the Command Palette, one unique feature that's only available through Code Action is Code Actions on Save. You can use it to execute a Code Action whenever a document is saved.

With this extension, you can create Code Action that executes sequence of commands. Then you can use it in the editor.codeActionsOnSave setting.

One way to know the ID of a command through the Command Palette is to click the gear icon to the right, then check the input box in the "Keyboard Shortcuts" page.

Example configuration

"codeActionFromCommands.codeActions.definitions": {
    // Convert tab to spaces for ALL languages
    "tabToSpaces": {
        "commands": [
            "editor.action.indentationToSpaces"
        ]
    },

    // Preview the Markdown file on save
    "previewMarkdown": {
        "commands": [
            "markdown.showPreview"
        ],
        "languages": ["markdown"]
    },

    // No-op due to empty "languages" array
    "memo": {
        "commands": [
            "workbench.action.editor.changeEOL"
        ],
        "languages": []
    }
}

// enable Code Actions on Save
"editor.codeActionsOnSave": {
    "source.codeActionFromCommands.tabToSpaces": "always",
    "source.codeActionFromCommands.previewMarkdown": "explicit"
}

Attribution

Extension icon: Action figure icons created by Freepik - Flaticon