|
| 1 | +/*--------------------------------------------------------------------------------------------- |
| 2 | + * Copyright (c) Microsoft Corporation. All rights reserved. |
| 3 | + * Licensed under the MIT License. See License.txt in the project root for license information. |
| 4 | + *--------------------------------------------------------------------------------------------*/ |
| 5 | + |
| 6 | +import * as assert from 'assert'; |
| 7 | +import { CancellationToken } from 'vs/base/common/cancellation'; |
| 8 | +import { canceled } from 'vs/base/common/errors'; |
| 9 | +import { DisposableStore } from 'vs/base/common/lifecycle'; |
| 10 | +import { ITextModel } from 'vs/editor/common/model'; |
| 11 | +import { DocumentSemanticTokensProvider, DocumentSemanticTokensProviderRegistry, ProviderResult, SemanticTokens, SemanticTokensEdits, SemanticTokensLegend } from 'vs/editor/common/modes'; |
| 12 | +import { getDocumentSemanticTokens } from 'vs/editor/common/services/getSemanticTokens'; |
| 13 | +import { createTextModel } from 'vs/editor/test/common/editorTestUtils'; |
| 14 | + |
| 15 | +suite('getSemanticTokens', () => { |
| 16 | + |
| 17 | + test('issue #136540: semantic highlighting flickers', async () => { |
| 18 | + const disposables = new DisposableStore(); |
| 19 | + |
| 20 | + const provider = new class implements DocumentSemanticTokensProvider { |
| 21 | + getLegend(): SemanticTokensLegend { |
| 22 | + return { tokenTypes: ['test'], tokenModifiers: [] }; |
| 23 | + } |
| 24 | + provideDocumentSemanticTokens(model: ITextModel, lastResultId: string | null, token: CancellationToken): ProviderResult<SemanticTokens | SemanticTokensEdits> { |
| 25 | + throw canceled(); |
| 26 | + } |
| 27 | + releaseDocumentSemanticTokens(resultId: string | undefined): void { |
| 28 | + } |
| 29 | + }; |
| 30 | + |
| 31 | + disposables.add(DocumentSemanticTokensProviderRegistry.register('testLang', provider)); |
| 32 | + |
| 33 | + const textModel = disposables.add(createTextModel('example', undefined, 'testLang')); |
| 34 | + |
| 35 | + await getDocumentSemanticTokens(textModel, null, null, CancellationToken.None).then((res) => { |
| 36 | + assert.fail(); |
| 37 | + }, (err) => { |
| 38 | + assert.ok(!!err); |
| 39 | + }); |
| 40 | + |
| 41 | + disposables.dispose(); |
| 42 | + }); |
| 43 | + |
| 44 | +}); |
0 commit comments