@@ -261,6 +261,13 @@ class DocumentPullStateTracker {
261261 return states . has ( key ) ;
262262 }
263263
264+ public tracksSameVersion ( kind : PullState , document : TextDocument ) : boolean {
265+ const key = document . uri . toString ( ) ;
266+ const states = kind === PullState . document ? this . documentPullStates : this . workspacePullStates ;
267+ const state = states . get ( key ) ;
268+ return state !== undefined && state . pulledVersion === document . version ;
269+ }
270+
264271 public getResultId ( kind : PullState , document : TextDocument | Uri ) : string | undefined {
265272 const key = DocumentOrUri . asKey ( document ) ;
266273 const states = kind === PullState . document ? this . documentPullStates : this . workspacePullStates ;
@@ -318,6 +325,22 @@ class DiagnosticRequestor implements Disposable {
318325 return this . documentStates . tracks ( kind , document ) || this . openRequests . has ( uri . toString ( ) ) ;
319326 }
320327
328+ public knowsSameVersion ( kind : PullState , document : TextDocument ) : boolean {
329+ const requestState = this . openRequests . get ( document . uri . toString ( ) ) ;
330+ if ( requestState === undefined ) {
331+ return this . documentStates . tracksSameVersion ( kind , document ) ;
332+ }
333+ // A reschedule request is independent of a version so it will trigger
334+ // on the latest version no matter what.
335+ if ( requestState . state === RequestStateKind . reschedule ) {
336+ return true ;
337+ }
338+ if ( requestState . state === RequestStateKind . outDated ) {
339+ return false ;
340+ }
341+ return requestState . version === document . version ;
342+ }
343+
321344 private forget ( kind : PullState , document : TextDocument | Uri ) : void {
322345 this . documentStates . unTrack ( kind , document ) ;
323346 }
@@ -408,7 +431,7 @@ class DiagnosticRequestor implements Disposable {
408431 const request = this . openRequests . get ( key ) ;
409432 if ( this . options . workspaceDiagnostics ) {
410433 // If we run workspace diagnostic pull a last time for the diagnostics
411- // and the rely on getting them from the workspace result.
434+ // and then rely on getting them from the workspace result.
412435 if ( request !== undefined ) {
413436 this . openRequests . set ( key , { state : RequestStateKind . reschedule , document : document } ) ;
414437 } else {
@@ -865,7 +888,7 @@ class DiagnosticFeatureProviderImpl implements DiagnosticProviderShape {
865888 disposables . push ( openFeature . onNotificationSent ( ( event ) => {
866889 const textDocument = event . textDocument ;
867890 // We already know about this document. This can happen via a tab open.
868- if ( this . diagnosticRequestor . knows ( PullState . document , textDocument ) ) {
891+ if ( this . diagnosticRequestor . knowsSameVersion ( PullState . document , textDocument ) ) {
869892 return ;
870893 }
871894 if ( matches ( textDocument ) ) {
0 commit comments