fix(python): skip empty semantic recovery nodes (#8328)

Цей коміт міститься в:
l0ng-ai authored and GitHub committed 2026-12-06 20:35:20 +08:00
1 джерело c4b2d24d7e
коміт 5fc201ccf4
2 files changed
+13

No files matched your search

+9
Переглянути файл
@@ -12,6 +12,15 @@ async function parse(source: string) {
}
describe("Python PyCharm categories", () => {
it.each(["async def ():\n ", "def ():\n ", "class :\n "])(
"does not color zero-width recovery nodes in %j",
async (source) => {
const { tree, doc } = await parse(source);
const ranges = [...pythonSyntaxRanges(tree, doc), ...pythonFallbackRanges(tree, doc)];
expect(ranges.filter((range) => range.from >= range.to)).toEqual([]);
},
);
it("uses the completed tree when initial parsing exceeds its time budget", async () => {
await parse("");
// Exceed the initial 20 ms parse budget, but stay within ensureSyntaxTree's budget.
+4
Переглянути файл
@@ -459,6 +459,7 @@ export function pythonSymbolKinds(tree: Tree, doc: Text): Map<string, PythonSymb
tree.iterate({
enter(cursor) {
const node = cursor.node;
if (node.from === node.to) return;
if (node.name !== "VariableName" && node.name !== "PropertyName") return;
const kind = kindFor(node);
if (kind) out.set(`${node.from}:${node.to}`, kind);
@@ -479,6 +480,8 @@ export function pythonSyntaxRanges(
tree.iterate({
enter(cursor) {
const node = cursor.node;
// Incomplete declarations may contain zero-width recovery nodes.
if (node.from === node.to) return;
if (
![
"VariableName",
@@ -766,6 +769,7 @@ export function pythonFallbackRanges(
tree.iterate({
enter(cursor) {
const node = cursor.node;
if (node.from === node.to) return;
if (node.name !== "VariableName" && node.name !== "PropertyName") return;
const name = doc.sliceString(node.from, node.to);
const kind =