Skip to content

Commit 64995e3

Browse files
committed
fix: avoid double-capturing Python methods and functions; correct method range
1 parent 7717b1e commit 64995e3

File tree

5 files changed

+430
-9
lines changed

5 files changed

+430
-9
lines changed

pkg/codegraph/parser/c_resolver_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ func TestCResolver(t *testing.T) {
1515
logger := initLogger() // 如果有日志初始化
1616
parser := NewSourceFileParser(logger) // 假设有类似 Java 的解析器
1717
res, err := parser.Parse(context.Background(), &types.SourceFile{
18-
Path: "testdata/cpp/test.cpp",
19-
Content: readFile("testdata/cpp/test.cpp"),
18+
Path: "testdata/python/test.py",
19+
Content: readFile("testdata/python/test.py"),
2020
})
2121
assert.NoError(t, err)
2222
assert.NotNil(t, res)

pkg/codegraph/parser/queries/base/python.scm

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,30 +55,28 @@
5555
;; ------------------------------------method-----------------------------------
5656
;; 带装饰器
5757
(class_definition
58-
name: (identifier) @definition.method.owner
5958
body: (block
6059
(decorated_definition
61-
(decorator) @definition.method.decorator
60+
(decorator)
6261
definition: (function_definition
6362
name: (identifier) @definition.method.name
6463
parameters: (parameters) @definition.method.parameters
6564
return_type: (type)? @definition.method.return_type
66-
)
65+
)@definition.method
6766
)
6867
)
69-
) @definition.method
68+
)
7069

7170
;; 无装饰器
7271
(class_definition
73-
name: (identifier) @definition.method.owner
7472
body: (block
7573
(function_definition
7674
name: (identifier) @definition.method.name
7775
parameters: (parameters) @definition.method.parameters
7876
return_type: (type)? @definition.method.return_type
79-
)
77+
)@definition.method
8078
)
81-
) @definition.method
79+
)
8280

8381
;; ----------------------------------Variable-------------------------------------
8482
;; Variable assignments

0 commit comments

Comments
 (0)