@cstart/coldstart 2.0.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 +236 -0
- package/dist/cache/disk-cache.d.ts +14 -0
- package/dist/cache/disk-cache.d.ts.map +1 -0
- package/dist/cache/disk-cache.js +371 -0
- package/dist/cache/disk-cache.js.map +1 -0
- package/dist/cli.d.ts +18 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +206 -0
- package/dist/cli.js.map +1 -0
- package/dist/constants.d.ts +8 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +111 -0
- package/dist/constants.js.map +1 -0
- package/dist/daemon-lock.d.ts +63 -0
- package/dist/daemon-lock.d.ts.map +1 -0
- package/dist/daemon-lock.js +218 -0
- package/dist/daemon-lock.js.map +1 -0
- package/dist/daemon-log.d.ts +26 -0
- package/dist/daemon-log.d.ts.map +1 -0
- package/dist/daemon-log.js +110 -0
- package/dist/daemon-log.js.map +1 -0
- package/dist/index-manager.d.ts +103 -0
- package/dist/index-manager.d.ts.map +1 -0
- package/dist/index-manager.js +361 -0
- package/dist/index-manager.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +724 -0
- package/dist/index.js.map +1 -0
- package/dist/indexer/content-tokens.d.ts +74 -0
- package/dist/indexer/content-tokens.d.ts.map +1 -0
- package/dist/indexer/content-tokens.js +406 -0
- package/dist/indexer/content-tokens.js.map +1 -0
- package/dist/indexer/cpp-include-roots.d.ts +7 -0
- package/dist/indexer/cpp-include-roots.d.ts.map +1 -0
- package/dist/indexer/cpp-include-roots.js +166 -0
- package/dist/indexer/cpp-include-roots.js.map +1 -0
- package/dist/indexer/csharp-synthetic.d.ts +9 -0
- package/dist/indexer/csharp-synthetic.d.ts.map +1 -0
- package/dist/indexer/csharp-synthetic.js +51 -0
- package/dist/indexer/csharp-synthetic.js.map +1 -0
- package/dist/indexer/django-synthetic.d.ts +12 -0
- package/dist/indexer/django-synthetic.d.ts.map +1 -0
- package/dist/indexer/django-synthetic.js +49 -0
- package/dist/indexer/django-synthetic.js.map +1 -0
- package/dist/indexer/extractors/angularjs.d.ts +16 -0
- package/dist/indexer/extractors/angularjs.d.ts.map +1 -0
- package/dist/indexer/extractors/angularjs.js +49 -0
- package/dist/indexer/extractors/angularjs.js.map +1 -0
- package/dist/indexer/extractors/cpp.d.ts +9 -0
- package/dist/indexer/extractors/cpp.d.ts.map +1 -0
- package/dist/indexer/extractors/cpp.js +254 -0
- package/dist/indexer/extractors/cpp.js.map +1 -0
- package/dist/indexer/extractors/csharp.d.ts +19 -0
- package/dist/indexer/extractors/csharp.d.ts.map +1 -0
- package/dist/indexer/extractors/csharp.js +327 -0
- package/dist/indexer/extractors/csharp.js.map +1 -0
- package/dist/indexer/extractors/env.d.ts +9 -0
- package/dist/indexer/extractors/env.d.ts.map +1 -0
- package/dist/indexer/extractors/env.js +43 -0
- package/dist/indexer/extractors/env.js.map +1 -0
- package/dist/indexer/extractors/go.d.ts +9 -0
- package/dist/indexer/extractors/go.d.ts.map +1 -0
- package/dist/indexer/extractors/go.js +227 -0
- package/dist/indexer/extractors/go.js.map +1 -0
- package/dist/indexer/extractors/graphql.d.ts +22 -0
- package/dist/indexer/extractors/graphql.d.ts.map +1 -0
- package/dist/indexer/extractors/graphql.js +88 -0
- package/dist/indexer/extractors/graphql.js.map +1 -0
- package/dist/indexer/extractors/groovy.d.ts +9 -0
- package/dist/indexer/extractors/groovy.d.ts.map +1 -0
- package/dist/indexer/extractors/groovy.js +356 -0
- package/dist/indexer/extractors/groovy.js.map +1 -0
- package/dist/indexer/extractors/java.d.ts +10 -0
- package/dist/indexer/extractors/java.d.ts.map +1 -0
- package/dist/indexer/extractors/java.js +586 -0
- package/dist/indexer/extractors/java.js.map +1 -0
- package/dist/indexer/extractors/kotlin.d.ts +10 -0
- package/dist/indexer/extractors/kotlin.d.ts.map +1 -0
- package/dist/indexer/extractors/kotlin.js +398 -0
- package/dist/indexer/extractors/kotlin.js.map +1 -0
- package/dist/indexer/extractors/node-helpers.d.ts +13 -0
- package/dist/indexer/extractors/node-helpers.d.ts.map +1 -0
- package/dist/indexer/extractors/node-helpers.js +17 -0
- package/dist/indexer/extractors/node-helpers.js.map +1 -0
- package/dist/indexer/extractors/parser-factory.d.ts +4 -0
- package/dist/indexer/extractors/parser-factory.d.ts.map +1 -0
- package/dist/indexer/extractors/parser-factory.js +28 -0
- package/dist/indexer/extractors/parser-factory.js.map +1 -0
- package/dist/indexer/extractors/php.d.ts +17 -0
- package/dist/indexer/extractors/php.d.ts.map +1 -0
- package/dist/indexer/extractors/php.js +363 -0
- package/dist/indexer/extractors/php.js.map +1 -0
- package/dist/indexer/extractors/python.d.ts +14 -0
- package/dist/indexer/extractors/python.d.ts.map +1 -0
- package/dist/indexer/extractors/python.js +449 -0
- package/dist/indexer/extractors/python.js.map +1 -0
- package/dist/indexer/extractors/ruby.d.ts +10 -0
- package/dist/indexer/extractors/ruby.d.ts.map +1 -0
- package/dist/indexer/extractors/ruby.js +996 -0
- package/dist/indexer/extractors/ruby.js.map +1 -0
- package/dist/indexer/extractors/rust.d.ts +9 -0
- package/dist/indexer/extractors/rust.d.ts.map +1 -0
- package/dist/indexer/extractors/rust.js +322 -0
- package/dist/indexer/extractors/rust.js.map +1 -0
- package/dist/indexer/extractors/toml.d.ts +9 -0
- package/dist/indexer/extractors/toml.d.ts.map +1 -0
- package/dist/indexer/extractors/toml.js +84 -0
- package/dist/indexer/extractors/toml.js.map +1 -0
- package/dist/indexer/extractors/xml.d.ts +9 -0
- package/dist/indexer/extractors/xml.d.ts.map +1 -0
- package/dist/indexer/extractors/xml.js +163 -0
- package/dist/indexer/extractors/xml.js.map +1 -0
- package/dist/indexer/extractors/yaml.d.ts +9 -0
- package/dist/indexer/extractors/yaml.d.ts.map +1 -0
- package/dist/indexer/extractors/yaml.js +117 -0
- package/dist/indexer/extractors/yaml.js.map +1 -0
- package/dist/indexer/git.d.ts +19 -0
- package/dist/indexer/git.d.ts.map +1 -0
- package/dist/indexer/git.js +55 -0
- package/dist/indexer/git.js.map +1 -0
- package/dist/indexer/graph.d.ts +7 -0
- package/dist/indexer/graph.d.ts.map +1 -0
- package/dist/indexer/graph.js +20 -0
- package/dist/indexer/graph.js.map +1 -0
- package/dist/indexer/indexed-file.d.ts +15 -0
- package/dist/indexer/indexed-file.d.ts.map +1 -0
- package/dist/indexer/indexed-file.js +50 -0
- package/dist/indexer/indexed-file.js.map +1 -0
- package/dist/indexer/invariants.d.ts +15 -0
- package/dist/indexer/invariants.d.ts.map +1 -0
- package/dist/indexer/invariants.js +96 -0
- package/dist/indexer/invariants.js.map +1 -0
- package/dist/indexer/laravel-synthetic.d.ts +10 -0
- package/dist/indexer/laravel-synthetic.d.ts.map +1 -0
- package/dist/indexer/laravel-synthetic.js +78 -0
- package/dist/indexer/laravel-synthetic.js.map +1 -0
- package/dist/indexer/parser.d.ts +4 -0
- package/dist/indexer/parser.d.ts.map +1 -0
- package/dist/indexer/parser.js +499 -0
- package/dist/indexer/parser.js.map +1 -0
- package/dist/indexer/patch.d.ts +3 -0
- package/dist/indexer/patch.d.ts.map +1 -0
- package/dist/indexer/patch.js +291 -0
- package/dist/indexer/patch.js.map +1 -0
- package/dist/indexer/rails-synthetic.d.ts +11 -0
- package/dist/indexer/rails-synthetic.d.ts.map +1 -0
- package/dist/indexer/rails-synthetic.js +80 -0
- package/dist/indexer/rails-synthetic.js.map +1 -0
- package/dist/indexer/reconcile.d.ts +9 -0
- package/dist/indexer/reconcile.d.ts.map +1 -0
- package/dist/indexer/reconcile.js +96 -0
- package/dist/indexer/reconcile.js.map +1 -0
- package/dist/indexer/resolvers/cpp.d.ts +15 -0
- package/dist/indexer/resolvers/cpp.d.ts.map +1 -0
- package/dist/indexer/resolvers/cpp.js +35 -0
- package/dist/indexer/resolvers/cpp.js.map +1 -0
- package/dist/indexer/resolvers/csharp.d.ts +2 -0
- package/dist/indexer/resolvers/csharp.d.ts.map +1 -0
- package/dist/indexer/resolvers/csharp.js +89 -0
- package/dist/indexer/resolvers/csharp.js.map +1 -0
- package/dist/indexer/resolvers/generic.d.ts +10 -0
- package/dist/indexer/resolvers/generic.d.ts.map +1 -0
- package/dist/indexer/resolvers/generic.js +35 -0
- package/dist/indexer/resolvers/generic.js.map +1 -0
- package/dist/indexer/resolvers/go.d.ts +2 -0
- package/dist/indexer/resolvers/go.d.ts.map +1 -0
- package/dist/indexer/resolvers/go.js +171 -0
- package/dist/indexer/resolvers/go.js.map +1 -0
- package/dist/indexer/resolvers/index.d.ts +26 -0
- package/dist/indexer/resolvers/index.d.ts.map +1 -0
- package/dist/indexer/resolvers/index.js +301 -0
- package/dist/indexer/resolvers/index.js.map +1 -0
- package/dist/indexer/resolvers/java.d.ts +17 -0
- package/dist/indexer/resolvers/java.d.ts.map +1 -0
- package/dist/indexer/resolvers/java.js +104 -0
- package/dist/indexer/resolvers/java.js.map +1 -0
- package/dist/indexer/resolvers/php.d.ts +2 -0
- package/dist/indexer/resolvers/php.d.ts.map +1 -0
- package/dist/indexer/resolvers/php.js +108 -0
- package/dist/indexer/resolvers/php.js.map +1 -0
- package/dist/indexer/resolvers/python.d.ts +17 -0
- package/dist/indexer/resolvers/python.d.ts.map +1 -0
- package/dist/indexer/resolvers/python.js +63 -0
- package/dist/indexer/resolvers/python.js.map +1 -0
- package/dist/indexer/resolvers/ruby.d.ts +13 -0
- package/dist/indexer/resolvers/ruby.d.ts.map +1 -0
- package/dist/indexer/resolvers/ruby.js +199 -0
- package/dist/indexer/resolvers/ruby.js.map +1 -0
- package/dist/indexer/resolvers/rust.d.ts +12 -0
- package/dist/indexer/resolvers/rust.d.ts.map +1 -0
- package/dist/indexer/resolvers/rust.js +61 -0
- package/dist/indexer/resolvers/rust.js.map +1 -0
- package/dist/indexer/resolvers/shared.d.ts +18 -0
- package/dist/indexer/resolvers/shared.d.ts.map +1 -0
- package/dist/indexer/resolvers/shared.js +71 -0
- package/dist/indexer/resolvers/shared.js.map +1 -0
- package/dist/indexer/rust-workspace.d.ts +25 -0
- package/dist/indexer/rust-workspace.d.ts.map +1 -0
- package/dist/indexer/rust-workspace.js +155 -0
- package/dist/indexer/rust-workspace.js.map +1 -0
- package/dist/indexer/symbol-edges.d.ts +19 -0
- package/dist/indexer/symbol-edges.d.ts.map +1 -0
- package/dist/indexer/symbol-edges.js +117 -0
- package/dist/indexer/symbol-edges.js.map +1 -0
- package/dist/indexer/tokenize.d.ts +26 -0
- package/dist/indexer/tokenize.d.ts.map +1 -0
- package/dist/indexer/tokenize.js +200 -0
- package/dist/indexer/tokenize.js.map +1 -0
- package/dist/indexer/ts-parser.d.ts +10 -0
- package/dist/indexer/ts-parser.d.ts.map +1 -0
- package/dist/indexer/ts-parser.js +605 -0
- package/dist/indexer/ts-parser.js.map +1 -0
- package/dist/indexer/walker.d.ts +9 -0
- package/dist/indexer/walker.d.ts.map +1 -0
- package/dist/indexer/walker.js +91 -0
- package/dist/indexer/walker.js.map +1 -0
- package/dist/init.d.ts +111 -0
- package/dist/init.d.ts.map +1 -0
- package/dist/init.js +787 -0
- package/dist/init.js.map +1 -0
- package/dist/kb/cli.d.ts +2 -0
- package/dist/kb/cli.d.ts.map +1 -0
- package/dist/kb/cli.js +377 -0
- package/dist/kb/cli.js.map +1 -0
- package/dist/kb/commit.d.ts +6 -0
- package/dist/kb/commit.d.ts.map +1 -0
- package/dist/kb/commit.js +84 -0
- package/dist/kb/commit.js.map +1 -0
- package/dist/kb/fold.d.ts +42 -0
- package/dist/kb/fold.d.ts.map +1 -0
- package/dist/kb/fold.js +285 -0
- package/dist/kb/fold.js.map +1 -0
- package/dist/kb/freshness.d.ts +9 -0
- package/dist/kb/freshness.d.ts.map +1 -0
- package/dist/kb/freshness.js +52 -0
- package/dist/kb/freshness.js.map +1 -0
- package/dist/kb/git.d.ts +4 -0
- package/dist/kb/git.d.ts.map +1 -0
- package/dist/kb/git.js +28 -0
- package/dist/kb/git.js.map +1 -0
- package/dist/kb/ids.d.ts +8 -0
- package/dist/kb/ids.d.ts.map +1 -0
- package/dist/kb/ids.js +42 -0
- package/dist/kb/ids.js.map +1 -0
- package/dist/kb/lint.d.ts +23 -0
- package/dist/kb/lint.d.ts.map +1 -0
- package/dist/kb/lint.js +102 -0
- package/dist/kb/lint.js.map +1 -0
- package/dist/kb/lookup.d.ts +55 -0
- package/dist/kb/lookup.d.ts.map +1 -0
- package/dist/kb/lookup.js +92 -0
- package/dist/kb/lookup.js.map +1 -0
- package/dist/kb/notes-index.d.ts +31 -0
- package/dist/kb/notes-index.d.ts.map +1 -0
- package/dist/kb/notes-index.js +0 -0
- package/dist/kb/notes-index.js.map +1 -0
- package/dist/kb/raw-log.d.ts +34 -0
- package/dist/kb/raw-log.d.ts.map +1 -0
- package/dist/kb/raw-log.js +106 -0
- package/dist/kb/raw-log.js.map +1 -0
- package/dist/kb/render.d.ts +17 -0
- package/dist/kb/render.d.ts.map +1 -0
- package/dist/kb/render.js +101 -0
- package/dist/kb/render.js.map +1 -0
- package/dist/kb/search.d.ts +110 -0
- package/dist/kb/search.d.ts.map +1 -0
- package/dist/kb/search.js +453 -0
- package/dist/kb/search.js.map +1 -0
- package/dist/kb/store.d.ts +35 -0
- package/dist/kb/store.d.ts.map +1 -0
- package/dist/kb/store.js +160 -0
- package/dist/kb/store.js.map +1 -0
- package/dist/kb/types.d.ts +142 -0
- package/dist/kb/types.d.ts.map +1 -0
- package/dist/kb/types.js +13 -0
- package/dist/kb/types.js.map +1 -0
- package/dist/kb/view-template.d.ts +8 -0
- package/dist/kb/view-template.d.ts.map +1 -0
- package/dist/kb/view-template.js +8 -0
- package/dist/kb/view-template.js.map +1 -0
- package/dist/kb/view.d.ts +42 -0
- package/dist/kb/view.d.ts.map +1 -0
- package/dist/kb/view.js +118 -0
- package/dist/kb/view.js.map +1 -0
- package/dist/kb/write.d.ts +72 -0
- package/dist/kb/write.d.ts.map +1 -0
- package/dist/kb/write.js +345 -0
- package/dist/kb/write.js.map +1 -0
- package/dist/keeper-state.d.ts +29 -0
- package/dist/keeper-state.d.ts.map +1 -0
- package/dist/keeper-state.js +89 -0
- package/dist/keeper-state.js.map +1 -0
- package/dist/keeper.d.ts +23 -0
- package/dist/keeper.d.ts.map +1 -0
- package/dist/keeper.js +105 -0
- package/dist/keeper.js.map +1 -0
- package/dist/migrate.d.ts +9 -0
- package/dist/migrate.d.ts.map +1 -0
- package/dist/migrate.js +102 -0
- package/dist/migrate.js.map +1 -0
- package/dist/restart.d.ts +15 -0
- package/dist/restart.d.ts.map +1 -0
- package/dist/restart.js +48 -0
- package/dist/restart.js.map +1 -0
- package/dist/server/find.d.ts +39 -0
- package/dist/server/find.d.ts.map +1 -0
- package/dist/server/find.js +979 -0
- package/dist/server/find.js.map +1 -0
- package/dist/server/mcp.d.ts +117 -0
- package/dist/server/mcp.d.ts.map +1 -0
- package/dist/server/mcp.js +301 -0
- package/dist/server/mcp.js.map +1 -0
- package/dist/server/searcher.d.ts +14 -0
- package/dist/server/searcher.d.ts.map +1 -0
- package/dist/server/searcher.js +146 -0
- package/dist/server/searcher.js.map +1 -0
- package/dist/server/tools.d.ts +17 -0
- package/dist/server/tools.d.ts.map +1 -0
- package/dist/server/tools.js +875 -0
- package/dist/server/tools.js.map +1 -0
- package/dist/status.d.ts +12 -0
- package/dist/status.d.ts.map +1 -0
- package/dist/status.js +157 -0
- package/dist/status.js.map +1 -0
- package/dist/types.d.ts +138 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/dist/watcher.d.ts +11 -0
- package/dist/watcher.d.ts.map +1 -0
- package/dist/watcher.js +67 -0
- package/dist/watcher.js.map +1 -0
- package/hooks/canonical-find-key.mjs +68 -0
- package/hooks/codex-find-nudge.mjs +15 -0
- package/hooks/codex-find-preguard.mjs +14 -0
- package/hooks/codex-kb-elicit.mjs +329 -0
- package/hooks/codex-kb-recall.mjs +151 -0
- package/hooks/codex-nudge-handler.mjs +370 -0
- package/hooks/codex-preguard-handler.mjs +75 -0
- package/hooks/codex-run-hook.mjs +132 -0
- package/hooks/coldstart-call.mjs +58 -0
- package/hooks/cursor-find-nudge.mjs +15 -0
- package/hooks/cursor-find-preguard.mjs +14 -0
- package/hooks/cursor-input.mjs +72 -0
- package/hooks/cursor-kb-elicit.mjs +335 -0
- package/hooks/cursor-kb-recall.mjs +138 -0
- package/hooks/cursor-nudge-handler.mjs +33 -0
- package/hooks/cursor-preguard-handler.mjs +39 -0
- package/hooks/cursor-run-hook.mjs +129 -0
- package/hooks/find-nudge.mjs +15 -0
- package/hooks/find-preguard.mjs +14 -0
- package/hooks/kb-elicit.mjs +334 -0
- package/hooks/kb-recall.mjs +151 -0
- package/hooks/nudge-handler.mjs +370 -0
- package/hooks/preguard-handler.mjs +75 -0
- package/hooks/run-hook.mjs +132 -0
- package/package.json +69 -0
- package/templates/coldstart.cli.md +60 -0
- package/templates/coldstart.mcp.md +59 -0
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { dirname, join } from 'node:path';
|
|
2
|
+
import { toFileId, tryResolveBase, MAX_DIR_WALK_DEPTH } from './shared.js';
|
|
3
|
+
/**
|
|
4
|
+
* Python resolver: handles both relative and absolute imports.
|
|
5
|
+
*
|
|
6
|
+
* Relative imports (starting with '.'):
|
|
7
|
+
* from .models import User → specifier '.models' → {dirname}/models.py
|
|
8
|
+
* from ..utils import X → specifier '..utils' → {parent_dir}/utils.py
|
|
9
|
+
* from . import X → specifier '.' → {dirname}/__init__.py
|
|
10
|
+
*
|
|
11
|
+
* Absolute imports (project-internal):
|
|
12
|
+
* from django.db.models import Model → specifier 'django.db.models'
|
|
13
|
+
* → dots to slashes → try {rootDir}/django/db/models.py or __init__.py
|
|
14
|
+
*
|
|
15
|
+
* Stdlib and third-party package names simply won't exist under rootDir and
|
|
16
|
+
* will return null — no explicit exclusion list needed.
|
|
17
|
+
*/
|
|
18
|
+
export async function resolvePython(specifier, fromFile, fileIdSet, rootDir, _aliasMap) {
|
|
19
|
+
if (specifier.startsWith('.')) {
|
|
20
|
+
// Count leading dots: '.' = 1, '..' = 2, '.models' = 1, '..utils' = 2
|
|
21
|
+
let dots = 0;
|
|
22
|
+
while (dots < specifier.length && specifier[dots] === '.')
|
|
23
|
+
dots++;
|
|
24
|
+
const module = specifier.slice(dots); // '' for bare '.', 'models' for '.models'
|
|
25
|
+
// dots=1 → current package (dirname of file)
|
|
26
|
+
// dots=2 → parent package
|
|
27
|
+
let base = dirname(fromFile);
|
|
28
|
+
for (let i = 1; i < dots; i++) {
|
|
29
|
+
base = dirname(base);
|
|
30
|
+
}
|
|
31
|
+
if (!module) {
|
|
32
|
+
// from . import X — the package __init__.py
|
|
33
|
+
const id = toFileId(join(base, '__init__.py'), rootDir);
|
|
34
|
+
if (fileIdSet.has(id))
|
|
35
|
+
return id;
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
// Convert dotted submodule to path: 'utils.helpers' → 'utils/helpers'
|
|
39
|
+
return tryResolveBase(join(base, module.replace(/\./g, '/')), fileIdSet, rootDir);
|
|
40
|
+
}
|
|
41
|
+
// Absolute import: 'django.db.models' → try walking up from the file's own
|
|
42
|
+
// directory, looking for {ancestor}/<path> or {ancestor}/src/<path>. This
|
|
43
|
+
// handles repos where the project source lives in a subdirectory of rootDir
|
|
44
|
+
// (e.g. /repos/django/django-coldstart/django/...) and multi-project repos.
|
|
45
|
+
const relPath = specifier.replace(/\./g, '/');
|
|
46
|
+
let dir = dirname(fromFile);
|
|
47
|
+
for (let i = 0; i < MAX_DIR_WALK_DEPTH; i++) {
|
|
48
|
+
const direct = await tryResolveBase(join(dir, relPath), fileIdSet, rootDir);
|
|
49
|
+
if (direct)
|
|
50
|
+
return direct;
|
|
51
|
+
const srcLayout = await tryResolveBase(join(dir, 'src', relPath), fileIdSet, rootDir);
|
|
52
|
+
if (srcLayout)
|
|
53
|
+
return srcLayout;
|
|
54
|
+
if (dir === rootDir)
|
|
55
|
+
break;
|
|
56
|
+
const parent = dirname(dir);
|
|
57
|
+
if (parent === dir || !parent.startsWith(rootDir))
|
|
58
|
+
break;
|
|
59
|
+
dir = parent;
|
|
60
|
+
}
|
|
61
|
+
return null;
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=python.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"python.js","sourceRoot":"","sources":["../../../src/indexer/resolvers/python.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,QAAQ,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAE3E;;;;;;;;;;;;;;GAcG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CACjC,SAAiB,EACjB,QAAgB,EAChB,SAAsB,EACtB,OAAe,EACf,SAAgC;IAEhC,IAAI,SAAS,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;QAC9B,sEAAsE;QACtE,IAAI,IAAI,GAAG,CAAC,CAAC;QACb,OAAO,IAAI,GAAG,SAAS,CAAC,MAAM,IAAI,SAAS,CAAC,IAAI,CAAC,KAAK,GAAG;YAAE,IAAI,EAAE,CAAC;QAClE,MAAM,MAAM,GAAG,SAAS,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,0CAA0C;QAEhF,6CAA6C;QAC7C,0BAA0B;QAC1B,IAAI,IAAI,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;QAC7B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,EAAE,CAAC,EAAE,EAAE,CAAC;YAC9B,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;QACvB,CAAC;QAED,IAAI,CAAC,MAAM,EAAE,CAAC;YACZ,4CAA4C;YAC5C,MAAM,EAAE,GAAG,QAAQ,CAAC,IAAI,CAAC,IAAI,EAAE,aAAa,CAAC,EAAE,OAAO,CAAC,CAAC;YACxD,IAAI,S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string, _aliasMap: Map<string, string[]>): Promise<string | null>;
|
|
2
|
+
/** Build FQCN index: snake_case_path → fileId (relative to rootDir). Built once per Rails app. */
|
|
3
|
+
export declare function buildRailsFqcnIndex(appRoot: string, fileIdSet: Set<string>, rootDir: string): Promise<Map<string, string>>;
|
|
4
|
+
/**
|
|
5
|
+
* Resolve an ordered candidate group (innermost-nesting first, bare last) to a
|
|
6
|
+
* fileId, taking the first candidate that maps to a real file. Mirrors Ruby's
|
|
7
|
+
* lexical constant lookup. Returns the matched FQCN so callers can label the edge.
|
|
8
|
+
*/
|
|
9
|
+
export declare function resolveRailsConstantCandidates(candidates: string[], fqcnIndex: Map<string, string>): {
|
|
10
|
+
fileId: string;
|
|
11
|
+
fqcn: string;
|
|
12
|
+
} | null;
|
|
13
|
+
//# sourceMappingURL=ruby.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ruby.d.ts","sourceRoot":"","sources":["../../../src/indexer/resolvers/ruby.ts"],"names":[],"mappings":"AA8DA,wBAAsB,WAAW,CAC/B,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,GAAG,CAAC,MAAM,CAAC,EACtB,OAAO,EAAE,MAAM,EACf,SAAS,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,GAC/B,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAiCxB;AA+BD,kGAAkG;AAClG,wBAAsB,mBAAmB,CACvC,OAAO,EAAE,MAAM,EACf,SAAS,EAAE,GAAG,CAAC,MAAM,CAAC,EACtB,OAAO,EAAE,MAAM,GACd,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAmD9B;AAED;;;;GAIG;AACH,wBAAgB,8BAA8B,CAC5C,UAAU,EAAE,MAAM,EAAE,EACpB,SAAS,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,GAC7B;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CAMzC"}
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
import { dirname, resolve, join, relative, sep } from 'node:path';
|
|
2
|
+
import { readFile, readdir } from 'node:fs/promises';
|
|
3
|
+
import { existsSync } from 'node:fs';
|
|
4
|
+
import { tryResolveBase, MAX_DIR_WALK_DEPTH } from './shared.js';
|
|
5
|
+
import { buildFileId } from '../parser.js';
|
|
6
|
+
/**
|
|
7
|
+
* Ruby resolver: handles relative requires and load-path requires.
|
|
8
|
+
*
|
|
9
|
+
* `require_relative` paths are prefixed with `./` by the Ruby extractor.
|
|
10
|
+
*
|
|
11
|
+
* For bare `require 'foo'`, Ruby searches a load path. We approximate by
|
|
12
|
+
* walking up from the file's directory; at each ancestor try the conventional
|
|
13
|
+
* Rails load-path roots (lib/, app/, spec/, test/) plus any Gemfile-declared
|
|
14
|
+
* path gems' lib/ directory. This handles repos where the Rails project lives
|
|
15
|
+
* in a subdirectory of rootDir, multi-project repos, and engines with their
|
|
16
|
+
* own Gemfile.
|
|
17
|
+
*
|
|
18
|
+
* Gemfile path gems: `gem 'name', path: '../some/gem'` entries map
|
|
19
|
+
* `require 'name'` (and `require 'name/module'`) to the gem's lib/ directory.
|
|
20
|
+
*/
|
|
21
|
+
const RUBY_LOAD_ROOTS = ['lib', 'app', 'spec', 'test'];
|
|
22
|
+
// Caches keyed by the discovered Gemfile directory.
|
|
23
|
+
const gemPathsByDir = new Map();
|
|
24
|
+
const startDirToGemfileDir = new Map();
|
|
25
|
+
async function findGemfileDir(startDir, rootDir) {
|
|
26
|
+
if (startDirToGemfileDir.has(startDir))
|
|
27
|
+
return startDirToGemfileDir.get(startDir);
|
|
28
|
+
let dir = startDir;
|
|
29
|
+
for (let i = 0; i < MAX_DIR_WALK_DEPTH; i++) {
|
|
30
|
+
try {
|
|
31
|
+
await readFile(join(dir, 'Gemfile'), 'utf-8');
|
|
32
|
+
startDirToGemfileDir.set(startDir, dir);
|
|
33
|
+
return dir;
|
|
34
|
+
}
|
|
35
|
+
catch { /* not here */ }
|
|
36
|
+
if (dir === rootDir)
|
|
37
|
+
break;
|
|
38
|
+
const parent = dirname(dir);
|
|
39
|
+
if (parent === dir || !parent.startsWith(rootDir))
|
|
40
|
+
break;
|
|
41
|
+
dir = parent;
|
|
42
|
+
}
|
|
43
|
+
startDirToGemfileDir.set(startDir, null);
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
async function loadGemPaths(gemfileDir) {
|
|
47
|
+
const cached = gemPathsByDir.get(gemfileDir);
|
|
48
|
+
if (cached)
|
|
49
|
+
return cached;
|
|
50
|
+
const pathMap = new Map();
|
|
51
|
+
try {
|
|
52
|
+
const content = await readFile(join(gemfileDir, 'Gemfile'), 'utf-8');
|
|
53
|
+
const re = /gem\s+['"]([^'"]+)['"]\s*,[^#\n]*\bpath:\s*['"]([^'"]+)['"]/g;
|
|
54
|
+
let m;
|
|
55
|
+
while ((m = re.exec(content)) !== null) {
|
|
56
|
+
pathMap.set(m[1], join(gemfileDir, m[2], 'lib'));
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
catch { /* no Gemfile */ }
|
|
60
|
+
gemPathsByDir.set(gemfileDir, pathMap);
|
|
61
|
+
return pathMap;
|
|
62
|
+
}
|
|
63
|
+
export async function resolveRuby(specifier, fromFile, fileIdSet, rootDir, _aliasMap) {
|
|
64
|
+
if (specifier.startsWith('.') || specifier.startsWith('/')) {
|
|
65
|
+
const base = resolve(dirname(fromFile), specifier);
|
|
66
|
+
return tryResolveBase(base, fileIdSet, rootDir);
|
|
67
|
+
}
|
|
68
|
+
// Walk up from file dir; at each ancestor, try Rails load-path roots.
|
|
69
|
+
let dir = dirname(fromFile);
|
|
70
|
+
for (let i = 0; i < MAX_DIR_WALK_DEPTH; i++) {
|
|
71
|
+
for (const loadRoot of RUBY_LOAD_ROOTS) {
|
|
72
|
+
const base = join(dir, loadRoot, specifier);
|
|
73
|
+
const result = tryResolveBase(base, fileIdSet, rootDir);
|
|
74
|
+
if (result)
|
|
75
|
+
return result;
|
|
76
|
+
}
|
|
77
|
+
if (dir === rootDir)
|
|
78
|
+
break;
|
|
79
|
+
const parent = dirname(dir);
|
|
80
|
+
if (parent === dir || !parent.startsWith(rootDir))
|
|
81
|
+
break;
|
|
82
|
+
dir = parent;
|
|
83
|
+
}
|
|
84
|
+
// Gemfile path gems: find the nearest Gemfile and resolve against it.
|
|
85
|
+
const gemfileDir = await findGemfileDir(dirname(fromFile), rootDir);
|
|
86
|
+
if (gemfileDir) {
|
|
87
|
+
const gemPaths = await loadGemPaths(gemfileDir);
|
|
88
|
+
for (const [gemName, libDir] of gemPaths) {
|
|
89
|
+
if (specifier === gemName || specifier.startsWith(gemName + '/')) {
|
|
90
|
+
const result = tryResolveBase(join(libDir, specifier), fileIdSet, rootDir);
|
|
91
|
+
if (result)
|
|
92
|
+
return result;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
return null;
|
|
97
|
+
}
|
|
98
|
+
// ---------------------------------------------------------------------------
|
|
99
|
+
// Rails autoload constant resolution (v1: constants + render)
|
|
100
|
+
// ---------------------------------------------------------------------------
|
|
101
|
+
/** underscore conversion matching ActiveSupport::Inflector */
|
|
102
|
+
function underscore(s) {
|
|
103
|
+
return s
|
|
104
|
+
.replace(/::/g, '/')
|
|
105
|
+
.replace(/([A-Z]+)([A-Z][a-z])/g, '$1_$2')
|
|
106
|
+
.replace(/([a-z\d])([A-Z])/g, '$1_$2')
|
|
107
|
+
.toLowerCase();
|
|
108
|
+
}
|
|
109
|
+
/** Walk dir tree collecting files (used once per app root) */
|
|
110
|
+
async function walkRbFiles(dir) {
|
|
111
|
+
const files = [];
|
|
112
|
+
async function walk(d) {
|
|
113
|
+
let entries;
|
|
114
|
+
try {
|
|
115
|
+
entries = await readdir(d, { withFileTypes: true });
|
|
116
|
+
}
|
|
117
|
+
catch {
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
for (const e of entries) {
|
|
121
|
+
const p = join(d, e.name);
|
|
122
|
+
if (e.isDirectory())
|
|
123
|
+
await walk(p);
|
|
124
|
+
else if (e.isFile() && e.name.endsWith('.rb'))
|
|
125
|
+
files.push(p);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
await walk(dir);
|
|
129
|
+
return files;
|
|
130
|
+
}
|
|
131
|
+
/** Build FQCN index: snake_case_path → fileId (relative to rootDir). Built once per Rails app. */
|
|
132
|
+
export async function buildRailsFqcnIndex(appRoot, fileIdSet, rootDir) {
|
|
133
|
+
const idx = new Map();
|
|
134
|
+
// Discover autoload roots: app/<category>/, app/<category>/concerns/, and optionally lib/
|
|
135
|
+
const appDir = join(appRoot, 'app');
|
|
136
|
+
if (!existsSync(appDir))
|
|
137
|
+
return idx;
|
|
138
|
+
const autoloadRoots = [];
|
|
139
|
+
try {
|
|
140
|
+
const entries = await readdir(appDir, { withFileTypes: true });
|
|
141
|
+
for (const e of entries) {
|
|
142
|
+
if (!e.isDirectory())
|
|
143
|
+
continue;
|
|
144
|
+
const name = e.name;
|
|
145
|
+
if (name === 'views' || name === 'javascript' || name === 'assets')
|
|
146
|
+
continue;
|
|
147
|
+
autoloadRoots.push(join(appDir, name));
|
|
148
|
+
// concerns/ is a sub-root
|
|
149
|
+
const concerns = join(appDir, name, 'concerns');
|
|
150
|
+
if (existsSync(concerns))
|
|
151
|
+
autoloadRoots.push(concerns);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
catch { /* no app/ */ }
|
|
155
|
+
// Optional: lib/ — check config/application.rb for autoload_lib or autoload_paths
|
|
156
|
+
const libRoot = join(appRoot, 'lib');
|
|
157
|
+
if (existsSync(libRoot)) {
|
|
158
|
+
try {
|
|
159
|
+
const appConfig = await readFile(join(appRoot, 'config', 'application.rb'), 'utf-8');
|
|
160
|
+
if (/config\.autoload(?:_lib|_paths)/.test(appConfig)) {
|
|
161
|
+
autoloadRoots.push(libRoot);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
catch { /* no config, skip lib */ }
|
|
165
|
+
}
|
|
166
|
+
// Index each root
|
|
167
|
+
for (const root of autoloadRoots) {
|
|
168
|
+
const rbFiles = await walkRbFiles(root);
|
|
169
|
+
for (const f of rbFiles) {
|
|
170
|
+
let rel = f.slice(root.length + 1).slice(0, -3); // relative path without .rb
|
|
171
|
+
// Strip concerns/ segment if present (Visibility in app/models/concerns → "visibility", not "concerns/visibility")
|
|
172
|
+
if (rel.startsWith('concerns' + sep) || rel.startsWith('concerns/')) {
|
|
173
|
+
rel = rel.slice('concerns/'.length);
|
|
174
|
+
}
|
|
175
|
+
const key = rel.split(sep).join('/');
|
|
176
|
+
// First root wins (app/models before app/models/concerns, etc.)
|
|
177
|
+
if (!idx.has(key)) {
|
|
178
|
+
const fileId = buildFileId(relative(rootDir, f));
|
|
179
|
+
if (fileIdSet.has(fileId))
|
|
180
|
+
idx.set(key, fileId);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
return idx;
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Resolve an ordered candidate group (innermost-nesting first, bare last) to a
|
|
188
|
+
* fileId, taking the first candidate that maps to a real file. Mirrors Ruby's
|
|
189
|
+
* lexical constant lookup. Returns the matched FQCN so callers can label the edge.
|
|
190
|
+
*/
|
|
191
|
+
export function resolveRailsConstantCandidates(candidates, fqcnIndex) {
|
|
192
|
+
for (const fqcn of candidates) {
|
|
193
|
+
const fileId = fqcnIndex.get(underscore(fqcn));
|
|
194
|
+
if (fileId)
|
|
195
|
+
return { fileId, fqcn };
|
|
196
|
+
}
|
|
197
|
+
return null;
|
|
198
|
+
}
|
|
199
|
+
//# sourceMappingURL=ruby.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ruby.js","sourceRoot":"","sources":["../../../src/indexer/resolvers/ruby.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE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C9B,MAAM,MAAM,GAAG,SAAS,CAAC,GAAG,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC;QAC/C,IAAI,MAAM;YAAE,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC;IACtC,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Rust resolver:
|
|
3
|
+
* 1. Mod declarations — `mod foo` → sibling `./foo.rs` or `./foo/mod.rs`.
|
|
4
|
+
* 2. Cross-crate `use` paths — `use tokio::sync::Mutex` → resolve to a file
|
|
5
|
+
* in the tokio crate, located via the workspace Cargo.toml.
|
|
6
|
+
*
|
|
7
|
+
* External-crate uses (those whose leading segment isn't a workspace member)
|
|
8
|
+
* are filtered out at parse time by the Rust extractor, so they never reach
|
|
9
|
+
* this resolver. See src/indexer/extractors/rust.ts.
|
|
10
|
+
*/
|
|
11
|
+
export declare function resolveRust(specifier: string, fromFile: string, fileIdSet: Set<string>, rootDir: string, _aliasMap: Map<string, string[]>): Promise<string | null>;
|
|
12
|
+
//# sourceMappingURL=rust.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rust.d.ts","sourceRoot":"","sources":["../../../src/indexer/resolvers/rust.ts"],"names":[],"mappings":"AAIA;;;;;;;;;GASG;AACH,wBAAsB,WAAW,CAC/B,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,GAAG,CAAC,MAAM,CAAC,EACtB,OAAO,EAAE,MAAM,EACf,SAAS,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,GAC/B,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAuCxB"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { dirname, resolve, join } from 'node:path';
|
|
2
|
+
import { toFileId } from './shared.js';
|
|
3
|
+
import { findRustWorkspace } from '../rust-workspace.js';
|
|
4
|
+
/**
|
|
5
|
+
* Rust resolver:
|
|
6
|
+
* 1. Mod declarations — `mod foo` → sibling `./foo.rs` or `./foo/mod.rs`.
|
|
7
|
+
* 2. Cross-crate `use` paths — `use tokio::sync::Mutex` → resolve to a file
|
|
8
|
+
* in the tokio crate, located via the workspace Cargo.toml.
|
|
9
|
+
*
|
|
10
|
+
* External-crate uses (those whose leading segment isn't a workspace member)
|
|
11
|
+
* are filtered out at parse time by the Rust extractor, so they never reach
|
|
12
|
+
* this resolver. See src/indexer/extractors/rust.ts.
|
|
13
|
+
*/
|
|
14
|
+
export async function resolveRust(specifier, fromFile, fileIdSet, rootDir, _aliasMap) {
|
|
15
|
+
// Single-segment specifier → mod declaration or bare `extern crate X`.
|
|
16
|
+
// Try sibling-file resolution first; only fall through to workspace lookup
|
|
17
|
+
// if that misses.
|
|
18
|
+
if (!specifier.includes('::')) {
|
|
19
|
+
const base = resolve(dirname(fromFile), specifier);
|
|
20
|
+
const rsId = toFileId(base + '.rs', rootDir);
|
|
21
|
+
if (fileIdSet.has(rsId))
|
|
22
|
+
return rsId;
|
|
23
|
+
const modRsId = toFileId(join(base, 'mod.rs'), rootDir);
|
|
24
|
+
if (fileIdSet.has(modRsId))
|
|
25
|
+
return modRsId;
|
|
26
|
+
}
|
|
27
|
+
const segments = specifier.split('::').filter(s => s.length > 0);
|
|
28
|
+
if (segments.length === 0)
|
|
29
|
+
return null;
|
|
30
|
+
const ws = await findRustWorkspace(dirname(fromFile));
|
|
31
|
+
if (!ws)
|
|
32
|
+
return null;
|
|
33
|
+
const crate = ws.crates.get(segments[0]);
|
|
34
|
+
if (!crate)
|
|
35
|
+
return null;
|
|
36
|
+
// Last path segment is usually a symbol (e.g. `Mutex` in `tokio::sync::Mutex`),
|
|
37
|
+
// not a file. Try progressively less-specific paths so we land on the deepest
|
|
38
|
+
// file that actually exists.
|
|
39
|
+
const rest = segments.slice(1);
|
|
40
|
+
for (let depth = rest.length; depth >= 0; depth--) {
|
|
41
|
+
if (depth === 0) {
|
|
42
|
+
const libId = toFileId(join(crate.srcRoot, 'lib.rs'), rootDir);
|
|
43
|
+
if (fileIdSet.has(libId))
|
|
44
|
+
return libId;
|
|
45
|
+
const mainId = toFileId(join(crate.srcRoot, 'main.rs'), rootDir);
|
|
46
|
+
if (fileIdSet.has(mainId))
|
|
47
|
+
return mainId;
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
const subPath = rest.slice(0, depth).join('/');
|
|
51
|
+
const rsId = toFileId(join(crate.srcRoot, subPath + '.rs'), rootDir);
|
|
52
|
+
if (fileIdSet.has(rsId))
|
|
53
|
+
return rsId;
|
|
54
|
+
const modId = toFileId(join(crate.srcRoot, subPath, 'mod.rs'), rootDir);
|
|
55
|
+
if (fileIdSet.has(modId))
|
|
56
|
+
return modId;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=rust.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rust.js","sourceRoot":"","sources":["../../../src/indexer/resolvers/rust.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACnD,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAEzD;;;;;;;;;GASG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAC/B,SAAiB,EACjB,QAAgB,EAChB,SAAsB,EACtB,OAAe,EACf,SAAgC;IAEhC,uEAAuE;IACvE,2EAA2E;IAC3E,kBAAkB;IAClB,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;QAC9B,MAAM,IAAI,GAAG,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,SAAS,CAAC,CAAC;QACnD,MAAM,IAAI,GAAG,QAAQ,C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AAC;YACvC,MAAM,MAAM,GAAG,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,SAAS,CAAC,EAAE,OAAO,CAAC,CAAC;YACjE,IAAI,SAAS,CAAC,GAAG,CAAC,MAAM,CAAC;gBAAE,OAAO,MAAM,CAAC;QAC3C,CAAC;aAAM,CAAC;YACN,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;YAC/C,MAAM,IAAI,GAAG,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,OAAO,GAAG,KAAK,CAAC,EAAE,OAAO,CAAC,CAAC;YACrE,IAAI,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC;gBAAE,OAAO,IAAI,CAAC;YACrC,MAAM,KAAK,GAAG,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,OAAO,EAAE,QAAQ,CAAC,EAAE,OAAO,CAAC,CAAC;YACxE,IAAI,SAAS,CAAC,GAAG,CAAC,KAAK,CAAC;gBAAE,OAAO,KAAK,CAAC;QACzC,CAAC;IACH,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export declare const MAX_DIR_WALK_DEPTH = 64;
|
|
2
|
+
export declare const RESOLVABLE_EXTENSIONS: string[];
|
|
3
|
+
export declare const INDEX_FILES: string[];
|
|
4
|
+
/** Converts an absolute path to a normalized forward-slash file ID relative to rootDir. */
|
|
5
|
+
export declare function toFileId(absolutePath: string, rootDir: string): string;
|
|
6
|
+
/**
|
|
7
|
+
* Given a base path (no extension, or already has one), try to find a match
|
|
8
|
+
* in fileIdSet using only in-memory lookups — no filesystem I/O.
|
|
9
|
+
*
|
|
10
|
+
* 1. Exact match if base already has an extension
|
|
11
|
+
* 1b. JS→TS substitution: `foo.js` → `foo.ts` / `foo.tsx` (TypeScript ESM)
|
|
12
|
+
* 2. Each entry in RESOLVABLE_EXTENSIONS appended to base (no-extension path)
|
|
13
|
+
* 3. Each INDEX_FILES entry inside base as a directory
|
|
14
|
+
*
|
|
15
|
+
* Returns a rootDir-relative forward-slash path if found in fileIdSet, else null.
|
|
16
|
+
*/
|
|
17
|
+
export declare function tryResolveBase(base: string, fileIdSet: Set<string>, rootDir: string): string | null;
|
|
18
|
+
//# sourceMappingURL=shared.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shared.d.ts","sourceRoot":"","sources":["../../../src/indexer/resolvers/shared.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,kBAAkB,KAAK,CAAC;AAUrC,eAAO,MAAM,qBAAqB,UAMjC,CAAC;AAEF,eAAO,MAAM,WAAW,UAIvB,CAAC;AAEF,2FAA2F;AAC3F,wBAAgB,QAAQ,CAAC,YAAY,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CAEtE;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,cAAc,CAC5B,IAAI,EAAE,MAAM,EACZ,SAAS,EAAE,GAAG,CAAC,MAAM,CAAC,EACtB,OAAO,EAAE,MAAM,GACd,MAAM,GAAG,IAAI,CA6Bf"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { relative, extname } from 'node:path';
|
|
2
|
+
// Upper bound on how many directory ancestors a resolver walks when searching
|
|
3
|
+
// for a project marker (go.mod, composer.json, Gemfile, a load-path root, …).
|
|
4
|
+
// A safety valve against an unbounded loop, not a real-world depth — no source
|
|
5
|
+
// tree is 64 directories deep.
|
|
6
|
+
export const MAX_DIR_WALK_DEPTH = 64;
|
|
7
|
+
// TypeScript ESM: `from './foo.js'` may resolve to `foo.ts` on disk.
|
|
8
|
+
const JS_TO_TS = {
|
|
9
|
+
'.js': ['.ts', '.tsx'],
|
|
10
|
+
'.jsx': ['.tsx'],
|
|
11
|
+
'.mjs': ['.mts'],
|
|
12
|
+
'.cjs': ['.cts'],
|
|
13
|
+
};
|
|
14
|
+
export const RESOLVABLE_EXTENSIONS = [
|
|
15
|
+
'.ts', '.tsx', '.mts', '.cts', '.d.ts',
|
|
16
|
+
'.js', '.jsx', '.mjs', '.cjs',
|
|
17
|
+
'.py', '.go', '.rs', '.java', '.cs',
|
|
18
|
+
'.cpp', '.c', '.h', '.hpp',
|
|
19
|
+
'.rb', '.php', '.swift', '.kt', '.dart',
|
|
20
|
+
];
|
|
21
|
+
export const INDEX_FILES = [
|
|
22
|
+
'index.ts', 'index.tsx', 'index.js', 'index.jsx',
|
|
23
|
+
'index.mjs', 'index.cjs', 'index.py', 'index.go',
|
|
24
|
+
'__init__.py', 'mod.rs',
|
|
25
|
+
];
|
|
26
|
+
/** Converts an absolute path to a normalized forward-slash file ID relative to rootDir. */
|
|
27
|
+
export function toFileId(absolutePath, rootDir) {
|
|
28
|
+
return relative(rootDir, absolutePath).replace(/\\/g, '/');
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Given a base path (no extension, or already has one), try to find a match
|
|
32
|
+
* in fileIdSet using only in-memory lookups — no filesystem I/O.
|
|
33
|
+
*
|
|
34
|
+
* 1. Exact match if base already has an extension
|
|
35
|
+
* 1b. JS→TS substitution: `foo.js` → `foo.ts` / `foo.tsx` (TypeScript ESM)
|
|
36
|
+
* 2. Each entry in RESOLVABLE_EXTENSIONS appended to base (no-extension path)
|
|
37
|
+
* 3. Each INDEX_FILES entry inside base as a directory
|
|
38
|
+
*
|
|
39
|
+
* Returns a rootDir-relative forward-slash path if found in fileIdSet, else null.
|
|
40
|
+
*/
|
|
41
|
+
export function tryResolveBase(base, fileIdSet, rootDir) {
|
|
42
|
+
const ext = extname(base);
|
|
43
|
+
const id = toFileId(base, rootDir);
|
|
44
|
+
if (ext) {
|
|
45
|
+
if (fileIdSet.has(id))
|
|
46
|
+
return id;
|
|
47
|
+
// TypeScript ESM: `from './foo.js'` may be indexed as `foo.ts`
|
|
48
|
+
const tsAlts = JS_TO_TS[ext];
|
|
49
|
+
if (tsAlts) {
|
|
50
|
+
const stem = id.slice(0, -ext.length);
|
|
51
|
+
for (const alt of tsAlts) {
|
|
52
|
+
const altId = stem + alt;
|
|
53
|
+
if (fileIdSet.has(altId))
|
|
54
|
+
return altId;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return null; // has an extension — don't append more
|
|
58
|
+
}
|
|
59
|
+
for (const e of RESOLVABLE_EXTENSIONS) {
|
|
60
|
+
const candidate = id + e;
|
|
61
|
+
if (fileIdSet.has(candidate))
|
|
62
|
+
return candidate;
|
|
63
|
+
}
|
|
64
|
+
for (const idx of INDEX_FILES) {
|
|
65
|
+
const candidate = id + '/' + idx;
|
|
66
|
+
if (fileIdSet.has(candidate))
|
|
67
|
+
return candidate;
|
|
68
|
+
}
|
|
69
|
+
return null;
|
|
70
|
+
}
|
|
71
|
+
//# sourceMappingURL=shared.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shared.js","sourceRoot":"","sources":["../../../src/indexer/resolvers/shared.ts"],"names":[],"mappings":"AAAA,OAAO,EAAQ,QAAQ,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpD,8EAA8E;AAC9E,8EAA8E;AAC9E,+EAA+E;AAC/E,+BAA+B;AAC/B,MAAM,CAAC,MAAM,kBAAkB,GAAG,EAAE,CAAC;AAErC,qEAAqE;AACrE,MAAM,QAAQ,GAA6B;IACzC,KAAK,EAAG,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,MAAM,EAAE,CAAC,MAAM,CAAC;IAChB,MAAM,EAAE,CAAC,MAAM,CAAC;IAChB,MAAM,EAAE,CAAC,MAAM,CAAC;CACjB,CAAC;AAEF,MAAM,CAAC,MAAM,qBAAqB,GAAG;IACnC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO;IACtC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;IAC7B,KAAK,EAAE,KAAK,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AC,uCAAuC;IACtD,CAAC;IAED,KAAK,MAAM,CAAC,IAAI,qBAAqB,EAAE,CAAC;QACtC,MAAM,SAAS,GAAG,EAAE,GAAG,CAAC,CAAC;QACzB,IAAI,SAAS,CAAC,GAAG,CAAC,SAAS,CAAC;YAAE,OAAO,SAAS,CAAC;IACjD,CAAC;IAED,KAAK,MAAM,GAAG,IAAI,WAAW,EAAE,CAAC;QAC9B,MAAM,SAAS,GAAG,EAAE,GAAG,GAAG,GAAG,GAAG,CAAC;QACjC,IAAI,SAAS,CAAC,GAAG,CAAC,SAAS,CAAC;YAAE,OAAO,SAAS,CAAC;IACjD,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared Cargo workspace discovery used by both the Rust extractor and resolver.
|
|
3
|
+
*
|
|
4
|
+
* Walks up from a file's directory to find the nearest Cargo.toml with a
|
|
5
|
+
* [workspace] section (or the nearest plain package Cargo.toml as a fallback
|
|
6
|
+
* for single-crate repos). Parses the workspace's member list and each
|
|
7
|
+
* member's [package] name to build a crateName → src-root map.
|
|
8
|
+
*
|
|
9
|
+
* Crate names are stored with `-` normalised to `_` because Rust identifiers
|
|
10
|
+
* use the underscore form (a crate named "tokio-util" is `use tokio_util::...`
|
|
11
|
+
* in source).
|
|
12
|
+
*
|
|
13
|
+
* Caches by Cargo.toml path so multiple files in the same workspace share
|
|
14
|
+
* parsed state.
|
|
15
|
+
*/
|
|
16
|
+
export interface RustCrateInfo {
|
|
17
|
+
name: string;
|
|
18
|
+
srcRoot: string;
|
|
19
|
+
}
|
|
20
|
+
export interface RustWorkspaceInfo {
|
|
21
|
+
workspaceDir: string;
|
|
22
|
+
crates: Map<string, RustCrateInfo>;
|
|
23
|
+
}
|
|
24
|
+
export declare function findRustWorkspace(startDir: string): Promise<RustWorkspaceInfo | null>;
|
|
25
|
+
//# sourceMappingURL=rust-workspace.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rust-workspace.d.ts","sourceRoot":"","sources":["../../src/indexer/rust-workspace.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;;GAcG;AAEH,MAAM,WAAW,aAAa;IAAG,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;CAAE;AACjE,MAAM,WAAW,iBAAiB;IAAG,YAAY,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;CAAE;AAmGhG,wBAAsB,iBAAiB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,iBAAiB,GAAG,IAAI,CAAC,CAmD3F"}
|