diff --git a/platform/syntax/syntax-api/src/com/intellij/platform/syntax/LazyParser.kt b/platform/syntax/syntax-api/src/com/intellij/platform/syntax/LazyParser.kt index 6af74d197799..c0418acd0737 100644 --- a/platform/syntax/syntax-api/src/com/intellij/platform/syntax/LazyParser.kt +++ b/platform/syntax/syntax-api/src/com/intellij/platform/syntax/LazyParser.kt @@ -77,7 +77,8 @@ fun canLazyNodeBeReparsedIncrementally(parsingContext: LazyParsingContext): Bool } fun createLexer(lexerContext: LazyLexingContext): Lexer? { - return lexerContext.node.type.lazyParser!!.createLexer(lexerContext) + val lazyParser = lexerContext.node.type.lazyParser ?: error("Node ${lexerContext.node} is not lazy parseable") + return lazyParser.createLexer(lexerContext) } /** diff --git a/platform/syntax/syntax-tree/src/com/intellij/platform/syntax/tree/KmpSyntaxNode.kt b/platform/syntax/syntax-tree/src/com/intellij/platform/syntax/tree/KmpSyntaxNode.kt index f73b6f78da8a..f55d48e6e5f6 100644 --- a/platform/syntax/syntax-tree/src/com/intellij/platform/syntax/tree/KmpSyntaxNode.kt +++ b/platform/syntax/syntax-tree/src/com/intellij/platform/syntax/tree/KmpSyntaxNode.kt @@ -437,8 +437,8 @@ class KmpSyntaxNode internal constructor( var currentLexer = rootLexer while (node != null && node.startOffset <= startOffset && node.endOffset > endOffset) { val type = node.type - val nodeText = newText.subSequence(node.startOffset, node.endOffset) if (type.isLazyParseable()) { + val nodeText = newText.subSequence(node.startOffset, node.endOffset) val startLexemeIndex = currentTokens .tokenIndexAtOffset((node.startOffset - node.context.offset)) .onMinusOne(currentTokens.tokenCount - 1) @@ -466,19 +466,19 @@ class KmpSyntaxNode internal constructor( currentLexer != rootLexer ) } - } - val lexingContext = LazyLexingContext(node, cancellationProvider) - val lexer = performWithExtensionSupport(context.extensions()) { - createLexer(lexingContext) - } - if (lexer != null && lexer != currentLexer) { - currentLexer = lexer - currentTokens = context.tokenizationPolicy.tokenize( - text = nodeText, - lexer = lexer, - cancellationProvider = cancellationProvider, - ) + val lexingContext = LazyLexingContext(node, cancellationProvider) + val lexer = performWithExtensionSupport(context.extensions()) { + createLexer(lexingContext) + } + if (lexer != null && lexer != currentLexer) { + currentLexer = lexer + currentTokens = context.tokenizationPolicy.tokenize( + text = nodeText, + lexer = lexer, + cancellationProvider = cancellationProvider, + ) + } } node = node.children() .firstOrNull { it.startOffset <= startOffset && it.endOffset >= endOffset } as KmpSyntaxNode?