Allow to pass language mode for workbench.action.editor.changeLanguageMode action (fix #213688) (#213912)

This commit is contained in:
Benjamin Pasero 2024-05-31 16:35:08 +02:00 committed by GitHub
parent e33013da3f
commit aaa5cb462e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1079,11 +1079,20 @@ export class ChangeLanguageAction extends Action2 {
weight: KeybindingWeight.WorkbenchContrib,
primary: KeyChord(KeyMod.CtrlCmd | KeyCode.KeyK, KeyCode.KeyM)
},
precondition: ContextKeyExpr.not('notebookEditorFocused')
precondition: ContextKeyExpr.not('notebookEditorFocused'),
metadata: {
description: localize('changeLanguageMode.description', "Change the language mode of the active text editor."),
args: [
{
name: localize('changeLanguageMode.arg.name', "The name of the language mode to change to."),
constraint: (value: any) => typeof value === 'string',
}
]
}
});
}
override async run(accessor: ServicesAccessor): Promise<void> {
override async run(accessor: ServicesAccessor, languageMode?: string): Promise<void> {
const quickInputService = accessor.get(IQuickInputService);
const editorService = accessor.get(IEditorService);
const languageService = accessor.get(ILanguageService);
@ -1162,7 +1171,7 @@ export class ChangeLanguageAction extends Action2 {
};
picks.unshift(autoDetectLanguage);
const pick = await quickInputService.pick(picks, { placeHolder: localize('pickLanguage', "Select Language Mode"), matchOnDescription: true });
const pick = typeof languageMode === 'string' ? { label: languageMode } : await quickInputService.pick(picks, { placeHolder: localize('pickLanguage', "Select Language Mode"), matchOnDescription: true });
if (!pick) {
return;
}