@@ -7,7 +7,7 @@ import * as vscode from 'vscode';
7
7
import { describe , test , expect , beforeAll , afterAll } from '@jest/globals' ;
8
8
import testAssetWorkspace from './testAssets/testAssetWorkspace' ;
9
9
import { AnalysisSetting } from '../../../src/lsptoolshost/diagnostics/buildDiagnosticsService' ;
10
- import { getCode , setBackgroundAnalysisScopes , waitForExpectedDiagnostics } from './diagnosticsHelpers' ;
10
+ import { getCode , setDiagnosticSettings , waitForExpectedDiagnostics } from './diagnosticsHelpers' ;
11
11
import { activateCSharpExtension , describeIfCSharp } from './integrationHelpers' ;
12
12
13
13
// Restarting the server is required for these tests, but not supported with C# Dev Kit.
@@ -20,11 +20,12 @@ describeIfCSharp(`Workspace Diagnostic Tests`, () => {
20
20
await testAssetWorkspace . cleanupWorkspace ( ) ;
21
21
} ) ;
22
22
23
- describe ( 'Full solution diagnostics' , ( ) => {
24
- test ( 'Compiler and analyzer diagnostics reported for closed files when set to FullSolution' , async ( ) => {
25
- await setBackgroundAnalysisScopes ( {
26
- compiler : AnalysisSetting . FullSolution ,
27
- analyzer : AnalysisSetting . FullSolution ,
23
+ describe ( `Full solution diagnostics` , ( ) => {
24
+ test ( 'Compiler and analyzer diagnostics reported for closed files when set to FullSolution (reportInformationAsHint: true)' , async ( ) => {
25
+ await setDiagnosticSettings ( {
26
+ compilerScope : AnalysisSetting . FullSolution ,
27
+ analyzerScope : AnalysisSetting . FullSolution ,
28
+ reportInformationAsHint : true ,
28
29
} ) ;
29
30
30
31
await waitForExpectedDiagnostics ( ( diagnostics ) => {
@@ -63,11 +64,55 @@ describeIfCSharp(`Workspace Diagnostic Tests`, () => {
63
64
expect ( diagnosticsInCompletionCs [ 0 ] . severity ) . toBe ( vscode . DiagnosticSeverity . Hint ) ;
64
65
} ) ;
65
66
} ) ;
67
+ test ( 'Compiler and analyzer diagnostics reported for closed files when set to FullSolution (reportInformationAsHint: false)' , async ( ) => {
68
+ await setDiagnosticSettings ( {
69
+ compilerScope : AnalysisSetting . FullSolution ,
70
+ analyzerScope : AnalysisSetting . FullSolution ,
71
+ reportInformationAsHint : false ,
72
+ } ) ;
73
+
74
+ await waitForExpectedDiagnostics ( ( diagnostics ) => {
75
+ expect ( diagnostics . length ) . toBeGreaterThan ( 2 ) ;
76
+
77
+ const diagnosticsInDiagnosticsCs = diagnostics
78
+ . filter ( ( [ uri , _ ] ) => uri . fsPath . endsWith ( 'diagnostics.cs' ) )
79
+ . flatMap ( ( [ _ , diagnostics ] ) => diagnostics ) ;
80
+ const diagnosticsInCompletionCs = diagnostics
81
+ . filter ( ( [ uri , _ ] ) => uri . fsPath . endsWith ( 'completion.cs' ) )
82
+ . flatMap ( ( [ _ , diagnostics ] ) => diagnostics ) ;
83
+
84
+ expect ( diagnosticsInDiagnosticsCs ) . toHaveLength ( 5 ) ;
85
+ expect ( diagnosticsInCompletionCs ) . toHaveLength ( 5 ) ;
86
+
87
+ // Compiler diagnostic in diagnostics.cs
88
+ expect ( getCode ( diagnosticsInDiagnosticsCs [ 3 ] ) ) . toBe ( 'CS0219' ) ;
89
+ expect ( diagnosticsInDiagnosticsCs [ 3 ] . message ) . toBe (
90
+ "The variable 'notUsed' is assigned but its value is never used"
91
+ ) ;
92
+ expect ( diagnosticsInDiagnosticsCs [ 3 ] . range ) . toEqual ( new vscode . Range ( 8 , 16 , 8 , 23 ) ) ;
93
+ expect ( diagnosticsInDiagnosticsCs [ 3 ] . severity ) . toBe ( vscode . DiagnosticSeverity . Warning ) ;
94
+
95
+ // Analyzer diagnostic in diagnostics.cs
96
+ expect ( getCode ( diagnosticsInDiagnosticsCs [ 2 ] ) ) . toBe ( 'CA1822' ) ;
97
+ expect ( diagnosticsInDiagnosticsCs [ 2 ] . message ) . toBe (
98
+ "Member 'FooBarBar' does not access instance data and can be marked as static"
99
+ ) ;
100
+ expect ( diagnosticsInDiagnosticsCs [ 2 ] . range ) . toEqual ( new vscode . Range ( 6 , 20 , 6 , 29 ) ) ;
101
+ expect ( diagnosticsInDiagnosticsCs [ 2 ] . severity ) . toBe ( vscode . DiagnosticSeverity . Information ) ;
102
+
103
+ // Analyzer diagnostic in completion.cs
104
+ expect ( getCode ( diagnosticsInCompletionCs [ 0 ] ) ) . toBe ( 'IDE0005' ) ;
105
+ expect ( diagnosticsInCompletionCs [ 0 ] . message ) . toBe ( 'Using directive is unnecessary.' ) ;
106
+ expect ( diagnosticsInCompletionCs [ 0 ] . range ) . toEqual ( new vscode . Range ( 0 , 0 , 0 , 13 ) ) ;
107
+ expect ( diagnosticsInCompletionCs [ 0 ] . severity ) . toBe ( vscode . DiagnosticSeverity . Hint ) ;
108
+ } ) ;
109
+ } ) ;
66
110
67
111
test ( 'No compiler diagnostics reported for closed files when set to OpenFiles' , async ( ) => {
68
- await setBackgroundAnalysisScopes ( {
69
- compiler : AnalysisSetting . OpenFiles ,
70
- analyzer : AnalysisSetting . FullSolution ,
112
+ await setDiagnosticSettings ( {
113
+ compilerScope : AnalysisSetting . OpenFiles ,
114
+ analyzerScope : AnalysisSetting . FullSolution ,
115
+ reportInformationAsHint : true ,
71
116
} ) ;
72
117
73
118
await waitForExpectedDiagnostics ( ( diagnostics ) => {
@@ -83,9 +128,10 @@ describeIfCSharp(`Workspace Diagnostic Tests`, () => {
83
128
} ) ;
84
129
85
130
test ( 'No compiler diagnostics reported for closed files when set to None' , async ( ) => {
86
- await setBackgroundAnalysisScopes ( {
87
- compiler : AnalysisSetting . None ,
88
- analyzer : AnalysisSetting . FullSolution ,
131
+ await setDiagnosticSettings ( {
132
+ compilerScope : AnalysisSetting . None ,
133
+ analyzerScope : AnalysisSetting . FullSolution ,
134
+ reportInformationAsHint : true ,
89
135
} ) ;
90
136
91
137
await waitForExpectedDiagnostics ( ( diagnostics ) => {
@@ -101,9 +147,10 @@ describeIfCSharp(`Workspace Diagnostic Tests`, () => {
101
147
} ) ;
102
148
103
149
test ( 'No analyzer diagnostics reported for closed files when set to OpenFiles' , async ( ) => {
104
- await setBackgroundAnalysisScopes ( {
105
- compiler : AnalysisSetting . FullSolution ,
106
- analyzer : AnalysisSetting . OpenFiles ,
150
+ await setDiagnosticSettings ( {
151
+ compilerScope : AnalysisSetting . FullSolution ,
152
+ analyzerScope : AnalysisSetting . OpenFiles ,
153
+ reportInformationAsHint : true ,
107
154
} ) ;
108
155
109
156
await waitForExpectedDiagnostics ( ( diagnostics ) => {
@@ -130,9 +177,10 @@ describeIfCSharp(`Workspace Diagnostic Tests`, () => {
130
177
} ) ;
131
178
132
179
test ( 'No analyzer diagnostics reported for closed files when set to None' , async ( ) => {
133
- await setBackgroundAnalysisScopes ( {
134
- compiler : AnalysisSetting . FullSolution ,
135
- analyzer : AnalysisSetting . None ,
180
+ await setDiagnosticSettings ( {
181
+ compilerScope : AnalysisSetting . FullSolution ,
182
+ analyzerScope : AnalysisSetting . None ,
183
+ reportInformationAsHint : true ,
136
184
} ) ;
137
185
138
186
await waitForExpectedDiagnostics ( ( diagnostics ) => {
0 commit comments