From 9b6c7960ad63e53b330cc969a300dc8c47912ff7 Mon Sep 17 00:00:00 2001 From: Laurens Thibideau Date: Wed, 2 Apr 2025 23:39:14 -0700 Subject: [PATCH] Fixed --- contentprovider-sample/src/provider.ts | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/contentprovider-sample/src/provider.ts b/contentprovider-sample/src/provider.ts index 45146e696..d791bbca8 100644 --- a/contentprovider-sample/src/provider.ts +++ b/contentprovider-sample/src/provider.ts @@ -15,10 +15,20 @@ export default class Provider implements vscode.TextDocumentContentProvider, vsc private _subscriptions: vscode.Disposable; constructor() { - - // Listen to the `closeTextDocument`-event which means we must - // clear the corresponding model object - `ReferencesDocument` - this._subscriptions = vscode.workspace.onDidCloseTextDocument(doc => this._documents.delete(doc.uri.toString())); + this._subscriptions = vscode.Disposable.from( + // Listen to the `closeTextDocument`-event which means we must + // clear the corresponding model object - `ReferencesDocument` + vscode.workspace.onDidCloseTextDocument(doc => this._documents.delete(doc.uri.toString())), + + // This is necessary due to a race in ExtHostDocumentContentProvider where + // the onDidChange event may be triggered before the new document has been + // registered with ExtHostDocumentsAndEditors + vscode.workspace.onDidOpenTextDocument(doc => { + if (doc.uri.scheme === Provider.scheme) { + this._onDidChange.fire(doc.uri); + } + }) + ); } dispose() {