@@ -116,7 +116,7 @@ export class RoslynLanguageServer {
116
116
this . registerTelemetryChanged ( ) ;
117
117
118
118
this . _diagnosticsReportedByBuild = vscode . languages . createDiagnosticCollection ( 'csharp-build' ) ;
119
- this . addDiagnostics ( ) ;
119
+ this . registerDocumentOpenForDiagnostics ( ) ;
120
120
121
121
// Register Razor dynamic file info handling
122
122
this . registerDynamicFileInfo ( ) ;
@@ -705,7 +705,8 @@ export class RoslynLanguageServer {
705
705
) ;
706
706
}
707
707
708
- private addDiagnostics ( ) {
708
+ private registerDocumentOpenForDiagnostics ( ) {
709
+ // When a file is opened process any build diagnostics that may be shown
709
710
this . _languageClient . addDisposable (
710
711
vscode . workspace . onDidOpenTextDocument ( async ( event ) => this . _onFileOpened ( event ) )
711
712
) ;
@@ -744,12 +745,12 @@ export class RoslynLanguageServer {
744
745
745
746
private async _onFileOpened ( document : vscode . TextDocument ) {
746
747
const uri = document . uri ;
747
- const buildIds = await this . getBuildOnlyDiagnosticIds ( CancellationToken . None ) ;
748
- const currentFileBuildDiagnostics = this . _allBuildDiagnostics . find ( ( [ u ] ) => this . compareUri ( u , uri ) ) ;
748
+ const currentFileBuildDiagnostics = this . _allBuildDiagnostics ?. find ( ( [ u ] ) => this . compareUri ( u , uri ) ) ;
749
749
750
750
// The document is now open in the editor and live diagnostics are being shown. Filter diagnostics
751
751
// reported by the build to show build-only problems.
752
752
if ( currentFileBuildDiagnostics ) {
753
+ const buildIds = await this . getBuildOnlyDiagnosticIds ( CancellationToken . None ) ;
753
754
const buildDiagnostics = this . _getBuildOnlyDiagnostics ( currentFileBuildDiagnostics [ 1 ] , buildIds ) ;
754
755
this . _diagnosticsReportedByBuild . set ( uri , buildDiagnostics ) ;
755
756
}
0 commit comments