@lsctech/polaris 0.1.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 +87 -0
- package/dist/__mocks__/tool-server-linear.js +34 -0
- package/dist/cli/adopt-approve.js +60 -0
- package/dist/cli/adopt-cognition.js +199 -0
- package/dist/cli/adopt-instructions.js +143 -0
- package/dist/cli/adopt-rules.js +169 -0
- package/dist/cli/adopt-scan.js +25 -0
- package/dist/cli/adopt-smartdocs.js +192 -0
- package/dist/cli/adoption-inventory.js +350 -0
- package/dist/cli/adoption-plan.js +222 -0
- package/dist/cli/args.js +28 -0
- package/dist/cli/args.test.js +30 -0
- package/dist/cli/branding.js +41 -0
- package/dist/cli/graph.js +358 -0
- package/dist/cli/index.js +127 -0
- package/dist/cli/index.test.js +162 -0
- package/dist/cli/init-detect.js +61 -0
- package/dist/cli/init.js +492 -0
- package/dist/cli/init.test.js +259 -0
- package/dist/cli/librarian.js +32 -0
- package/dist/cli/medic.js +96 -0
- package/dist/cli/startup.test.js +23 -0
- package/dist/cli/tracker.js +130 -0
- package/dist/cli/tracker.test.js +126 -0
- package/dist/cli/version.js +10 -0
- package/dist/cli/version.test.js +11 -0
- package/dist/cli/worker.js +287 -0
- package/dist/cluster-state/fixtures/test-clusters.json +19 -0
- package/dist/cluster-state/store.js +302 -0
- package/dist/cluster-state/store.test.js +145 -0
- package/dist/cluster-state/types.js +2 -0
- package/dist/cognition/archive.js +158 -0
- package/dist/cognition/closeout-librarian-types.js +161 -0
- package/dist/cognition/cognition.test.js +623 -0
- package/dist/cognition/index.js +41 -0
- package/dist/cognition/librarian-dispatch.js +391 -0
- package/dist/cognition/librarian-dispatch.test.js +247 -0
- package/dist/cognition/librarian-packet.js +313 -0
- package/dist/cognition/librarian-types.js +57 -0
- package/dist/cognition/route-cognition-delta.js +350 -0
- package/dist/cognition/summary-delta.js +279 -0
- package/dist/cognition/validate.js +162 -0
- package/dist/config/defaults.js +98 -0
- package/dist/config/doctor.js +273 -0
- package/dist/config/index.js +14 -0
- package/dist/config/loader.js +58 -0
- package/dist/config/provider-detect.js +60 -0
- package/dist/config/provider-detect.test.js +119 -0
- package/dist/config/schema.js +2 -0
- package/dist/config/show.js +44 -0
- package/dist/config/show.test.js +42 -0
- package/dist/config/validator.js +675 -0
- package/dist/config/validator.test.js +77 -0
- package/dist/docs/canon-check.js +334 -0
- package/dist/docs/canon-check.test.js +207 -0
- package/dist/docs/doctrine.js +133 -0
- package/dist/docs/doctrine.test.js +139 -0
- package/dist/docs/index.js +168 -0
- package/dist/docs/index.test.js +83 -0
- package/dist/docs/ingest.js +295 -0
- package/dist/docs/ingest.test.js +71 -0
- package/dist/docs/migrate.js +165 -0
- package/dist/docs/migrate.test.js +136 -0
- package/dist/docs/seed-instructions.js +147 -0
- package/dist/docs/seed-instructions.test.js +137 -0
- package/dist/docs/validate-instructions.js +267 -0
- package/dist/docs/validate-instructions.test.js +238 -0
- package/dist/finalize/artifact-policy.js +214 -0
- package/dist/finalize/artifact-policy.test.js +84 -0
- package/dist/finalize/delivery-integrity.js +141 -0
- package/dist/finalize/finalize.test.js +210 -0
- package/dist/finalize/github.js +41 -0
- package/dist/finalize/index.js +474 -0
- package/dist/finalize/linear.js +213 -0
- package/dist/finalize/run-report.js +47 -0
- package/dist/finalize/steps/01-map-update.js +11 -0
- package/dist/finalize/steps/02-map-validate.js +11 -0
- package/dist/finalize/steps/03-schema-validate.js +11 -0
- package/dist/finalize/steps/04-run-checks.js +118 -0
- package/dist/finalize/steps/05-generate-report.js +14 -0
- package/dist/finalize/steps/06-commit.js +39 -0
- package/dist/finalize/steps/07-push.js +10 -0
- package/dist/finalize/steps/08-create-pr.js +9 -0
- package/dist/finalize/steps/09-update-state.js +9 -0
- package/dist/finalize/steps/10-append-jsonl.js +23 -0
- package/dist/finalize/steps/11-update-linear.js +22 -0
- package/dist/finalize/steps/12-archive.js +21 -0
- package/dist/graph/adapter/c/adapter.js +45 -0
- package/dist/graph/adapter/c/extract.js +135 -0
- package/dist/graph/adapter/c/index.js +10 -0
- package/dist/graph/adapter/c/runtime.js +67 -0
- package/dist/graph/adapter/cpp/adapter.js +45 -0
- package/dist/graph/adapter/cpp/extract.js +159 -0
- package/dist/graph/adapter/cpp/index.js +10 -0
- package/dist/graph/adapter/cpp/runtime.js +61 -0
- package/dist/graph/adapter/csharp/adapter.js +45 -0
- package/dist/graph/adapter/csharp/extract.js +127 -0
- package/dist/graph/adapter/csharp/index.js +10 -0
- package/dist/graph/adapter/csharp/runtime.js +61 -0
- package/dist/graph/adapter/dart/adapter.js +56 -0
- package/dist/graph/adapter/dart/extract.js +130 -0
- package/dist/graph/adapter/dart/index.js +10 -0
- package/dist/graph/adapter/dart/runtime.js +61 -0
- package/dist/graph/adapter/go/adapter.js +45 -0
- package/dist/graph/adapter/go/extract.js +112 -0
- package/dist/graph/adapter/go/index.js +10 -0
- package/dist/graph/adapter/go/runtime.js +58 -0
- package/dist/graph/adapter/kotlin-java/extract-common.js +83 -0
- package/dist/graph/adapter/kotlin-java/index.js +15 -0
- package/dist/graph/adapter/kotlin-java/java-adapter.js +45 -0
- package/dist/graph/adapter/kotlin-java/java-extract.js +42 -0
- package/dist/graph/adapter/kotlin-java/kotlin-adapter.js +48 -0
- package/dist/graph/adapter/kotlin-java/kotlin-extract.js +58 -0
- package/dist/graph/adapter/kotlin-java/runtime.js +75 -0
- package/dist/graph/adapter/python/adapter.js +45 -0
- package/dist/graph/adapter/python/extract.js +121 -0
- package/dist/graph/adapter/python/index.js +10 -0
- package/dist/graph/adapter/python/runtime.js +70 -0
- package/dist/graph/adapter/registry.js +82 -0
- package/dist/graph/adapter/rust/adapter.js +45 -0
- package/dist/graph/adapter/rust/extract.js +110 -0
- package/dist/graph/adapter/rust/index.js +10 -0
- package/dist/graph/adapter/rust/runtime.js +74 -0
- package/dist/graph/adapter/shell/adapter.js +34 -0
- package/dist/graph/adapter/shell/extract.js +98 -0
- package/dist/graph/adapter/shell/index.js +8 -0
- package/dist/graph/adapter/svelte/adapter.js +91 -0
- package/dist/graph/adapter/svelte/extract.js +41 -0
- package/dist/graph/adapter/svelte/index.js +8 -0
- package/dist/graph/adapter/swift/adapter.js +45 -0
- package/dist/graph/adapter/swift/extract.js +120 -0
- package/dist/graph/adapter/swift/index.js +10 -0
- package/dist/graph/adapter/swift/runtime.js +70 -0
- package/dist/graph/adapter/types.js +2 -0
- package/dist/graph/adapter/typescript-javascript/adapter.js +72 -0
- package/dist/graph/adapter/typescript-javascript/extract.js +115 -0
- package/dist/graph/adapter/typescript-javascript/index.js +10 -0
- package/dist/graph/adapter/typescript-javascript/runtime.js +97 -0
- package/dist/graph/capability/index.js +105 -0
- package/dist/graph/governance.js +104 -0
- package/dist/graph/parser/extract.js +5 -0
- package/dist/graph/parser/loader.js +2 -0
- package/dist/graph/parser/pipeline.js +194 -0
- package/dist/graph/query/index.js +277 -0
- package/dist/graph/query/types.js +5 -0
- package/dist/graph/resolver/build-edges.js +211 -0
- package/dist/graph/resolver/index.js +23 -0
- package/dist/graph/resolver/resolve-imports.js +168 -0
- package/dist/graph/store/adapter.js +132 -0
- package/dist/graph/store/queries.js +124 -0
- package/dist/graph/store/types.js +4 -0
- package/dist/ignore/defaults.js +41 -0
- package/dist/ignore/parser.js +39 -0
- package/dist/lint/map-reference-validator.js +72 -0
- package/dist/loop/abort.js +188 -0
- package/dist/loop/abort.test.js +151 -0
- package/dist/loop/adapters/__tests__/terminal-cli.test.js +92 -0
- package/dist/loop/adapters/agent-subtask.js +137 -0
- package/dist/loop/adapters/agent-subtask.test.js +151 -0
- package/dist/loop/adapters/cli-subtask-bridge.js +108 -0
- package/dist/loop/adapters/index.js +9 -0
- package/dist/loop/adapters/registry.js +17 -0
- package/dist/loop/adapters/terminal-cli.js +403 -0
- package/dist/loop/adapters/types.js +2 -0
- package/dist/loop/adapters/worker-instructions.js +85 -0
- package/dist/loop/body-parser.js +226 -0
- package/dist/loop/bootstrap-packet.js +97 -0
- package/dist/loop/bootstrap-packet.test.js +171 -0
- package/dist/loop/branch-governance.js +54 -0
- package/dist/loop/budget.js +63 -0
- package/dist/loop/budget.test.js +163 -0
- package/dist/loop/checkpoint.js +325 -0
- package/dist/loop/compact-return.js +59 -0
- package/dist/loop/continue.js +645 -0
- package/dist/loop/continue.test.js +337 -0
- package/dist/loop/dispatch-boundary.js +335 -0
- package/dist/loop/dispatch-state.js +223 -0
- package/dist/loop/dispatch-state.test.js +186 -0
- package/dist/loop/dispatch.js +1236 -0
- package/dist/loop/dispatch.test.js +499 -0
- package/dist/loop/ephemeral-smoke.test.js +160 -0
- package/dist/loop/evidence-backfill.js +216 -0
- package/dist/loop/execution-adapter.js +141 -0
- package/dist/loop/execution-adapter.test.js +66 -0
- package/dist/loop/finalize-evidence.js +169 -0
- package/dist/loop/git-custody.js +250 -0
- package/dist/loop/impl-packet-input.js +38 -0
- package/dist/loop/index.js +270 -0
- package/dist/loop/ledger.js +49 -0
- package/dist/loop/ledger.test.js +127 -0
- package/dist/loop/lifecycle-dispatch.js +348 -0
- package/dist/loop/lifecycle-dispatch.test.js +318 -0
- package/dist/loop/lifecycle.js +93 -0
- package/dist/loop/lifecycle.test.js +150 -0
- package/dist/loop/orphan-recovery.js +276 -0
- package/dist/loop/orphan-recovery.test.js +236 -0
- package/dist/loop/parent.js +1566 -0
- package/dist/loop/parent.test.js +738 -0
- package/dist/loop/provider-sealed-packet.test.js +164 -0
- package/dist/loop/resume.js +295 -0
- package/dist/loop/resume.test.js +172 -0
- package/dist/loop/run-bootstrap.js +234 -0
- package/dist/loop/run-preflight.js +203 -0
- package/dist/loop/status.js +665 -0
- package/dist/loop/status.test.js +235 -0
- package/dist/loop/wait.js +86 -0
- package/dist/loop/worker-packet.js +406 -0
- package/dist/loop/worker-packet.test.js +243 -0
- package/dist/loop/worker-prompt.js +260 -0
- package/dist/loop/worker-prompt.test.js +247 -0
- package/dist/loop/worker.js +498 -0
- package/dist/loop/worker.test.js +372 -0
- package/dist/map/atlas.js +77 -0
- package/dist/map/backfill.js +171 -0
- package/dist/map/backfill.test.js +120 -0
- package/dist/map/index.js +255 -0
- package/dist/map/inference.js +73 -0
- package/dist/map/inference.test.js +35 -0
- package/dist/map/query.js +157 -0
- package/dist/map/query.test.js +174 -0
- package/dist/map/update.js +355 -0
- package/dist/map/update.test.js +67 -0
- package/dist/map/validate.js +153 -0
- package/dist/map/validate.test.js +90 -0
- package/dist/map/welfare.js +86 -0
- package/dist/mcp/lib/invoke.js +35 -0
- package/dist/mcp/lib/redact.js +24 -0
- package/dist/mcp/lib/redact.test.js +112 -0
- package/dist/mcp/lib/root.js +41 -0
- package/dist/mcp/lib/root.test.js +114 -0
- package/dist/mcp/server.js +15 -0
- package/dist/mcp/tools/claim-child.js +119 -0
- package/dist/mcp/tools/claim-child.test.js +69 -0
- package/dist/mcp/tools/current-state.js +73 -0
- package/dist/mcp/tools/current-state.test.js +114 -0
- package/dist/mcp/tools/dispatch-result.js +186 -0
- package/dist/mcp/tools/dispatch-result.test.js +109 -0
- package/dist/mcp/tools/index.js +222 -0
- package/dist/mcp/tools/index.test.js +172 -0
- package/dist/mcp/tools/linear.js +74 -0
- package/dist/mcp/tools/loop-continue.js +159 -0
- package/dist/mcp/tools/loop-continue.test.js +186 -0
- package/dist/mcp/tools/loop-dry-run.js +15 -0
- package/dist/mcp/tools/status.js +65 -0
- package/dist/medic/chart-id.js +75 -0
- package/dist/medic/chart-schema.js +139 -0
- package/dist/runs/index.js +119 -0
- package/dist/runs/index.test.js +184 -0
- package/dist/runs/ledger-tail.js +15 -0
- package/dist/runs/list.js +29 -0
- package/dist/runs/reconcile.js +74 -0
- package/dist/runs/show.js +10 -0
- package/dist/runtime/audit/logger.js +15 -0
- package/dist/runtime/audit/reader.js +42 -0
- package/dist/runtime/checkpoint.js +89 -0
- package/dist/runtime/continuation/confirmed.js +225 -0
- package/dist/runtime/continuation/confirmed.test.js +421 -0
- package/dist/runtime/continuation/dry-run.js +74 -0
- package/dist/runtime/execution-window.js +106 -0
- package/dist/runtime/scheduling/child-selector.js +16 -0
- package/dist/runtime/state.js +43 -0
- package/dist/runtime/status.js +46 -0
- package/dist/runtime/verification/envelope.js +80 -0
- package/dist/runtime/verification/fingerprint.js +26 -0
- package/dist/skill-packet/cli.test.js +105 -0
- package/dist/skill-packet/generator.js +225 -0
- package/dist/skill-packet/generator.test.js +159 -0
- package/dist/skill-packet/index.js +49 -0
- package/dist/skill-packet/types.js +2 -0
- package/dist/smartdocs-engine/audit.js +194 -0
- package/dist/smartdocs-engine/audit.test.js +122 -0
- package/dist/smartdocs-engine/canon-check.js +340 -0
- package/dist/smartdocs-engine/canon-check.test.js +234 -0
- package/dist/smartdocs-engine/doctrine.js +633 -0
- package/dist/smartdocs-engine/doctrine.test.js +374 -0
- package/dist/smartdocs-engine/index.js +456 -0
- package/dist/smartdocs-engine/index.test.js +82 -0
- package/dist/smartdocs-engine/ingest.js +495 -0
- package/dist/smartdocs-engine/ingest.test.js +163 -0
- package/dist/smartdocs-engine/migrate.js +217 -0
- package/dist/smartdocs-engine/migrate.test.js +200 -0
- package/dist/smartdocs-engine/seed-instructions.js +335 -0
- package/dist/smartdocs-engine/seed-instructions.test.js +275 -0
- package/dist/smartdocs-engine/smartdoc-ignore.js +258 -0
- package/dist/smartdocs-engine/smartdoc-ignore.test.js +146 -0
- package/dist/smartdocs-engine/validate-instructions.js +366 -0
- package/dist/smartdocs-engine/validate-instructions.test.js +283 -0
- package/dist/tracker/adapters/github/index.js +305 -0
- package/dist/tracker/adapters/jira/index.js +293 -0
- package/dist/tracker/adapters/linear/http-errors.test.js +51 -0
- package/dist/tracker/adapters/linear/index.js +621 -0
- package/dist/tracker/adapters/linear/index.test.js +238 -0
- package/dist/tracker/adapters/linear.js +50 -0
- package/dist/tracker/adapters/local/index.js +10 -0
- package/dist/tracker/adapters/local-file/index.js +159 -0
- package/dist/tracker/adapters/mcp-bridge.js +158 -0
- package/dist/tracker/adapters/mcp-bridge.test.js +12 -0
- package/dist/tracker/adapters/spec/index.js +146 -0
- package/dist/tracker/capabilities.js +2 -0
- package/dist/tracker/index.js +49 -0
- package/dist/tracker/lifecycle-policy.js +139 -0
- package/dist/tracker/lifecycle-transition.js +164 -0
- package/dist/tracker/local-graph.js +98 -0
- package/dist/tracker/migration.js +56 -0
- package/dist/tracker/schema.js +86 -0
- package/dist/tracker/sync/index.js +404 -0
- package/dist/tracker/sync/queue-store.js +95 -0
- package/dist/tracker/sync/queue-store.test.js +104 -0
- package/dist/tracker/types.js +11 -0
- package/dist/types/linear.js +3 -0
- package/dist/types/result-packet.js +12 -0
- package/dist/types/runtime-state.js +2 -0
- package/dist/types/work-contract.js +2 -0
- package/dist/utils/monotonic-timestamp.js +13 -0
- package/dist/utils/monotonic-timestamp.test.js +19 -0
- package/package.json +64 -0
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.extractCSymbolsFromTree = extractCSymbolsFromTree;
|
|
4
|
+
function extractCSymbolsFromTree(tree) {
|
|
5
|
+
const symbols = [];
|
|
6
|
+
walkNode(tree.rootNode, symbols);
|
|
7
|
+
const deduped = dedupeSymbols(symbols);
|
|
8
|
+
deduped.sort(compareExtractedSymbols);
|
|
9
|
+
return {
|
|
10
|
+
language: "c",
|
|
11
|
+
symbols: deduped,
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
function walkNode(node, output) {
|
|
15
|
+
const current = toExtractedSymbol(node);
|
|
16
|
+
if (current) {
|
|
17
|
+
output.push(current);
|
|
18
|
+
}
|
|
19
|
+
for (const child of node.namedChildren ?? []) {
|
|
20
|
+
walkNode(child, output);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
function toExtractedSymbol(node) {
|
|
24
|
+
if (node.type === "preproc_include") {
|
|
25
|
+
const include = extractIncludeName(node.text);
|
|
26
|
+
if (!include) {
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
return buildSymbol(node, "import", include, null);
|
|
30
|
+
}
|
|
31
|
+
if (node.type === "struct_specifier") {
|
|
32
|
+
const name = extractStructName(node);
|
|
33
|
+
return buildSymbol(node, "class", name, null);
|
|
34
|
+
}
|
|
35
|
+
if (node.type === "function_definition" || node.type === "declaration") {
|
|
36
|
+
const functionNode = node.type === "declaration" ? findDescendant(node, "function_declarator") : node;
|
|
37
|
+
if (!functionNode) {
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
const name = extractFunctionName(functionNode);
|
|
41
|
+
const signature = sanitizeSignature(node.text);
|
|
42
|
+
return buildSymbol(node, "function", name, signature);
|
|
43
|
+
}
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
function buildSymbol(node, kind, name, signature) {
|
|
47
|
+
if (!name) {
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
return {
|
|
51
|
+
kind,
|
|
52
|
+
name,
|
|
53
|
+
signature,
|
|
54
|
+
exported: /\bextern\b/.test(node.text),
|
|
55
|
+
startLine: node.startPosition.row + 1,
|
|
56
|
+
startColumn: node.startPosition.column,
|
|
57
|
+
endLine: node.endPosition.row + 1,
|
|
58
|
+
endColumn: node.endPosition.column,
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
function extractIncludeName(text) {
|
|
62
|
+
const match = text.match(/#include\s*[<"]([^>"]+)[>"]/);
|
|
63
|
+
return match?.[1] ?? null;
|
|
64
|
+
}
|
|
65
|
+
function extractStructName(node) {
|
|
66
|
+
const nameNode = node.childForFieldName?.("name");
|
|
67
|
+
if (nameNode?.text?.trim()) {
|
|
68
|
+
return nameNode.text.trim();
|
|
69
|
+
}
|
|
70
|
+
const match = node.text.match(/\bstruct\s+([A-Za-z_][A-Za-z0-9_]*)/);
|
|
71
|
+
return match?.[1] ?? null;
|
|
72
|
+
}
|
|
73
|
+
function extractFunctionName(node) {
|
|
74
|
+
const byField = node.childForFieldName?.("declarator") ?? node.childForFieldName?.("name");
|
|
75
|
+
if (byField) {
|
|
76
|
+
const found = extractIdentifier(byField);
|
|
77
|
+
if (found) {
|
|
78
|
+
return found;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return extractIdentifier(node);
|
|
82
|
+
}
|
|
83
|
+
function extractIdentifier(node) {
|
|
84
|
+
if (IDENTIFIER_NODE_TYPES.has(node.type) && node.text.trim().length > 0) {
|
|
85
|
+
return node.text.trim();
|
|
86
|
+
}
|
|
87
|
+
for (const child of node.namedChildren ?? []) {
|
|
88
|
+
const found = extractIdentifier(child);
|
|
89
|
+
if (found) {
|
|
90
|
+
return found;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
const match = node.text.match(/\b([A-Za-z_][A-Za-z0-9_]*)\s*\(/);
|
|
94
|
+
return match?.[1] ?? null;
|
|
95
|
+
}
|
|
96
|
+
function findDescendant(node, type) {
|
|
97
|
+
if (node.type === type) {
|
|
98
|
+
return node;
|
|
99
|
+
}
|
|
100
|
+
for (const child of node.namedChildren ?? []) {
|
|
101
|
+
const found = findDescendant(child, type);
|
|
102
|
+
if (found) {
|
|
103
|
+
return found;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
return null;
|
|
107
|
+
}
|
|
108
|
+
function sanitizeSignature(signature) {
|
|
109
|
+
const compact = signature.replace(/\s+/g, " ").trim();
|
|
110
|
+
return compact.length === 0 ? null : compact;
|
|
111
|
+
}
|
|
112
|
+
function dedupeSymbols(symbols) {
|
|
113
|
+
const byFingerprint = new Map();
|
|
114
|
+
for (const symbol of symbols) {
|
|
115
|
+
const fingerprint = [
|
|
116
|
+
symbol.kind,
|
|
117
|
+
symbol.name,
|
|
118
|
+
symbol.startLine,
|
|
119
|
+
symbol.startColumn,
|
|
120
|
+
symbol.endLine,
|
|
121
|
+
symbol.endColumn,
|
|
122
|
+
].join(":");
|
|
123
|
+
byFingerprint.set(fingerprint, symbol);
|
|
124
|
+
}
|
|
125
|
+
return Array.from(byFingerprint.values());
|
|
126
|
+
}
|
|
127
|
+
function compareExtractedSymbols(left, right) {
|
|
128
|
+
return (left.startLine - right.startLine ||
|
|
129
|
+
left.startColumn - right.startColumn ||
|
|
130
|
+
left.endLine - right.endLine ||
|
|
131
|
+
left.endColumn - right.endColumn ||
|
|
132
|
+
left.kind.localeCompare(right.kind) ||
|
|
133
|
+
left.name.localeCompare(right.name));
|
|
134
|
+
}
|
|
135
|
+
const IDENTIFIER_NODE_TYPES = new Set(["identifier", "field_identifier", "type_identifier"]);
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.loadTreeSitterRuntime = exports.extractCSymbolsFromTree = exports.createCAdapter = exports.CAdapter = void 0;
|
|
4
|
+
var adapter_js_1 = require("./adapter.js");
|
|
5
|
+
Object.defineProperty(exports, "CAdapter", { enumerable: true, get: function () { return adapter_js_1.CAdapter; } });
|
|
6
|
+
Object.defineProperty(exports, "createCAdapter", { enumerable: true, get: function () { return adapter_js_1.createCAdapter; } });
|
|
7
|
+
var extract_js_1 = require("./extract.js");
|
|
8
|
+
Object.defineProperty(exports, "extractCSymbolsFromTree", { enumerable: true, get: function () { return extract_js_1.extractCSymbolsFromTree; } });
|
|
9
|
+
var runtime_js_1 = require("./runtime.js");
|
|
10
|
+
Object.defineProperty(exports, "loadTreeSitterRuntime", { enumerable: true, get: function () { return runtime_js_1.loadTreeSitterRuntime; } });
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.loadTreeSitterRuntime = loadTreeSitterRuntime;
|
|
4
|
+
let cachedRuntime = null;
|
|
5
|
+
let cachedRuntimePromise = null;
|
|
6
|
+
async function loadTreeSitterRuntime() {
|
|
7
|
+
if (cachedRuntime) {
|
|
8
|
+
return cachedRuntime;
|
|
9
|
+
}
|
|
10
|
+
if (cachedRuntimePromise) {
|
|
11
|
+
return await cachedRuntimePromise;
|
|
12
|
+
}
|
|
13
|
+
cachedRuntimePromise = (async () => {
|
|
14
|
+
const loaded = await loadTreeSitterModules();
|
|
15
|
+
const parser = new loaded.parserConstructor();
|
|
16
|
+
parser.setLanguage(loaded.language);
|
|
17
|
+
const runtime = {
|
|
18
|
+
parse(source) {
|
|
19
|
+
return parser.parse(source);
|
|
20
|
+
},
|
|
21
|
+
};
|
|
22
|
+
cachedRuntime = runtime;
|
|
23
|
+
cachedRuntimePromise = null;
|
|
24
|
+
return runtime;
|
|
25
|
+
})();
|
|
26
|
+
return await cachedRuntimePromise;
|
|
27
|
+
}
|
|
28
|
+
async function loadTreeSitterModules() {
|
|
29
|
+
const dynamicImport = createDynamicImporter();
|
|
30
|
+
const [treeSitterModule, cModule] = await Promise.all([dynamicImport("tree-sitter"), dynamicImport("tree-sitter-c")]);
|
|
31
|
+
return {
|
|
32
|
+
parserConstructor: resolveParserConstructor(treeSitterModule),
|
|
33
|
+
language: resolveGrammar(cModule, "tree-sitter-c"),
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
function createDynamicImporter() {
|
|
37
|
+
const importer = new Function("specifier", "return import(specifier);");
|
|
38
|
+
return (specifier) => importer(specifier);
|
|
39
|
+
}
|
|
40
|
+
function resolveParserConstructor(moduleValue) {
|
|
41
|
+
if (typeof moduleValue === "function") {
|
|
42
|
+
return moduleValue;
|
|
43
|
+
}
|
|
44
|
+
if (moduleValue && typeof moduleValue === "object") {
|
|
45
|
+
const directDefault = moduleValue.default;
|
|
46
|
+
if (typeof directDefault === "function") {
|
|
47
|
+
return directDefault;
|
|
48
|
+
}
|
|
49
|
+
const namedParser = moduleValue.Parser;
|
|
50
|
+
if (typeof namedParser === "function") {
|
|
51
|
+
return namedParser;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
throw new Error("Unable to resolve tree-sitter parser constructor.");
|
|
55
|
+
}
|
|
56
|
+
function resolveGrammar(moduleValue, packageName) {
|
|
57
|
+
if (moduleValue && typeof moduleValue === "object") {
|
|
58
|
+
const directDefault = moduleValue.default;
|
|
59
|
+
if (directDefault) {
|
|
60
|
+
return directDefault;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
if (moduleValue) {
|
|
64
|
+
return moduleValue;
|
|
65
|
+
}
|
|
66
|
+
throw new Error(`Unable to resolve ${packageName} grammar.`);
|
|
67
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CppAdapter = void 0;
|
|
4
|
+
exports.createCppAdapter = createCppAdapter;
|
|
5
|
+
const node_path_1 = require("node:path");
|
|
6
|
+
const extract_js_1 = require("./extract.js");
|
|
7
|
+
const runtime_js_1 = require("./runtime.js");
|
|
8
|
+
const DEFAULT_EXTENSIONS = [".cpp", ".cc", ".cxx", ".hpp"];
|
|
9
|
+
class CppAdapter {
|
|
10
|
+
loadRuntime;
|
|
11
|
+
languageId = "cpp";
|
|
12
|
+
fileExtensions = DEFAULT_EXTENSIONS;
|
|
13
|
+
confidence = "high";
|
|
14
|
+
limitations = [
|
|
15
|
+
"Extracts declaration-level symbols only (classes, functions, methods, includes).",
|
|
16
|
+
"Does not perform macro expansion or template instantiation.",
|
|
17
|
+
];
|
|
18
|
+
constructor(loadRuntime) {
|
|
19
|
+
this.loadRuntime = loadRuntime;
|
|
20
|
+
}
|
|
21
|
+
async extractSymbols(filePath, source) {
|
|
22
|
+
const language = detectLanguage(filePath);
|
|
23
|
+
if (!language) {
|
|
24
|
+
throw new Error(`Unsupported C++ file extension: ${(0, node_path_1.extname)(filePath)}`);
|
|
25
|
+
}
|
|
26
|
+
const runtime = await this.loadRuntime();
|
|
27
|
+
const tree = runtime.parse(source, language);
|
|
28
|
+
return (0, extract_js_1.extractCppSymbolsFromTree)(tree);
|
|
29
|
+
}
|
|
30
|
+
resolveImportSpecifier(specifier, _context) {
|
|
31
|
+
const trimmed = specifier.trim();
|
|
32
|
+
if (trimmed.length === 0) {
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
return trimmed;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
exports.CppAdapter = CppAdapter;
|
|
39
|
+
function createCppAdapter(options = {}) {
|
|
40
|
+
return new CppAdapter(options.loadRuntime ?? runtime_js_1.loadTreeSitterRuntime);
|
|
41
|
+
}
|
|
42
|
+
function detectLanguage(filePath) {
|
|
43
|
+
const extension = (0, node_path_1.extname)(filePath).toLowerCase();
|
|
44
|
+
return extension === ".cpp" || extension === ".cc" || extension === ".cxx" || extension === ".hpp" ? "cpp" : null;
|
|
45
|
+
}
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.extractCppSymbolsFromTree = extractCppSymbolsFromTree;
|
|
4
|
+
function extractCppSymbolsFromTree(tree) {
|
|
5
|
+
const classNames = collectClassNames(tree.rootNode);
|
|
6
|
+
const symbols = [];
|
|
7
|
+
walkNode(tree.rootNode, symbols, classNames);
|
|
8
|
+
const deduped = dedupeSymbols(symbols);
|
|
9
|
+
deduped.sort(compareExtractedSymbols);
|
|
10
|
+
return {
|
|
11
|
+
language: "cpp",
|
|
12
|
+
symbols: deduped,
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
function collectClassNames(root) {
|
|
16
|
+
const names = new Set();
|
|
17
|
+
function walk(node) {
|
|
18
|
+
if (node.type === "class_specifier" || node.type === "struct_specifier") {
|
|
19
|
+
const name = extractTypeName(node);
|
|
20
|
+
if (name)
|
|
21
|
+
names.add(name);
|
|
22
|
+
}
|
|
23
|
+
for (const child of node.namedChildren ?? []) {
|
|
24
|
+
walk(child);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
walk(root);
|
|
28
|
+
return names;
|
|
29
|
+
}
|
|
30
|
+
function walkNode(node, output, classNames) {
|
|
31
|
+
const current = toExtractedSymbol(node, classNames);
|
|
32
|
+
if (current) {
|
|
33
|
+
output.push(current);
|
|
34
|
+
}
|
|
35
|
+
for (const child of node.namedChildren ?? []) {
|
|
36
|
+
walkNode(child, output, classNames);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
function toExtractedSymbol(node, classNames) {
|
|
40
|
+
if (node.type === "preproc_include") {
|
|
41
|
+
const include = extractIncludeName(node.text);
|
|
42
|
+
if (!include) {
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
return buildSymbol(node, "import", include, null);
|
|
46
|
+
}
|
|
47
|
+
if (node.type === "class_specifier" || node.type === "struct_specifier") {
|
|
48
|
+
const name = extractTypeName(node);
|
|
49
|
+
return buildSymbol(node, "class", name, null);
|
|
50
|
+
}
|
|
51
|
+
if (node.type === "function_definition" || node.type === "declaration") {
|
|
52
|
+
const functionDeclarator = node.type === "declaration"
|
|
53
|
+
? findDescendant(node, "function_declarator") ?? findDescendant(node, "function_declarator")
|
|
54
|
+
: findDescendant(node, "function_declarator") ?? node;
|
|
55
|
+
if (!functionDeclarator) {
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
const extracted = extractFunctionName(functionDeclarator.text);
|
|
59
|
+
if (!extracted) {
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
const signature = sanitizeSignature(node.text);
|
|
63
|
+
const symbolKind = isMethod(node, extracted.rawName, classNames) ? "method" : "function";
|
|
64
|
+
return buildSymbol(node, symbolKind, extracted.name, signature);
|
|
65
|
+
}
|
|
66
|
+
return null;
|
|
67
|
+
}
|
|
68
|
+
function buildSymbol(node, kind, name, signature) {
|
|
69
|
+
if (!name) {
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
72
|
+
return {
|
|
73
|
+
kind,
|
|
74
|
+
name,
|
|
75
|
+
signature,
|
|
76
|
+
exported: /\b(public|extern)\b/.test(node.text),
|
|
77
|
+
startLine: node.startPosition.row + 1,
|
|
78
|
+
startColumn: node.startPosition.column,
|
|
79
|
+
endLine: node.endPosition.row + 1,
|
|
80
|
+
endColumn: node.endPosition.column,
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
function extractIncludeName(text) {
|
|
84
|
+
const match = text.match(/#include\s*[<"]([^>"]+)[>"]/);
|
|
85
|
+
return match?.[1] ?? null;
|
|
86
|
+
}
|
|
87
|
+
function extractTypeName(node) {
|
|
88
|
+
const nameNode = node.childForFieldName?.("name");
|
|
89
|
+
if (nameNode?.text?.trim()) {
|
|
90
|
+
return nameNode.text.trim();
|
|
91
|
+
}
|
|
92
|
+
const byText = node.text.match(/\b(class|struct)\s+([A-Za-z_][A-Za-z0-9_]*)/);
|
|
93
|
+
return byText?.[2] ?? null;
|
|
94
|
+
}
|
|
95
|
+
function extractFunctionName(text) {
|
|
96
|
+
const compact = text.replace(/\s+/g, " ").trim();
|
|
97
|
+
const match = compact.match(/([~A-Za-z_][A-Za-z0-9_:~]*)\s*\(/);
|
|
98
|
+
if (!match) {
|
|
99
|
+
return null;
|
|
100
|
+
}
|
|
101
|
+
const rawName = match[1];
|
|
102
|
+
const simple = rawName.includes("::") ? rawName.split("::").at(-1) ?? rawName : rawName;
|
|
103
|
+
return { name: simple, rawName };
|
|
104
|
+
}
|
|
105
|
+
// Returns true only when the qualifier before the last '::' names a known class/struct,
|
|
106
|
+
// or the node is lexically nested inside a class/struct specifier.
|
|
107
|
+
function isMethod(node, rawName, classNames) {
|
|
108
|
+
if (rawName.includes("::")) {
|
|
109
|
+
const qualifier = rawName.split("::")[0];
|
|
110
|
+
return classNames.has(qualifier);
|
|
111
|
+
}
|
|
112
|
+
let current = node.parent ?? null;
|
|
113
|
+
while (current) {
|
|
114
|
+
if (current.type === "class_specifier" || current.type === "struct_specifier") {
|
|
115
|
+
return true;
|
|
116
|
+
}
|
|
117
|
+
current = current.parent ?? null;
|
|
118
|
+
}
|
|
119
|
+
return false;
|
|
120
|
+
}
|
|
121
|
+
function findDescendant(node, type) {
|
|
122
|
+
if (node.type === type) {
|
|
123
|
+
return node;
|
|
124
|
+
}
|
|
125
|
+
for (const child of node.namedChildren ?? []) {
|
|
126
|
+
const found = findDescendant(child, type);
|
|
127
|
+
if (found) {
|
|
128
|
+
return found;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
return null;
|
|
132
|
+
}
|
|
133
|
+
function sanitizeSignature(signature) {
|
|
134
|
+
const compact = signature.replace(/\s+/g, " ").trim();
|
|
135
|
+
return compact.length === 0 ? null : compact;
|
|
136
|
+
}
|
|
137
|
+
function dedupeSymbols(symbols) {
|
|
138
|
+
const byFingerprint = new Map();
|
|
139
|
+
for (const symbol of symbols) {
|
|
140
|
+
const fingerprint = [
|
|
141
|
+
symbol.kind,
|
|
142
|
+
symbol.name,
|
|
143
|
+
symbol.startLine,
|
|
144
|
+
symbol.startColumn,
|
|
145
|
+
symbol.endLine,
|
|
146
|
+
symbol.endColumn,
|
|
147
|
+
].join(":");
|
|
148
|
+
byFingerprint.set(fingerprint, symbol);
|
|
149
|
+
}
|
|
150
|
+
return Array.from(byFingerprint.values());
|
|
151
|
+
}
|
|
152
|
+
function compareExtractedSymbols(left, right) {
|
|
153
|
+
return (left.startLine - right.startLine ||
|
|
154
|
+
left.startColumn - right.startColumn ||
|
|
155
|
+
left.endLine - right.endLine ||
|
|
156
|
+
left.endColumn - right.endColumn ||
|
|
157
|
+
left.kind.localeCompare(right.kind) ||
|
|
158
|
+
left.name.localeCompare(right.name));
|
|
159
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.loadTreeSitterRuntime = exports.extractCppSymbolsFromTree = exports.createCppAdapter = exports.CppAdapter = void 0;
|
|
4
|
+
var adapter_js_1 = require("./adapter.js");
|
|
5
|
+
Object.defineProperty(exports, "CppAdapter", { enumerable: true, get: function () { return adapter_js_1.CppAdapter; } });
|
|
6
|
+
Object.defineProperty(exports, "createCppAdapter", { enumerable: true, get: function () { return adapter_js_1.createCppAdapter; } });
|
|
7
|
+
var extract_js_1 = require("./extract.js");
|
|
8
|
+
Object.defineProperty(exports, "extractCppSymbolsFromTree", { enumerable: true, get: function () { return extract_js_1.extractCppSymbolsFromTree; } });
|
|
9
|
+
var runtime_js_1 = require("./runtime.js");
|
|
10
|
+
Object.defineProperty(exports, "loadTreeSitterRuntime", { enumerable: true, get: function () { return runtime_js_1.loadTreeSitterRuntime; } });
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.loadTreeSitterRuntime = loadTreeSitterRuntime;
|
|
4
|
+
let cachedRuntime = null;
|
|
5
|
+
async function loadTreeSitterRuntime() {
|
|
6
|
+
if (cachedRuntime) {
|
|
7
|
+
return cachedRuntime;
|
|
8
|
+
}
|
|
9
|
+
const loaded = await loadTreeSitterModules();
|
|
10
|
+
const parser = new loaded.parserConstructor();
|
|
11
|
+
parser.setLanguage(loaded.language);
|
|
12
|
+
cachedRuntime = {
|
|
13
|
+
parse(source) {
|
|
14
|
+
return parser.parse(source);
|
|
15
|
+
},
|
|
16
|
+
};
|
|
17
|
+
return cachedRuntime;
|
|
18
|
+
}
|
|
19
|
+
async function loadTreeSitterModules() {
|
|
20
|
+
const dynamicImport = createDynamicImporter();
|
|
21
|
+
const [treeSitterModule, cppModule] = await Promise.all([
|
|
22
|
+
dynamicImport("tree-sitter"),
|
|
23
|
+
dynamicImport("tree-sitter-cpp"),
|
|
24
|
+
]);
|
|
25
|
+
return {
|
|
26
|
+
parserConstructor: resolveParserConstructor(treeSitterModule),
|
|
27
|
+
language: resolveGrammar(cppModule, "tree-sitter-cpp"),
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
function createDynamicImporter() {
|
|
31
|
+
const importer = new Function("specifier", "return import(specifier);");
|
|
32
|
+
return (specifier) => importer(specifier);
|
|
33
|
+
}
|
|
34
|
+
function resolveParserConstructor(moduleValue) {
|
|
35
|
+
if (typeof moduleValue === "function") {
|
|
36
|
+
return moduleValue;
|
|
37
|
+
}
|
|
38
|
+
if (moduleValue && typeof moduleValue === "object") {
|
|
39
|
+
const directDefault = moduleValue.default;
|
|
40
|
+
if (typeof directDefault === "function") {
|
|
41
|
+
return directDefault;
|
|
42
|
+
}
|
|
43
|
+
const namedParser = moduleValue.Parser;
|
|
44
|
+
if (typeof namedParser === "function") {
|
|
45
|
+
return namedParser;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
throw new Error("Unable to resolve tree-sitter parser constructor.");
|
|
49
|
+
}
|
|
50
|
+
function resolveGrammar(moduleValue, packageName) {
|
|
51
|
+
if (moduleValue && typeof moduleValue === "object") {
|
|
52
|
+
const directDefault = moduleValue.default;
|
|
53
|
+
if (directDefault) {
|
|
54
|
+
return directDefault;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
if (moduleValue) {
|
|
58
|
+
return moduleValue;
|
|
59
|
+
}
|
|
60
|
+
throw new Error(`Unable to resolve ${packageName} grammar.`);
|
|
61
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CSharpAdapter = void 0;
|
|
4
|
+
exports.createCSharpAdapter = createCSharpAdapter;
|
|
5
|
+
const node_path_1 = require("node:path");
|
|
6
|
+
const extract_js_1 = require("./extract.js");
|
|
7
|
+
const runtime_js_1 = require("./runtime.js");
|
|
8
|
+
const DEFAULT_EXTENSIONS = [".cs"];
|
|
9
|
+
class CSharpAdapter {
|
|
10
|
+
loadRuntime;
|
|
11
|
+
languageId = "csharp";
|
|
12
|
+
fileExtensions = DEFAULT_EXTENSIONS;
|
|
13
|
+
confidence = "high";
|
|
14
|
+
limitations = [
|
|
15
|
+
"Extracts declaration-level symbols only (classes, methods, static methods, using directives).",
|
|
16
|
+
"Does not perform generic type or semantic symbol resolution.",
|
|
17
|
+
];
|
|
18
|
+
constructor(loadRuntime) {
|
|
19
|
+
this.loadRuntime = loadRuntime;
|
|
20
|
+
}
|
|
21
|
+
async extractSymbols(filePath, source) {
|
|
22
|
+
const language = detectLanguage(filePath);
|
|
23
|
+
if (!language) {
|
|
24
|
+
throw new Error(`Unsupported C# file extension: ${(0, node_path_1.extname)(filePath)}`);
|
|
25
|
+
}
|
|
26
|
+
const runtime = await this.loadRuntime();
|
|
27
|
+
const tree = runtime.parse(source, language);
|
|
28
|
+
return (0, extract_js_1.extractCSharpSymbolsFromTree)(tree);
|
|
29
|
+
}
|
|
30
|
+
resolveImportSpecifier(specifier, _context) {
|
|
31
|
+
const trimmed = specifier.trim();
|
|
32
|
+
if (trimmed.length === 0) {
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
return trimmed;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
exports.CSharpAdapter = CSharpAdapter;
|
|
39
|
+
function createCSharpAdapter(options = {}) {
|
|
40
|
+
return new CSharpAdapter(options.loadRuntime ?? runtime_js_1.loadTreeSitterRuntime);
|
|
41
|
+
}
|
|
42
|
+
function detectLanguage(filePath) {
|
|
43
|
+
const extension = (0, node_path_1.extname)(filePath).toLowerCase();
|
|
44
|
+
return extension === ".cs" ? "csharp" : null;
|
|
45
|
+
}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.extractCSharpSymbolsFromTree = extractCSharpSymbolsFromTree;
|
|
4
|
+
function extractCSharpSymbolsFromTree(tree) {
|
|
5
|
+
const symbols = [];
|
|
6
|
+
walkNode(tree.rootNode, symbols);
|
|
7
|
+
const deduped = dedupeSymbols(symbols);
|
|
8
|
+
deduped.sort(compareExtractedSymbols);
|
|
9
|
+
return {
|
|
10
|
+
language: "csharp",
|
|
11
|
+
symbols: deduped,
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
function walkNode(node, output) {
|
|
15
|
+
const current = toExtractedSymbol(node);
|
|
16
|
+
if (current) {
|
|
17
|
+
output.push(current);
|
|
18
|
+
}
|
|
19
|
+
for (const child of node.namedChildren ?? []) {
|
|
20
|
+
walkNode(child, output);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
function toExtractedSymbol(node) {
|
|
24
|
+
if (node.type === "using_directive") {
|
|
25
|
+
const name = extractUsingName(node);
|
|
26
|
+
return buildSymbol(node, "import", name, null);
|
|
27
|
+
}
|
|
28
|
+
if (node.type === "class_declaration") {
|
|
29
|
+
const name = extractName(node);
|
|
30
|
+
return buildSymbol(node, "class", name, null);
|
|
31
|
+
}
|
|
32
|
+
if (node.type === "method_declaration") {
|
|
33
|
+
const name = extractName(node);
|
|
34
|
+
const signature = sanitizeSignature(node.text);
|
|
35
|
+
const kind = isStatic(node) ? "function" : "method";
|
|
36
|
+
return buildSymbol(node, kind, name, signature);
|
|
37
|
+
}
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
function buildSymbol(node, kind, name, signature) {
|
|
41
|
+
if (!name) {
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
const exported = checkExported(node);
|
|
45
|
+
return {
|
|
46
|
+
kind,
|
|
47
|
+
name,
|
|
48
|
+
signature,
|
|
49
|
+
exported,
|
|
50
|
+
startLine: node.startPosition.row + 1,
|
|
51
|
+
startColumn: node.startPosition.column,
|
|
52
|
+
endLine: node.endPosition.row + 1,
|
|
53
|
+
endColumn: node.endPosition.column,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
function checkExported(node) {
|
|
57
|
+
const modifiers = node.childForFieldName?.("modifiers");
|
|
58
|
+
if (modifiers?.text) {
|
|
59
|
+
return /\bpublic\b/.test(modifiers.text);
|
|
60
|
+
}
|
|
61
|
+
const headerText = getNodeHeader(node.text);
|
|
62
|
+
return /\bpublic\b/.test(headerText);
|
|
63
|
+
}
|
|
64
|
+
function getNodeHeader(text) {
|
|
65
|
+
const openBrace = text.indexOf("{");
|
|
66
|
+
if (openBrace !== -1) {
|
|
67
|
+
return text.substring(0, openBrace);
|
|
68
|
+
}
|
|
69
|
+
return text;
|
|
70
|
+
}
|
|
71
|
+
function extractUsingName(node) {
|
|
72
|
+
const match = node.text.match(/\busing\s+(?:static\s+)?(?:[A-Za-z_][A-Za-z0-9_]*\s*=\s*)?([A-Za-z_][A-Za-z0-9_.]*)\s*;/);
|
|
73
|
+
return match?.[1] ?? null;
|
|
74
|
+
}
|
|
75
|
+
function extractName(node) {
|
|
76
|
+
const byField = node.childForFieldName?.("name");
|
|
77
|
+
if (byField?.text?.trim()) {
|
|
78
|
+
return byField.text.trim();
|
|
79
|
+
}
|
|
80
|
+
for (const child of node.namedChildren ?? []) {
|
|
81
|
+
if (IDENTIFIER_NODE_TYPES.has(child.type) && child.text.trim().length > 0) {
|
|
82
|
+
return child.text.trim();
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
const methodMatch = node.text.match(/\b([A-Za-z_][A-Za-z0-9_]*)\s*\(/);
|
|
86
|
+
if (methodMatch) {
|
|
87
|
+
return methodMatch[1];
|
|
88
|
+
}
|
|
89
|
+
const classMatch = node.text.match(/\bclass\s+([A-Za-z_][A-Za-z0-9_]*)/);
|
|
90
|
+
return classMatch?.[1] ?? null;
|
|
91
|
+
}
|
|
92
|
+
function isStatic(node) {
|
|
93
|
+
const modifiers = node.childForFieldName?.("modifiers");
|
|
94
|
+
if (modifiers?.text) {
|
|
95
|
+
return /\bstatic\b/.test(modifiers.text);
|
|
96
|
+
}
|
|
97
|
+
const headerText = getNodeHeader(node.text);
|
|
98
|
+
return /\bstatic\b/.test(headerText);
|
|
99
|
+
}
|
|
100
|
+
function sanitizeSignature(signature) {
|
|
101
|
+
const compact = signature.replace(/\s+/g, " ").trim();
|
|
102
|
+
return compact.length === 0 ? null : compact;
|
|
103
|
+
}
|
|
104
|
+
function dedupeSymbols(symbols) {
|
|
105
|
+
const byFingerprint = new Map();
|
|
106
|
+
for (const symbol of symbols) {
|
|
107
|
+
const fingerprint = [
|
|
108
|
+
symbol.kind,
|
|
109
|
+
symbol.name,
|
|
110
|
+
symbol.startLine,
|
|
111
|
+
symbol.startColumn,
|
|
112
|
+
symbol.endLine,
|
|
113
|
+
symbol.endColumn,
|
|
114
|
+
].join(":");
|
|
115
|
+
byFingerprint.set(fingerprint, symbol);
|
|
116
|
+
}
|
|
117
|
+
return Array.from(byFingerprint.values());
|
|
118
|
+
}
|
|
119
|
+
function compareExtractedSymbols(left, right) {
|
|
120
|
+
return (left.startLine - right.startLine ||
|
|
121
|
+
left.startColumn - right.startColumn ||
|
|
122
|
+
left.endLine - right.endLine ||
|
|
123
|
+
left.endColumn - right.endColumn ||
|
|
124
|
+
left.kind.localeCompare(right.kind) ||
|
|
125
|
+
left.name.localeCompare(right.name));
|
|
126
|
+
}
|
|
127
|
+
const IDENTIFIER_NODE_TYPES = new Set(["identifier"]);
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.loadTreeSitterRuntime = exports.extractCSharpSymbolsFromTree = exports.createCSharpAdapter = exports.CSharpAdapter = void 0;
|
|
4
|
+
var adapter_js_1 = require("./adapter.js");
|
|
5
|
+
Object.defineProperty(exports, "CSharpAdapter", { enumerable: true, get: function () { return adapter_js_1.CSharpAdapter; } });
|
|
6
|
+
Object.defineProperty(exports, "createCSharpAdapter", { enumerable: true, get: function () { return adapter_js_1.createCSharpAdapter; } });
|
|
7
|
+
var extract_js_1 = require("./extract.js");
|
|
8
|
+
Object.defineProperty(exports, "extractCSharpSymbolsFromTree", { enumerable: true, get: function () { return extract_js_1.extractCSharpSymbolsFromTree; } });
|
|
9
|
+
var runtime_js_1 = require("./runtime.js");
|
|
10
|
+
Object.defineProperty(exports, "loadTreeSitterRuntime", { enumerable: true, get: function () { return runtime_js_1.loadTreeSitterRuntime; } });
|