Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 27 additions & 4 deletions src/features/diagnosticsProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ export class Advisor {
}

private _onProjectChange(info: protocol.ProjectInformationResponse): void {
if (info.DnxProject && info.DnxProject.SourceFiles) {
this._projectSourceFileCounts[info.DnxProject.Path] = info.DnxProject.SourceFiles.length;
if (info.DotNetProject && info.DotNetProject.SourceFiles) {
this._projectSourceFileCounts[info.DotNetProject.Path] = info.DotNetProject.SourceFiles.length;
}
if (info.MsBuildProject && info.MsBuildProject.SourceFiles) {
this._projectSourceFileCounts[info.MsBuildProject.Path] = info.MsBuildProject.SourceFiles.length;
Expand Down Expand Up @@ -94,7 +94,7 @@ class DiagnosticsProvider extends AbstractSupport {
constructor(server: OmnisharpServer, validationAdvisor: Advisor) {
super(server);
this._validationAdvisor = validationAdvisor;
this._diagnostics = languages.createDiagnosticCollection('omnisharp');
this._diagnostics = languages.createDiagnosticCollection('csharp');

let d1 = this._server.onPackageRestore(this._validateProject, this);
let d2 = this._server.onProjectChange(this._validateProject, this);
Expand All @@ -108,9 +108,11 @@ class DiagnosticsProvider extends AbstractSupport {
if (this._projectValidation) {
this._projectValidation.dispose();
}

for (let key in this._documentValidations) {
this._documentValidations[key].dispose();
}

this._disposable.dispose();
}

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

return;
}

// (re)set new diagnostics for this document
let diagnostics = value.QuickFixes.map(DiagnosticsProvider._asDiagnostic);

this._diagnostics.set(document.uri, diagnostics);
});
}, 750);
Expand Down Expand Up @@ -190,11 +201,22 @@ class DiagnosticsProvider extends AbstractSupport {
if (lastEntry && lastEntry[0].toString() === uri.toString()) {
lastEntry[1].push(diag);
} else {
// We're replacing all diagnostics in this file. Pushing an entry with undefined for
// the diagnostics first ensures that the previous diagnostics for this file are
// cleared. Otherwise, new entries will be merged with the old ones.
entries.push([uri, undefined]);
lastEntry = [uri, [diag]];
entries.push(lastEntry);
}
}

// Clear diagnostics for files that no longer have any diagnostics.
this._diagnostics.forEach((uri, diagnostics) => {
if (!entries.find(tuple => tuple[0] === uri)) {
this._diagnostics.delete(uri);
}
});

// replace all entries
this._diagnostics.set(entries);
});
Expand All @@ -216,10 +238,11 @@ class DiagnosticsProvider extends AbstractSupport {

private static _asDiagnosticSeverity(logLevel: string): DiagnosticSeverity {
switch (logLevel.toLowerCase()) {
case 'hidden':
case 'warning':
case 'warn':
return DiagnosticSeverity.Warning;
case 'hidden':
return DiagnosticSeverity.Information;
default:
return DiagnosticSeverity.Error;
}
Expand Down
7 changes: 2 additions & 5 deletions src/features/status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,11 +165,8 @@ export function reportDocumentStatus(server: OmnisharpServer): vscode.Disposable
}
}

// show dnx projects if applicable
if ('Dnx' in info) {
addDnxOrDotNetProjects(info.Dnx.Projects);
}
else if ('DotNet' in info) {
// show .NET Core projects if applicable
if ('DotNet' in info) {
addDnxOrDotNetProjects(info.DotNet.Projects);
}

Expand Down
26 changes: 1 addition & 25 deletions src/omnisharp/protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,12 +212,11 @@ export interface AutoCompleteResponse {

export interface ProjectInformationResponse {
MsBuildProject: MSBuildProject;
DnxProject: DnxProject;
DotNetProject: DotNetProject;
}

export interface WorkspaceInformationResponse {
MsBuild: MsBuildWorkspaceInformation;
Dnx: DnxWorkspaceInformation;
DotNet: DotNetWorkspaceInformation;
ScriptCs: ScriptCsContext;
}
Expand All @@ -244,29 +243,6 @@ export interface MSBuildProject {
SourceFiles: string[];
}

export interface DnxWorkspaceInformation {
RuntimePath: string;
DesignTimeHostPort: number;
Projects: DnxProject[];
}

export interface DnxProject {
Path: string;
Name: string;
Commands: { [name: string]: string; };
Configurations: string[];
ProjectSearchPaths: string[];
Frameworks: DnxFramework[];
GlobalJsonPath: string;
SourceFiles: string[];
}

export interface DnxFramework {
Name: string;
FriendlyName: string;
ShortName: string;
}

export interface DotNetWorkspaceInformation {
Projects: DotNetProject[];
RuntimePath: string;
Expand Down