@@ -7,7 +7,7 @@ import * as vscode from 'vscode';
77import { describe , test , expect , beforeAll , afterAll } from '@jest/globals' ;
88import testAssetWorkspace from './testAssets/testAssetWorkspace' ;
99import { AnalysisSetting } from '../../../src/lsptoolshost/diagnostics/buildDiagnosticsService' ;
10- import { getCode , setBackgroundAnalysisScopes , waitForExpectedDiagnostics } from './diagnosticsHelpers' ;
10+ import { getCode , setDiagnosticSettings , waitForExpectedDiagnostics } from './diagnosticsHelpers' ;
1111import { activateCSharpExtension , describeIfCSharp } from './integrationHelpers' ;
1212
1313// Restarting the server is required for these tests, but not supported with C# Dev Kit.
@@ -20,11 +20,12 @@ describeIfCSharp(`Workspace Diagnostic Tests`, () => {
2020 await testAssetWorkspace . cleanupWorkspace ( ) ;
2121 } ) ;
2222
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 ,
2829 } ) ;
2930
3031 await waitForExpectedDiagnostics ( ( diagnostics ) => {
@@ -63,11 +64,55 @@ describeIfCSharp(`Workspace Diagnostic Tests`, () => {
6364 expect ( diagnosticsInCompletionCs [ 0 ] . severity ) . toBe ( vscode . DiagnosticSeverity . Hint ) ;
6465 } ) ;
6566 } ) ;
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+ } ) ;
66110
67111 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 ,
71116 } ) ;
72117
73118 await waitForExpectedDiagnostics ( ( diagnostics ) => {
@@ -83,9 +128,10 @@ describeIfCSharp(`Workspace Diagnostic Tests`, () => {
83128 } ) ;
84129
85130 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 ,
89135 } ) ;
90136
91137 await waitForExpectedDiagnostics ( ( diagnostics ) => {
@@ -101,9 +147,10 @@ describeIfCSharp(`Workspace Diagnostic Tests`, () => {
101147 } ) ;
102148
103149 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 ,
107154 } ) ;
108155
109156 await waitForExpectedDiagnostics ( ( diagnostics ) => {
@@ -130,9 +177,10 @@ describeIfCSharp(`Workspace Diagnostic Tests`, () => {
130177 } ) ;
131178
132179 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 ,
136184 } ) ;
137185
138186 await waitForExpectedDiagnostics ( ( diagnostics ) => {
0 commit comments