opencode-forge 0.1.5
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.
Potentially problematic release.
This version of opencode-forge might be problematic. Click here for more details.
- package/LICENSE +21 -0
- package/README.md +534 -0
- package/config.jsonc +47 -0
- package/dist/agents/architect.d.ts +3 -0
- package/dist/agents/architect.d.ts.map +1 -0
- package/dist/agents/architect.js +152 -0
- package/dist/agents/architect.js.map +1 -0
- package/dist/agents/auditor.d.ts +3 -0
- package/dist/agents/auditor.d.ts.map +1 -0
- package/dist/agents/auditor.js +168 -0
- package/dist/agents/auditor.js.map +1 -0
- package/dist/agents/code.d.ts +3 -0
- package/dist/agents/code.d.ts.map +1 -0
- package/dist/agents/code.js +67 -0
- package/dist/agents/code.js.map +1 -0
- package/dist/agents/index.d.ts +4 -0
- package/dist/agents/index.d.ts.map +1 -0
- package/dist/agents/index.js +9 -0
- package/dist/agents/index.js.map +1 -0
- package/dist/agents/prompts.d.ts +1 -0
- package/dist/agents/prompts.d.ts.map +1 -0
- package/dist/agents/prompts.js +4 -0
- package/dist/agents/prompts.js.map +1 -0
- package/dist/agents/types.d.ts +34 -0
- package/dist/agents/types.d.ts.map +1 -0
- package/dist/agents/types.js +2 -0
- package/dist/agents/types.js.map +1 -0
- package/dist/cache/index.d.ts +4 -0
- package/dist/cache/index.d.ts.map +1 -0
- package/dist/cache/index.js +5 -0
- package/dist/cache/index.js.map +1 -0
- package/dist/cache/memory-cache.d.ts +14 -0
- package/dist/cache/memory-cache.d.ts.map +1 -0
- package/dist/cache/memory-cache.js +51 -0
- package/dist/cache/memory-cache.js.map +1 -0
- package/dist/cache/types.d.ts +8 -0
- package/dist/cache/types.d.ts.map +1 -0
- package/dist/cache/types.js +2 -0
- package/dist/cache/types.js.map +1 -0
- package/dist/cli/commands/cancel.d.ts +15 -0
- package/dist/cli/commands/cancel.d.ts.map +1 -0
- package/dist/cli/commands/cancel.js +194 -0
- package/dist/cli/commands/cancel.js.map +1 -0
- package/dist/cli/commands/graph.d.ts +16 -0
- package/dist/cli/commands/graph.d.ts.map +1 -0
- package/dist/cli/commands/graph.js +208 -0
- package/dist/cli/commands/graph.js.map +1 -0
- package/dist/cli/commands/restart.d.ts +15 -0
- package/dist/cli/commands/restart.d.ts.map +1 -0
- package/dist/cli/commands/restart.js +268 -0
- package/dist/cli/commands/restart.js.map +1 -0
- package/dist/cli/commands/status.d.ts +17 -0
- package/dist/cli/commands/status.d.ts.map +1 -0
- package/dist/cli/commands/status.js +356 -0
- package/dist/cli/commands/status.js.map +1 -0
- package/dist/cli/commands/upgrade.d.ts +3 -0
- package/dist/cli/commands/upgrade.d.ts.map +1 -0
- package/dist/cli/commands/upgrade.js +40 -0
- package/dist/cli/commands/upgrade.js.map +1 -0
- package/dist/cli/index.d.ts +3 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +224 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/cli/utils.d.ts +36 -0
- package/dist/cli/utils.d.ts.map +1 -0
- package/dist/cli/utils.js +163 -0
- package/dist/cli/utils.js.map +1 -0
- package/dist/command/template/review.txt +101 -0
- package/dist/config.d.ts +5 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +186 -0
- package/dist/config.js.map +1 -0
- package/dist/constants/loop.d.ts +10 -0
- package/dist/constants/loop.d.ts.map +1 -0
- package/dist/constants/loop.js +6 -0
- package/dist/constants/loop.js.map +1 -0
- package/dist/graph/cache.d.ts +17 -0
- package/dist/graph/cache.d.ts.map +1 -0
- package/dist/graph/cache.js +50 -0
- package/dist/graph/cache.js.map +1 -0
- package/dist/graph/client.d.ts +51 -0
- package/dist/graph/client.d.ts.map +1 -0
- package/dist/graph/client.js +152 -0
- package/dist/graph/client.js.map +1 -0
- package/dist/graph/clone-detection.d.ts +9 -0
- package/dist/graph/clone-detection.d.ts.map +1 -0
- package/dist/graph/clone-detection.js +148 -0
- package/dist/graph/clone-detection.js.map +1 -0
- package/dist/graph/constants.d.ts +18 -0
- package/dist/graph/constants.d.ts.map +1 -0
- package/dist/graph/constants.js +532 -0
- package/dist/graph/constants.js.map +1 -0
- package/dist/graph/database.d.ts +11 -0
- package/dist/graph/database.d.ts.map +1 -0
- package/dist/graph/database.js +250 -0
- package/dist/graph/database.js.map +1 -0
- package/dist/graph/index.d.ts +14 -0
- package/dist/graph/index.d.ts.map +1 -0
- package/dist/graph/index.js +13 -0
- package/dist/graph/index.js.map +1 -0
- package/dist/graph/repo-map.d.ts +59 -0
- package/dist/graph/repo-map.d.ts.map +1 -0
- package/dist/graph/repo-map.js +948 -0
- package/dist/graph/repo-map.js.map +1 -0
- package/dist/graph/rpc.d.ts +34 -0
- package/dist/graph/rpc.d.ts.map +1 -0
- package/dist/graph/rpc.js +139 -0
- package/dist/graph/rpc.js.map +1 -0
- package/dist/graph/service.d.ts +46 -0
- package/dist/graph/service.d.ts.map +1 -0
- package/dist/graph/service.js +329 -0
- package/dist/graph/service.js.map +1 -0
- package/dist/graph/tree-sitter.d.ts +40 -0
- package/dist/graph/tree-sitter.d.ts.map +1 -0
- package/dist/graph/tree-sitter.js +799 -0
- package/dist/graph/tree-sitter.js.map +1 -0
- package/dist/graph/types.d.ts +175 -0
- package/dist/graph/types.d.ts.map +1 -0
- package/dist/graph/types.js +105 -0
- package/dist/graph/types.js.map +1 -0
- package/dist/graph/utils.d.ts +64 -0
- package/dist/graph/utils.d.ts.map +1 -0
- package/dist/graph/utils.js +406 -0
- package/dist/graph/utils.js.map +1 -0
- package/dist/graph/worker.d.ts +2 -0
- package/dist/graph/worker.d.ts.map +1 -0
- package/dist/graph/worker.js +6043 -0
- package/dist/graph/worker.js.map +1 -0
- package/dist/hooks/compaction-utils.d.ts +21 -0
- package/dist/hooks/compaction-utils.d.ts.map +1 -0
- package/dist/hooks/compaction-utils.js +82 -0
- package/dist/hooks/compaction-utils.js.map +1 -0
- package/dist/hooks/graph-command.d.ts +27 -0
- package/dist/hooks/graph-command.d.ts.map +1 -0
- package/dist/hooks/graph-command.js +57 -0
- package/dist/hooks/graph-command.js.map +1 -0
- package/dist/hooks/graph-tools.d.ts +11 -0
- package/dist/hooks/graph-tools.d.ts.map +1 -0
- package/dist/hooks/graph-tools.js +125 -0
- package/dist/hooks/graph-tools.js.map +1 -0
- package/dist/hooks/index.d.ts +5 -0
- package/dist/hooks/index.d.ts.map +1 -0
- package/dist/hooks/index.js +5 -0
- package/dist/hooks/index.js.map +1 -0
- package/dist/hooks/loop.d.ts +23 -0
- package/dist/hooks/loop.d.ts.map +1 -0
- package/dist/hooks/loop.js +667 -0
- package/dist/hooks/loop.js.map +1 -0
- package/dist/hooks/sandbox-tools.d.ts +13 -0
- package/dist/hooks/sandbox-tools.d.ts.map +1 -0
- package/dist/hooks/sandbox-tools.js +105 -0
- package/dist/hooks/sandbox-tools.js.map +1 -0
- package/dist/hooks/session.d.ts +19 -0
- package/dist/hooks/session.d.ts.map +1 -0
- package/dist/hooks/session.js +56 -0
- package/dist/hooks/session.js.map +1 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +298 -0
- package/dist/index.js.map +1 -0
- package/dist/sandbox/context.d.ts +27 -0
- package/dist/sandbox/context.d.ts.map +1 -0
- package/dist/sandbox/context.js +18 -0
- package/dist/sandbox/context.js.map +1 -0
- package/dist/sandbox/docker.d.ts +29 -0
- package/dist/sandbox/docker.d.ts.map +1 -0
- package/dist/sandbox/docker.js +213 -0
- package/dist/sandbox/docker.js.map +1 -0
- package/dist/sandbox/manager.d.ts +23 -0
- package/dist/sandbox/manager.d.ts.map +1 -0
- package/dist/sandbox/manager.js +131 -0
- package/dist/sandbox/manager.js.map +1 -0
- package/dist/sandbox/path.d.ts +4 -0
- package/dist/sandbox/path.d.ts.map +1 -0
- package/dist/sandbox/path.js +27 -0
- package/dist/sandbox/path.js.map +1 -0
- package/dist/services/kv.d.ts +17 -0
- package/dist/services/kv.d.ts.map +1 -0
- package/dist/services/kv.js +62 -0
- package/dist/services/kv.js.map +1 -0
- package/dist/services/loop.d.ts +96 -0
- package/dist/services/loop.d.ts.map +1 -0
- package/dist/services/loop.js +315 -0
- package/dist/services/loop.js.map +1 -0
- package/dist/setup.d.ts +4 -0
- package/dist/setup.d.ts.map +1 -0
- package/dist/setup.js +118 -0
- package/dist/setup.js.map +1 -0
- package/dist/storage/database.d.ts +6 -0
- package/dist/storage/database.d.ts.map +1 -0
- package/dist/storage/database.js +90 -0
- package/dist/storage/database.js.map +1 -0
- package/dist/storage/graph-projects.d.ts +80 -0
- package/dist/storage/graph-projects.d.ts.map +1 -0
- package/dist/storage/graph-projects.js +154 -0
- package/dist/storage/graph-projects.js.map +1 -0
- package/dist/storage/index.d.ts +5 -0
- package/dist/storage/index.d.ts.map +1 -0
- package/dist/storage/index.js +3 -0
- package/dist/storage/index.js.map +1 -0
- package/dist/storage/kv-queries.d.ts +18 -0
- package/dist/storage/kv-queries.d.ts.map +1 -0
- package/dist/storage/kv-queries.js +70 -0
- package/dist/storage/kv-queries.js.map +1 -0
- package/dist/tools/graph.d.ts +9 -0
- package/dist/tools/graph.d.ts.map +1 -0
- package/dist/tools/graph.js +272 -0
- package/dist/tools/graph.js.map +1 -0
- package/dist/tools/index.d.ts +6 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/index.js +16 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/tools/loop.d.ts +21 -0
- package/dist/tools/loop.d.ts.map +1 -0
- package/dist/tools/loop.js +570 -0
- package/dist/tools/loop.js.map +1 -0
- package/dist/tools/plan-approval.d.ts +15 -0
- package/dist/tools/plan-approval.d.ts.map +1 -0
- package/dist/tools/plan-approval.js +203 -0
- package/dist/tools/plan-approval.js.map +1 -0
- package/dist/tools/plan-execute.d.ts +4 -0
- package/dist/tools/plan-execute.d.ts.map +1 -0
- package/dist/tools/plan-execute.js +85 -0
- package/dist/tools/plan-execute.js.map +1 -0
- package/dist/tools/plan-kv.d.ts +4 -0
- package/dist/tools/plan-kv.d.ts.map +1 -0
- package/dist/tools/plan-kv.js +107 -0
- package/dist/tools/plan-kv.js.map +1 -0
- package/dist/tools/review.d.ts +4 -0
- package/dist/tools/review.d.ts.map +1 -0
- package/dist/tools/review.js +90 -0
- package/dist/tools/review.js.map +1 -0
- package/dist/tools/sandbox-fs.d.ts +22 -0
- package/dist/tools/sandbox-fs.d.ts.map +1 -0
- package/dist/tools/sandbox-fs.js +83 -0
- package/dist/tools/sandbox-fs.js.map +1 -0
- package/dist/tools/types.d.ts +26 -0
- package/dist/tools/types.d.ts.map +1 -0
- package/dist/tools/types.js +2 -0
- package/dist/tools/types.js.map +1 -0
- package/dist/tui.d.ts +3 -0
- package/dist/tui.js +2061 -0
- package/dist/types.d.ts +124 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/utils/git-branch.d.ts +11 -0
- package/dist/utils/git-branch.d.ts.map +1 -0
- package/dist/utils/git-branch.js +35 -0
- package/dist/utils/git-branch.js.map +1 -0
- package/dist/utils/graph-status-store.d.ts +72 -0
- package/dist/utils/graph-status-store.d.ts.map +1 -0
- package/dist/utils/graph-status-store.js +62 -0
- package/dist/utils/graph-status-store.js.map +1 -0
- package/dist/utils/logger.d.ts +8 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/logger.js +89 -0
- package/dist/utils/logger.js.map +1 -0
- package/dist/utils/loop-format.d.ts +5 -0
- package/dist/utils/loop-format.d.ts.map +1 -0
- package/dist/utils/loop-format.js +29 -0
- package/dist/utils/loop-format.js.map +1 -0
- package/dist/utils/loop-helpers.d.ts +9 -0
- package/dist/utils/loop-helpers.d.ts.map +1 -0
- package/dist/utils/loop-helpers.js +20 -0
- package/dist/utils/loop-helpers.js.map +1 -0
- package/dist/utils/loop-launch.d.ts +32 -0
- package/dist/utils/loop-launch.d.ts.map +1 -0
- package/dist/utils/loop-launch.js +162 -0
- package/dist/utils/loop-launch.js.map +1 -0
- package/dist/utils/model-fallback.d.ts +27 -0
- package/dist/utils/model-fallback.d.ts.map +1 -0
- package/dist/utils/model-fallback.js +33 -0
- package/dist/utils/model-fallback.js.map +1 -0
- package/dist/utils/partial-match.d.ts +7 -0
- package/dist/utils/partial-match.d.ts.map +1 -0
- package/dist/utils/partial-match.js +56 -0
- package/dist/utils/partial-match.js.map +1 -0
- package/dist/utils/plan-execution.d.ts +65 -0
- package/dist/utils/plan-execution.d.ts.map +1 -0
- package/dist/utils/plan-execution.js +107 -0
- package/dist/utils/plan-execution.js.map +1 -0
- package/dist/utils/session-stats.d.ts +36 -0
- package/dist/utils/session-stats.d.ts.map +1 -0
- package/dist/utils/session-stats.js +145 -0
- package/dist/utils/session-stats.js.map +1 -0
- package/dist/utils/tui-graph-status.d.ts +38 -0
- package/dist/utils/tui-graph-status.d.ts.map +1 -0
- package/dist/utils/tui-graph-status.js +95 -0
- package/dist/utils/tui-graph-status.js.map +1 -0
- package/dist/utils/tui-plan-store.d.ts +54 -0
- package/dist/utils/tui-plan-store.d.ts.map +1 -0
- package/dist/utils/tui-plan-store.js +168 -0
- package/dist/utils/tui-plan-store.js.map +1 -0
- package/dist/utils/tui-refresh-helpers.d.ts +44 -0
- package/dist/utils/tui-refresh-helpers.d.ts.map +1 -0
- package/dist/utils/tui-refresh-helpers.js +120 -0
- package/dist/utils/tui-refresh-helpers.js.map +1 -0
- package/dist/utils/upgrade.d.ts +23 -0
- package/dist/utils/upgrade.d.ts.map +1 -0
- package/dist/utils/upgrade.js +111 -0
- package/dist/utils/upgrade.js.map +1 -0
- package/dist/version.d.ts +2 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +2 -0
- package/dist/version.js.map +1 -0
- package/package.json +92 -0
- package/scripts/build.ts +67 -0
- package/src/command/template/review.txt +101 -0
|
@@ -0,0 +1,799 @@
|
|
|
1
|
+
import { existsSync } from "node:fs";
|
|
2
|
+
import { readFile } from "node:fs/promises";
|
|
3
|
+
import { dirname, join, resolve } from "node:path";
|
|
4
|
+
import { detectLanguageFromPath, } from "./types";
|
|
5
|
+
// Tree-sitter query patterns per language
|
|
6
|
+
const QUERIES = {
|
|
7
|
+
typescript: `
|
|
8
|
+
(function_declaration name: (identifier) @name) @func
|
|
9
|
+
(export_statement (function_declaration name: (identifier) @name)) @func
|
|
10
|
+
(class_declaration name: (type_identifier) @name) @class
|
|
11
|
+
(method_definition name: (property_identifier) @name) @method
|
|
12
|
+
(interface_declaration name: (type_identifier) @name) @iface
|
|
13
|
+
(type_alias_declaration name: (type_identifier) @name) @type
|
|
14
|
+
(lexical_declaration (variable_declarator name: (identifier) @name)) @var
|
|
15
|
+
(import_statement source: (string) @source) @import
|
|
16
|
+
(export_statement) @export
|
|
17
|
+
`,
|
|
18
|
+
javascript: `
|
|
19
|
+
(function_declaration name: (identifier) @name) @func
|
|
20
|
+
(class_declaration name: (identifier) @name) @class
|
|
21
|
+
(method_definition name: (property_identifier) @name) @method
|
|
22
|
+
(lexical_declaration (variable_declarator name: (identifier) @name)) @var
|
|
23
|
+
(import_statement source: (string) @source) @import
|
|
24
|
+
(export_statement) @export
|
|
25
|
+
`,
|
|
26
|
+
python: `
|
|
27
|
+
(function_definition name: (identifier) @name) @func
|
|
28
|
+
(class_definition name: (identifier) @name) @class
|
|
29
|
+
(class_definition body: (block (function_definition name: (identifier) @name) @method))
|
|
30
|
+
(import_statement) @import
|
|
31
|
+
(import_from_statement) @import
|
|
32
|
+
`,
|
|
33
|
+
go: `
|
|
34
|
+
(function_declaration name: (identifier) @name) @func
|
|
35
|
+
(method_declaration name: (field_identifier) @name) @func
|
|
36
|
+
(type_declaration (type_spec name: (type_identifier) @name)) @type
|
|
37
|
+
(import_declaration) @import
|
|
38
|
+
`,
|
|
39
|
+
rust: `
|
|
40
|
+
(function_item name: (identifier) @name) @func
|
|
41
|
+
(struct_item name: (type_identifier) @name) @struct
|
|
42
|
+
(trait_item name: (type_identifier) @name) @trait
|
|
43
|
+
(type_item name: (type_identifier) @name) @type
|
|
44
|
+
(impl_item (declaration_list (function_item name: (identifier) @name) @method))
|
|
45
|
+
(use_declaration) @import
|
|
46
|
+
(impl_item) @impl
|
|
47
|
+
`,
|
|
48
|
+
java: `
|
|
49
|
+
(method_declaration name: (identifier) @name) @func
|
|
50
|
+
(class_declaration name: (identifier) @name) @class
|
|
51
|
+
(interface_declaration name: (identifier) @name) @iface
|
|
52
|
+
(enum_declaration name: (identifier) @name) @type
|
|
53
|
+
(import_declaration) @import
|
|
54
|
+
`,
|
|
55
|
+
c: `
|
|
56
|
+
(function_definition declarator: (function_declarator declarator: (identifier) @name)) @func
|
|
57
|
+
(struct_specifier name: (type_identifier) @name) @struct
|
|
58
|
+
(enum_specifier name: (type_identifier) @name) @type
|
|
59
|
+
(type_definition declarator: (type_identifier) @name) @type
|
|
60
|
+
(preproc_include) @import
|
|
61
|
+
`,
|
|
62
|
+
cpp: `
|
|
63
|
+
(function_definition declarator: (function_declarator declarator: (identifier) @name)) @func
|
|
64
|
+
(class_specifier name: (type_identifier) @name) @class
|
|
65
|
+
(struct_specifier name: (type_identifier) @name) @struct
|
|
66
|
+
(enum_specifier name: (type_identifier) @name) @type
|
|
67
|
+
(namespace_definition name: (namespace_identifier) @name) @type
|
|
68
|
+
(preproc_include) @import
|
|
69
|
+
`,
|
|
70
|
+
csharp: `
|
|
71
|
+
(method_declaration name: (identifier) @name) @func
|
|
72
|
+
(class_declaration name: (identifier) @name) @class
|
|
73
|
+
(interface_declaration name: (identifier) @name) @iface
|
|
74
|
+
(struct_declaration name: (identifier) @name) @struct
|
|
75
|
+
(enum_declaration name: (identifier) @name) @type
|
|
76
|
+
(namespace_declaration name: (identifier) @name) @type
|
|
77
|
+
(using_directive) @import
|
|
78
|
+
`,
|
|
79
|
+
ruby: `
|
|
80
|
+
(method name: (identifier) @name) @func
|
|
81
|
+
(class name: (constant) @name) @class
|
|
82
|
+
(module name: (constant) @name) @type
|
|
83
|
+
(call method: (identifier) @name) @import
|
|
84
|
+
`,
|
|
85
|
+
php: `
|
|
86
|
+
(function_definition name: (name) @name) @func
|
|
87
|
+
(method_declaration name: (name) @name) @func
|
|
88
|
+
(class_declaration name: (name) @name) @class
|
|
89
|
+
(interface_declaration name: (name) @name) @iface
|
|
90
|
+
(trait_declaration name: (name) @name) @trait
|
|
91
|
+
(namespace_use_declaration) @import
|
|
92
|
+
`,
|
|
93
|
+
swift: `
|
|
94
|
+
(function_declaration (simple_identifier) @name) @func
|
|
95
|
+
(class_declaration name: (type_identifier) @name) @class
|
|
96
|
+
(protocol_declaration name: (type_identifier) @name) @iface
|
|
97
|
+
(import_declaration) @import
|
|
98
|
+
`,
|
|
99
|
+
kotlin: `
|
|
100
|
+
(function_declaration (simple_identifier) @name) @func
|
|
101
|
+
(class_declaration (type_identifier) @name) @class
|
|
102
|
+
(object_declaration (type_identifier) @name) @class
|
|
103
|
+
(import_header) @import
|
|
104
|
+
`,
|
|
105
|
+
scala: `
|
|
106
|
+
(function_definition name: (identifier) @name) @func
|
|
107
|
+
(class_definition name: (identifier) @name) @class
|
|
108
|
+
(trait_definition name: (identifier) @name) @trait
|
|
109
|
+
(object_definition name: (identifier) @name) @class
|
|
110
|
+
(import_declaration) @import
|
|
111
|
+
`,
|
|
112
|
+
lua: `
|
|
113
|
+
(function_definition_statement name: (identifier) @name) @func
|
|
114
|
+
(local_function_definition_statement name: (identifier) @name) @func
|
|
115
|
+
`,
|
|
116
|
+
elixir: `
|
|
117
|
+
(call target: (identifier) @name) @func
|
|
118
|
+
`,
|
|
119
|
+
dart: `
|
|
120
|
+
(function_signature (identifier) @name) @func
|
|
121
|
+
(class_definition name: (identifier) @name) @class
|
|
122
|
+
(enum_declaration name: (identifier) @name) @type
|
|
123
|
+
(mixin_declaration name: (identifier) @name) @class
|
|
124
|
+
(import_or_export) @import
|
|
125
|
+
`,
|
|
126
|
+
zig: `
|
|
127
|
+
(function_declaration name: (identifier) @name) @func
|
|
128
|
+
(variable_declaration name: (identifier) @name) @var
|
|
129
|
+
`,
|
|
130
|
+
bash: `
|
|
131
|
+
(function_definition name: (word) @name) @func
|
|
132
|
+
`,
|
|
133
|
+
ocaml: `
|
|
134
|
+
(value_definition (let_binding pattern: (value_name) @name)) @func
|
|
135
|
+
(type_definition (type_binding name: (type_constructor) @name)) @type
|
|
136
|
+
(module_definition (module_binding name: (module_name) @name)) @type
|
|
137
|
+
(open_module) @import
|
|
138
|
+
`,
|
|
139
|
+
objc: `
|
|
140
|
+
(function_definition declarator: (function_declarator declarator: (identifier) @name)) @func
|
|
141
|
+
(class_interface . (identifier) @name) @class
|
|
142
|
+
(protocol_declaration . (identifier) @name) @iface
|
|
143
|
+
(preproc_include) @import
|
|
144
|
+
`,
|
|
145
|
+
css: `
|
|
146
|
+
(rule_set (selectors) @name) @var
|
|
147
|
+
(keyframes_statement (keyframes_name) @name) @type
|
|
148
|
+
`,
|
|
149
|
+
html: `
|
|
150
|
+
(element (start_tag (tag_name) @name)) @var
|
|
151
|
+
`,
|
|
152
|
+
vue: `
|
|
153
|
+
(element (start_tag (tag_name) @name)) @var
|
|
154
|
+
`,
|
|
155
|
+
rescript: `
|
|
156
|
+
(let_declaration (let_binding pattern: (value_identifier) @name)) @func
|
|
157
|
+
(type_declaration (type_binding name: (type_identifier) @name)) @type
|
|
158
|
+
(module_declaration (module_binding name: (module_identifier) @name)) @type
|
|
159
|
+
`,
|
|
160
|
+
solidity: `
|
|
161
|
+
(contract_declaration name: (identifier) @name) @class
|
|
162
|
+
(function_definition name: (identifier) @name) @func
|
|
163
|
+
(event_definition name: (identifier) @name) @type
|
|
164
|
+
(struct_declaration name: (identifier) @name) @struct
|
|
165
|
+
(enum_declaration name: (identifier) @name) @type
|
|
166
|
+
(import_directive) @import
|
|
167
|
+
`,
|
|
168
|
+
tlaplus: `
|
|
169
|
+
(operator_definition name: (identifier) @name) @func
|
|
170
|
+
(function_definition name: (identifier) @name) @func
|
|
171
|
+
`,
|
|
172
|
+
elisp: `
|
|
173
|
+
(function_definition name: (symbol) @name) @func
|
|
174
|
+
(special_form . (symbol) @name) @var
|
|
175
|
+
`,
|
|
176
|
+
};
|
|
177
|
+
const GRAMMAR_FILES = {
|
|
178
|
+
tsx: "tree-sitter-tsx.wasm",
|
|
179
|
+
javascript: "tree-sitter-javascript.wasm",
|
|
180
|
+
python: "tree-sitter-python.wasm",
|
|
181
|
+
go: "tree-sitter-go.wasm",
|
|
182
|
+
rust: "tree-sitter-rust.wasm",
|
|
183
|
+
java: "tree-sitter-java.wasm",
|
|
184
|
+
c: "tree-sitter-c.wasm",
|
|
185
|
+
cpp: "tree-sitter-cpp.wasm",
|
|
186
|
+
csharp: "tree-sitter-c_sharp.wasm",
|
|
187
|
+
ruby: "tree-sitter-ruby.wasm",
|
|
188
|
+
php: "tree-sitter-php.wasm",
|
|
189
|
+
swift: "tree-sitter-swift.wasm",
|
|
190
|
+
kotlin: "tree-sitter-kotlin.wasm",
|
|
191
|
+
scala: "tree-sitter-scala.wasm",
|
|
192
|
+
lua: "tree-sitter-lua.wasm",
|
|
193
|
+
elixir: "tree-sitter-elixir.wasm",
|
|
194
|
+
dart: "tree-sitter-dart.wasm",
|
|
195
|
+
zig: "tree-sitter-zig.wasm",
|
|
196
|
+
bash: "tree-sitter-bash.wasm",
|
|
197
|
+
ocaml: "tree-sitter-ocaml.wasm",
|
|
198
|
+
objc: "tree-sitter-objc.wasm",
|
|
199
|
+
css: "tree-sitter-css.wasm",
|
|
200
|
+
html: "tree-sitter-html.wasm",
|
|
201
|
+
json: "tree-sitter-json.wasm",
|
|
202
|
+
toml: "tree-sitter-toml.wasm",
|
|
203
|
+
vue: "tree-sitter-vue.wasm",
|
|
204
|
+
rescript: "tree-sitter-rescript.wasm",
|
|
205
|
+
solidity: "tree-sitter-solidity.wasm",
|
|
206
|
+
tlaplus: "tree-sitter-tlaplus.wasm",
|
|
207
|
+
elisp: "tree-sitter-elisp.wasm",
|
|
208
|
+
};
|
|
209
|
+
let TSQueryClass = null;
|
|
210
|
+
function createQuery(lang, source) {
|
|
211
|
+
if (!TSQueryClass)
|
|
212
|
+
throw new Error("tree-sitter not initialized");
|
|
213
|
+
return new TSQueryClass(lang, source);
|
|
214
|
+
}
|
|
215
|
+
export class TreeSitterBackend {
|
|
216
|
+
parser = null;
|
|
217
|
+
languages = new Map();
|
|
218
|
+
failedLanguages = new Set();
|
|
219
|
+
initPromise = null;
|
|
220
|
+
cache = null;
|
|
221
|
+
treeCache = new Map();
|
|
222
|
+
treeCacheMaxSize = 50;
|
|
223
|
+
supportsLanguage(language) {
|
|
224
|
+
const key = language === "typescript" ? "tsx" : language;
|
|
225
|
+
return key in GRAMMAR_FILES;
|
|
226
|
+
}
|
|
227
|
+
setCache(cache) {
|
|
228
|
+
this.cache = cache;
|
|
229
|
+
}
|
|
230
|
+
async initialize(_cwd) {
|
|
231
|
+
if (this.parser)
|
|
232
|
+
return;
|
|
233
|
+
if (this.initPromise)
|
|
234
|
+
return this.initPromise;
|
|
235
|
+
this.initPromise = this.doInit();
|
|
236
|
+
return this.initPromise;
|
|
237
|
+
}
|
|
238
|
+
dispose() {
|
|
239
|
+
for (const entry of this.treeCache.values()) {
|
|
240
|
+
entry.tree.delete();
|
|
241
|
+
}
|
|
242
|
+
this.treeCache.clear();
|
|
243
|
+
this.parser?.delete();
|
|
244
|
+
this.parser = null;
|
|
245
|
+
this.languages.clear();
|
|
246
|
+
this.initPromise = null;
|
|
247
|
+
}
|
|
248
|
+
async getFileOutline(file) {
|
|
249
|
+
const tree = await this.parseFile(file);
|
|
250
|
+
if (!tree)
|
|
251
|
+
return null;
|
|
252
|
+
const language = this.detectLang(file);
|
|
253
|
+
const tsLang = this.languages.get(this.grammarKeyForFile(file));
|
|
254
|
+
if (!tsLang) {
|
|
255
|
+
tree.delete();
|
|
256
|
+
return null;
|
|
257
|
+
}
|
|
258
|
+
const symbols = [];
|
|
259
|
+
const imports = [];
|
|
260
|
+
const exports = [];
|
|
261
|
+
const absFile = resolve(file);
|
|
262
|
+
const mainQueryStr = QUERIES[language];
|
|
263
|
+
if (mainQueryStr) {
|
|
264
|
+
const mainQuery = createQuery(tsLang, mainQueryStr);
|
|
265
|
+
try {
|
|
266
|
+
const matches = mainQuery.matches(tree.rootNode);
|
|
267
|
+
for (const match of matches) {
|
|
268
|
+
const nameCapture = match.captures.find((c) => c.name === "name");
|
|
269
|
+
const sourceCapture = match.captures.find((c) => c.name === "source");
|
|
270
|
+
const patternCapture = match.captures.find((c) => c.name !== "name" && c.name !== "source");
|
|
271
|
+
if (patternCapture?.name === "import") {
|
|
272
|
+
const node = patternCapture.node;
|
|
273
|
+
const source = sourceCapture ? sourceCapture.node.text.replace(/['"]/g, "") : node.text;
|
|
274
|
+
const specifiers = extractImportSpecifiers(node, language);
|
|
275
|
+
const isDefault = specifiers.length > 0 &&
|
|
276
|
+
node.text.includes("import ") &&
|
|
277
|
+
!node.text.includes("{") &&
|
|
278
|
+
!node.text.includes("*");
|
|
279
|
+
const isNamespace = node.text.includes("* as ");
|
|
280
|
+
imports.push({
|
|
281
|
+
source,
|
|
282
|
+
specifiers,
|
|
283
|
+
isDefault,
|
|
284
|
+
isNamespace,
|
|
285
|
+
location: {
|
|
286
|
+
file: absFile,
|
|
287
|
+
line: node.startPosition.row + 1,
|
|
288
|
+
column: node.startPosition.column + 1,
|
|
289
|
+
endLine: node.endPosition.row + 1,
|
|
290
|
+
},
|
|
291
|
+
});
|
|
292
|
+
continue;
|
|
293
|
+
}
|
|
294
|
+
if (patternCapture?.name === "export") {
|
|
295
|
+
const node = patternCapture.node;
|
|
296
|
+
const isDefault = node.text.includes("export default");
|
|
297
|
+
const decl = node.namedChildren.find((c) => c != null &&
|
|
298
|
+
(c.type === "function_declaration" ||
|
|
299
|
+
c.type === "class_declaration" ||
|
|
300
|
+
c.type === "interface_declaration" ||
|
|
301
|
+
c.type === "type_alias_declaration" ||
|
|
302
|
+
c.type === "lexical_declaration"));
|
|
303
|
+
if (decl) {
|
|
304
|
+
const expNameNode = decl.childForFieldName("name") ??
|
|
305
|
+
decl.namedChildren
|
|
306
|
+
.find((c) => c != null && c.type === "variable_declarator")
|
|
307
|
+
?.childForFieldName("name");
|
|
308
|
+
if (expNameNode) {
|
|
309
|
+
let kind = "variable";
|
|
310
|
+
if (decl.type.includes("function"))
|
|
311
|
+
kind = "function";
|
|
312
|
+
else if (decl.type.includes("class"))
|
|
313
|
+
kind = "class";
|
|
314
|
+
else if (decl.type.includes("interface"))
|
|
315
|
+
kind = "interface";
|
|
316
|
+
else if (decl.type.includes("type"))
|
|
317
|
+
kind = "type";
|
|
318
|
+
exports.push({
|
|
319
|
+
name: expNameNode.text,
|
|
320
|
+
isDefault,
|
|
321
|
+
kind,
|
|
322
|
+
location: {
|
|
323
|
+
file: absFile,
|
|
324
|
+
line: node.startPosition.row + 1,
|
|
325
|
+
column: node.startPosition.column + 1,
|
|
326
|
+
endLine: node.endPosition.row + 1,
|
|
327
|
+
},
|
|
328
|
+
});
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
continue;
|
|
332
|
+
}
|
|
333
|
+
if (nameCapture) {
|
|
334
|
+
const kind = this.captureToKind(patternCapture?.name ?? "unknown");
|
|
335
|
+
const declNode = patternCapture?.node ?? nameCapture.node.parent ?? nameCapture.node;
|
|
336
|
+
const symbol = {
|
|
337
|
+
name: nameCapture.node.text,
|
|
338
|
+
kind,
|
|
339
|
+
location: {
|
|
340
|
+
file: absFile,
|
|
341
|
+
line: nameCapture.node.startPosition.row + 1,
|
|
342
|
+
column: nameCapture.node.startPosition.column + 1,
|
|
343
|
+
endLine: declNode.endPosition.row + 1,
|
|
344
|
+
},
|
|
345
|
+
};
|
|
346
|
+
// Deduplicate symbols by file, name, kind, and location to prevent
|
|
347
|
+
// overlapping query captures from creating duplicate entries.
|
|
348
|
+
// Column is included to distinguish same-line declarations (e.g., getter/setter pairs).
|
|
349
|
+
const isDuplicate = symbols.some((s) => s.name === symbol.name &&
|
|
350
|
+
s.kind === symbol.kind &&
|
|
351
|
+
s.location.line === symbol.location.line &&
|
|
352
|
+
s.location.column === symbol.location.column &&
|
|
353
|
+
s.location.endLine === symbol.location.endLine);
|
|
354
|
+
if (!isDuplicate) {
|
|
355
|
+
symbols.push(symbol);
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
finally {
|
|
361
|
+
mainQuery.delete();
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
tree.delete();
|
|
365
|
+
if (exports.length === 0 && language !== "typescript" && language !== "javascript") {
|
|
366
|
+
const content = await this.readFileContent(file);
|
|
367
|
+
if (content) {
|
|
368
|
+
const lines = content.split("\n");
|
|
369
|
+
for (const sym of symbols) {
|
|
370
|
+
const line = lines[sym.location.line - 1] ?? "";
|
|
371
|
+
if (isPublicSymbol(sym.name, line, language, file)) {
|
|
372
|
+
exports.push({
|
|
373
|
+
name: sym.name,
|
|
374
|
+
isDefault: false,
|
|
375
|
+
kind: sym.kind,
|
|
376
|
+
location: sym.location,
|
|
377
|
+
});
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
return {
|
|
383
|
+
file: absFile,
|
|
384
|
+
language,
|
|
385
|
+
symbols,
|
|
386
|
+
imports,
|
|
387
|
+
exports,
|
|
388
|
+
};
|
|
389
|
+
}
|
|
390
|
+
static MIN_HASH_LINES = 5;
|
|
391
|
+
static HASHABLE_KEYWORDS = [
|
|
392
|
+
"function",
|
|
393
|
+
"method",
|
|
394
|
+
"class",
|
|
395
|
+
"impl",
|
|
396
|
+
"struct",
|
|
397
|
+
"trait",
|
|
398
|
+
"module",
|
|
399
|
+
"constructor",
|
|
400
|
+
];
|
|
401
|
+
static isHashableType(nodeType) {
|
|
402
|
+
return TreeSitterBackend.HASHABLE_KEYWORDS.some((kw) => nodeType.includes(kw));
|
|
403
|
+
}
|
|
404
|
+
serializeShape(node, depth) {
|
|
405
|
+
if (depth > 40)
|
|
406
|
+
return node.type;
|
|
407
|
+
const childCount = node.namedChildCount;
|
|
408
|
+
if (childCount === 0)
|
|
409
|
+
return node.type;
|
|
410
|
+
const children = [];
|
|
411
|
+
for (let i = 0; i < childCount; i++) {
|
|
412
|
+
const child = node.namedChild(i);
|
|
413
|
+
if (child)
|
|
414
|
+
children.push(this.serializeShape(child, depth + 1));
|
|
415
|
+
}
|
|
416
|
+
return `${node.type}(${children.join(",")})`;
|
|
417
|
+
}
|
|
418
|
+
countNodes(node, depth) {
|
|
419
|
+
if (depth > 40)
|
|
420
|
+
return 1;
|
|
421
|
+
let count = 1;
|
|
422
|
+
const childCount = node.namedChildCount;
|
|
423
|
+
for (let i = 0; i < childCount; i++) {
|
|
424
|
+
const child = node.namedChild(i);
|
|
425
|
+
if (child)
|
|
426
|
+
count += this.countNodes(child, depth + 1);
|
|
427
|
+
}
|
|
428
|
+
return count;
|
|
429
|
+
}
|
|
430
|
+
extractNodeName(node) {
|
|
431
|
+
const nameNode = node.childForFieldName("name");
|
|
432
|
+
if (nameNode)
|
|
433
|
+
return nameNode.text;
|
|
434
|
+
if (node.type === "arrow_function" || node.type === "function_expression") {
|
|
435
|
+
const parent = node.parent;
|
|
436
|
+
if (parent?.type === "variable_declarator") {
|
|
437
|
+
const varName = parent.childForFieldName("name");
|
|
438
|
+
if (varName)
|
|
439
|
+
return varName.text;
|
|
440
|
+
}
|
|
441
|
+
if (parent?.type === "pair" || parent?.type === "property") {
|
|
442
|
+
const key = parent.childForFieldName("key");
|
|
443
|
+
if (key)
|
|
444
|
+
return key.text;
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
if (node.type === "lexical_declaration" || node.type === "variable_declaration") {
|
|
448
|
+
const declarator = node.namedChildren.find((c) => c != null && c.type === "variable_declarator");
|
|
449
|
+
if (declarator) {
|
|
450
|
+
const varName = declarator.childForFieldName("name");
|
|
451
|
+
if (varName)
|
|
452
|
+
return varName.text;
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
return "(anonymous)";
|
|
456
|
+
}
|
|
457
|
+
collectHashableNodes(node, results, depth) {
|
|
458
|
+
if (depth > 10)
|
|
459
|
+
return;
|
|
460
|
+
if (TreeSitterBackend.isHashableType(node.type)) {
|
|
461
|
+
const lines = node.endPosition.row - node.startPosition.row + 1;
|
|
462
|
+
if (lines >= TreeSitterBackend.MIN_HASH_LINES) {
|
|
463
|
+
const name = this.extractNodeName(node);
|
|
464
|
+
const kind = node.type
|
|
465
|
+
.replace(/_declaration|_definition|_item|_statement|_specifier/, "")
|
|
466
|
+
.replace(/^local_/, "");
|
|
467
|
+
results.push({ node, name, kind });
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
if (node.type === "lexical_declaration" || node.type === "variable_declaration") {
|
|
471
|
+
const lines = node.endPosition.row - node.startPosition.row + 1;
|
|
472
|
+
if (lines >= TreeSitterBackend.MIN_HASH_LINES) {
|
|
473
|
+
const hasArrow = node.namedChildren.some((c) => {
|
|
474
|
+
if (!c || c.type !== "variable_declarator")
|
|
475
|
+
return false;
|
|
476
|
+
return c.namedChildren.some((gc) => gc != null && (gc.type === "arrow_function" || gc.type === "function_expression"));
|
|
477
|
+
});
|
|
478
|
+
if (hasArrow) {
|
|
479
|
+
const name = this.extractNodeName(node);
|
|
480
|
+
results.push({ node, name, kind: "function" });
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
const childCount = node.namedChildCount;
|
|
485
|
+
for (let i = 0; i < childCount; i++) {
|
|
486
|
+
const child = node.namedChild(i);
|
|
487
|
+
if (child)
|
|
488
|
+
this.collectHashableNodes(child, results, depth + 1);
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
async getShapeHashes(file) {
|
|
492
|
+
const tree = await this.parseFile(file);
|
|
493
|
+
if (!tree)
|
|
494
|
+
return null;
|
|
495
|
+
try {
|
|
496
|
+
const nodes = [];
|
|
497
|
+
this.collectHashableNodes(tree.rootNode, nodes, 0);
|
|
498
|
+
if (nodes.length === 0)
|
|
499
|
+
return [];
|
|
500
|
+
const results = [];
|
|
501
|
+
for (const { node, name, kind } of nodes) {
|
|
502
|
+
const serialized = this.serializeShape(node, 0);
|
|
503
|
+
const hash = Bun.hash(serialized).toString(16);
|
|
504
|
+
const nodeCount = this.countNodes(node, 0);
|
|
505
|
+
results.push({
|
|
506
|
+
name,
|
|
507
|
+
kind,
|
|
508
|
+
line: node.startPosition.row + 1,
|
|
509
|
+
endLine: node.endPosition.row + 1,
|
|
510
|
+
shapeHash: hash,
|
|
511
|
+
nodeCount,
|
|
512
|
+
});
|
|
513
|
+
}
|
|
514
|
+
return results;
|
|
515
|
+
}
|
|
516
|
+
finally {
|
|
517
|
+
tree.delete();
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
async doInit() {
|
|
521
|
+
const wasmPath = this.resolveWasm("tree-sitter.wasm");
|
|
522
|
+
if (!existsSync(wasmPath)) {
|
|
523
|
+
throw new Error(`tree-sitter.wasm not found`);
|
|
524
|
+
}
|
|
525
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
526
|
+
const mod = await import("web-tree-sitter");
|
|
527
|
+
TSQueryClass = mod.Query;
|
|
528
|
+
const ParserClass = mod.Parser;
|
|
529
|
+
await ParserClass.init({
|
|
530
|
+
locateFile: () => wasmPath,
|
|
531
|
+
});
|
|
532
|
+
this.parser = new ParserClass();
|
|
533
|
+
}
|
|
534
|
+
resolveWasm(filename) {
|
|
535
|
+
const basename = filename.split("/").pop() ?? filename;
|
|
536
|
+
let dir = import.meta.dir;
|
|
537
|
+
for (let i = 0; i < 5; i++) {
|
|
538
|
+
for (const sub of ["node_modules/web-tree-sitter", "node_modules/tree-sitter-wasms/out"]) {
|
|
539
|
+
const p = join(dir, sub, basename);
|
|
540
|
+
if (existsSync(p))
|
|
541
|
+
return p;
|
|
542
|
+
}
|
|
543
|
+
const parent = dirname(dir);
|
|
544
|
+
if (parent === dir)
|
|
545
|
+
break;
|
|
546
|
+
dir = parent;
|
|
547
|
+
}
|
|
548
|
+
throw new Error(`tree-sitter.wasm not found`);
|
|
549
|
+
}
|
|
550
|
+
async loadLanguage(language) {
|
|
551
|
+
const cached = this.languages.get(language);
|
|
552
|
+
if (cached)
|
|
553
|
+
return cached;
|
|
554
|
+
if (this.failedLanguages.has(language))
|
|
555
|
+
return null;
|
|
556
|
+
const wasmFile = GRAMMAR_FILES[language];
|
|
557
|
+
if (!wasmFile)
|
|
558
|
+
return null;
|
|
559
|
+
try {
|
|
560
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
561
|
+
const mod = await import("web-tree-sitter");
|
|
562
|
+
const wasmPath = this.resolveWasm(`tree-sitter-wasms/out/${wasmFile}`);
|
|
563
|
+
const lang = await mod.Language.load(wasmPath);
|
|
564
|
+
if (this.parser) {
|
|
565
|
+
this.parser.setLanguage(lang);
|
|
566
|
+
const tree = this.parser.parse("# validate");
|
|
567
|
+
tree?.delete();
|
|
568
|
+
}
|
|
569
|
+
this.languages.set(language, lang);
|
|
570
|
+
return lang;
|
|
571
|
+
}
|
|
572
|
+
catch {
|
|
573
|
+
this.failedLanguages.add(language);
|
|
574
|
+
return null;
|
|
575
|
+
}
|
|
576
|
+
}
|
|
577
|
+
async parseFile(file) {
|
|
578
|
+
if (!this.parser)
|
|
579
|
+
return null;
|
|
580
|
+
const absPath = resolve(file);
|
|
581
|
+
const content = await this.readFileContent(absPath);
|
|
582
|
+
if (!content)
|
|
583
|
+
return null;
|
|
584
|
+
const cached = this.treeCache.get(absPath);
|
|
585
|
+
if (cached && cached.content === content) {
|
|
586
|
+
return cached.tree.copy();
|
|
587
|
+
}
|
|
588
|
+
const grammarKey = this.grammarKeyForFile(file);
|
|
589
|
+
const lang = await this.loadLanguage(grammarKey);
|
|
590
|
+
if (!lang)
|
|
591
|
+
return null;
|
|
592
|
+
this.parser.setLanguage(lang);
|
|
593
|
+
let tree;
|
|
594
|
+
try {
|
|
595
|
+
tree = this.parser.parse(content);
|
|
596
|
+
}
|
|
597
|
+
catch {
|
|
598
|
+
this.failedLanguages.add(grammarKey);
|
|
599
|
+
this.languages.delete(grammarKey);
|
|
600
|
+
return null;
|
|
601
|
+
}
|
|
602
|
+
if (!tree)
|
|
603
|
+
return null;
|
|
604
|
+
if (cached)
|
|
605
|
+
cached.tree.delete();
|
|
606
|
+
if (this.treeCache.size >= this.treeCacheMaxSize) {
|
|
607
|
+
const firstKey = this.treeCache.keys().next().value;
|
|
608
|
+
if (firstKey) {
|
|
609
|
+
this.treeCache.get(firstKey)?.tree.delete();
|
|
610
|
+
this.treeCache.delete(firstKey);
|
|
611
|
+
}
|
|
612
|
+
}
|
|
613
|
+
this.treeCache.set(absPath, { tree: tree.copy(), content });
|
|
614
|
+
return tree;
|
|
615
|
+
}
|
|
616
|
+
async readFileContent(file) {
|
|
617
|
+
const absPath = resolve(file);
|
|
618
|
+
if (this.cache) {
|
|
619
|
+
return this.cache.get(absPath);
|
|
620
|
+
}
|
|
621
|
+
try {
|
|
622
|
+
return await readFile(absPath, "utf-8");
|
|
623
|
+
}
|
|
624
|
+
catch {
|
|
625
|
+
return null;
|
|
626
|
+
}
|
|
627
|
+
}
|
|
628
|
+
detectLang(file) {
|
|
629
|
+
return detectLanguageFromPath(file);
|
|
630
|
+
}
|
|
631
|
+
grammarKeyForFile(file) {
|
|
632
|
+
const language = this.detectLang(file);
|
|
633
|
+
if (language === "typescript")
|
|
634
|
+
return "tsx";
|
|
635
|
+
return language;
|
|
636
|
+
}
|
|
637
|
+
captureToKind(captureName) {
|
|
638
|
+
switch (captureName) {
|
|
639
|
+
case "func":
|
|
640
|
+
return "function";
|
|
641
|
+
case "method":
|
|
642
|
+
return "method";
|
|
643
|
+
case "class":
|
|
644
|
+
case "struct":
|
|
645
|
+
return "class";
|
|
646
|
+
case "iface":
|
|
647
|
+
case "trait":
|
|
648
|
+
return "interface";
|
|
649
|
+
case "type":
|
|
650
|
+
return "type";
|
|
651
|
+
case "var":
|
|
652
|
+
return "variable";
|
|
653
|
+
case "impl":
|
|
654
|
+
return "class";
|
|
655
|
+
default:
|
|
656
|
+
return "unknown";
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
}
|
|
660
|
+
function extractImportSpecifiers(node, language) {
|
|
661
|
+
const specifiers = [];
|
|
662
|
+
collectSpecifiers(node, language, specifiers);
|
|
663
|
+
return specifiers;
|
|
664
|
+
}
|
|
665
|
+
function collectSpecifiers(node, language, out) {
|
|
666
|
+
const type = node.type;
|
|
667
|
+
if (language === "typescript" || language === "javascript") {
|
|
668
|
+
if (type === "import_specifier") {
|
|
669
|
+
const name = node.childForFieldName("name");
|
|
670
|
+
if (name)
|
|
671
|
+
out.push(name.text);
|
|
672
|
+
return;
|
|
673
|
+
}
|
|
674
|
+
if (type === "identifier" && node.parent?.type === "import_clause") {
|
|
675
|
+
out.push(node.text);
|
|
676
|
+
return;
|
|
677
|
+
}
|
|
678
|
+
if (type === "namespace_import") {
|
|
679
|
+
const name = node.namedChildren.find((c) => c != null && c.type === "identifier");
|
|
680
|
+
if (name)
|
|
681
|
+
out.push(name.text);
|
|
682
|
+
return;
|
|
683
|
+
}
|
|
684
|
+
}
|
|
685
|
+
else if (language === "python") {
|
|
686
|
+
if (type === "aliased_import") {
|
|
687
|
+
const name = node.childForFieldName("name");
|
|
688
|
+
if (name) {
|
|
689
|
+
const text = name.text;
|
|
690
|
+
const last = text.split(".").pop();
|
|
691
|
+
if (last)
|
|
692
|
+
out.push(last);
|
|
693
|
+
}
|
|
694
|
+
return;
|
|
695
|
+
}
|
|
696
|
+
if (type === "dotted_name" && node.parent?.type === "import_from_statement") {
|
|
697
|
+
const field = node.parent.childForFieldName("module_name");
|
|
698
|
+
if (node !== field) {
|
|
699
|
+
const last = node.text.split(".").pop();
|
|
700
|
+
if (last)
|
|
701
|
+
out.push(last);
|
|
702
|
+
return;
|
|
703
|
+
}
|
|
704
|
+
}
|
|
705
|
+
if (type === "dotted_name" && node.parent?.type === "import_statement") {
|
|
706
|
+
const last = node.text.split(".").pop();
|
|
707
|
+
if (last)
|
|
708
|
+
out.push(last);
|
|
709
|
+
return;
|
|
710
|
+
}
|
|
711
|
+
}
|
|
712
|
+
else if (language === "rust") {
|
|
713
|
+
if (type === "use_as_clause") {
|
|
714
|
+
const path = node.childForFieldName("path");
|
|
715
|
+
if (path) {
|
|
716
|
+
const name = path.childForFieldName("name");
|
|
717
|
+
out.push(name ? name.text : path.text);
|
|
718
|
+
return;
|
|
719
|
+
}
|
|
720
|
+
}
|
|
721
|
+
if (type === "identifier" &&
|
|
722
|
+
(node.parent?.type === "use_list" ||
|
|
723
|
+
node.parent?.type === "scoped_use_list" ||
|
|
724
|
+
node.parent?.type === "use_declaration")) {
|
|
725
|
+
out.push(node.text);
|
|
726
|
+
return;
|
|
727
|
+
}
|
|
728
|
+
if (type === "scoped_identifier" && !node.parent?.type?.includes("use_list")) {
|
|
729
|
+
const name = node.childForFieldName("name");
|
|
730
|
+
if (name)
|
|
731
|
+
out.push(name.text);
|
|
732
|
+
return;
|
|
733
|
+
}
|
|
734
|
+
}
|
|
735
|
+
else if (language === "go") {
|
|
736
|
+
if (type === "import_spec") {
|
|
737
|
+
const name = node.childForFieldName("name");
|
|
738
|
+
const path = node.childForFieldName("path");
|
|
739
|
+
if (name && name.text !== ".") {
|
|
740
|
+
out.push(name.text);
|
|
741
|
+
}
|
|
742
|
+
else if (path) {
|
|
743
|
+
const raw = path.text.replace(/['"]/g, "");
|
|
744
|
+
const last = raw.split("/").pop();
|
|
745
|
+
if (last)
|
|
746
|
+
out.push(last);
|
|
747
|
+
}
|
|
748
|
+
return;
|
|
749
|
+
}
|
|
750
|
+
if (type === "interpreted_string_literal") {
|
|
751
|
+
const raw = node.text.replace(/['"]/g, "");
|
|
752
|
+
const last = raw.split("/").pop();
|
|
753
|
+
if (last)
|
|
754
|
+
out.push(last);
|
|
755
|
+
return;
|
|
756
|
+
}
|
|
757
|
+
}
|
|
758
|
+
const childCount = node.namedChildCount;
|
|
759
|
+
for (let i = 0; i < childCount; i++) {
|
|
760
|
+
const child = node.namedChild(i);
|
|
761
|
+
if (child)
|
|
762
|
+
collectSpecifiers(child, language, out);
|
|
763
|
+
}
|
|
764
|
+
}
|
|
765
|
+
function isPublicSymbol(name, sourceLine, language, _filePath) {
|
|
766
|
+
const trimmed = sourceLine.trimStart();
|
|
767
|
+
switch (language) {
|
|
768
|
+
case "go":
|
|
769
|
+
return /^[A-Z]/.test(name);
|
|
770
|
+
case "rust":
|
|
771
|
+
case "zig":
|
|
772
|
+
return trimmed.startsWith("pub ");
|
|
773
|
+
case "python":
|
|
774
|
+
case "dart":
|
|
775
|
+
return !name.startsWith("_");
|
|
776
|
+
case "java":
|
|
777
|
+
case "kotlin":
|
|
778
|
+
case "scala":
|
|
779
|
+
case "swift":
|
|
780
|
+
case "csharp":
|
|
781
|
+
return !/\bprivate\b/.test(trimmed);
|
|
782
|
+
case "php":
|
|
783
|
+
return !/\b(?:private|protected)\b/.test(trimmed);
|
|
784
|
+
case "ruby":
|
|
785
|
+
case "lua":
|
|
786
|
+
case "bash":
|
|
787
|
+
case "tlaplus":
|
|
788
|
+
case "rescript":
|
|
789
|
+
case "ocaml":
|
|
790
|
+
return true;
|
|
791
|
+
case "elixir":
|
|
792
|
+
return !trimmed.startsWith("defp ");
|
|
793
|
+
case "elisp":
|
|
794
|
+
return !name.startsWith("--");
|
|
795
|
+
default:
|
|
796
|
+
return true;
|
|
797
|
+
}
|
|
798
|
+
}
|
|
799
|
+
//# sourceMappingURL=tree-sitter.js.map
|