@@ -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 }
0 commit comments