Fixes #89552: Throw from the provider when semantic tokens cannot be computed and keep old semantic tokens if this happens

This commit is contained in:
Alex Dima 2020-01-29 16:21:55 +01:00
parent 4cb12d10c6
commit acf2931955
No known key found for this signature in database
GPG key ID: 6E58D7B045760DA0
2 changed files with 18 additions and 3 deletions

View file

@ -80,7 +80,11 @@ class DocumentSemanticTokensProvider implements vscode.DocumentSemanticTokensPro
if (versionBeforeRequest !== versionAfterRequest) {
// cannot convert result's offsets to (line;col) values correctly
// a new request will come in soon...
return null;
//
// here we cannot return null, because returning null would remove all semantic tokens.
// we must throw to indicate that the semantic tokens should not be removed.
// using the string busy here because it is not logged to error telemetry if the error text contains busy.
throw new Error('busy');
}
const tokenSpan = response.body.spans;

View file

@ -785,10 +785,21 @@ class ModelSemanticColoring extends Disposable {
contentChangeListener.dispose();
this._setSemanticTokens(provider, res || null, styling, pendingChanges);
}, (err) => {
errors.onUnexpectedError(err);
if (!err || typeof err.message !== 'string' || err.message.indexOf('busy') === -1) {
errors.onUnexpectedError(err);
}
// Semantic tokens eats up all errors and considers errors to mean that the result is temporarily not available
// The API does not have a special error kind to express this...
this._currentRequestCancellationTokenSource = null;
contentChangeListener.dispose();
this._setSemanticTokens(provider, null, styling, pendingChanges);
if (pendingChanges.length > 0) {
// More changes occurred while the request was running
if (!this._fetchSemanticTokens.isScheduled()) {
this._fetchSemanticTokens.schedule();
}
}
});
}