| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- /*---------------------------------------------------------------------------------------------
- * Copyright (c) Microsoft Corporation. All rights reserved.
- * Licensed under the MIT License. See License.txt in the project root for license information.
- *--------------------------------------------------------------------------------------------*/
- export function createScopedLineTokens(context, offset) {
- const tokenCount = context.getCount();
- const tokenIndex = context.findTokenIndexAtOffset(offset);
- const desiredLanguageId = context.getLanguageId(tokenIndex);
- let lastTokenIndex = tokenIndex;
- while (lastTokenIndex + 1 < tokenCount && context.getLanguageId(lastTokenIndex + 1) === desiredLanguageId) {
- lastTokenIndex++;
- }
- let firstTokenIndex = tokenIndex;
- while (firstTokenIndex > 0 && context.getLanguageId(firstTokenIndex - 1) === desiredLanguageId) {
- firstTokenIndex--;
- }
- return new ScopedLineTokens(context, desiredLanguageId, firstTokenIndex, lastTokenIndex + 1, context.getStartOffset(firstTokenIndex), context.getEndOffset(lastTokenIndex));
- }
- export class ScopedLineTokens {
- constructor(actual, languageId, firstTokenIndex, lastTokenIndex, firstCharOffset, lastCharOffset) {
- this._scopedLineTokensBrand = undefined;
- this._actual = actual;
- this.languageId = languageId;
- this._firstTokenIndex = firstTokenIndex;
- this._lastTokenIndex = lastTokenIndex;
- this.firstCharOffset = firstCharOffset;
- this._lastCharOffset = lastCharOffset;
- }
- getLineContent() {
- const actualLineContent = this._actual.getLineContent();
- return actualLineContent.substring(this.firstCharOffset, this._lastCharOffset);
- }
- getActualLineContentBefore(offset) {
- const actualLineContent = this._actual.getLineContent();
- return actualLineContent.substring(0, this.firstCharOffset + offset);
- }
- getTokenCount() {
- return this._lastTokenIndex - this._firstTokenIndex;
- }
- findTokenIndexAtOffset(offset) {
- return this._actual.findTokenIndexAtOffset(offset + this.firstCharOffset) - this._firstTokenIndex;
- }
- getStandardTokenType(tokenIndex) {
- return this._actual.getStandardTokenType(tokenIndex + this._firstTokenIndex);
- }
- }
- export function ignoreBracketsInToken(standardTokenType) {
- return (standardTokenType & 3 /* IgnoreBracketsInTokens.value */) !== 0;
- }
|