33 * Licensed under the MIT License. See License.txt in the project root for license information.
44 *--------------------------------------------------------------------------------------------*/
55import * as vscode from 'vscode' ;
6+ import { commonOptions } from '../shared/options' ;
67
78export enum AnalysisSetting {
89 FullSolution = 'fullSolution' ,
@@ -45,7 +46,7 @@ export class BuildDiagnosticsService {
4546 // Show the build-only diagnostics
4647 displayedBuildDiagnostics . push ( [
4748 uri ,
48- BuildDiagnosticsService . filerDiagnosticsFromBuild ( diagnosticList , buildOnlyIds , isDocumentOpen ) ,
49+ BuildDiagnosticsService . filterDiagnosticsFromBuild ( diagnosticList , buildOnlyIds , isDocumentOpen ) ,
4950 ] ) ;
5051 } ) ;
5152
@@ -63,7 +64,7 @@ export class BuildDiagnosticsService {
6364 // The document is now open in the editor and live diagnostics are being shown. Filter diagnostics
6465 // reported by the build to show build-only problems.
6566 if ( currentFileBuildDiagnostics ) {
66- const buildDiagnostics = BuildDiagnosticsService . filerDiagnosticsFromBuild (
67+ const buildDiagnostics = BuildDiagnosticsService . filterDiagnosticsFromBuild (
6768 currentFileBuildDiagnostics [ 1 ] ,
6869 buildOnlyIds ,
6970 true
@@ -72,64 +73,69 @@ export class BuildDiagnosticsService {
7273 }
7374 }
7475
75- public static filerDiagnosticsFromBuild (
76+ public static filterDiagnosticsFromBuild (
7677 diagnosticList : vscode . Diagnostic [ ] ,
7778 buildOnlyIds : string [ ] ,
7879 isDocumentOpen : boolean
7980 ) : vscode . Diagnostic [ ] {
80- const configuration = vscode . workspace . getConfiguration ( ) ;
81- const analyzerDiagnosticScope = configuration . get (
82- 'dotnet.backgroundAnalysis.analyzerDiagnosticsScope'
83- ) as AnalysisSetting ;
84- const compilerDiagnosticScope = configuration . get (
85- 'dotnet.backgroundAnalysis.compilerDiagnosticsScope'
86- ) as AnalysisSetting ;
81+ const analyzerDiagnosticScope = commonOptions . analyzerDiagnosticScope as AnalysisSetting ;
82+ const compilerDiagnosticScope = commonOptions . compilerDiagnosticScope as AnalysisSetting ;
8783
8884 // If compiler and analyzer diagnostics are set to "none", show everything reported by the build
8985 if ( analyzerDiagnosticScope === AnalysisSetting . None && compilerDiagnosticScope === AnalysisSetting . None ) {
9086 return diagnosticList ;
9187 }
9288
9389 // Filter the diagnostics reported by the build. Some may already be shown by live diagnostics.
94- const buildOnlyDiagnostics : vscode . Diagnostic [ ] = [ ] ;
95- diagnosticList . forEach ( ( d ) => {
96- if ( d . code ) {
97- // If it is a project system diagnostic (e.g. "Target framework out of support")
98- // then always show it. It cannot be reported by live.
99- if ( this . isProjectSystemDiagnostic ( d ) ) {
100- buildOnlyDiagnostics . push ( d ) ;
101- }
102- // If it is a "build-only"diagnostics (i.e. it can only be found by building)
103- // then always show it. It cannot be reported by live.
104- else if ( buildOnlyIds . find ( ( b_id ) => b_id === d . code ) ) {
105- buildOnlyDiagnostics . push ( d ) ;
106- } else {
107- const isAnalyzerDiagnostic = BuildDiagnosticsService . isAnalyzerDiagnostic ( d ) ;
108- const isCompilerDiagnostic = BuildDiagnosticsService . isCompilerDiagnostic ( d ) ;
109-
110- if (
111- ( isAnalyzerDiagnostic && analyzerDiagnosticScope === AnalysisSetting . None ) ||
112- ( isCompilerDiagnostic && compilerDiagnosticScope === AnalysisSetting . None )
113- ) {
114- // If live diagnostics are completely turned off for this type, then show the build diagnostic
115- buildOnlyDiagnostics . push ( d ) ;
116- } else if ( isDocumentOpen ) {
117- // no-op. The document is open and live diagnostis are on. This diagnostic is already being shown.
118- } else if (
119- ( isAnalyzerDiagnostic && analyzerDiagnosticScope === AnalysisSetting . FullSolution ) ||
120- ( isCompilerDiagnostic && compilerDiagnosticScope === AnalysisSetting . FullSolution )
121- ) {
122- // no-op. Full solution analysis is on for this diagnostic type. All diagnostics are already being shown.
123- } else {
124- // The document is closed, and the analysis setting is to only show for open files.
125- // Show the diagnostic reported by build.
126- buildOnlyDiagnostics . push ( d ) ;
127- }
128- }
129- }
130- } ) ;
90+ const buildDiagnosticsToDisplay : vscode . Diagnostic [ ] = [ ] ;
91+
92+ // If it is a project system diagnostic (e.g. "Target framework out of support")
93+ // then always show it. It cannot be reported by live.
94+ const projectSystemDiagnostics = diagnosticList . filter ( ( d ) =>
95+ BuildDiagnosticsService . isProjectSystemDiagnostic ( d )
96+ ) ;
97+ buildDiagnosticsToDisplay . push ( ...projectSystemDiagnostics ) ;
98+
99+ // If it is a "build-only"diagnostics (i.e. it can only be found by building)
100+ // then always show it. It cannot be reported by live.
101+ const buildOnlyDiagnostics = diagnosticList . filter ( ( d ) =>
102+ BuildDiagnosticsService . isBuildOnlyDiagnostic ( buildOnlyIds , d )
103+ ) ;
104+ buildDiagnosticsToDisplay . push ( ...buildOnlyDiagnostics ) ;
105+
106+ // Check the analyzer diagnostic setting. If the setting is "none" or if the file is closed,
107+ // then no live analyzers are being shown and bulid analyzers should be added.
108+ // If FSA is on, then this is a no-op as FSA will report all analyzer diagnostics
109+ if (
110+ analyzerDiagnosticScope === AnalysisSetting . None ||
111+ ( analyzerDiagnosticScope === AnalysisSetting . OpenFiles && ! isDocumentOpen )
112+ ) {
113+ const analyzerDiagnostics = diagnosticList . filter (
114+ // Needs to be analyzer diagnostics and not already reported as "build only"
115+ ( d ) => BuildDiagnosticsService . isAnalyzerDiagnostic ( d ) && ! this . isBuildOnlyDiagnostic ( buildOnlyIds , d )
116+ ) ;
117+ buildDiagnosticsToDisplay . push ( ...analyzerDiagnostics ) ;
118+ }
119+
120+ // Check the compiler diagnostic setting. If the setting is "none" or if the file is closed,
121+ // then no live compiler diagnostics are being shown and bulid compiler diagnostics should be added.
122+ // If FSA is on, then this is a no-op as FSA will report all compiler diagnostics
123+ if (
124+ compilerDiagnosticScope === AnalysisSetting . None ||
125+ ( compilerDiagnosticScope === AnalysisSetting . OpenFiles && ! isDocumentOpen )
126+ ) {
127+ const compilerDiagnostics = diagnosticList . filter (
128+ // Needs to be analyzer diagnostics and not already reported as "build only"
129+ ( d ) => BuildDiagnosticsService . isCompilerDiagnostic ( d ) && ! this . isBuildOnlyDiagnostic ( buildOnlyIds , d )
130+ ) ;
131+ buildDiagnosticsToDisplay . push ( ...compilerDiagnostics ) ;
132+ }
133+
134+ return buildDiagnosticsToDisplay ;
135+ }
131136
132- return buildOnlyDiagnostics ;
137+ private static isBuildOnlyDiagnostic ( buildOnlyIds : string [ ] , d : vscode . Diagnostic ) : boolean {
138+ return buildOnlyIds . find ( ( b_id ) => b_id === d . code ) !== undefined ;
133139 }
134140
135141 private static isCompilerDiagnostic ( d : vscode . Diagnostic ) : boolean {
0 commit comments