Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only fetch semantic tokens for visible documents #179396

Merged
merged 2 commits into from Apr 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -126,6 +126,11 @@ class ModelSemanticColoring extends Disposable {
this._fetchDocumentSemanticTokens.schedule(this._debounceInformation.get(this._model));
}
}));
this._register(this._model.onDidChangeAttached(() => {
if (!this._fetchDocumentSemanticTokens.isScheduled()) {
this._fetchDocumentSemanticTokens.schedule(this._debounceInformation.get(this._model));
}
}));
this._register(this._model.onDidChangeLanguage(() => {
// clear any outstanding state
if (this._currentDocumentResponse) {
Expand Down Expand Up @@ -201,6 +206,11 @@ class ModelSemanticColoring extends Disposable {
return;
}

if (!this._model.isAttachedToEditor()) {
// this document is not visible, there is no need to fetch semantic tokens for it
return;
}

const cancellationTokenSource = new CancellationTokenSource();
const lastProvider = this._currentDocumentResponse ? this._currentDocumentResponse.provider : null;
const lastResultId = this._currentDocumentResponse ? this._currentDocumentResponse.resultId || null : null;
Expand Down
Expand Up @@ -96,6 +96,8 @@ suite('ModelSemanticColoring', () => {
}));

const textModel = disposables.add(modelService.createModel('Hello world', languageService.createById('testMode')));
// pretend the text model is attached to an editor (so that semantic tokens are computed)
textModel.onBeforeAttached();

// wait for the provider to be called
await inFirstCall.wait();
Expand Down Expand Up @@ -151,6 +153,8 @@ suite('ModelSemanticColoring', () => {
}));

const textModel = disposables.add(modelService.createModel('', languageService.createById('testMode')));
// pretend the text model is attached to an editor (so that semantic tokens are computed)
textModel.onBeforeAttached();

// wait for the semantic tokens to be fetched
await Event.toPromise(textModel.onDidChangeTokens);
Expand Down Expand Up @@ -192,7 +196,9 @@ suite('ModelSemanticColoring', () => {
}
}));

disposables.add(modelService.createModel('', languageService.createById('testMode')));
const textModel = disposables.add(modelService.createModel('', languageService.createById('testMode')));
// pretend the text model is attached to an editor (so that semantic tokens are computed)
textModel.onBeforeAttached();

await timeout(5000);
assert.deepStrictEqual(requestCount, 2);
Expand Down