From bacec20c3cd084c0a1306039f395980752f3885b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BB=9D=E5=B0=98?= <237809796@qq.com> Date: Thu, 1 Oct 2026 08:27:49 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D:=20=E5=8F=98=E9=87=8F?= =?UTF-8?q?=E5=AE=9A=E4=B9=89=E5=88=A4=E5=AE=9A=E8=AF=AF=E4=BC=A4=E5=87=BD?= =?UTF-8?q?=E6=95=B0=E8=B0=83=E7=94=A8=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 子树包含判定改直取 value 节点 kind const x = arr.map(...) 不再误判为符号定义 subtree_contains_kind 无其他使用方一并删除 --- src-tauri/src/commands/ai/code_intel.rs | 21 ++++----------------- 1 file changed, 4 insertions(+), 17 deletions(-) diff --git a/src-tauri/src/commands/ai/code_intel.rs b/src-tauri/src/commands/ai/code_intel.rs index 60b70b0..2d05771 100644 --- a/src-tauri/src/commands/ai/code_intel.rs +++ b/src-tauri/src/commands/ai/code_intel.rs @@ -131,8 +131,9 @@ const FUNCTION_VALUE_KINDS: &[&str] = &["arrow_function", "function", "generator /// /// variable_declarator 单看 kind 过宽:`let msg = "fn main() {}"` 这类普通声明也命中, /// contains_definition 会对几乎任何 JS/TS 文件误报提示。收窄为 `const fn = () => {}` -/// 形态(初始化值是函数/类表达式)才算定义,contains_definition / read_symbol / -/// outline 三处共用同一判定。 +/// 形态(初始化值本身是函数/类表达式)才算定义,contains_definition / read_symbol / +/// outline 三处共用同一判定。判定看 value 节点自身 kind 而非子树包含—— +/// `const x = arr.map(n => ...)` 子树含 arrow_function,但 x 不是函数定义。 fn is_definition_node(node: &Node<'_>) -> bool { if !DEFINITION_KINDS.contains(&node.kind()) { return false; @@ -141,25 +142,11 @@ fn is_definition_node(node: &Node<'_>) -> bool { return true; } match node.child_by_field_name("value") { - Some(v) => subtree_contains_kind(v, FUNCTION_VALUE_KINDS), + Some(v) => FUNCTION_VALUE_KINDS.contains(&v.kind()), None => false, } } -/// 子树内是否含任一目标 kind 节点 -fn subtree_contains_kind(node: Node<'_>, kinds: &[&str]) -> bool { - if kinds.contains(&node.kind()) { - return true; - } - let mut cursor = node.walk(); - for child in node.children(&mut cursor) { - if subtree_contains_kind(child, kinds) { - return true; - } - } - false -} - /// 递归遍历语法树,判断是否含任一定义节点(contains_definition 的遍历内核)。 fn tree_has_definition(node: &Node<'_>) -> bool { if is_definition_node(node) {