@@ -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