3
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
4
*--------------------------------------------------------------------------------------------*/
5
5
import * as vscode from 'vscode' ;
6
+ import { commonOptions } from '../shared/options' ;
6
7
7
8
export enum AnalysisSetting {
8
9
FullSolution = 'fullSolution' ,
@@ -45,7 +46,7 @@ export class BuildDiagnosticsService {
45
46
// Show the build-only diagnostics
46
47
displayedBuildDiagnostics . push ( [
47
48
uri ,
48
- BuildDiagnosticsService . filerDiagnosticsFromBuild ( diagnosticList , buildOnlyIds , isDocumentOpen ) ,
49
+ BuildDiagnosticsService . filterDiagnosticsFromBuild ( diagnosticList , buildOnlyIds , isDocumentOpen ) ,
49
50
] ) ;
50
51
} ) ;
51
52
@@ -63,7 +64,7 @@ export class BuildDiagnosticsService {
63
64
// The document is now open in the editor and live diagnostics are being shown. Filter diagnostics
64
65
// reported by the build to show build-only problems.
65
66
if ( currentFileBuildDiagnostics ) {
66
- const buildDiagnostics = BuildDiagnosticsService . filerDiagnosticsFromBuild (
67
+ const buildDiagnostics = BuildDiagnosticsService . filterDiagnosticsFromBuild (
67
68
currentFileBuildDiagnostics [ 1 ] ,
68
69
buildOnlyIds ,
69
70
true
@@ -72,64 +73,69 @@ export class BuildDiagnosticsService {
72
73
}
73
74
}
74
75
75
- public static filerDiagnosticsFromBuild (
76
+ public static filterDiagnosticsFromBuild (
76
77
diagnosticList : vscode . Diagnostic [ ] ,
77
78
buildOnlyIds : string [ ] ,
78
79
isDocumentOpen : boolean
79
80
) : 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 ;
87
83
88
84
// If compiler and analyzer diagnostics are set to "none", show everything reported by the build
89
85
if ( analyzerDiagnosticScope === AnalysisSetting . None && compilerDiagnosticScope === AnalysisSetting . None ) {
90
86
return diagnosticList ;
91
87
}
92
88
93
89
// 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
+ }
131
136
132
- return buildOnlyDiagnostics ;
137
+ private static isBuildOnlyDiagnostic ( buildOnlyIds : string [ ] , d : vscode . Diagnostic ) : boolean {
138
+ return buildOnlyIds . find ( ( b_id ) => b_id === d . code ) !== undefined ;
133
139
}
134
140
135
141
private static isCompilerDiagnostic ( d : vscode . Diagnostic ) : boolean {
0 commit comments