Skip to content

Commit a273bb3

Browse files
committed
Add integration tests for reportInformationAsHint setting
1 parent 5b9d4f5 commit a273bb3

File tree

3 files changed

+135
-38
lines changed

3 files changed

+135
-38
lines changed

test/lsptoolshost/integrationTests/diagnosticsHelpers.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,15 @@ export async function waitForExpectedDiagnostics(
4343
);
4444
}
4545

46-
export async function setBackgroundAnalysisScopes(scopes: { compiler: string; analyzer: string }): Promise<void> {
46+
export async function setDiagnosticSettings(options: {
47+
compilerScope: string;
48+
analyzerScope: string;
49+
reportInformationAsHint: boolean;
50+
}): Promise<void> {
4751
const dotnetConfig = vscode.workspace.getConfiguration('dotnet');
48-
await dotnetConfig.update('backgroundAnalysis.compilerDiagnosticsScope', scopes.compiler);
49-
await dotnetConfig.update('backgroundAnalysis.analyzerDiagnosticsScope', scopes.analyzer);
52+
await dotnetConfig.update('backgroundAnalysis.compilerDiagnosticsScope', options.compilerScope);
53+
await dotnetConfig.update('backgroundAnalysis.analyzerDiagnosticsScope', options.analyzerScope);
54+
await dotnetConfig.update('diagnostics.reportInformationAsHint', options.reportInformationAsHint);
5055

5156
// Restart the language server to ensure diagnostics are reported with the correct configuration.
5257
// While in normal user scenarios it isn't necessary to restart the server to pickup diagnostic config changes,

test/lsptoolshost/integrationTests/documentDiagnostics.integration.test.ts

Lines changed: 61 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { describe, test, beforeAll, afterAll, expect, beforeEach, afterEach } fr
88
import testAssetWorkspace from './testAssets/testAssetWorkspace';
99
import { AnalysisSetting } from '../../../src/lsptoolshost/diagnostics/buildDiagnosticsService';
1010
import path from 'path';
11-
import { getCode, setBackgroundAnalysisScopes, waitForExpectedDiagnostics } from './diagnosticsHelpers';
11+
import { getCode, setDiagnosticSettings, waitForExpectedDiagnostics } from './diagnosticsHelpers';
1212
import {
1313
activateCSharpExtension,
1414
closeAllEditorsAsync,
@@ -36,10 +36,11 @@ describeIfCSharp(`Document Diagnostics Tests`, () => {
3636
await closeAllEditorsAsync();
3737
});
3838

39-
test('Compiler and analyzer diagnostics reported for open file when set to OpenFiles', async () => {
40-
await setBackgroundAnalysisScopes({
41-
compiler: AnalysisSetting.OpenFiles,
42-
analyzer: AnalysisSetting.OpenFiles,
39+
test('Compiler and analyzer diagnostics reported for open file when set to OpenFiles (reportInformationAsHint: true)', async () => {
40+
await setDiagnosticSettings({
41+
compilerScope: AnalysisSetting.OpenFiles,
42+
analyzerScope: AnalysisSetting.OpenFiles,
43+
reportInformationAsHint: true,
4344
});
4445

4546
await waitForExpectedFileDiagnostics((diagnostics) => {
@@ -74,10 +75,50 @@ describeIfCSharp(`Document Diagnostics Tests`, () => {
7475
}, file);
7576
});
7677

78+
test('Compiler and analyzer diagnostics reported for open file when set to OpenFiles (reportInformationAsHint: false)', async () => {
79+
await setDiagnosticSettings({
80+
compilerScope: AnalysisSetting.OpenFiles,
81+
analyzerScope: AnalysisSetting.OpenFiles,
82+
reportInformationAsHint: false,
83+
});
84+
85+
await waitForExpectedFileDiagnostics((diagnostics) => {
86+
expect(diagnostics).toHaveLength(5);
87+
88+
expect(getCode(diagnostics[0])).toBe('IDE0005');
89+
expect(diagnostics[0].message).toBe('Using directive is unnecessary.');
90+
expect(diagnostics[0].range).toEqual(new vscode.Range(0, 0, 0, 16));
91+
expect(diagnostics[0].severity).toBe(vscode.DiagnosticSeverity.Hint);
92+
93+
expect(getCode(diagnostics[1])).toBe('IDE0130');
94+
expect(diagnostics[1].message).toBe('Namespace "Foo" does not match folder structure, expected "app"');
95+
expect(diagnostics[1].range).toEqual(new vscode.Range(2, 10, 2, 13));
96+
expect(diagnostics[1].severity).toBe(vscode.DiagnosticSeverity.Information);
97+
98+
expect(getCode(diagnostics[2])).toBe('CA1822');
99+
expect(diagnostics[2].message).toBe(
100+
"Member 'FooBarBar' does not access instance data and can be marked as static"
101+
);
102+
expect(diagnostics[2].range).toEqual(new vscode.Range(6, 20, 6, 29));
103+
expect(diagnostics[2].severity).toBe(vscode.DiagnosticSeverity.Information);
104+
105+
expect(getCode(diagnostics[3])).toBe('CS0219');
106+
expect(diagnostics[3].message).toBe("The variable 'notUsed' is assigned but its value is never used");
107+
expect(diagnostics[3].range).toEqual(new vscode.Range(8, 16, 8, 23));
108+
expect(diagnostics[3].severity).toBe(vscode.DiagnosticSeverity.Warning);
109+
110+
expect(getCode(diagnostics[4])).toBe('IDE0059');
111+
expect(diagnostics[4].message).toBe("Unnecessary assignment of a value to 'notUsed'");
112+
expect(diagnostics[4].range).toEqual(new vscode.Range(8, 16, 8, 23));
113+
expect(diagnostics[4].severity).toBe(vscode.DiagnosticSeverity.Information);
114+
}, file);
115+
});
116+
77117
test('Compiler diagnostics reported for open file when set to FullSolution', async () => {
78-
await setBackgroundAnalysisScopes({
79-
compiler: AnalysisSetting.FullSolution,
80-
analyzer: AnalysisSetting.OpenFiles,
118+
await setDiagnosticSettings({
119+
compilerScope: AnalysisSetting.FullSolution,
120+
analyzerScope: AnalysisSetting.OpenFiles,
121+
reportInformationAsHint: true,
81122
});
82123

83124
await waitForExpectedFileDiagnostics((diagnostics) => {
@@ -91,9 +132,10 @@ describeIfCSharp(`Document Diagnostics Tests`, () => {
91132
});
92133

93134
test('No compiler diagnostics reported for open file when set to None', async () => {
94-
await setBackgroundAnalysisScopes({
95-
compiler: AnalysisSetting.None,
96-
analyzer: AnalysisSetting.OpenFiles,
135+
await setDiagnosticSettings({
136+
compilerScope: AnalysisSetting.None,
137+
analyzerScope: AnalysisSetting.OpenFiles,
138+
reportInformationAsHint: true,
97139
});
98140

99141
await waitForExpectedFileDiagnostics((diagnostics) => {
@@ -104,9 +146,10 @@ describeIfCSharp(`Document Diagnostics Tests`, () => {
104146
});
105147

106148
test('Analyzer diagnostics reported for open file when set to FullSolution', async () => {
107-
await setBackgroundAnalysisScopes({
108-
compiler: AnalysisSetting.OpenFiles,
109-
analyzer: AnalysisSetting.FullSolution,
149+
await setDiagnosticSettings({
150+
compilerScope: AnalysisSetting.OpenFiles,
151+
analyzerScope: AnalysisSetting.FullSolution,
152+
reportInformationAsHint: true,
110153
});
111154

112155
await waitForExpectedFileDiagnostics((diagnostics) => {
@@ -137,9 +180,10 @@ describeIfCSharp(`Document Diagnostics Tests`, () => {
137180
});
138181

139182
test('No analyzer diagnostics reported for open file when set to None', async () => {
140-
await setBackgroundAnalysisScopes({
141-
compiler: AnalysisSetting.OpenFiles,
142-
analyzer: AnalysisSetting.None,
183+
await setDiagnosticSettings({
184+
compilerScope: AnalysisSetting.OpenFiles,
185+
analyzerScope: AnalysisSetting.None,
186+
reportInformationAsHint: true,
143187
});
144188

145189
await waitForExpectedFileDiagnostics((diagnostics) => {

test/lsptoolshost/integrationTests/workspaceDiagnostics.integration.test.ts

Lines changed: 66 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import * as vscode from 'vscode';
77
import { describe, test, expect, beforeAll, afterAll } from '@jest/globals';
88
import testAssetWorkspace from './testAssets/testAssetWorkspace';
99
import { AnalysisSetting } from '../../../src/lsptoolshost/diagnostics/buildDiagnosticsService';
10-
import { getCode, setBackgroundAnalysisScopes, waitForExpectedDiagnostics } from './diagnosticsHelpers';
10+
import { getCode, setDiagnosticSettings, waitForExpectedDiagnostics } from './diagnosticsHelpers';
1111
import { 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

Comments
 (0)