I have a Visual Studio Code extension where I try to open a virtual editor:
vscode.workspace.openTextDocument(vscode.Uri.parse(previewSchema + ":" + path))
context.subscriptions.push(extractHibernateLogCommand, vscode.Disposable.from(
vscode.workspace.registerTextDocumentContentProvider(previewSchema, hibernateExtractorProvider)
));
Those documents are always language:plain-text. Is it possible to change this programmatically to "SQL" to have the correct highlighting?
Full code
Since VSCode 1.28 (September 2018), it's also possible to set the language mode for a document after it has been created using languages.setTextDocumentLanguage()
:
Set (and change) the language that is associated with the given document.
Note that calling this function will trigger the
onDidCloseTextDocument
event followed by theonDidOpenTextDocument
event.
Here's a simple example that opens a document containing {}
and sets the language to JSON:
vscode.workspace.openTextDocument({content: "{}"}).then(document => {
vscode.window.showTextDocument(document);
vscode.languages.setTextDocumentLanguage(document, "json");
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With