From ad5796787b2392cbc35e5543b588479b2af50bd3 Mon Sep 17 00:00:00 2001 From: cruldra Date: Fri, 2 Oct 2026 00:16:19 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix(vscode):=20Pydantic=20?= =?UTF-8?q?=E8=A7=84=E5=88=99=E7=9A=84=E7=B1=BB=E5=9E=8B=E6=A3=80=E6=9F=A5?= =?UTF-8?q?=E6=94=B6=E7=B4=A7=E7=A9=BA=E8=8A=82=E7=82=B9=E5=92=8C=E5=B7=AE?= =?UTF-8?q?=E5=BC=82=E6=A0=BC=E5=AD=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- vscode/src/codeReader/rules/pydantic.test.ts | 4 ++-- vscode/src/codeReader/rules/pydantic.ts | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/vscode/src/codeReader/rules/pydantic.test.ts b/vscode/src/codeReader/rules/pydantic.test.ts index 4374538..e81ead5 100644 --- a/vscode/src/codeReader/rules/pydantic.test.ts +++ b/vscode/src/codeReader/rules/pydantic.test.ts @@ -262,8 +262,8 @@ describe('pydantic 库规则(Python)', () => { const traceFields = properties(trace).findIndex(row => row.label === '字段') const cell = traceChange.marks?.rows?.changed[traceFields].items?.changed[2].cells?.[2] expect(cell?.map(part => part.change)).toEqual(['del', 'add']) - expect(cell?.[0].segments.map(segment => segment.text).join('')).toBe('空') - expect(cell?.[1].segments.map(segment => segment.text).join('')).toBe('""') + expect(flatSegments(cell?.[0].segments ?? []).map(segment => segment.text).join('')).toBe('空') + expect(flatSegments(cell?.[1].segments ?? []).map(segment => segment.text).join('')).toBe('""') expect(diff.stats).toEqual({ add: 0, mod: 2, del: 0 }) }) }) diff --git a/vscode/src/codeReader/rules/pydantic.ts b/vscode/src/codeReader/rules/pydantic.ts index 3a408c3..81656c8 100644 --- a/vscode/src/codeReader/rules/pydantic.ts +++ b/vscode/src/codeReader/rules/pydantic.ts @@ -161,6 +161,8 @@ function namesInSource(root: Node): LibraryNames { for (const statement of syntaxChildren(root)) { if (statement.type === 'import_statement') { for (const item of statement.childrenForFieldName('name')) { + if (!item) + continue const original = item.type === 'aliased_import' ? item.childForFieldName('name') : item const alias = item.type === 'aliased_import' ? item.childForFieldName('alias') : null if (original && fromPydantic(original.text)) @@ -173,6 +175,8 @@ function namesInSource(root: Node): LibraryNames { if (!module || !fromPydantic(module.text)) continue for (const item of statement.childrenForFieldName('name')) { + if (!item) + continue const original = item.type === 'aliased_import' ? item.childForFieldName('name') : item const alias = item.type === 'aliased_import' ? item.childForFieldName('alias') : null if (original)