Skip to content

Commit b45dfaf

Browse files
committed
PR feedback, and fix a bug
1 parent 0fe3547 commit b45dfaf

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

src/lsptoolshost/razor/htmlDocumentManager.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,20 @@ export class HtmlDocumentManager {
2525

2626
public register() {
2727
const didCloseRegistration = vscode.workspace.onDidCloseTextDocument(async (document) => {
28-
if (document.languageId !== 'html') {
28+
// We log when a virtual document is closed just in case it helps track down future bugs
29+
if (document.uri.scheme === HtmlDocumentContentProvider.scheme) {
30+
this.logger.logVerbose(`Virtual document '${document.uri}' timed out.`);
2931
return;
3032
}
3133

32-
await this.closeDocument(document.uri);
34+
// When a Razor document is closed, only then can we be sure its okay to remove the virtual document.
35+
if (document.languageId === 'aspnetcorerazor') {
36+
this.logger.logVerbose(`Document '${document.uri}' was closed.`);
37+
38+
await this.closeDocument(document.uri);
39+
40+
// TODO: Send a notification back to the server so it can cancel any pending sync requests and clear its cache.
41+
}
3342
});
3443

3544
const providerRegistration = vscode.workspace.registerTextDocumentContentProvider(
@@ -51,10 +60,10 @@ export class HtmlDocumentManager {
5160
}
5261

5362
private async closeDocument(uri: vscode.Uri) {
54-
const document = await this.getDocument(uri);
63+
const document = await this.findDocument(uri);
5564

5665
if (document) {
57-
this.logger.logVerbose(`Document '${document.uri}' was closed. Removing from the document manager.`);
66+
this.logger.logVerbose(`Removing '${document.uri}' from the document manager.`);
5867

5968
delete this.htmlDocuments[document.path];
6069
}

0 commit comments

Comments
 (0)