@optave/codegraph 3.1.5 → 3.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -2
- package/package.json +7 -7
- package/src/ast-analysis/engine.js +252 -258
- package/src/ast-analysis/shared.js +0 -12
- package/src/ast-analysis/visitors/cfg-visitor.js +635 -649
- package/src/ast-analysis/visitors/complexity-visitor.js +135 -139
- package/src/ast-analysis/visitors/dataflow-visitor.js +230 -224
- package/src/cli/commands/ast.js +2 -1
- package/src/cli/commands/audit.js +2 -1
- package/src/cli/commands/batch.js +2 -1
- package/src/cli/commands/brief.js +12 -0
- package/src/cli/commands/cfg.js +2 -1
- package/src/cli/commands/check.js +20 -23
- package/src/cli/commands/children.js +6 -1
- package/src/cli/commands/complexity.js +2 -1
- package/src/cli/commands/context.js +6 -1
- package/src/cli/commands/dataflow.js +2 -1
- package/src/cli/commands/deps.js +8 -3
- package/src/cli/commands/flow.js +2 -1
- package/src/cli/commands/fn-impact.js +6 -1
- package/src/cli/commands/owners.js +4 -2
- package/src/cli/commands/query.js +6 -1
- package/src/cli/commands/roles.js +2 -1
- package/src/cli/commands/search.js +8 -2
- package/src/cli/commands/sequence.js +2 -1
- package/src/cli/commands/triage.js +38 -27
- package/src/db/connection.js +18 -12
- package/src/db/migrations.js +41 -64
- package/src/db/query-builder.js +60 -4
- package/src/db/repository/in-memory-repository.js +27 -16
- package/src/db/repository/nodes.js +8 -10
- package/src/domain/analysis/brief.js +155 -0
- package/src/domain/analysis/context.js +174 -190
- package/src/domain/analysis/dependencies.js +200 -146
- package/src/domain/analysis/exports.js +3 -2
- package/src/domain/analysis/impact.js +267 -152
- package/src/domain/analysis/module-map.js +247 -221
- package/src/domain/analysis/roles.js +8 -5
- package/src/domain/analysis/symbol-lookup.js +7 -5
- package/src/domain/graph/builder/helpers.js +1 -1
- package/src/domain/graph/builder/incremental.js +116 -90
- package/src/domain/graph/builder/pipeline.js +106 -80
- package/src/domain/graph/builder/stages/build-edges.js +318 -239
- package/src/domain/graph/builder/stages/detect-changes.js +198 -177
- package/src/domain/graph/builder/stages/insert-nodes.js +147 -139
- package/src/domain/graph/watcher.js +2 -2
- package/src/domain/parser.js +20 -11
- package/src/domain/queries.js +1 -0
- package/src/domain/search/search/filters.js +9 -5
- package/src/domain/search/search/keyword.js +12 -5
- package/src/domain/search/search/prepare.js +13 -5
- package/src/extractors/csharp.js +224 -207
- package/src/extractors/go.js +176 -172
- package/src/extractors/hcl.js +94 -78
- package/src/extractors/java.js +213 -207
- package/src/extractors/javascript.js +274 -304
- package/src/extractors/php.js +234 -221
- package/src/extractors/python.js +252 -250
- package/src/extractors/ruby.js +192 -185
- package/src/extractors/rust.js +182 -167
- package/src/features/ast.js +5 -3
- package/src/features/audit.js +4 -2
- package/src/features/boundaries.js +98 -83
- package/src/features/cfg.js +134 -143
- package/src/features/communities.js +68 -53
- package/src/features/complexity.js +143 -132
- package/src/features/dataflow.js +146 -149
- package/src/features/export.js +3 -3
- package/src/features/graph-enrichment.js +2 -2
- package/src/features/manifesto.js +9 -6
- package/src/features/owners.js +4 -3
- package/src/features/sequence.js +152 -141
- package/src/features/shared/find-nodes.js +31 -0
- package/src/features/structure.js +130 -99
- package/src/features/triage.js +83 -68
- package/src/graph/classifiers/risk.js +3 -2
- package/src/graph/classifiers/roles.js +6 -3
- package/src/index.js +1 -0
- package/src/mcp/server.js +65 -56
- package/src/mcp/tool-registry.js +13 -0
- package/src/mcp/tools/brief.js +8 -0
- package/src/mcp/tools/index.js +2 -0
- package/src/presentation/brief.js +51 -0
- package/src/presentation/queries-cli/exports.js +21 -14
- package/src/presentation/queries-cli/impact.js +55 -39
- package/src/presentation/queries-cli/inspect.js +184 -189
- package/src/presentation/queries-cli/overview.js +57 -58
- package/src/presentation/queries-cli/path.js +36 -29
- package/src/presentation/table.js +0 -8
- package/src/shared/generators.js +7 -3
- package/src/shared/kinds.js +1 -1
package/src/extractors/python.js
CHANGED
|
@@ -4,292 +4,294 @@ import { findChild, nodeEndLine, pythonVisibility } from './helpers.js';
|
|
|
4
4
|
* Extract symbols from Python files.
|
|
5
5
|
*/
|
|
6
6
|
export function extractPythonSymbols(tree, _filePath) {
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
7
|
+
const ctx = {
|
|
8
|
+
definitions: [],
|
|
9
|
+
calls: [],
|
|
10
|
+
imports: [],
|
|
11
|
+
classes: [],
|
|
12
|
+
exports: [],
|
|
13
|
+
};
|
|
12
14
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
const nameNode = node.childForFieldName('name');
|
|
17
|
-
if (nameNode) {
|
|
18
|
-
const decorators = [];
|
|
19
|
-
if (node.previousSibling && node.previousSibling.type === 'decorator') {
|
|
20
|
-
decorators.push(node.previousSibling.text);
|
|
21
|
-
}
|
|
22
|
-
const parentClass = findPythonParentClass(node);
|
|
23
|
-
const fullName = parentClass ? `${parentClass}.${nameNode.text}` : nameNode.text;
|
|
24
|
-
const kind = parentClass ? 'method' : 'function';
|
|
25
|
-
const fnChildren = extractPythonParameters(node);
|
|
26
|
-
definitions.push({
|
|
27
|
-
name: fullName,
|
|
28
|
-
kind,
|
|
29
|
-
line: node.startPosition.row + 1,
|
|
30
|
-
endLine: nodeEndLine(node),
|
|
31
|
-
decorators,
|
|
32
|
-
children: fnChildren.length > 0 ? fnChildren : undefined,
|
|
33
|
-
visibility: pythonVisibility(nameNode.text),
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
break;
|
|
37
|
-
}
|
|
15
|
+
walkPythonNode(tree.rootNode, ctx);
|
|
16
|
+
return ctx;
|
|
17
|
+
}
|
|
38
18
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
break;
|
|
66
|
-
}
|
|
19
|
+
function walkPythonNode(node, ctx) {
|
|
20
|
+
switch (node.type) {
|
|
21
|
+
case 'function_definition':
|
|
22
|
+
handlePyFunctionDef(node, ctx);
|
|
23
|
+
break;
|
|
24
|
+
case 'class_definition':
|
|
25
|
+
handlePyClassDef(node, ctx);
|
|
26
|
+
break;
|
|
27
|
+
case 'decorated_definition':
|
|
28
|
+
for (let i = 0; i < node.childCount; i++) walkPythonNode(node.child(i), ctx);
|
|
29
|
+
return;
|
|
30
|
+
case 'call':
|
|
31
|
+
handlePyCall(node, ctx);
|
|
32
|
+
break;
|
|
33
|
+
case 'import_statement':
|
|
34
|
+
handlePyImport(node, ctx);
|
|
35
|
+
break;
|
|
36
|
+
case 'expression_statement':
|
|
37
|
+
handlePyExpressionStmt(node, ctx);
|
|
38
|
+
break;
|
|
39
|
+
case 'import_from_statement':
|
|
40
|
+
handlePyImportFrom(node, ctx);
|
|
41
|
+
break;
|
|
42
|
+
}
|
|
67
43
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
return;
|
|
71
|
-
}
|
|
44
|
+
for (let i = 0; i < node.childCount; i++) walkPythonNode(node.child(i), ctx);
|
|
45
|
+
}
|
|
72
46
|
|
|
73
|
-
|
|
74
|
-
const fn = node.childForFieldName('function');
|
|
75
|
-
if (fn) {
|
|
76
|
-
let callName = null;
|
|
77
|
-
let receiver;
|
|
78
|
-
if (fn.type === 'identifier') callName = fn.text;
|
|
79
|
-
else if (fn.type === 'attribute') {
|
|
80
|
-
const attr = fn.childForFieldName('attribute');
|
|
81
|
-
if (attr) callName = attr.text;
|
|
82
|
-
const obj = fn.childForFieldName('object');
|
|
83
|
-
if (obj) receiver = obj.text;
|
|
84
|
-
}
|
|
85
|
-
if (callName) {
|
|
86
|
-
const call = { name: callName, line: node.startPosition.row + 1 };
|
|
87
|
-
if (receiver) call.receiver = receiver;
|
|
88
|
-
calls.push(call);
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
break;
|
|
92
|
-
}
|
|
47
|
+
// ── Walk-path per-node-type handlers ────────────────────────────────────────
|
|
93
48
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
49
|
+
function handlePyFunctionDef(node, ctx) {
|
|
50
|
+
const nameNode = node.childForFieldName('name');
|
|
51
|
+
if (!nameNode) return;
|
|
52
|
+
const decorators = [];
|
|
53
|
+
if (node.previousSibling && node.previousSibling.type === 'decorator') {
|
|
54
|
+
decorators.push(node.previousSibling.text);
|
|
55
|
+
}
|
|
56
|
+
const parentClass = findPythonParentClass(node);
|
|
57
|
+
const fullName = parentClass ? `${parentClass}.${nameNode.text}` : nameNode.text;
|
|
58
|
+
const kind = parentClass ? 'method' : 'function';
|
|
59
|
+
const fnChildren = extractPythonParameters(node);
|
|
60
|
+
ctx.definitions.push({
|
|
61
|
+
name: fullName,
|
|
62
|
+
kind,
|
|
63
|
+
line: node.startPosition.row + 1,
|
|
64
|
+
endLine: nodeEndLine(node),
|
|
65
|
+
decorators,
|
|
66
|
+
children: fnChildren.length > 0 ? fnChildren : undefined,
|
|
67
|
+
visibility: pythonVisibility(nameNode.text),
|
|
68
|
+
});
|
|
69
|
+
}
|
|
115
70
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
71
|
+
function handlePyClassDef(node, ctx) {
|
|
72
|
+
const nameNode = node.childForFieldName('name');
|
|
73
|
+
if (!nameNode) return;
|
|
74
|
+
const clsChildren = extractPythonClassProperties(node);
|
|
75
|
+
ctx.definitions.push({
|
|
76
|
+
name: nameNode.text,
|
|
77
|
+
kind: 'class',
|
|
78
|
+
line: node.startPosition.row + 1,
|
|
79
|
+
endLine: nodeEndLine(node),
|
|
80
|
+
children: clsChildren.length > 0 ? clsChildren : undefined,
|
|
81
|
+
});
|
|
82
|
+
const superclasses = node.childForFieldName('superclasses') || findChild(node, 'argument_list');
|
|
83
|
+
if (superclasses) {
|
|
84
|
+
for (let i = 0; i < superclasses.childCount; i++) {
|
|
85
|
+
const child = superclasses.child(i);
|
|
86
|
+
if (child && child.type === 'identifier') {
|
|
87
|
+
ctx.classes.push({
|
|
88
|
+
name: nameNode.text,
|
|
89
|
+
extends: child.text,
|
|
90
|
+
line: node.startPosition.row + 1,
|
|
91
|
+
});
|
|
132
92
|
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
133
96
|
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
97
|
+
function handlePyCall(node, ctx) {
|
|
98
|
+
const fn = node.childForFieldName('function');
|
|
99
|
+
if (!fn) return;
|
|
100
|
+
let callName = null;
|
|
101
|
+
let receiver;
|
|
102
|
+
if (fn.type === 'identifier') callName = fn.text;
|
|
103
|
+
else if (fn.type === 'attribute') {
|
|
104
|
+
const attr = fn.childForFieldName('attribute');
|
|
105
|
+
if (attr) callName = attr.text;
|
|
106
|
+
const obj = fn.childForFieldName('object');
|
|
107
|
+
if (obj) receiver = obj.text;
|
|
108
|
+
}
|
|
109
|
+
if (callName) {
|
|
110
|
+
const call = { name: callName, line: node.startPosition.row + 1 };
|
|
111
|
+
if (receiver) call.receiver = receiver;
|
|
112
|
+
ctx.calls.push(call);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function handlePyImport(node, ctx) {
|
|
117
|
+
const names = [];
|
|
118
|
+
for (let i = 0; i < node.childCount; i++) {
|
|
119
|
+
const child = node.child(i);
|
|
120
|
+
if (child && (child.type === 'dotted_name' || child.type === 'aliased_import')) {
|
|
121
|
+
const name =
|
|
122
|
+
child.type === 'aliased_import'
|
|
123
|
+
? (child.childForFieldName('alias') || child.childForFieldName('name'))?.text
|
|
124
|
+
: child.text;
|
|
125
|
+
if (name) names.push(name);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
if (names.length > 0)
|
|
129
|
+
ctx.imports.push({
|
|
130
|
+
source: names[0],
|
|
131
|
+
names,
|
|
132
|
+
line: node.startPosition.row + 1,
|
|
133
|
+
pythonImport: true,
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
function handlePyExpressionStmt(node, ctx) {
|
|
138
|
+
if (node.parent && node.parent.type === 'module') {
|
|
139
|
+
const assignment = findChild(node, 'assignment');
|
|
140
|
+
if (assignment) {
|
|
141
|
+
const left = assignment.childForFieldName('left');
|
|
142
|
+
if (left && left.type === 'identifier' && /^[A-Z_][A-Z0-9_]*$/.test(left.text)) {
|
|
143
|
+
ctx.definitions.push({
|
|
144
|
+
name: left.text,
|
|
145
|
+
kind: 'constant',
|
|
146
|
+
line: node.startPosition.row + 1,
|
|
147
|
+
});
|
|
153
148
|
}
|
|
154
149
|
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
155
152
|
|
|
156
|
-
|
|
153
|
+
function handlePyImportFrom(node, ctx) {
|
|
154
|
+
let source = '';
|
|
155
|
+
const names = [];
|
|
156
|
+
for (let i = 0; i < node.childCount; i++) {
|
|
157
|
+
const child = node.child(i);
|
|
158
|
+
if (!child) continue;
|
|
159
|
+
if (child.type === 'dotted_name' || child.type === 'relative_import') {
|
|
160
|
+
if (!source) source = child.text;
|
|
161
|
+
else names.push(child.text);
|
|
162
|
+
}
|
|
163
|
+
if (child.type === 'aliased_import') {
|
|
164
|
+
const n = child.childForFieldName('name') || child.child(0);
|
|
165
|
+
if (n) names.push(n.text);
|
|
166
|
+
}
|
|
167
|
+
if (child.type === 'wildcard_import') names.push('*');
|
|
157
168
|
}
|
|
169
|
+
if (source)
|
|
170
|
+
ctx.imports.push({ source, names, line: node.startPosition.row + 1, pythonImport: true });
|
|
171
|
+
}
|
|
158
172
|
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
173
|
+
// ── Python-specific helpers ─────────────────────────────────────────────────
|
|
174
|
+
|
|
175
|
+
function extractPythonParameters(fnNode) {
|
|
176
|
+
const params = [];
|
|
177
|
+
const paramsNode = fnNode.childForFieldName('parameters') || findChild(fnNode, 'parameters');
|
|
178
|
+
if (!paramsNode) return params;
|
|
179
|
+
for (let i = 0; i < paramsNode.childCount; i++) {
|
|
180
|
+
const child = paramsNode.child(i);
|
|
181
|
+
if (!child) continue;
|
|
182
|
+
const t = child.type;
|
|
183
|
+
if (t === 'identifier') {
|
|
184
|
+
params.push({ name: child.text, kind: 'parameter', line: child.startPosition.row + 1 });
|
|
185
|
+
} else if (
|
|
186
|
+
t === 'typed_parameter' ||
|
|
187
|
+
t === 'default_parameter' ||
|
|
188
|
+
t === 'typed_default_parameter'
|
|
189
|
+
) {
|
|
190
|
+
const nameNode = child.childForFieldName('name') || child.child(0);
|
|
191
|
+
if (nameNode && nameNode.type === 'identifier') {
|
|
192
|
+
params.push({
|
|
193
|
+
name: nameNode.text,
|
|
194
|
+
kind: 'parameter',
|
|
195
|
+
line: child.startPosition.row + 1,
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
} else if (t === 'list_splat_pattern' || t === 'dictionary_splat_pattern') {
|
|
199
|
+
for (let j = 0; j < child.childCount; j++) {
|
|
200
|
+
const inner = child.child(j);
|
|
201
|
+
if (inner && inner.type === 'identifier') {
|
|
202
|
+
params.push({ name: inner.text, kind: 'parameter', line: child.startPosition.row + 1 });
|
|
203
|
+
break;
|
|
190
204
|
}
|
|
191
205
|
}
|
|
192
206
|
}
|
|
193
|
-
return params;
|
|
194
207
|
}
|
|
208
|
+
return params;
|
|
209
|
+
}
|
|
195
210
|
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
211
|
+
function extractPythonClassProperties(classNode) {
|
|
212
|
+
const props = [];
|
|
213
|
+
const seen = new Set();
|
|
214
|
+
const body = classNode.childForFieldName('body') || findChild(classNode, 'block');
|
|
215
|
+
if (!body) return props;
|
|
201
216
|
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
217
|
+
for (let i = 0; i < body.childCount; i++) {
|
|
218
|
+
const child = body.child(i);
|
|
219
|
+
if (!child) continue;
|
|
205
220
|
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
});
|
|
219
|
-
}
|
|
221
|
+
if (child.type === 'expression_statement') {
|
|
222
|
+
const assignment = findChild(child, 'assignment');
|
|
223
|
+
if (assignment) {
|
|
224
|
+
const left = assignment.childForFieldName('left');
|
|
225
|
+
if (left && left.type === 'identifier' && !seen.has(left.text)) {
|
|
226
|
+
seen.add(left.text);
|
|
227
|
+
props.push({
|
|
228
|
+
name: left.text,
|
|
229
|
+
kind: 'property',
|
|
230
|
+
line: child.startPosition.row + 1,
|
|
231
|
+
visibility: pythonVisibility(left.text),
|
|
232
|
+
});
|
|
220
233
|
}
|
|
221
234
|
}
|
|
235
|
+
}
|
|
222
236
|
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
walkInitBody(initBody, seen, props);
|
|
230
|
-
}
|
|
237
|
+
if (child.type === 'function_definition') {
|
|
238
|
+
const fnName = child.childForFieldName('name');
|
|
239
|
+
if (fnName && fnName.text === '__init__') {
|
|
240
|
+
const initBody = child.childForFieldName('body') || findChild(child, 'block');
|
|
241
|
+
if (initBody) {
|
|
242
|
+
walkInitBody(initBody, seen, props);
|
|
231
243
|
}
|
|
232
244
|
}
|
|
245
|
+
}
|
|
233
246
|
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
walkInitBody(initBody, seen, props);
|
|
244
|
-
}
|
|
247
|
+
if (child.type === 'decorated_definition') {
|
|
248
|
+
for (let j = 0; j < child.childCount; j++) {
|
|
249
|
+
const inner = child.child(j);
|
|
250
|
+
if (inner && inner.type === 'function_definition') {
|
|
251
|
+
const fnName = inner.childForFieldName('name');
|
|
252
|
+
if (fnName && fnName.text === '__init__') {
|
|
253
|
+
const initBody = inner.childForFieldName('body') || findChild(inner, 'block');
|
|
254
|
+
if (initBody) {
|
|
255
|
+
walkInitBody(initBody, seen, props);
|
|
245
256
|
}
|
|
246
257
|
}
|
|
247
258
|
}
|
|
248
259
|
}
|
|
249
260
|
}
|
|
250
|
-
return props;
|
|
251
261
|
}
|
|
262
|
+
return props;
|
|
263
|
+
}
|
|
252
264
|
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
attr
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
props.push({
|
|
272
|
-
name: attr.text,
|
|
273
|
-
kind: 'property',
|
|
274
|
-
line: stmt.startPosition.row + 1,
|
|
275
|
-
visibility: pythonVisibility(attr.text),
|
|
276
|
-
});
|
|
277
|
-
}
|
|
265
|
+
function walkInitBody(bodyNode, seen, props) {
|
|
266
|
+
for (let i = 0; i < bodyNode.childCount; i++) {
|
|
267
|
+
const stmt = bodyNode.child(i);
|
|
268
|
+
if (!stmt || stmt.type !== 'expression_statement') continue;
|
|
269
|
+
const assignment = findChild(stmt, 'assignment');
|
|
270
|
+
if (!assignment) continue;
|
|
271
|
+
const left = assignment.childForFieldName('left');
|
|
272
|
+
if (!left || left.type !== 'attribute') continue;
|
|
273
|
+
const obj = left.childForFieldName('object');
|
|
274
|
+
const attr = left.childForFieldName('attribute');
|
|
275
|
+
if (obj && obj.text === 'self' && attr && attr.type === 'identifier' && !seen.has(attr.text)) {
|
|
276
|
+
seen.add(attr.text);
|
|
277
|
+
props.push({
|
|
278
|
+
name: attr.text,
|
|
279
|
+
kind: 'property',
|
|
280
|
+
line: stmt.startPosition.row + 1,
|
|
281
|
+
visibility: pythonVisibility(attr.text),
|
|
282
|
+
});
|
|
278
283
|
}
|
|
279
284
|
}
|
|
285
|
+
}
|
|
280
286
|
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
}
|
|
288
|
-
current = current.parent;
|
|
287
|
+
function findPythonParentClass(node) {
|
|
288
|
+
let current = node.parent;
|
|
289
|
+
while (current) {
|
|
290
|
+
if (current.type === 'class_definition') {
|
|
291
|
+
const nameNode = current.childForFieldName('name');
|
|
292
|
+
return nameNode ? nameNode.text : null;
|
|
289
293
|
}
|
|
290
|
-
|
|
294
|
+
current = current.parent;
|
|
291
295
|
}
|
|
292
|
-
|
|
293
|
-
walkPythonNode(tree.rootNode);
|
|
294
|
-
return { definitions, calls, imports, classes, exports };
|
|
296
|
+
return null;
|
|
295
297
|
}
|