@@ -770,6 +770,7 @@ export class ModelSemanticColoring extends Disposable {
770
770
private _currentDocumentResponse : SemanticTokensResponse | null ;
771
771
private _currentDocumentRequestCancellationTokenSource : CancellationTokenSource | null ;
772
772
private _documentProvidersChangeListeners : IDisposable [ ] ;
773
+ private _providersChangedDuringRequest : boolean ;
773
774
774
775
constructor (
775
776
model : ITextModel ,
@@ -789,6 +790,7 @@ export class ModelSemanticColoring extends Disposable {
789
790
this . _currentDocumentResponse = null ;
790
791
this . _currentDocumentRequestCancellationTokenSource = null ;
791
792
this . _documentProvidersChangeListeners = [ ] ;
793
+ this . _providersChangedDuringRequest = false ;
792
794
793
795
this . _register ( this . _model . onDidChangeContent ( ( ) => {
794
796
if ( ! this . _fetchDocumentSemanticTokens . isScheduled ( ) ) {
@@ -814,7 +816,14 @@ export class ModelSemanticColoring extends Disposable {
814
816
this . _documentProvidersChangeListeners = [ ] ;
815
817
for ( const provider of this . _provider . all ( model ) ) {
816
818
if ( typeof provider . onDidChange === 'function' ) {
817
- this . _documentProvidersChangeListeners . push ( provider . onDidChange ( ( ) => this . _fetchDocumentSemanticTokens . schedule ( 0 ) ) ) ;
819
+ this . _documentProvidersChangeListeners . push ( provider . onDidChange ( ( ) => {
820
+ if ( this . _currentDocumentRequestCancellationTokenSource ) {
821
+ // there is already a request running,
822
+ this . _providersChangedDuringRequest = true ;
823
+ return ;
824
+ }
825
+ this . _fetchDocumentSemanticTokens . schedule ( 0 ) ;
826
+ } ) ) ;
818
827
}
819
828
}
820
829
} ;
@@ -868,6 +877,7 @@ export class ModelSemanticColoring extends Disposable {
868
877
const lastResultId = this . _currentDocumentResponse ? this . _currentDocumentResponse . resultId || null : null ;
869
878
const request = getDocumentSemanticTokens ( this . _provider , this . _model , lastProvider , lastResultId , cancellationTokenSource . token ) ;
870
879
this . _currentDocumentRequestCancellationTokenSource = cancellationTokenSource ;
880
+ this . _providersChangedDuringRequest = false ;
871
881
872
882
const pendingChanges : IModelContentChangedEvent [ ] = [ ] ;
873
883
const contentChangeListener = this . _model . onDidChangeContent ( ( e ) => {
@@ -898,7 +908,7 @@ export class ModelSemanticColoring extends Disposable {
898
908
this . _currentDocumentRequestCancellationTokenSource = null ;
899
909
contentChangeListener . dispose ( ) ;
900
910
901
- if ( pendingChanges . length > 0 ) {
911
+ if ( pendingChanges . length > 0 || this . _providersChangedDuringRequest ) {
902
912
// More changes occurred while the request was running
903
913
if ( ! this . _fetchDocumentSemanticTokens . isScheduled ( ) ) {
904
914
this . _fetchDocumentSemanticTokens . schedule ( this . _debounceInformation . get ( this . _model ) ) ;
@@ -918,7 +928,7 @@ export class ModelSemanticColoring extends Disposable {
918
928
private _setDocumentSemanticTokens ( provider : DocumentSemanticTokensProvider | null , tokens : SemanticTokens | SemanticTokensEdits | null , styling : SemanticTokensProviderStyling | null , pendingChanges : IModelContentChangedEvent [ ] ) : void {
919
929
const currentResponse = this . _currentDocumentResponse ;
920
930
const rescheduleIfNeeded = ( ) => {
921
- if ( pendingChanges . length > 0 && ! this . _fetchDocumentSemanticTokens . isScheduled ( ) ) {
931
+ if ( ( pendingChanges . length > 0 || this . _providersChangedDuringRequest ) && ! this . _fetchDocumentSemanticTokens . isScheduled ( ) ) {
922
932
this . _fetchDocumentSemanticTokens . schedule ( this . _debounceInformation . get ( this . _model ) ) ;
923
933
}
924
934
} ;
0 commit comments