Skip to content

Commit 4d205e0

Browse files
Fix several issues with diagnostics
1. The diagnostics provider won't refresh diagnostics while the OmniSharp server is restoring packages. Instead, it waits until it receives an event from OmniSharp afterward. However, that event was only expecting the old DNX protocol, so the diagnostics provider never automatically updated after packages were restored. This change gets rid of the DNX protocol and changes the diagnostic provider to look for .NET Core projects. 2. Hidden diagnostics should have DiagnosticSeverity.Info rather DiagnosticSeverity.Warning. 3. When the processing *all* of the diagnostics (not just those for the current file), the previous diagnostics were not cleared out first. This resulted in new diagnostics being merged with old diagnostics, creating duplicates diagnostics. Now we clear the diagnostics for a file before adding new ones.
1 parent ff2d0b4 commit 4d205e0

File tree

3 files changed

+30
-34
lines changed

3 files changed

+30
-34
lines changed

src/features/diagnosticsProvider.ts

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ export class Advisor {
4343
}
4444

4545
private _onProjectChange(info: protocol.ProjectInformationResponse): void {
46-
if (info.DnxProject && info.DnxProject.SourceFiles) {
47-
this._projectSourceFileCounts[info.DnxProject.Path] = info.DnxProject.SourceFiles.length;
46+
if (info.DotNetProject && info.DotNetProject.SourceFiles) {
47+
this._projectSourceFileCounts[info.DotNetProject.Path] = info.DotNetProject.SourceFiles.length;
4848
}
4949
if (info.MsBuildProject && info.MsBuildProject.SourceFiles) {
5050
this._projectSourceFileCounts[info.MsBuildProject.Path] = info.MsBuildProject.SourceFiles.length;
@@ -94,7 +94,7 @@ class DiagnosticsProvider extends AbstractSupport {
9494
constructor(server: OmnisharpServer, validationAdvisor: Advisor) {
9595
super(server);
9696
this._validationAdvisor = validationAdvisor;
97-
this._diagnostics = languages.createDiagnosticCollection('omnisharp');
97+
this._diagnostics = languages.createDiagnosticCollection('csharp');
9898

9999
let d1 = this._server.onPackageRestore(this._validateProject, this);
100100
let d2 = this._server.onProjectChange(this._validateProject, this);
@@ -108,9 +108,11 @@ class DiagnosticsProvider extends AbstractSupport {
108108
if (this._projectValidation) {
109109
this._projectValidation.dispose();
110110
}
111+
111112
for (let key in this._documentValidations) {
112113
this._documentValidations[key].dispose();
113114
}
115+
114116
this._disposable.dispose();
115117
}
116118

@@ -153,9 +155,18 @@ class DiagnosticsProvider extends AbstractSupport {
153155
let source = new CancellationTokenSource();
154156
let handle = setTimeout(() => {
155157
serverUtils.codeCheck(this._server, { Filename: document.fileName }, source.token).then(value => {
158+
// Easy case: If there are no diagnostics in the file, we can clear it quickly.
159+
if (value.QuickFixes.length === 0) {
160+
if (this._diagnostics.has(document.uri)) {
161+
this._diagnostics.delete(document.uri);
162+
}
156163

164+
return;
165+
}
166+
157167
// (re)set new diagnostics for this document
158168
let diagnostics = value.QuickFixes.map(DiagnosticsProvider._asDiagnostic);
169+
159170
this._diagnostics.set(document.uri, diagnostics);
160171
});
161172
}, 750);
@@ -190,11 +201,22 @@ class DiagnosticsProvider extends AbstractSupport {
190201
if (lastEntry && lastEntry[0].toString() === uri.toString()) {
191202
lastEntry[1].push(diag);
192203
} else {
204+
// We're replacing all diagnostics in this file. Pushing an entry with undefined for
205+
// the diagnostics first ensures that the previous diagnostics for this file are
206+
// cleared. Otherwise, new entries will be merged with the old ones.
207+
entries.push([uri, undefined]);
193208
lastEntry = [uri, [diag]];
194209
entries.push(lastEntry);
195210
}
196211
}
197212

213+
// Clear diagnostics for files that no longer have any diagnostics.
214+
this._diagnostics.forEach((uri, diagnostics) => {
215+
if (!entries.find(tuple => tuple[0] === uri)) {
216+
this._diagnostics.delete(uri);
217+
}
218+
});
219+
198220
// replace all entries
199221
this._diagnostics.set(entries);
200222
});
@@ -216,10 +238,11 @@ class DiagnosticsProvider extends AbstractSupport {
216238

217239
private static _asDiagnosticSeverity(logLevel: string): DiagnosticSeverity {
218240
switch (logLevel.toLowerCase()) {
219-
case 'hidden':
220241
case 'warning':
221242
case 'warn':
222243
return DiagnosticSeverity.Warning;
244+
case 'hidden':
245+
return DiagnosticSeverity.Information;
223246
default:
224247
return DiagnosticSeverity.Error;
225248
}

src/features/status.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -165,11 +165,8 @@ export function reportDocumentStatus(server: OmnisharpServer): vscode.Disposable
165165
}
166166
}
167167

168-
// show dnx projects if applicable
169-
if ('Dnx' in info) {
170-
addDnxOrDotNetProjects(info.Dnx.Projects);
171-
}
172-
else if ('DotNet' in info) {
168+
// show .NET Core projects if applicable
169+
if ('DotNet' in info) {
173170
addDnxOrDotNetProjects(info.DotNet.Projects);
174171
}
175172

src/omnisharp/protocol.ts

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -212,12 +212,11 @@ export interface AutoCompleteResponse {
212212

213213
export interface ProjectInformationResponse {
214214
MsBuildProject: MSBuildProject;
215-
DnxProject: DnxProject;
215+
DotNetProject: DotNetProject;
216216
}
217217

218218
export interface WorkspaceInformationResponse {
219219
MsBuild: MsBuildWorkspaceInformation;
220-
Dnx: DnxWorkspaceInformation;
221220
DotNet: DotNetWorkspaceInformation;
222221
ScriptCs: ScriptCsContext;
223222
}
@@ -244,29 +243,6 @@ export interface MSBuildProject {
244243
SourceFiles: string[];
245244
}
246245

247-
export interface DnxWorkspaceInformation {
248-
RuntimePath: string;
249-
DesignTimeHostPort: number;
250-
Projects: DnxProject[];
251-
}
252-
253-
export interface DnxProject {
254-
Path: string;
255-
Name: string;
256-
Commands: { [name: string]: string; };
257-
Configurations: string[];
258-
ProjectSearchPaths: string[];
259-
Frameworks: DnxFramework[];
260-
GlobalJsonPath: string;
261-
SourceFiles: string[];
262-
}
263-
264-
export interface DnxFramework {
265-
Name: string;
266-
FriendlyName: string;
267-
ShortName: string;
268-
}
269-
270246
export interface DotNetWorkspaceInformation {
271247
Projects: DotNetProject[];
272248
RuntimePath: string;

0 commit comments

Comments
 (0)