Path: blob/main/src/vs/editor/test/common/modesTestUtils.ts
3296 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/45import { LineTokens } from '../../common/tokens/lineTokens.js';6import { StandardTokenType, MetadataConsts } from '../../common/encodedTokenAttributes.js';7import { ScopedLineTokens, createScopedLineTokens } from '../../common/languages/supports.js';8import { LanguageIdCodec } from '../../common/services/languagesRegistry.js';910export interface TokenText {11text: string;12type: StandardTokenType;13}1415export function createFakeScopedLineTokens(rawTokens: TokenText[]): ScopedLineTokens {16const tokens = new Uint32Array(rawTokens.length << 1);17let line = '';1819for (let i = 0, len = rawTokens.length; i < len; i++) {20const rawToken = rawTokens[i];2122const startOffset = line.length;23const metadata = (24(rawToken.type << MetadataConsts.TOKEN_TYPE_OFFSET)25) >>> 0;2627tokens[(i << 1)] = startOffset;28tokens[(i << 1) + 1] = metadata;29line += rawToken.text;30}3132LineTokens.convertToEndOffset(tokens, line.length);33return createScopedLineTokens(new LineTokens(tokens, line, new LanguageIdCodec()), 0);34}353637