@mortice/mapwright 0.8.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/CHANGELOG.md +161 -0
- package/LICENSE +21 -0
- package/README.md +262 -0
- package/dist/catalogue/canonicalisation.d.ts +36 -0
- package/dist/catalogue/canonicalisation.js +262 -0
- package/dist/catalogue/config.d.ts +13 -0
- package/dist/catalogue/config.js +77 -0
- package/dist/catalogue/deterministic.d.ts +3 -0
- package/dist/catalogue/deterministic.js +25 -0
- package/dist/catalogue/diagnostics.d.ts +2 -0
- package/dist/catalogue/diagnostics.js +34 -0
- package/dist/catalogue/evidence.d.ts +1 -0
- package/dist/catalogue/evidence.js +10 -0
- package/dist/catalogue/examples.d.ts +3 -0
- package/dist/catalogue/examples.js +20 -0
- package/dist/catalogue/identity.d.ts +61 -0
- package/dist/catalogue/identity.js +114 -0
- package/dist/catalogue/ignore.d.ts +4 -0
- package/dist/catalogue/ignore.js +29 -0
- package/dist/catalogue/indexer.d.ts +20 -0
- package/dist/catalogue/indexer.js +1393 -0
- package/dist/catalogue/linkage.d.ts +16 -0
- package/dist/catalogue/linkage.js +419 -0
- package/dist/catalogue/moduleResolution.d.ts +4 -0
- package/dist/catalogue/moduleResolution.js +67 -0
- package/dist/catalogue/ordering.d.ts +13 -0
- package/dist/catalogue/ordering.js +86 -0
- package/dist/catalogue/packages.d.ts +12 -0
- package/dist/catalogue/packages.js +475 -0
- package/dist/catalogue/pythonReExports.d.ts +7 -0
- package/dist/catalogue/pythonReExports.js +113 -0
- package/dist/catalogue/resolveRefs.d.ts +40 -0
- package/dist/catalogue/resolveRefs.js +284 -0
- package/dist/catalogue/scanner.d.ts +8 -0
- package/dist/catalogue/scanner.js +99 -0
- package/dist/catalogue/schema.d.ts +289 -0
- package/dist/catalogue/schema.js +1 -0
- package/dist/catalogue/store.d.ts +41 -0
- package/dist/catalogue/store.js +209 -0
- package/dist/catalogue/templates.d.ts +18 -0
- package/dist/catalogue/templates.js +158 -0
- package/dist/catalogue/version.d.ts +12 -0
- package/dist/catalogue/version.js +30 -0
- package/dist/cli/commands/adoptionPlan.d.ts +8 -0
- package/dist/cli/commands/adoptionPlan.js +24 -0
- package/dist/cli/commands/auditDocs.d.ts +8 -0
- package/dist/cli/commands/auditDocs.js +24 -0
- package/dist/cli/commands/changeImpact.d.ts +10 -0
- package/dist/cli/commands/changeImpact.js +36 -0
- package/dist/cli/commands/changes.d.ts +12 -0
- package/dist/cli/commands/changes.js +31 -0
- package/dist/cli/commands/check.d.ts +9 -0
- package/dist/cli/commands/check.js +4 -0
- package/dist/cli/commands/compatibility.d.ts +10 -0
- package/dist/cli/commands/compatibility.js +43 -0
- package/dist/cli/commands/diff.d.ts +31 -0
- package/dist/cli/commands/diff.js +118 -0
- package/dist/cli/commands/dogfood.d.ts +8 -0
- package/dist/cli/commands/dogfood.js +24 -0
- package/dist/cli/commands/drift.d.ts +8 -0
- package/dist/cli/commands/drift.js +13 -0
- package/dist/cli/commands/index.d.ts +9 -0
- package/dist/cli/commands/index.js +9 -0
- package/dist/cli/commands/indexWorkspace.d.ts +8 -0
- package/dist/cli/commands/indexWorkspace.js +23 -0
- package/dist/cli/commands/recommendConfig.d.ts +7 -0
- package/dist/cli/commands/recommendConfig.js +20 -0
- package/dist/cli/commands/schema.d.ts +1 -0
- package/dist/cli/commands/schema.js +37 -0
- package/dist/cli/commands/template.d.ts +5 -0
- package/dist/cli/commands/template.js +44 -0
- package/dist/cli/commands/validate.d.ts +9 -0
- package/dist/cli/commands/validate.js +85 -0
- package/dist/cli/index.d.ts +2 -0
- package/dist/cli/index.js +211 -0
- package/dist/comparison/artefactValidate.d.ts +19 -0
- package/dist/comparison/artefactValidate.js +334 -0
- package/dist/comparison/candidates.d.ts +12 -0
- package/dist/comparison/candidates.js +391 -0
- package/dist/comparison/compare.d.ts +15 -0
- package/dist/comparison/compare.js +240 -0
- package/dist/comparison/compatibility.d.ts +26 -0
- package/dist/comparison/compatibility.js +316 -0
- package/dist/comparison/drift.d.ts +34 -0
- package/dist/comparison/drift.js +71 -0
- package/dist/comparison/identity.d.ts +30 -0
- package/dist/comparison/identity.js +73 -0
- package/dist/comparison/impact.d.ts +14 -0
- package/dist/comparison/impact.js +291 -0
- package/dist/comparison/index.d.ts +6 -0
- package/dist/comparison/index.js +6 -0
- package/dist/comparison/integrity.d.ts +12 -0
- package/dist/comparison/integrity.js +199 -0
- package/dist/comparison/ordering.d.ts +4 -0
- package/dist/comparison/ordering.js +69 -0
- package/dist/comparison/projections.d.ts +19 -0
- package/dist/comparison/projections.js +185 -0
- package/dist/comparison/relationshipPolicy.d.ts +19 -0
- package/dist/comparison/relationshipPolicy.js +98 -0
- package/dist/comparison/schema.d.ts +178 -0
- package/dist/comparison/schema.js +16 -0
- package/dist/comparison/store.d.ts +58 -0
- package/dist/comparison/store.js +462 -0
- package/dist/comparison/validate.d.ts +23 -0
- package/dist/comparison/validate.js +137 -0
- package/dist/comparison/version.d.ts +9 -0
- package/dist/comparison/version.js +11 -0
- package/dist/extractors/docTags.d.ts +9 -0
- package/dist/extractors/docTags.js +106 -0
- package/dist/extractors/generic.d.ts +5 -0
- package/dist/extractors/generic.js +3 -0
- package/dist/extractors/javascript.d.ts +3 -0
- package/dist/extractors/javascript.js +4 -0
- package/dist/extractors/markdown.d.ts +7 -0
- package/dist/extractors/markdown.js +269 -0
- package/dist/extractors/python.d.ts +7 -0
- package/dist/extractors/python.js +314 -0
- package/dist/extractors/typescript.d.ts +7 -0
- package/dist/extractors/typescript.js +387 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/mcp/resources.d.ts +18 -0
- package/dist/mcp/resources.js +57 -0
- package/dist/mcp/server.d.ts +2 -0
- package/dist/mcp/server.js +95 -0
- package/dist/mcp/tools.d.ts +29 -0
- package/dist/mcp/tools.js +902 -0
- package/dist/queries/adoption.d.ts +62 -0
- package/dist/queries/adoption.js +366 -0
- package/dist/queries/capabilities.d.ts +45 -0
- package/dist/queries/capabilities.js +124 -0
- package/dist/queries/changes.d.ts +33 -0
- package/dist/queries/changes.js +53 -0
- package/dist/queries/dependencies.d.ts +17 -0
- package/dist/queries/dependencies.js +94 -0
- package/dist/queries/dogfood.d.ts +50 -0
- package/dist/queries/dogfood.js +116 -0
- package/dist/queries/editingContext.d.ts +84 -0
- package/dist/queries/editingContext.js +240 -0
- package/dist/queries/examples.d.ts +8 -0
- package/dist/queries/examples.js +16 -0
- package/dist/queries/files.d.ts +8 -0
- package/dist/queries/files.js +14 -0
- package/dist/queries/lists.d.ts +94 -0
- package/dist/queries/lists.js +184 -0
- package/dist/queries/overview.d.ts +2 -0
- package/dist/queries/overview.js +8 -0
- package/dist/queries/publicApis.d.ts +60 -0
- package/dist/queries/publicApis.js +120 -0
- package/dist/queries/ranking.d.ts +67 -0
- package/dist/queries/ranking.js +387 -0
- package/dist/queries/recommendConfig.d.ts +47 -0
- package/dist/queries/recommendConfig.js +123 -0
- package/dist/queries/relationships.d.ts +5 -0
- package/dist/queries/relationships.js +15 -0
- package/dist/queries/reuseCandidates.d.ts +34 -0
- package/dist/queries/reuseCandidates.js +181 -0
- package/dist/queries/symbols.d.ts +40 -0
- package/dist/queries/symbols.js +41 -0
- package/dist/security/pathPolicy.d.ts +12 -0
- package/dist/security/pathPolicy.js +46 -0
- package/dist/security/secretPatterns.d.ts +1 -0
- package/dist/security/secretPatterns.js +4 -0
- package/dist/security/sourceAccess.d.ts +12 -0
- package/dist/security/sourceAccess.js +35 -0
- package/package.json +60 -0
|
@@ -0,0 +1,314 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { readFileSync } from "node:fs";
|
|
3
|
+
import { parseDocTags } from "./docTags.js";
|
|
4
|
+
import { createExternalPackageId, resolvePythonRelativeModuleTarget } from "../catalogue/moduleResolution.js";
|
|
5
|
+
import { truncateEvidenceText } from "../catalogue/evidence.js";
|
|
6
|
+
import { implementationFingerprint, relationshipIdentityId, signatureFingerprint, symbolIdentityId } from "../catalogue/identity.js";
|
|
7
|
+
export function extractPythonSymbols(workspaceRoot, file, packageRecord) {
|
|
8
|
+
const absolute = path.resolve(workspaceRoot, file.path);
|
|
9
|
+
const sourceText = readFileSync(absolute, "utf8");
|
|
10
|
+
const lines = sourceText.split(/\r?\n/);
|
|
11
|
+
const symbols = [];
|
|
12
|
+
const relationships = [];
|
|
13
|
+
const diagnostics = [];
|
|
14
|
+
const packageId = packageRecord?.id ?? "package:unknown";
|
|
15
|
+
const modulePath = file.path;
|
|
16
|
+
const symbolProvenance = file.isGenerated ? "generated_declaration" : "authored_source";
|
|
17
|
+
const explicitExports = parseDunderAll(lines);
|
|
18
|
+
const importStatements = [];
|
|
19
|
+
const stack = [];
|
|
20
|
+
for (let i = 0; i < lines.length; i += 1) {
|
|
21
|
+
const line = lines[i] ?? "";
|
|
22
|
+
const indent = line.match(/^\s*/)?.[0].length ?? 0;
|
|
23
|
+
while (stack.length > 0 && indent <= stack[stack.length - 1].indent) {
|
|
24
|
+
stack.pop();
|
|
25
|
+
}
|
|
26
|
+
const classMatch = line.match(/^\s*class\s+([A-Za-z_][A-Za-z0-9_]*)/);
|
|
27
|
+
const functionMatch = line.match(/^\s*def\s+([A-Za-z_][A-Za-z0-9_]*)\s*\(([^)]*)\)/);
|
|
28
|
+
if (classMatch || functionMatch) {
|
|
29
|
+
const isClass = Boolean(classMatch);
|
|
30
|
+
const name = (classMatch?.[1] ?? functionMatch?.[1] ?? "").trim();
|
|
31
|
+
const signature = line.trim();
|
|
32
|
+
const parent = stack[stack.length - 1];
|
|
33
|
+
const kind = isClass ? "class" : parent?.kind === "class" ? "method" : "function";
|
|
34
|
+
const containerPath = parent ? (parent.containerPath ? `${parent.containerPath}.${parent.name}` : parent.name) : "";
|
|
35
|
+
const doc = readDocstring(lines, i + 1, indent);
|
|
36
|
+
const parsed = doc ? parseDocTags(doc.text, file.path) : { summary: "", tags: [], diagnostics: [] };
|
|
37
|
+
diagnostics.push(...parsed.diagnostics);
|
|
38
|
+
const id = symbolIdentityId({
|
|
39
|
+
language: "python",
|
|
40
|
+
kind,
|
|
41
|
+
packageId,
|
|
42
|
+
modulePath,
|
|
43
|
+
qualifiedContainerPath: containerPath,
|
|
44
|
+
declaredName: name
|
|
45
|
+
});
|
|
46
|
+
const nameExported = explicitExports ? explicitExports.has(name) : !name.startsWith("_");
|
|
47
|
+
const exported = !file.isTest && nameExported;
|
|
48
|
+
const visibility = file.isTest ? "test_only" : exported ? "published" : "private";
|
|
49
|
+
symbols.push({
|
|
50
|
+
id,
|
|
51
|
+
name,
|
|
52
|
+
qualifiedName: `${file.path}::${name}`,
|
|
53
|
+
kind,
|
|
54
|
+
language: "python",
|
|
55
|
+
filePath: file.path,
|
|
56
|
+
packageId,
|
|
57
|
+
modulePath,
|
|
58
|
+
qualifiedContainerPath: containerPath,
|
|
59
|
+
range: { startLine: i + 1, startColumn: indent + 1 },
|
|
60
|
+
signature,
|
|
61
|
+
signatureFingerprint: signatureFingerprint([kind, signature]),
|
|
62
|
+
implementationFingerprint: implementationFingerprint([kind, signature]),
|
|
63
|
+
canonicalSymbolId: id,
|
|
64
|
+
duplicateOf: null,
|
|
65
|
+
symbolProvenance,
|
|
66
|
+
visibility,
|
|
67
|
+
exported,
|
|
68
|
+
doc: {
|
|
69
|
+
present: Boolean(doc),
|
|
70
|
+
text: parsed.summary,
|
|
71
|
+
tags: parsed.tags
|
|
72
|
+
},
|
|
73
|
+
capabilities: parsed.tags.filter((t) => t.tag === "capability").map((t) => t.value),
|
|
74
|
+
parents: parent ? [parent.id] : [],
|
|
75
|
+
children: [],
|
|
76
|
+
confidence: 0.8,
|
|
77
|
+
provenance: { source: "python-static", extractors: ["python"] }
|
|
78
|
+
});
|
|
79
|
+
file.symbols.push(id);
|
|
80
|
+
relationships.push({
|
|
81
|
+
id: relationshipIdentityId({
|
|
82
|
+
type: "defines",
|
|
83
|
+
fromKind: "file",
|
|
84
|
+
fromId: file.path,
|
|
85
|
+
toKind: "symbol",
|
|
86
|
+
toId: id,
|
|
87
|
+
discriminant: null
|
|
88
|
+
}),
|
|
89
|
+
type: "defines",
|
|
90
|
+
from: { kind: "file", id: file.path },
|
|
91
|
+
to: { kind: "symbol", id },
|
|
92
|
+
confidence: 1,
|
|
93
|
+
provenance: { source: "python-static" }
|
|
94
|
+
});
|
|
95
|
+
if (exported) {
|
|
96
|
+
relationships.push({
|
|
97
|
+
id: relationshipIdentityId({
|
|
98
|
+
type: "exports",
|
|
99
|
+
fromKind: "file",
|
|
100
|
+
fromId: file.path,
|
|
101
|
+
toKind: "symbol",
|
|
102
|
+
toId: id,
|
|
103
|
+
discriminant: explicitExports ? "__all__" : null
|
|
104
|
+
}),
|
|
105
|
+
type: "exports",
|
|
106
|
+
from: { kind: "file", id: file.path },
|
|
107
|
+
to: { kind: "symbol", id },
|
|
108
|
+
localDiscriminant: explicitExports ? "__all__" : null,
|
|
109
|
+
evidence: { filePath: file.path, startLine: i + 1, endLine: i + 1, text: truncateEvidenceText(signature) },
|
|
110
|
+
confidence: explicitExports ? 0.95 : 0.7,
|
|
111
|
+
provenance: { source: "python-static" }
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
if (parent) {
|
|
115
|
+
const parentSymbol = symbols.find((s) => s.id === parent.id);
|
|
116
|
+
parentSymbol?.children.push(id);
|
|
117
|
+
relationships.push({
|
|
118
|
+
id: relationshipIdentityId({
|
|
119
|
+
type: "contains",
|
|
120
|
+
fromKind: "symbol",
|
|
121
|
+
fromId: parent.id,
|
|
122
|
+
toKind: "symbol",
|
|
123
|
+
toId: id,
|
|
124
|
+
discriminant: null
|
|
125
|
+
}),
|
|
126
|
+
type: "contains",
|
|
127
|
+
from: { kind: "symbol", id: parent.id },
|
|
128
|
+
to: { kind: "symbol", id },
|
|
129
|
+
confidence: 0.9,
|
|
130
|
+
provenance: { source: "python-static" }
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
stack.push({ indent, id, kind: isClass ? "class" : "function", name, containerPath });
|
|
134
|
+
}
|
|
135
|
+
const fromImportMatch = line.match(/^\s*from\s+([.A-Za-z_][A-Za-z0-9_.]*)\s+import\s+(.+)$/);
|
|
136
|
+
if (fromImportMatch) {
|
|
137
|
+
const moduleSpecifier = fromImportMatch[1]?.trim() ?? "";
|
|
138
|
+
const importedNames = fromImportMatch[2]
|
|
139
|
+
.split(",")
|
|
140
|
+
.map((part) => part.trim())
|
|
141
|
+
.filter(Boolean)
|
|
142
|
+
.map((part) => part.split(/\s+as\s+/i)[0]?.trim() ?? part);
|
|
143
|
+
importStatements.push({
|
|
144
|
+
moduleSpecifier,
|
|
145
|
+
importedNames,
|
|
146
|
+
startLine: i + 1,
|
|
147
|
+
text: line.trim(),
|
|
148
|
+
importKind: moduleSpecifier.startsWith(".") ? "relative" : "absolute"
|
|
149
|
+
});
|
|
150
|
+
continue;
|
|
151
|
+
}
|
|
152
|
+
const importMatch = line.match(/^\s*import\s+([A-Za-z_][A-Za-z0-9_.]*)(?:\s+as\s+[A-Za-z_][A-Za-z0-9_]*)?\s*$/);
|
|
153
|
+
if (importMatch) {
|
|
154
|
+
const moduleSpecifier = importMatch[1]?.trim() ?? "";
|
|
155
|
+
importStatements.push({
|
|
156
|
+
moduleSpecifier,
|
|
157
|
+
importedNames: [],
|
|
158
|
+
startLine: i + 1,
|
|
159
|
+
text: line.trim(),
|
|
160
|
+
importKind: moduleSpecifier.startsWith(".") ? "relative" : "absolute"
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
for (const statement of importStatements) {
|
|
165
|
+
const localTarget = resolvePythonRelativeModuleTarget(workspaceRoot, file.path, statement.moduleSpecifier);
|
|
166
|
+
if (statement.importKind === "relative") {
|
|
167
|
+
if (localTarget) {
|
|
168
|
+
relationships.push({
|
|
169
|
+
id: relationshipIdentityId({
|
|
170
|
+
type: "imports",
|
|
171
|
+
fromKind: "file",
|
|
172
|
+
fromId: file.path,
|
|
173
|
+
toKind: "file",
|
|
174
|
+
toId: localTarget,
|
|
175
|
+
discriminant: "relative"
|
|
176
|
+
}),
|
|
177
|
+
type: "imports",
|
|
178
|
+
from: { kind: "file", id: file.path },
|
|
179
|
+
to: { kind: "file", id: localTarget },
|
|
180
|
+
localDiscriminant: "relative",
|
|
181
|
+
evidence: { filePath: file.path, startLine: statement.startLine, endLine: statement.startLine, text: truncateEvidenceText(statement.text) },
|
|
182
|
+
confidence: 0.9,
|
|
183
|
+
provenance: { source: "python-static" }
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
else {
|
|
187
|
+
diagnostics.push({
|
|
188
|
+
id: `diag:${file.path}:${statement.startLine}:unresolved_import:${statement.moduleSpecifier}`,
|
|
189
|
+
severity: "warning",
|
|
190
|
+
category: "resolution",
|
|
191
|
+
code: "unresolved_import",
|
|
192
|
+
message: `Unresolved local import ${statement.moduleSpecifier}.`,
|
|
193
|
+
filePath: file.path,
|
|
194
|
+
range: { startLine: statement.startLine },
|
|
195
|
+
target: { kind: "file", id: file.path },
|
|
196
|
+
provenance: { source: "python-static" }
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
continue;
|
|
200
|
+
}
|
|
201
|
+
const externalId = createExternalPackageId(statement.moduleSpecifier);
|
|
202
|
+
relationships.push({
|
|
203
|
+
id: relationshipIdentityId({
|
|
204
|
+
type: "imports",
|
|
205
|
+
fromKind: "file",
|
|
206
|
+
fromId: file.path,
|
|
207
|
+
toKind: "externalPackage",
|
|
208
|
+
toId: externalId,
|
|
209
|
+
discriminant: "absolute"
|
|
210
|
+
}),
|
|
211
|
+
type: "imports",
|
|
212
|
+
from: { kind: "file", id: file.path },
|
|
213
|
+
to: { kind: "externalPackage", id: externalId },
|
|
214
|
+
localDiscriminant: "absolute",
|
|
215
|
+
evidence: { filePath: file.path, startLine: statement.startLine, endLine: statement.startLine, text: truncateEvidenceText(statement.text) },
|
|
216
|
+
confidence: 0.75,
|
|
217
|
+
provenance: { source: "python-static" }
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
return { symbols, relationships, diagnostics };
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* Statically parse a literal `__all__ = ["a", "b"]` (or tuple) assignment.
|
|
224
|
+
* Only literal string lists spanning contiguous lines are recognised; anything
|
|
225
|
+
* dynamic (concatenation with names, `+=`, function calls) yields no export set.
|
|
226
|
+
*/
|
|
227
|
+
function parseDunderAll(lines) {
|
|
228
|
+
for (let i = 0; i < lines.length; i += 1) {
|
|
229
|
+
const line = lines[i] ?? "";
|
|
230
|
+
const match = line.match(/^\s*__all__\s*(?::\s*[^=]+)?=\s*(.*)$/);
|
|
231
|
+
if (!match) {
|
|
232
|
+
continue;
|
|
233
|
+
}
|
|
234
|
+
let body = match[1] ?? "";
|
|
235
|
+
// Collect continuation lines until the bracket/paren balance closes.
|
|
236
|
+
let depth = bracketDelta(body);
|
|
237
|
+
let cursor = i;
|
|
238
|
+
while (depth > 0 && cursor + 1 < lines.length) {
|
|
239
|
+
cursor += 1;
|
|
240
|
+
const next = lines[cursor] ?? "";
|
|
241
|
+
body += `\n${next}`;
|
|
242
|
+
depth += bracketDelta(next);
|
|
243
|
+
}
|
|
244
|
+
const open = body.indexOf("[") >= 0 ? "[" : body.indexOf("(") >= 0 ? "(" : undefined;
|
|
245
|
+
if (!open) {
|
|
246
|
+
return undefined;
|
|
247
|
+
}
|
|
248
|
+
const close = open === "[" ? "]" : ")";
|
|
249
|
+
const start = body.indexOf(open);
|
|
250
|
+
const end = body.lastIndexOf(close);
|
|
251
|
+
if (start < 0 || end < 0 || end <= start) {
|
|
252
|
+
return undefined;
|
|
253
|
+
}
|
|
254
|
+
const inner = body.slice(start + 1, end);
|
|
255
|
+
// Reject dynamic constructs; only literal string entries are allowed.
|
|
256
|
+
const withoutStrings = inner.replace(/(["'])(?:\\.|(?!\1).)*\1/g, "").replace(/[\s,]/g, "");
|
|
257
|
+
if (withoutStrings.length > 0) {
|
|
258
|
+
return undefined;
|
|
259
|
+
}
|
|
260
|
+
const names = new Set();
|
|
261
|
+
for (const entry of inner.matchAll(/(["'])((?:\\.|(?!\1).)*)\1/g)) {
|
|
262
|
+
const value = entry[2]?.trim();
|
|
263
|
+
if (value) {
|
|
264
|
+
names.add(value);
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
return names;
|
|
268
|
+
}
|
|
269
|
+
return undefined;
|
|
270
|
+
}
|
|
271
|
+
function bracketDelta(text) {
|
|
272
|
+
let delta = 0;
|
|
273
|
+
for (const char of text) {
|
|
274
|
+
if (char === "[" || char === "(")
|
|
275
|
+
delta += 1;
|
|
276
|
+
else if (char === "]" || char === ")")
|
|
277
|
+
delta -= 1;
|
|
278
|
+
}
|
|
279
|
+
return delta;
|
|
280
|
+
}
|
|
281
|
+
function readDocstring(lines, start, parentIndent) {
|
|
282
|
+
for (let i = start; i < Math.min(start + 6, lines.length); i += 1) {
|
|
283
|
+
const line = lines[i] ?? "";
|
|
284
|
+
if (line.trim() === "") {
|
|
285
|
+
continue;
|
|
286
|
+
}
|
|
287
|
+
const indent = line.match(/^\s*/)?.[0].length ?? 0;
|
|
288
|
+
if (indent <= parentIndent) {
|
|
289
|
+
return undefined;
|
|
290
|
+
}
|
|
291
|
+
const tripleQuote = line.match(/^\s*["']{3}/);
|
|
292
|
+
if (!tripleQuote) {
|
|
293
|
+
return undefined;
|
|
294
|
+
}
|
|
295
|
+
const quote = line.includes('"""') ? '"""' : "'''";
|
|
296
|
+
const collected = [];
|
|
297
|
+
const first = line.substring(line.indexOf(quote) + 3);
|
|
298
|
+
if (first.includes(quote)) {
|
|
299
|
+
collected.push(first.substring(0, first.indexOf(quote)));
|
|
300
|
+
return { text: collected.join("\n") };
|
|
301
|
+
}
|
|
302
|
+
collected.push(first);
|
|
303
|
+
for (let j = i + 1; j < lines.length; j += 1) {
|
|
304
|
+
const current = lines[j] ?? "";
|
|
305
|
+
if (current.includes(quote)) {
|
|
306
|
+
collected.push(current.substring(0, current.indexOf(quote)));
|
|
307
|
+
return { text: collected.join("\n") };
|
|
308
|
+
}
|
|
309
|
+
collected.push(current);
|
|
310
|
+
}
|
|
311
|
+
return { text: collected.join("\n") };
|
|
312
|
+
}
|
|
313
|
+
return undefined;
|
|
314
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { FileRecord, PackageRecord, RelationshipRecord, SymbolRecord, DiagnosticRecord } from "../catalogue/schema.js";
|
|
2
|
+
export interface TsExtractionResult {
|
|
3
|
+
symbols: SymbolRecord[];
|
|
4
|
+
relationships: RelationshipRecord[];
|
|
5
|
+
diagnostics: DiagnosticRecord[];
|
|
6
|
+
}
|
|
7
|
+
export declare function extractTypeScriptSymbols(workspaceRoot: string, file: FileRecord, packageRecord?: PackageRecord): TsExtractionResult;
|