I try to figure out, how to update a virtual document with my own custom Provider, which I have opened in an editor. I neither understand the docu at https://code.visualstudio.com/api/extension-guides/virtual-documents#update-virtual-documents nor the example at https://github.com/microsoft/vscode-extension-samples/tree/master/contentprovider-sample
I tried to hack something like the following:
class MyProvider implements vscode.TextDocumentContentProvider {
public onDidChangeEmitter = new vscode.EventEmitter<vscode.Uri>();
onDidChange = this.onDidChangeEmitter.event;
public static instance: LocalChangesProvider | undefined;
public constructor() {
LocalChangesProvider.instance = this;
}
provideTextDocumentContent(uri: vscode.Uri) {
return someGlobal.text;
}
}
someGlobal.text = 'other text';
MyProvider.instance.onDidChangeEmitter.fire(myUriSchema);
But it seems I am missing something. I am kind of frustrated, that I am too stupid to simply notify vscode to update my own virtual document :/ Any help is appreciated :)
While working for a minimal full example I noticed, that the myUriSchema must match the title / path of the opened document, meaning:
const documentUriToUpdate = vscode.Uri.parse(myUriSchema + ':' + myTitle);
MyProvider.instance.onDidChangeEmitter.fire(documentUriToUpdate )
P.S.:
From a design perspective this instance-hack of mine definitely wins no price - just for PoC how it works :)
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