diff --git a/src/vs/editor/common/model/textModelTokens.ts b/src/vs/editor/common/model/textModelTokens.ts index 65098e266a16478c40b34b586424ccce9bcf467a..c5f2e74f03405ab91d3a739531c2a803414ea1d8 100644 --- a/src/vs/editor/common/model/textModelTokens.ts +++ b/src/vs/editor/common/model/textModelTokens.ts @@ -11,7 +11,7 @@ import { Range } from 'vs/editor/common/core/range'; import { TokenizationResult2 } from 'vs/editor/common/core/token'; import { ITextBuffer } from 'vs/editor/common/model'; import { IModelTokensChangedEvent } from 'vs/editor/common/model/textModelEvents'; -import { ColorId, FontStyle, IState, ITokenizationSupport, LanguageId, LanguageIdentifier, MetadataConsts, StandardTokenType } from 'vs/editor/common/modes'; +import { ColorId, FontStyle, IState, ITokenizationSupport, LanguageId, LanguageIdentifier, MetadataConsts, StandardTokenType, TokenMetadata } from 'vs/editor/common/modes'; import { nullTokenize2 } from 'vs/editor/common/modes/nullMode'; function getDefaultMetadata(topLevelLanguageId: LanguageId): number { @@ -262,8 +262,15 @@ export class ModelLinesTokens { } if (lineTextLength === 0) { - target._lineTokens = EMPTY_LINE_TOKENS; - return; + let hasDifferentLanguageId = false; + if (tokens && tokens.length > 1) { + hasDifferentLanguageId = (TokenMetadata.getLanguageId(tokens[1]) !== topLevelLanguageId); + } + + if (!hasDifferentLanguageId) { + target._lineTokens = EMPTY_LINE_TOKENS; + return; + } } if (!tokens || tokens.length === 0) { diff --git a/src/vs/editor/contrib/comment/test/lineCommentCommand.test.ts b/src/vs/editor/contrib/comment/test/lineCommentCommand.test.ts index d9bec641e92381a9fdc26da5bdbe612526574d25..a32458d6abdd53f27620abb7b5b07baa6fe8bfa7 100644 --- a/src/vs/editor/contrib/comment/test/lineCommentCommand.test.ts +++ b/src/vs/editor/contrib/comment/test/lineCommentCommand.test.ts @@ -1056,21 +1056,4 @@ suite('Editor Contrib - Line Comment in mixed modes', () => { new Selection(2, 8, 2, 8), ); }); - - test.skip('issue #63822: Commenting code in JSX tag body from line 0', () => { - testLineCommentCommand( - [ - '
', - '', - '
', - ], - new Selection(2, 1, 2, 1), - [ - '
', - '{/* */}', - '
', - ], - new Selection(2, 1, 2, 1), - ); - }); }); diff --git a/src/vs/editor/test/common/model/textModelWithTokens.test.ts b/src/vs/editor/test/common/model/textModelWithTokens.test.ts index d9c0cd42afeb1012f29c0e30715ca3064d64296a..a8aea6f754022d0d72549baf08864cdb08cedb3c 100644 --- a/src/vs/editor/test/common/model/textModelWithTokens.test.ts +++ b/src/vs/editor/test/common/model/textModelWithTokens.test.ts @@ -390,6 +390,34 @@ suite('TextModelWithTokens regression tests', () => { model.dispose(); registration.dispose(); }); + + test('issue #63822: Wrong embedded language detected for empty lines', () => { + const outerMode = new LanguageIdentifier('outerMode', 3); + const innerMode = new LanguageIdentifier('innerMode', 4); + + const tokenizationSupport: ITokenizationSupport = { + getInitialState: () => NULL_STATE, + tokenize: undefined, + tokenize2: (line, state) => { + let tokens = new Uint32Array(2); + tokens[0] = 0; + tokens[1] = ( + innerMode.id << MetadataConsts.LANGUAGEID_OFFSET + ) >>> 0; + return new TokenizationResult2(tokens, state); + } + }; + + let registration = TokenizationRegistry.register(outerMode.language, tokenizationSupport); + + let model = TextModel.createFromString('A model with one line', undefined, outerMode); + + model.forceTokenization(1); + assert.equal(model.getLanguageIdAtPosition(1, 1), innerMode.id); + + model.dispose(); + registration.dispose(); + }); }); suite('TextModel.getLineIndentGuide', () => {