дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-12-06 18:17:15 +02:00
fix(python): skip empty semantic recovery nodes (#8328)
Цей коміт міститься в:
1 джерело
c4b2d24d7e
коміт
5fc201ccf4
2 files changed
+13
No files matched your search
@@ -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.
|
||||
|
||||
@@ -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 =
|
||||
|
||||
Reference in new issue
Заблокувати користувача