Skip to content

Commit 41137cb

Browse files
committed
1 parent ff99db8 commit 41137cb

2 files changed

Lines changed: 53 additions & 5 deletions

File tree

src/vs/editor/common/model/tokensStore.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1034,10 +1034,12 @@ export class TokensStore2 {
10341034
aIndex++;
10351035
}
10361036

1037-
if (aIndex < aLen && aTokens.getEndOffset(aIndex) === bEndCharacter) {
1038-
// `a` ends exactly at the same spot as `b`!
1039-
emitToken(aTokens.getEndOffset(aIndex), (aTokens.getMetadata(aIndex) & aMask) | (bMetadata & bMask));
1040-
aIndex++;
1037+
if (aIndex < aLen) {
1038+
emitToken(bEndCharacter, (aTokens.getMetadata(aIndex) & aMask) | (bMetadata & bMask));
1039+
if (aTokens.getEndOffset(aIndex) === bEndCharacter) {
1040+
// `a` ends exactly at the same spot as `b`!
1041+
aIndex++;
1042+
}
10411043
} else {
10421044
const aMergeIndex = Math.min(Math.max(0, aIndex - 1), aLen - 1);
10431045

src/vs/editor/test/common/model/tokensStore.test.ts

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { MultilineTokens2, SparseEncodedTokens, TokensStore2 } from 'vs/editor/c
88
import { Range } from 'vs/editor/common/core/range';
99
import { TextModel } from 'vs/editor/common/model/textModel';
1010
import { IIdentifiedSingleEditOperation } from 'vs/editor/common/model';
11-
import { MetadataConsts, TokenMetadata } from 'vs/editor/common/modes';
11+
import { MetadataConsts, TokenMetadata, FontStyle } from 'vs/editor/common/modes';
1212
import { createTextModel } from 'vs/editor/test/common/editorTestUtils';
1313
import { LineTokens } from 'vs/editor/common/core/lineTokens';
1414

@@ -387,4 +387,50 @@ suite('TokensStore', () => {
387387
const lineTokens = store.addSemanticTokens(36451, new LineTokens(new Uint32Array([60, 1]), ` if (flags & ModifierFlags.Ambient) {`));
388388
assert.equal(lineTokens.getCount(), 7);
389389
});
390+
391+
392+
test('issue #95949: Identifiers are colored in bold when targetting keywords', () => {
393+
394+
function createTMMetadata(foreground: number, fontStyle: number, languageId: number): number {
395+
return (
396+
(languageId << MetadataConsts.LANGUAGEID_OFFSET)
397+
| (fontStyle << MetadataConsts.FONT_STYLE_OFFSET)
398+
| (foreground << MetadataConsts.FOREGROUND_OFFSET)
399+
) >>> 0;
400+
}
401+
402+
function toArr(lineTokens: LineTokens): number[] {
403+
let r: number[] = [];
404+
for (let i = 0; i < lineTokens.getCount(); i++) {
405+
r.push(lineTokens.getEndOffset(i));
406+
r.push(lineTokens.getMetadata(i));
407+
}
408+
return r;
409+
}
410+
411+
const store = new TokensStore2();
412+
413+
store.set([
414+
new MultilineTokens2(1, new SparseEncodedTokens(new Uint32Array([
415+
0, 6, 11, (1 << MetadataConsts.FOREGROUND_OFFSET) | MetadataConsts.SEMANTIC_USE_FOREGROUND,
416+
])))
417+
], true);
418+
419+
const lineTokens = store.addSemanticTokens(1, new LineTokens(new Uint32Array([
420+
5, createTMMetadata(5, FontStyle.Bold, 53),
421+
14, createTMMetadata(1, FontStyle.None, 53),
422+
17, createTMMetadata(6, FontStyle.None, 53),
423+
18, createTMMetadata(1, FontStyle.None, 53),
424+
]), `const hello = 123;`));
425+
426+
const actual = toArr(lineTokens);
427+
assert.deepEqual(actual, [
428+
5, createTMMetadata(5, FontStyle.Bold, 53),
429+
6, createTMMetadata(1, FontStyle.None, 53),
430+
11, createTMMetadata(1, FontStyle.None, 53),
431+
14, createTMMetadata(1, FontStyle.None, 53),
432+
17, createTMMetadata(6, FontStyle.None, 53),
433+
18, createTMMetadata(1, FontStyle.None, 53)
434+
]);
435+
});
390436
});

0 commit comments

Comments
 (0)