Zen
Zen

Reputation: 5500

How to change language mode programmatically via VS Code extension API?

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.

Upvotes: 6

Views: 1199

Answers (2)

Alex
Alex

Reputation: 67591

It was implemented at some point (1.28.0+ probably):

vscode.languages.setTextDocumentLanguage(activeEditor.document, languageId);

Upvotes: 5

dada1134
dada1134

Reputation: 111

Currently this is not possible. Here is the corresponding issue on GitHub. You should upvote (thumbs up) it to tell them we want this.

Upvotes: 1

Related Questions