@@ -8,6 +8,7 @@ import {localize} from 'vs/nls';
88import { IThreadService } from 'vs/workbench/services/thread/common/threadService' ;
99import { IMarkerData } from 'vs/platform/markers/common/markers' ;
1010import URI from 'vs/base/common/uri' ;
11+ import { compare } from 'vs/base/common/strings' ;
1112import Severity from 'vs/base/common/severity' ;
1213import * as vscode from 'vscode' ;
1314import { MainContext , MainThreadDiagnosticsShape , ExtHostDiagnosticsShape } from './extHost.protocol' ;
@@ -72,20 +73,23 @@ export class DiagnosticCollection implements vscode.DiagnosticCollection {
7273 } else if ( Array . isArray ( first ) ) {
7374 // update many rows
7475 toSync = [ ] ;
75- for ( let entry of first ) {
76- let [ uri , diagnostics ] = entry ;
77- toSync . push ( uri ) ;
76+ let lastUri : vscode . Uri ;
77+ for ( const entry of first . slice ( 0 ) . sort ( DiagnosticCollection . _compareTuplesByUri ) ) {
78+ const [ uri , diagnostics ] = entry ;
79+ if ( ! lastUri || uri . toString ( ) !== lastUri . toString ( ) ) {
80+ if ( lastUri && this . _data [ lastUri . toString ( ) ] . length === 0 ) {
81+ delete this . _data [ lastUri . toString ( ) ] ;
82+ }
83+ lastUri = uri ;
84+ toSync . push ( uri ) ;
85+ this . _data [ uri . toString ( ) ] = [ ] ;
86+ }
87+
7888 if ( ! diagnostics ) {
7989 // [Uri, undefined] means clear this
80- delete this . _data [ uri . toString ( ) ] ;
90+ this . _data [ uri . toString ( ) ] . length = 0 ;
8191 } else {
82- // set or merge diagnostics
83- let existing = this . _data [ uri . toString ( ) ] ;
84- if ( existing ) {
85- existing . push ( ...diagnostics ) ;
86- } else {
87- this . _data [ uri . toString ( ) ] = diagnostics ;
88- }
92+ this . _data [ uri . toString ( ) ] . push ( ...diagnostics ) ;
8993 }
9094 }
9195 }
@@ -196,6 +200,10 @@ export class DiagnosticCollection implements vscode.DiagnosticCollection {
196200 default : return Severity . Error ;
197201 }
198202 }
203+
204+ private static _compareTuplesByUri ( a : [ vscode . Uri , vscode . Diagnostic [ ] ] , b : [ vscode . Uri , vscode . Diagnostic [ ] ] ) : number {
205+ return compare ( a [ 0 ] . toString ( ) , b [ 0 ] . toString ( ) ) ;
206+ }
199207}
200208
201209export class ExtHostDiagnostics extends ExtHostDiagnosticsShape {
0 commit comments