Skip to content

Commit 4354914

Browse files
authored
Merge pull request #6475 from allisonchou/dev/allichou/CherryPickFix
Cherry pick #6473 to release
2 parents 1d7d3da + 3331149 commit 4354914

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

src/razor/src/document/razorDocumentManager.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ export class RazorDocumentManager implements IRazorDocumentManager {
2727
private readonly onRazorInitializedEmitter = new vscode.EventEmitter<void>();
2828

2929
public razorDocumentGenerationInitialized = false;
30-
private anyRazorDocumentOpen = false;
3130

3231
constructor(private readonly serverClient: RazorLanguageServerClient, private readonly logger: RazorLogger) {}
3332

@@ -156,7 +155,6 @@ export class RazorDocumentManager implements IRazorDocumentManager {
156155
}
157156

158157
private async openDocument(uri: vscode.Uri) {
159-
this.anyRazorDocumentOpen = true;
160158
await this.ensureRazorInitialized();
161159

162160
const document = this._getDocument(uri);
@@ -165,12 +163,11 @@ export class RazorDocumentManager implements IRazorDocumentManager {
165163
}
166164

167165
public async ensureRazorInitialized() {
168-
// On first open of a Razor document, we kick off the generation of all razor documents so that
169-
// components are discovered correctly. If we do this early, when we initialize everything, we
170-
// just spend a lot of time generating documents and json files that might not be needed.
171-
// If we wait for each individual document to be opened by the user, then locally defined components
172-
// don't work, which is a poor experience. This is the compromise.
173-
if (this.roslynActivated && !this.razorDocumentGenerationInitialized && this.anyRazorDocumentOpen) {
166+
// Kick off the generation of all Razor documents so that components are
167+
// discovered correctly. We need to do this even if a Razor file isn't
168+
// open yet to handle the scenario where the user opens a C# file before
169+
// a Razor file.
170+
if (this.roslynActivated && !this.razorDocumentGenerationInitialized) {
174171
this.razorDocumentGenerationInitialized = true;
175172
vscode.commands.executeCommand(razorInitializeCommand);
176173
for (const document of this.documents) {

0 commit comments

Comments
 (0)