@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,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, csharpModule] = await Promise.all([
|
|
22
|
+
dynamicImport("tree-sitter"),
|
|
23
|
+
dynamicImport("tree-sitter-c-sharp"),
|
|
24
|
+
]);
|
|
25
|
+
return {
|
|
26
|
+
parserConstructor: resolveParserConstructor(treeSitterModule),
|
|
27
|
+
language: resolveGrammar(csharpModule, "tree-sitter-c-sharp"),
|
|
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,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DartAdapter = void 0;
|
|
4
|
+
exports.createDartAdapter = createDartAdapter;
|
|
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 = [".dart"];
|
|
9
|
+
class DartAdapter {
|
|
10
|
+
loadRuntime;
|
|
11
|
+
languageId = "dart";
|
|
12
|
+
fileExtensions = DEFAULT_EXTENSIONS;
|
|
13
|
+
confidence = "medium";
|
|
14
|
+
limitations = [
|
|
15
|
+
"Extracts declaration-level symbols only (classes, top-level functions, class methods, imports).",
|
|
16
|
+
"Does not perform call/reference extraction in phase 1.",
|
|
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 Dart 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.extractDartSymbolsFromTree)(tree);
|
|
29
|
+
}
|
|
30
|
+
resolveImportSpecifier(specifier, context) {
|
|
31
|
+
const trimmed = specifier.trim();
|
|
32
|
+
if (trimmed.length === 0) {
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
if (trimmed.startsWith("package:") || trimmed.startsWith("dart:")) {
|
|
36
|
+
return trimmed;
|
|
37
|
+
}
|
|
38
|
+
if (trimmed.startsWith(".")) {
|
|
39
|
+
if ((0, node_path_1.extname)(trimmed).length > 0) {
|
|
40
|
+
return trimmed;
|
|
41
|
+
}
|
|
42
|
+
const candidate = context.candidateExtensions?.[0] ?? ".dart";
|
|
43
|
+
const normalized = candidate.startsWith(".") ? candidate : `.${candidate}`;
|
|
44
|
+
return `${trimmed}${normalized}`;
|
|
45
|
+
}
|
|
46
|
+
return trimmed;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
exports.DartAdapter = DartAdapter;
|
|
50
|
+
function createDartAdapter(options = {}) {
|
|
51
|
+
return new DartAdapter(options.loadRuntime ?? runtime_js_1.loadTreeSitterRuntime);
|
|
52
|
+
}
|
|
53
|
+
function detectLanguage(filePath) {
|
|
54
|
+
const extension = (0, node_path_1.extname)(filePath).toLowerCase();
|
|
55
|
+
return extension === ".dart" ? "dart" : null;
|
|
56
|
+
}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.extractDartSymbolsFromTree = extractDartSymbolsFromTree;
|
|
4
|
+
function extractDartSymbolsFromTree(tree) {
|
|
5
|
+
const symbols = [];
|
|
6
|
+
walkNode(tree.rootNode, symbols);
|
|
7
|
+
const deduped = dedupeSymbols(symbols);
|
|
8
|
+
deduped.sort(compareExtractedSymbols);
|
|
9
|
+
return {
|
|
10
|
+
language: "dart",
|
|
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 === "class_definition") {
|
|
25
|
+
return buildSymbol(node, "class", extractClassName(node), null);
|
|
26
|
+
}
|
|
27
|
+
if (node.type === "import_or_export") {
|
|
28
|
+
return buildSymbol(node, "import", extractImportSpecifier(node), null);
|
|
29
|
+
}
|
|
30
|
+
if (FUNCTION_LIKE_TYPES.has(node.type)) {
|
|
31
|
+
const kind = hasClassAncestor(node) ? "method" : "function";
|
|
32
|
+
return buildSymbol(node, kind, extractFunctionName(node), sanitizeSignature(node.text));
|
|
33
|
+
}
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
function buildSymbol(node, kind, name, signature) {
|
|
37
|
+
if (!name) {
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
return {
|
|
41
|
+
kind,
|
|
42
|
+
name,
|
|
43
|
+
signature,
|
|
44
|
+
exported: !name.startsWith("_"),
|
|
45
|
+
startLine: node.startPosition.row + 1,
|
|
46
|
+
startColumn: node.startPosition.column,
|
|
47
|
+
endLine: node.endPosition.row + 1,
|
|
48
|
+
endColumn: node.endPosition.column,
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
function extractClassName(node) {
|
|
52
|
+
const byField = node.childForFieldName?.("name");
|
|
53
|
+
if (byField?.text?.trim()) {
|
|
54
|
+
return byField.text.trim();
|
|
55
|
+
}
|
|
56
|
+
for (const child of node.namedChildren ?? []) {
|
|
57
|
+
if (IDENTIFIER_NODE_TYPES.has(child.type) && child.text.trim().length > 0) {
|
|
58
|
+
return child.text.trim();
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
const byText = node.text.match(/\bclass\s+([A-Za-z_][A-Za-z0-9_]*)\b/);
|
|
62
|
+
return byText?.[1] ?? null;
|
|
63
|
+
}
|
|
64
|
+
function extractFunctionName(node) {
|
|
65
|
+
const byField = node.childForFieldName?.("name");
|
|
66
|
+
if (byField?.text?.trim()) {
|
|
67
|
+
return byField.text.trim();
|
|
68
|
+
}
|
|
69
|
+
for (const child of node.namedChildren ?? []) {
|
|
70
|
+
if (IDENTIFIER_NODE_TYPES.has(child.type) && child.text.trim().length > 0) {
|
|
71
|
+
return child.text.trim();
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
const byText = node.text.match(/\b([A-Za-z_][A-Za-z0-9_]*)\s*\(/);
|
|
75
|
+
return byText?.[1] ?? null;
|
|
76
|
+
}
|
|
77
|
+
function extractImportSpecifier(node) {
|
|
78
|
+
const byField = node.childForFieldName?.("uri");
|
|
79
|
+
if (byField?.text) {
|
|
80
|
+
return normalizeQuotedSpecifier(byField.text);
|
|
81
|
+
}
|
|
82
|
+
const match = node.text.match(/^\s*(?:import|export)\s+['"]([^'"]+)['"]/m);
|
|
83
|
+
return match?.[1] ?? null;
|
|
84
|
+
}
|
|
85
|
+
function normalizeQuotedSpecifier(value) {
|
|
86
|
+
const trimmed = value.trim();
|
|
87
|
+
if ((trimmed.startsWith("'") && trimmed.endsWith("'")) || (trimmed.startsWith("\"") && trimmed.endsWith("\""))) {
|
|
88
|
+
return trimmed.slice(1, -1);
|
|
89
|
+
}
|
|
90
|
+
return trimmed.length === 0 ? null : trimmed;
|
|
91
|
+
}
|
|
92
|
+
function hasClassAncestor(node) {
|
|
93
|
+
let current = node.parent;
|
|
94
|
+
while (current) {
|
|
95
|
+
if (current.type === "class_definition") {
|
|
96
|
+
return true;
|
|
97
|
+
}
|
|
98
|
+
current = current.parent;
|
|
99
|
+
}
|
|
100
|
+
return false;
|
|
101
|
+
}
|
|
102
|
+
function sanitizeSignature(signature) {
|
|
103
|
+
const compact = signature.replace(/\s+/g, " ").trim();
|
|
104
|
+
return compact.length === 0 ? null : compact;
|
|
105
|
+
}
|
|
106
|
+
function dedupeSymbols(symbols) {
|
|
107
|
+
const byFingerprint = new Map();
|
|
108
|
+
for (const symbol of symbols) {
|
|
109
|
+
const fingerprint = [
|
|
110
|
+
symbol.kind,
|
|
111
|
+
symbol.name,
|
|
112
|
+
symbol.startLine,
|
|
113
|
+
symbol.startColumn,
|
|
114
|
+
symbol.endLine,
|
|
115
|
+
symbol.endColumn,
|
|
116
|
+
].join(":");
|
|
117
|
+
byFingerprint.set(fingerprint, symbol);
|
|
118
|
+
}
|
|
119
|
+
return Array.from(byFingerprint.values());
|
|
120
|
+
}
|
|
121
|
+
function compareExtractedSymbols(left, right) {
|
|
122
|
+
return (left.startLine - right.startLine ||
|
|
123
|
+
left.startColumn - right.startColumn ||
|
|
124
|
+
left.endLine - right.endLine ||
|
|
125
|
+
left.endColumn - right.endColumn ||
|
|
126
|
+
left.kind.localeCompare(right.kind) ||
|
|
127
|
+
left.name.localeCompare(right.name));
|
|
128
|
+
}
|
|
129
|
+
const FUNCTION_LIKE_TYPES = new Set(["function_signature", "method_signature"]);
|
|
130
|
+
const IDENTIFIER_NODE_TYPES = new Set(["identifier", "type_identifier"]);
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.loadTreeSitterRuntime = exports.extractDartSymbolsFromTree = exports.createDartAdapter = exports.DartAdapter = void 0;
|
|
4
|
+
var adapter_js_1 = require("./adapter.js");
|
|
5
|
+
Object.defineProperty(exports, "DartAdapter", { enumerable: true, get: function () { return adapter_js_1.DartAdapter; } });
|
|
6
|
+
Object.defineProperty(exports, "createDartAdapter", { enumerable: true, get: function () { return adapter_js_1.createDartAdapter; } });
|
|
7
|
+
var extract_js_1 = require("./extract.js");
|
|
8
|
+
Object.defineProperty(exports, "extractDartSymbolsFromTree", { enumerable: true, get: function () { return extract_js_1.extractDartSymbolsFromTree; } });
|
|
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, dartModule] = await Promise.all([
|
|
22
|
+
dynamicImport("tree-sitter"),
|
|
23
|
+
dynamicImport("tree-sitter-dart"),
|
|
24
|
+
]);
|
|
25
|
+
return {
|
|
26
|
+
parserConstructor: resolveParserConstructor(treeSitterModule),
|
|
27
|
+
language: resolveGrammar(dartModule, "tree-sitter-dart"),
|
|
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.GoAdapter = void 0;
|
|
4
|
+
exports.createGoAdapter = createGoAdapter;
|
|
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 = [".go"];
|
|
9
|
+
class GoAdapter {
|
|
10
|
+
loadRuntime;
|
|
11
|
+
languageId = "go";
|
|
12
|
+
fileExtensions = DEFAULT_EXTENSIONS;
|
|
13
|
+
confidence = "high";
|
|
14
|
+
limitations = [
|
|
15
|
+
"Extracts declaration-level symbols only (structs/interfaces, functions, methods, imports).",
|
|
16
|
+
"Does not perform package/module resolution or call/reference extraction.",
|
|
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 Go 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.extractGoSymbolsFromTree)(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.GoAdapter = GoAdapter;
|
|
39
|
+
function createGoAdapter(options = {}) {
|
|
40
|
+
return new GoAdapter(options.loadRuntime ?? runtime_js_1.loadTreeSitterRuntime);
|
|
41
|
+
}
|
|
42
|
+
function detectLanguage(filePath) {
|
|
43
|
+
const extension = (0, node_path_1.extname)(filePath).toLowerCase();
|
|
44
|
+
return extension === ".go" ? "go" : null;
|
|
45
|
+
}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.extractGoSymbolsFromTree = extractGoSymbolsFromTree;
|
|
4
|
+
function extractGoSymbolsFromTree(tree) {
|
|
5
|
+
const symbols = [];
|
|
6
|
+
walkNode(tree.rootNode, symbols);
|
|
7
|
+
const deduped = dedupeSymbols(symbols);
|
|
8
|
+
deduped.sort(compareExtractedSymbols);
|
|
9
|
+
return {
|
|
10
|
+
language: "go",
|
|
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 === "import_spec") {
|
|
25
|
+
const name = extractImportPath(node);
|
|
26
|
+
return buildSymbol(node, "import", name, null);
|
|
27
|
+
}
|
|
28
|
+
if (node.type === "type_spec") {
|
|
29
|
+
const extracted = extractTypeName(node);
|
|
30
|
+
if (!extracted) {
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
return buildSymbol(node, "class", extracted, null);
|
|
34
|
+
}
|
|
35
|
+
if (node.type === "function_declaration") {
|
|
36
|
+
return buildSymbol(node, "function", extractFunctionName(node), sanitizeSignature(node.text));
|
|
37
|
+
}
|
|
38
|
+
if (node.type === "method_declaration") {
|
|
39
|
+
return buildSymbol(node, "method", extractFunctionName(node), sanitizeSignature(node.text));
|
|
40
|
+
}
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
function buildSymbol(node, kind, name, signature) {
|
|
44
|
+
if (!name) {
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
return {
|
|
48
|
+
kind,
|
|
49
|
+
name,
|
|
50
|
+
signature,
|
|
51
|
+
exported: /^[A-Z]/.test(name),
|
|
52
|
+
startLine: node.startPosition.row + 1,
|
|
53
|
+
startColumn: node.startPosition.column,
|
|
54
|
+
endLine: node.endPosition.row + 1,
|
|
55
|
+
endColumn: node.endPosition.column,
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
function extractImportPath(node) {
|
|
59
|
+
const byField = node.childForFieldName?.("path");
|
|
60
|
+
if (byField?.text) {
|
|
61
|
+
return byField.text.replace(/^"|"$/g, "");
|
|
62
|
+
}
|
|
63
|
+
const byText = node.text.match(/"([^"]+)"/);
|
|
64
|
+
return byText?.[1] ?? null;
|
|
65
|
+
}
|
|
66
|
+
function extractTypeName(node) {
|
|
67
|
+
const typeNode = node.childForFieldName?.("type");
|
|
68
|
+
if (!typeNode || (typeNode.type !== "struct_type" && typeNode.type !== "interface_type")) {
|
|
69
|
+
return null;
|
|
70
|
+
}
|
|
71
|
+
const byField = node.childForFieldName?.("name");
|
|
72
|
+
if (byField?.text?.trim()) {
|
|
73
|
+
return byField.text.trim();
|
|
74
|
+
}
|
|
75
|
+
const byText = node.text.match(/^\s*([A-Za-z_][A-Za-z0-9_]*)\s+(struct|interface)\b/);
|
|
76
|
+
return byText?.[1] ?? null;
|
|
77
|
+
}
|
|
78
|
+
function extractFunctionName(node) {
|
|
79
|
+
const byField = node.childForFieldName?.("name");
|
|
80
|
+
if (byField?.text?.trim()) {
|
|
81
|
+
return byField.text.trim();
|
|
82
|
+
}
|
|
83
|
+
const byText = node.text.match(/\bfunc\b(?:\s*\([^)]*\))?\s*([A-Za-z_][A-Za-z0-9_]*)\s*\(/);
|
|
84
|
+
return byText?.[1] ?? null;
|
|
85
|
+
}
|
|
86
|
+
function sanitizeSignature(signature) {
|
|
87
|
+
const compact = signature.replace(/\s+/g, " ").trim();
|
|
88
|
+
return compact.length === 0 ? null : compact;
|
|
89
|
+
}
|
|
90
|
+
function dedupeSymbols(symbols) {
|
|
91
|
+
const byFingerprint = new Map();
|
|
92
|
+
for (const symbol of symbols) {
|
|
93
|
+
const fingerprint = [
|
|
94
|
+
symbol.kind,
|
|
95
|
+
symbol.name,
|
|
96
|
+
symbol.startLine,
|
|
97
|
+
symbol.startColumn,
|
|
98
|
+
symbol.endLine,
|
|
99
|
+
symbol.endColumn,
|
|
100
|
+
].join(":");
|
|
101
|
+
byFingerprint.set(fingerprint, symbol);
|
|
102
|
+
}
|
|
103
|
+
return Array.from(byFingerprint.values());
|
|
104
|
+
}
|
|
105
|
+
function compareExtractedSymbols(left, right) {
|
|
106
|
+
return (left.startLine - right.startLine ||
|
|
107
|
+
left.startColumn - right.startColumn ||
|
|
108
|
+
left.endLine - right.endLine ||
|
|
109
|
+
left.endColumn - right.endColumn ||
|
|
110
|
+
left.kind.localeCompare(right.kind) ||
|
|
111
|
+
left.name.localeCompare(right.name));
|
|
112
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.loadTreeSitterRuntime = exports.extractGoSymbolsFromTree = exports.createGoAdapter = exports.GoAdapter = void 0;
|
|
4
|
+
var adapter_js_1 = require("./adapter.js");
|
|
5
|
+
Object.defineProperty(exports, "GoAdapter", { enumerable: true, get: function () { return adapter_js_1.GoAdapter; } });
|
|
6
|
+
Object.defineProperty(exports, "createGoAdapter", { enumerable: true, get: function () { return adapter_js_1.createGoAdapter; } });
|
|
7
|
+
var extract_js_1 = require("./extract.js");
|
|
8
|
+
Object.defineProperty(exports, "extractGoSymbolsFromTree", { enumerable: true, get: function () { return extract_js_1.extractGoSymbolsFromTree; } });
|
|
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,58 @@
|
|
|
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, goModule] = await Promise.all([dynamicImport("tree-sitter"), dynamicImport("tree-sitter-go")]);
|
|
22
|
+
return {
|
|
23
|
+
parserConstructor: resolveParserConstructor(treeSitterModule),
|
|
24
|
+
language: resolveGrammar(goModule, "tree-sitter-go"),
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
function createDynamicImporter() {
|
|
28
|
+
const importer = new Function("specifier", "return import(specifier);");
|
|
29
|
+
return (specifier) => importer(specifier);
|
|
30
|
+
}
|
|
31
|
+
function resolveParserConstructor(moduleValue) {
|
|
32
|
+
if (typeof moduleValue === "function") {
|
|
33
|
+
return moduleValue;
|
|
34
|
+
}
|
|
35
|
+
if (moduleValue && typeof moduleValue === "object") {
|
|
36
|
+
const directDefault = moduleValue.default;
|
|
37
|
+
if (typeof directDefault === "function") {
|
|
38
|
+
return directDefault;
|
|
39
|
+
}
|
|
40
|
+
const namedParser = moduleValue.Parser;
|
|
41
|
+
if (typeof namedParser === "function") {
|
|
42
|
+
return namedParser;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
throw new Error("Unable to resolve tree-sitter parser constructor.");
|
|
46
|
+
}
|
|
47
|
+
function resolveGrammar(moduleValue, packageName) {
|
|
48
|
+
if (moduleValue && typeof moduleValue === "object") {
|
|
49
|
+
const directDefault = moduleValue.default;
|
|
50
|
+
if (directDefault) {
|
|
51
|
+
return directDefault;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
if (moduleValue) {
|
|
55
|
+
return moduleValue;
|
|
56
|
+
}
|
|
57
|
+
throw new Error(`Unable to resolve ${packageName} grammar.`);
|
|
58
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.walkNodes = walkNodes;
|
|
4
|
+
exports.createSymbol = createSymbol;
|
|
5
|
+
exports.extractDeclaredName = extractDeclaredName;
|
|
6
|
+
exports.sanitizeSignature = sanitizeSignature;
|
|
7
|
+
exports.dedupeAndSortSymbols = dedupeAndSortSymbols;
|
|
8
|
+
exports.isMethodContext = isMethodContext;
|
|
9
|
+
function walkNodes(node, visit) {
|
|
10
|
+
visit(node);
|
|
11
|
+
for (const child of node.namedChildren ?? []) {
|
|
12
|
+
walkNodes(child, visit);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
function createSymbol(node, kind, name, signature, exported) {
|
|
16
|
+
if (!name) {
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
return {
|
|
20
|
+
kind,
|
|
21
|
+
name,
|
|
22
|
+
signature,
|
|
23
|
+
exported,
|
|
24
|
+
startLine: node.startPosition.row + 1,
|
|
25
|
+
startColumn: node.startPosition.column,
|
|
26
|
+
endLine: node.endPosition.row + 1,
|
|
27
|
+
endColumn: node.endPosition.column,
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
function extractDeclaredName(node, identifierNodeTypes, fallbackPattern) {
|
|
31
|
+
const byField = node.childForFieldName?.("name");
|
|
32
|
+
if (byField?.text?.trim()) {
|
|
33
|
+
return byField.text.trim();
|
|
34
|
+
}
|
|
35
|
+
for (const child of node.namedChildren ?? []) {
|
|
36
|
+
if (identifierNodeTypes.has(child.type) && child.text.trim().length > 0) {
|
|
37
|
+
return child.text.trim();
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
if (fallbackPattern) {
|
|
41
|
+
return node.text.match(fallbackPattern)?.[1] ?? null;
|
|
42
|
+
}
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
function sanitizeSignature(signature) {
|
|
46
|
+
const compact = signature.replace(/\s+/g, " ").trim();
|
|
47
|
+
return compact.length === 0 ? null : compact;
|
|
48
|
+
}
|
|
49
|
+
function dedupeAndSortSymbols(symbols) {
|
|
50
|
+
const byFingerprint = new Map();
|
|
51
|
+
for (const symbol of symbols) {
|
|
52
|
+
const fingerprint = [
|
|
53
|
+
symbol.kind,
|
|
54
|
+
symbol.name,
|
|
55
|
+
symbol.startLine,
|
|
56
|
+
symbol.startColumn,
|
|
57
|
+
symbol.endLine,
|
|
58
|
+
symbol.endColumn,
|
|
59
|
+
].join(":");
|
|
60
|
+
byFingerprint.set(fingerprint, symbol);
|
|
61
|
+
}
|
|
62
|
+
const deduped = Array.from(byFingerprint.values());
|
|
63
|
+
deduped.sort(compareSymbols);
|
|
64
|
+
return deduped;
|
|
65
|
+
}
|
|
66
|
+
function isMethodContext(node, containerNodeTypes) {
|
|
67
|
+
let current = node.parent;
|
|
68
|
+
while (current) {
|
|
69
|
+
if (containerNodeTypes.has(current.type)) {
|
|
70
|
+
return true;
|
|
71
|
+
}
|
|
72
|
+
current = current.parent;
|
|
73
|
+
}
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
function compareSymbols(left, right) {
|
|
77
|
+
return (left.startLine - right.startLine ||
|
|
78
|
+
left.startColumn - right.startColumn ||
|
|
79
|
+
left.endLine - right.endLine ||
|
|
80
|
+
left.endColumn - right.endColumn ||
|
|
81
|
+
left.kind.localeCompare(right.kind) ||
|
|
82
|
+
left.name.localeCompare(right.name));
|
|
83
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.loadTreeSitterRuntime = exports.extractKotlinSymbolsFromTree = exports.extractJavaSymbolsFromTree = exports.createKotlinAdapter = exports.KotlinAdapter = exports.createJavaAdapter = exports.JavaAdapter = void 0;
|
|
4
|
+
var java_adapter_js_1 = require("./java-adapter.js");
|
|
5
|
+
Object.defineProperty(exports, "JavaAdapter", { enumerable: true, get: function () { return java_adapter_js_1.JavaAdapter; } });
|
|
6
|
+
Object.defineProperty(exports, "createJavaAdapter", { enumerable: true, get: function () { return java_adapter_js_1.createJavaAdapter; } });
|
|
7
|
+
var kotlin_adapter_js_1 = require("./kotlin-adapter.js");
|
|
8
|
+
Object.defineProperty(exports, "KotlinAdapter", { enumerable: true, get: function () { return kotlin_adapter_js_1.KotlinAdapter; } });
|
|
9
|
+
Object.defineProperty(exports, "createKotlinAdapter", { enumerable: true, get: function () { return kotlin_adapter_js_1.createKotlinAdapter; } });
|
|
10
|
+
var java_extract_js_1 = require("./java-extract.js");
|
|
11
|
+
Object.defineProperty(exports, "extractJavaSymbolsFromTree", { enumerable: true, get: function () { return java_extract_js_1.extractJavaSymbolsFromTree; } });
|
|
12
|
+
var kotlin_extract_js_1 = require("./kotlin-extract.js");
|
|
13
|
+
Object.defineProperty(exports, "extractKotlinSymbolsFromTree", { enumerable: true, get: function () { return kotlin_extract_js_1.extractKotlinSymbolsFromTree; } });
|
|
14
|
+
var runtime_js_1 = require("./runtime.js");
|
|
15
|
+
Object.defineProperty(exports, "loadTreeSitterRuntime", { enumerable: true, get: function () { return runtime_js_1.loadTreeSitterRuntime; } });
|