sublimelsp / LSP-typescript

TypeScript, JavaScript support for Sublime LSP plugin

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Possible to run code actions automatically, without needing to save the file?

JGJP opened this issue · comments

With this configuration in LSP, I can have LSP-typescript do a bunch of useful stuff when saving the file:

	"lsp_code_actions_on_save": {
		"source.fixAll.ts": true,
		"source.removeUnused.ts": true,
		"source.addMissingImports.ts": true,
	},

Is there any way to do the this same stuff without having to save the file? For example with a command or keyboard shortcut, that would execute the actions file-wide instead of per warning/error like the current code actions context menu does.

I tried this kind of keybinding, but it doesn't seem to work:

{
	"keys": ["ctrl+super+m"],
	"command": "lsp_typescript_code_action",
	"args": {
		"action": "source.addMissingImports.ts"
	}
}

You could create a keybindings like this:

    // Show Source Actions
{
    "command": "lsp_code_actions",
    "args": {
        "only_kinds": [
            "source"
        ]
    },
    "keys": [
        "UNBOUND"
    ],
    "context": [
        {
            "key": "lsp.session_with_capability",
            "operator": "equal",
            "operand": "codeActionProvider.codeActionKinds"
        }
    ]
},

That will list all available source code actions in a quick panel
and you can select the one you need.


If you need a keybinding for specifically one code action, that is currently not possible,
For that there is this open issue sublimelsp/LSP#1356

Also the lsp_code_actions command is also accessible via the context menu(the right click menu) LSP > Source Action....