I have tried vscode.commands.executeCommand('workbench.action.editor.changeLanguageMode', 'JSON');
. But it does nothing more than open a panel. And TextDocument.languageId
is an readonly property.
Currently this is not possible. Here is the corresponding issue on GitHub. You should upvote (thumbs up) it to tell them we want this.