PY-72185 Use PythonHighlightingLexer instead of plain Python lexer in reparse check of PyReparseableIdentifier

The problem previously appeared in situations when an identifier was changed to a keyword, i.e. `a: Tru` -> `a: True` and `True` keyword was not highlighted properly as it was substituted by an identifier AST leaf as is bypassing the highlighting lexer

Add a couple of tests on it

GitOrigin-RevId: ec25d2115ec650bf781a9fe8140e8708e849ff60
This commit is contained in:
Daniil Kalinin
2024-11-08 10:27:57 +01:00
committed by intellij-monorepo-bot
parent 0e2764b76b
commit c07b124c92
8 changed files with 39 additions and 1 deletions

View File

@@ -7,6 +7,7 @@ import com.intellij.openapi.util.registry.Registry;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.psi.PsiWhiteSpace;
import com.intellij.psi.impl.source.tree.TreeUtil;
import com.jetbrains.python.lexer.PythonHighlightingLexer;
import com.jetbrains.python.lexer.PythonLexer;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -50,7 +51,7 @@ public class PyReparseableIdentifier extends PyReparseableTokenType {
var currentLeaf = TreeUtil.findFirstLeaf(lexingContainer);
PythonLexer lexer = new PythonLexer();
PythonLexer lexer = new PythonHighlightingLexer(LanguageLevel.forElement(leaf.getPsi()));
lexer.start(updatedCharSequence);