Have distinct js/ts commands for organize imports

Fixes #46701
This commit is contained in:
Matt Bierner 2018-03-27 14:33:34 -07:00
parent ddd967559b
commit c059826ba2
3 changed files with 25 additions and 5 deletions

View file

@ -468,6 +468,11 @@
"command": "typescript.organizeImports",
"title": "%typescript.organizeImports%",
"category": "TypeScript"
},
{
"command": "javascript.organizeImports",
"title": "%typescript.organizeImports%",
"category": "JavaScript"
}
],
"keybindings": [
@ -525,7 +530,19 @@
},
{
"command": "typescript.organizeImports",
"when": "typescript.isManagedFile && typescript.canOrganizeImports"
"when": "editorLangId == typescriptreact && typescript.isManagedFile && typescript.canOrganizeImports"
},
{
"command": "typescript.organizeImports",
"when": "editorLangId == typescript && typescript.isManagedFile && typescript.canOrganizeImports"
},
{
"command": "javascript.organizeImports",
"when": "editorLangId == javascriptreact && typescript.isManagedFile && typescript.canOrganizeImports"
},
{
"command": "javascript.organizeImports",
"when": "editorLangId == javascript && typescript.isManagedFile && typescript.canOrganizeImports"
}
]
},

View file

@ -15,8 +15,9 @@ import { Lazy } from '../utils/lazy';
import TypeScriptServiceClientHost from '../typeScriptServiceClientHost';
export class OrganizeImportsCommand implements Command {
public static readonly ID = 'typescript.organizeImports';
public readonly id = OrganizeImportsCommand.ID;
public static readonly Ids = ['javascript.organizeImports', 'typescript.organizeImports'];
public readonly id = OrganizeImportsCommand.Ids;
constructor(
private readonly lazyClientHost: Lazy<TypeScriptServiceClientHost>

View file

@ -6,7 +6,7 @@
import * as vscode from 'vscode';
export interface Command {
readonly id: string;
readonly id: string | string[];
execute(...args: any[]): void;
}
@ -22,7 +22,9 @@ export class CommandManager {
}
public register<T extends Command>(command: T): T {
this.registerCommand(command.id, command.execute, command);
for (const id of Array.isArray(command.id) ? command.id : [command.id]) {
this.registerCommand(id, command.execute, command);
}
return command;
}