0c67d25646bd800f13d646de45204f919319b9e5e0d8d7f04cf687af138e121069bc8c8a3233f9a0ff6455f3b12587c24a2aa6c33028446abf5ea41b4cd76b 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. export function createScopedLineTokens(context, offset) {
  6. const tokenCount = context.getCount();
  7. const tokenIndex = context.findTokenIndexAtOffset(offset);
  8. const desiredLanguageId = context.getLanguageId(tokenIndex);
  9. let lastTokenIndex = tokenIndex;
  10. while (lastTokenIndex + 1 < tokenCount && context.getLanguageId(lastTokenIndex + 1) === desiredLanguageId) {
  11. lastTokenIndex++;
  12. }
  13. let firstTokenIndex = tokenIndex;
  14. while (firstTokenIndex > 0 && context.getLanguageId(firstTokenIndex - 1) === desiredLanguageId) {
  15. firstTokenIndex--;
  16. }
  17. return new ScopedLineTokens(context, desiredLanguageId, firstTokenIndex, lastTokenIndex + 1, context.getStartOffset(firstTokenIndex), context.getEndOffset(lastTokenIndex));
  18. }
  19. export class ScopedLineTokens {
  20. constructor(actual, languageId, firstTokenIndex, lastTokenIndex, firstCharOffset, lastCharOffset) {
  21. this._scopedLineTokensBrand = undefined;
  22. this._actual = actual;
  23. this.languageId = languageId;
  24. this._firstTokenIndex = firstTokenIndex;
  25. this._lastTokenIndex = lastTokenIndex;
  26. this.firstCharOffset = firstCharOffset;
  27. this._lastCharOffset = lastCharOffset;
  28. }
  29. getLineContent() {
  30. const actualLineContent = this._actual.getLineContent();
  31. return actualLineContent.substring(this.firstCharOffset, this._lastCharOffset);
  32. }
  33. getActualLineContentBefore(offset) {
  34. const actualLineContent = this._actual.getLineContent();
  35. return actualLineContent.substring(0, this.firstCharOffset + offset);
  36. }
  37. getTokenCount() {
  38. return this._lastTokenIndex - this._firstTokenIndex;
  39. }
  40. findTokenIndexAtOffset(offset) {
  41. return this._actual.findTokenIndexAtOffset(offset + this.firstCharOffset) - this._firstTokenIndex;
  42. }
  43. getStandardTokenType(tokenIndex) {
  44. return this._actual.getStandardTokenType(tokenIndex + this._firstTokenIndex);
  45. }
  46. }
  47. export function ignoreBracketsInToken(standardTokenType) {
  48. return (standardTokenType & 3 /* IgnoreBracketsInTokens.value */) !== 0;
  49. }