@zvec/zvec-grep 0.2.2 → 0.3.0-rc.2
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 -252
- package/bin/zg.exe +3 -0
- package/install.cjs +510 -0
- package/package.json +22 -72
- package/platforms.json +92 -0
- package/plugins.cjs +183 -0
- package/README_CN.md +0 -239
- package/dist/authorization/index.d.ts +0 -7
- package/dist/authorization/index.js +0 -7
- package/dist/authorization/index.js.map +0 -1
- package/dist/authorization/manager.d.ts +0 -8
- package/dist/authorization/manager.js +0 -19
- package/dist/authorization/manager.js.map +0 -1
- package/dist/authorization/operation.d.ts +0 -7
- package/dist/authorization/operation.js +0 -50
- package/dist/authorization/operation.js.map +0 -1
- package/dist/authorization/planner.d.ts +0 -21
- package/dist/authorization/planner.js +0 -97
- package/dist/authorization/planner.js.map +0 -1
- package/dist/authorization/prompt.d.ts +0 -12
- package/dist/authorization/prompt.js +0 -63
- package/dist/authorization/prompt.js.map +0 -1
- package/dist/authorization/store.d.ts +0 -20
- package/dist/authorization/store.js +0 -251
- package/dist/authorization/store.js.map +0 -1
- package/dist/authorization/target.d.ts +0 -15
- package/dist/authorization/target.js +0 -49
- package/dist/authorization/target.js.map +0 -1
- package/dist/authorization/types.d.ts +0 -61
- package/dist/authorization/types.js +0 -2
- package/dist/authorization/types.js.map +0 -1
- package/dist/cli/args.d.ts +0 -5
- package/dist/cli/args.js +0 -1210
- package/dist/cli/args.js.map +0 -1
- package/dist/cli/auth.d.ts +0 -21
- package/dist/cli/auth.js +0 -209
- package/dist/cli/auth.js.map +0 -1
- package/dist/cli/commands.d.ts +0 -4
- package/dist/cli/commands.js +0 -742
- package/dist/cli/commands.js.map +0 -1
- package/dist/cli/errors.d.ts +0 -9
- package/dist/cli/errors.js +0 -131
- package/dist/cli/errors.js.map +0 -1
- package/dist/cli/format/context.d.ts +0 -9
- package/dist/cli/format/context.js +0 -786
- package/dist/cli/format/context.js.map +0 -1
- package/dist/cli/format/debug.d.ts +0 -4
- package/dist/cli/format/debug.js +0 -60
- package/dist/cli/format/debug.js.map +0 -1
- package/dist/cli/format/highlight.d.ts +0 -3
- package/dist/cli/format/highlight.js +0 -106
- package/dist/cli/format/highlight.js.map +0 -1
- package/dist/cli/format/progress.d.ts +0 -13
- package/dist/cli/format/progress.js +0 -290
- package/dist/cli/format/progress.js.map +0 -1
- package/dist/cli/format/range.d.ts +0 -3
- package/dist/cli/format/range.js +0 -24
- package/dist/cli/format/range.js.map +0 -1
- package/dist/cli/format/status.d.ts +0 -83
- package/dist/cli/format/status.js +0 -530
- package/dist/cli/format/status.js.map +0 -1
- package/dist/cli/help.d.ts +0 -1
- package/dist/cli/help.js +0 -528
- package/dist/cli/help.js.map +0 -1
- package/dist/cli/index.d.ts +0 -2
- package/dist/cli/index.js +0 -34
- package/dist/cli/index.js.map +0 -1
- package/dist/cli/install.d.ts +0 -4
- package/dist/cli/install.js +0 -1661
- package/dist/cli/install.js.map +0 -1
- package/dist/cli/managed-rg.d.ts +0 -10
- package/dist/cli/managed-rg.js +0 -337
- package/dist/cli/managed-rg.js.map +0 -1
- package/dist/cli/server-search.d.ts +0 -3
- package/dist/cli/server-search.js +0 -12
- package/dist/cli/server-search.js.map +0 -1
- package/dist/cli/types.d.ts +0 -87
- package/dist/cli/types.js +0 -10
- package/dist/cli/types.js.map +0 -1
- package/dist/cli/version.d.ts +0 -1
- package/dist/cli/version.js +0 -13
- package/dist/cli/version.js.map +0 -1
- package/dist/client/daemon-client.d.ts +0 -31
- package/dist/client/daemon-client.js +0 -203
- package/dist/client/daemon-client.js.map +0 -1
- package/dist/client/mode-router.d.ts +0 -9
- package/dist/client/mode-router.js +0 -28
- package/dist/client/mode-router.js.map +0 -1
- package/dist/client/search-policy.d.ts +0 -11
- package/dist/client/search-policy.js +0 -15
- package/dist/client/search-policy.js.map +0 -1
- package/dist/daemon/backend.d.ts +0 -78
- package/dist/daemon/backend.js +0 -1089
- package/dist/daemon/backend.js.map +0 -1
- package/dist/daemon/change-set.d.ts +0 -30
- package/dist/daemon/change-set.js +0 -163
- package/dist/daemon/change-set.js.map +0 -1
- package/dist/daemon/config.d.ts +0 -27
- package/dist/daemon/config.js +0 -107
- package/dist/daemon/config.js.map +0 -1
- package/dist/daemon/errors.d.ts +0 -5
- package/dist/daemon/errors.js +0 -11
- package/dist/daemon/errors.js.map +0 -1
- package/dist/daemon/http-server.d.ts +0 -30
- package/dist/daemon/http-server.js +0 -288
- package/dist/daemon/http-server.js.map +0 -1
- package/dist/daemon/index-coordinator.d.ts +0 -22
- package/dist/daemon/index-coordinator.js +0 -55
- package/dist/daemon/index-coordinator.js.map +0 -1
- package/dist/daemon/job-scheduler.d.ts +0 -73
- package/dist/daemon/job-scheduler.js +0 -434
- package/dist/daemon/job-scheduler.js.map +0 -1
- package/dist/daemon/logger.d.ts +0 -9
- package/dist/daemon/logger.js +0 -53
- package/dist/daemon/logger.js.map +0 -1
- package/dist/daemon/model-pool.d.ts +0 -45
- package/dist/daemon/model-pool.js +0 -187
- package/dist/daemon/model-pool.js.map +0 -1
- package/dist/daemon/root-lease.d.ts +0 -14
- package/dist/daemon/root-lease.js +0 -197
- package/dist/daemon/root-lease.js.map +0 -1
- package/dist/daemon/root-runtime.d.ts +0 -80
- package/dist/daemon/root-runtime.js +0 -340
- package/dist/daemon/root-runtime.js.map +0 -1
- package/dist/daemon/runtime-manager.d.ts +0 -47
- package/dist/daemon/runtime-manager.js +0 -252
- package/dist/daemon/runtime-manager.js.map +0 -1
- package/dist/daemon/runtime.d.ts +0 -12
- package/dist/daemon/runtime.js +0 -104
- package/dist/daemon/runtime.js.map +0 -1
- package/dist/daemon/server-controller.d.ts +0 -38
- package/dist/daemon/server-controller.js +0 -327
- package/dist/daemon/server-controller.js.map +0 -1
- package/dist/daemon/watch-manager.d.ts +0 -55
- package/dist/daemon/watch-manager.js +0 -347
- package/dist/daemon/watch-manager.js.map +0 -1
- package/dist/daemon/workspace-read-session-cache.d.ts +0 -31
- package/dist/daemon/workspace-read-session-cache.js +0 -115
- package/dist/daemon/workspace-read-session-cache.js.map +0 -1
- package/dist/engine/code-formats.d.ts +0 -3
- package/dist/engine/code-formats.js +0 -14
- package/dist/engine/code-formats.js.map +0 -1
- package/dist/engine/config.d.ts +0 -50
- package/dist/engine/config.js +0 -321
- package/dist/engine/config.js.map +0 -1
- package/dist/engine/errors.d.ts +0 -20
- package/dist/engine/errors.js +0 -51
- package/dist/engine/errors.js.map +0 -1
- package/dist/engine/extraction/code/adapter.d.ts +0 -19
- package/dist/engine/extraction/code/adapter.js +0 -24
- package/dist/engine/extraction/code/adapter.js.map +0 -1
- package/dist/engine/extraction/code/extractor.d.ts +0 -13
- package/dist/engine/extraction/code/extractor.js +0 -696
- package/dist/engine/extraction/code/extractor.js.map +0 -1
- package/dist/engine/extraction/code/families/c-family.d.ts +0 -2
- package/dist/engine/extraction/code/families/c-family.js +0 -122
- package/dist/engine/extraction/code/families/c-family.js.map +0 -1
- package/dist/engine/extraction/code/families/js-ts.d.ts +0 -12
- package/dist/engine/extraction/code/families/js-ts.js +0 -118
- package/dist/engine/extraction/code/families/js-ts.js.map +0 -1
- package/dist/engine/extraction/code/families/metadata.d.ts +0 -8
- package/dist/engine/extraction/code/families/metadata.js +0 -86
- package/dist/engine/extraction/code/families/metadata.js.map +0 -1
- package/dist/engine/extraction/code/families/name-field.d.ts +0 -3
- package/dist/engine/extraction/code/families/name-field.js +0 -22
- package/dist/engine/extraction/code/families/name-field.js.map +0 -1
- package/dist/engine/extraction/code/languages/c.d.ts +0 -1
- package/dist/engine/extraction/code/languages/c.js +0 -12
- package/dist/engine/extraction/code/languages/c.js.map +0 -1
- package/dist/engine/extraction/code/languages/cpp.d.ts +0 -1
- package/dist/engine/extraction/code/languages/cpp.js +0 -18
- package/dist/engine/extraction/code/languages/cpp.js.map +0 -1
- package/dist/engine/extraction/code/languages/go.d.ts +0 -2
- package/dist/engine/extraction/code/languages/go.js +0 -70
- package/dist/engine/extraction/code/languages/go.js.map +0 -1
- package/dist/engine/extraction/code/languages/java.d.ts +0 -1
- package/dist/engine/extraction/code/languages/java.js +0 -17
- package/dist/engine/extraction/code/languages/java.js.map +0 -1
- package/dist/engine/extraction/code/languages/javascript.d.ts +0 -2
- package/dist/engine/extraction/code/languages/javascript.js +0 -23
- package/dist/engine/extraction/code/languages/javascript.js.map +0 -1
- package/dist/engine/extraction/code/languages/python.d.ts +0 -2
- package/dist/engine/extraction/code/languages/python.js +0 -52
- package/dist/engine/extraction/code/languages/python.js.map +0 -1
- package/dist/engine/extraction/code/languages/rust.d.ts +0 -2
- package/dist/engine/extraction/code/languages/rust.js +0 -25
- package/dist/engine/extraction/code/languages/rust.js.map +0 -1
- package/dist/engine/extraction/code/languages/typescript.d.ts +0 -2
- package/dist/engine/extraction/code/languages/typescript.js +0 -37
- package/dist/engine/extraction/code/languages/typescript.js.map +0 -1
- package/dist/engine/extraction/code/tree-sitter/grammar.d.ts +0 -4
- package/dist/engine/extraction/code/tree-sitter/grammar.js +0 -49
- package/dist/engine/extraction/code/tree-sitter/grammar.js.map +0 -1
- package/dist/engine/extraction/code/tree-sitter/nodes.d.ts +0 -3
- package/dist/engine/extraction/code/tree-sitter/nodes.js +0 -27
- package/dist/engine/extraction/code/tree-sitter/nodes.js.map +0 -1
- package/dist/engine/extraction/code/tree-sitter/parser.d.ts +0 -2
- package/dist/engine/extraction/code/tree-sitter/parser.js +0 -31
- package/dist/engine/extraction/code/tree-sitter/parser.js.map +0 -1
- package/dist/engine/extraction/ids.d.ts +0 -1
- package/dist/engine/extraction/ids.js +0 -5
- package/dist/engine/extraction/ids.js.map +0 -1
- package/dist/engine/extraction/image/extractor.d.ts +0 -5
- package/dist/engine/extraction/image/extractor.js +0 -35
- package/dist/engine/extraction/image/extractor.js.map +0 -1
- package/dist/engine/extraction/index.d.ts +0 -4
- package/dist/engine/extraction/index.js +0 -3
- package/dist/engine/extraction/index.js.map +0 -1
- package/dist/engine/extraction/markdown/extractor.d.ts +0 -7
- package/dist/engine/extraction/markdown/extractor.js +0 -362
- package/dist/engine/extraction/markdown/extractor.js.map +0 -1
- package/dist/engine/extraction/runtime.d.ts +0 -9
- package/dist/engine/extraction/runtime.js +0 -37
- package/dist/engine/extraction/runtime.js.map +0 -1
- package/dist/engine/extraction/source.d.ts +0 -18
- package/dist/engine/extraction/source.js +0 -22
- package/dist/engine/extraction/source.js.map +0 -1
- package/dist/engine/extraction/text/extractor.d.ts +0 -7
- package/dist/engine/extraction/text/extractor.js +0 -168
- package/dist/engine/extraction/text/extractor.js.map +0 -1
- package/dist/engine/extraction/types.d.ts +0 -4
- package/dist/engine/extraction/types.js +0 -2
- package/dist/engine/extraction/types.js.map +0 -1
- package/dist/engine/extraction/vector-content.d.ts +0 -5
- package/dist/engine/extraction/vector-content.js +0 -83
- package/dist/engine/extraction/vector-content.js.map +0 -1
- package/dist/engine/file-size-policy.d.ts +0 -6
- package/dist/engine/file-size-policy.js +0 -20
- package/dist/engine/file-size-policy.js.map +0 -1
- package/dist/engine/file-type.d.ts +0 -15
- package/dist/engine/file-type.js +0 -152
- package/dist/engine/file-type.js.map +0 -1
- package/dist/engine/index-status.d.ts +0 -9
- package/dist/engine/index-status.js +0 -38
- package/dist/engine/index-status.js.map +0 -1
- package/dist/engine/manifest.d.ts +0 -13
- package/dist/engine/manifest.js +0 -124
- package/dist/engine/manifest.js.map +0 -1
- package/dist/engine/models/artifact-cache-lock.d.ts +0 -16
- package/dist/engine/models/artifact-cache-lock.js +0 -228
- package/dist/engine/models/artifact-cache-lock.js.map +0 -1
- package/dist/engine/models/artifact-downloader.d.ts +0 -77
- package/dist/engine/models/artifact-downloader.js +0 -766
- package/dist/engine/models/artifact-downloader.js.map +0 -1
- package/dist/engine/models/backends/llama-cpp.d.ts +0 -99
- package/dist/engine/models/backends/llama-cpp.js +0 -573
- package/dist/engine/models/backends/llama-cpp.js.map +0 -1
- package/dist/engine/models/backends/model2vec-runtime.d.ts +0 -63
- package/dist/engine/models/backends/model2vec-runtime.js +0 -112
- package/dist/engine/models/backends/model2vec-runtime.js.map +0 -1
- package/dist/engine/models/backends/model2vec-tokenizer.d.ts +0 -2
- package/dist/engine/models/backends/model2vec-tokenizer.js +0 -42
- package/dist/engine/models/backends/model2vec-tokenizer.js.map +0 -1
- package/dist/engine/models/backends/model2vec-worker-pool.d.ts +0 -25
- package/dist/engine/models/backends/model2vec-worker-pool.js +0 -264
- package/dist/engine/models/backends/model2vec-worker-pool.js.map +0 -1
- package/dist/engine/models/backends/model2vec-worker.d.ts +0 -1
- package/dist/engine/models/backends/model2vec-worker.js +0 -41
- package/dist/engine/models/backends/model2vec-worker.js.map +0 -1
- package/dist/engine/models/backends/model2vec.d.ts +0 -38
- package/dist/engine/models/backends/model2vec.js +0 -344
- package/dist/engine/models/backends/model2vec.js.map +0 -1
- package/dist/engine/models/backends/qwen.d.ts +0 -44
- package/dist/engine/models/backends/qwen.js +0 -411
- package/dist/engine/models/backends/qwen.js.map +0 -1
- package/dist/engine/models/backends/transformers-js.d.ts +0 -87
- package/dist/engine/models/backends/transformers-js.js +0 -360
- package/dist/engine/models/backends/transformers-js.js.map +0 -1
- package/dist/engine/models/catalog.d.ts +0 -490
- package/dist/engine/models/catalog.js +0 -522
- package/dist/engine/models/catalog.js.map +0 -1
- package/dist/engine/models/download-progress.d.ts +0 -16
- package/dist/engine/models/download-progress.js +0 -47
- package/dist/engine/models/download-progress.js.map +0 -1
- package/dist/engine/models/embeddings.d.ts +0 -69
- package/dist/engine/models/embeddings.js +0 -125
- package/dist/engine/models/embeddings.js.map +0 -1
- package/dist/engine/models/factory.d.ts +0 -2
- package/dist/engine/models/factory.js +0 -51
- package/dist/engine/models/factory.js.map +0 -1
- package/dist/engine/models/index.d.ts +0 -4
- package/dist/engine/models/index.js +0 -5
- package/dist/engine/models/index.js.map +0 -1
- package/dist/engine/models/ranking.d.ts +0 -19
- package/dist/engine/models/ranking.js +0 -2
- package/dist/engine/models/ranking.js.map +0 -1
- package/dist/engine/models/resolution.d.ts +0 -8
- package/dist/engine/models/resolution.js +0 -22
- package/dist/engine/models/resolution.js.map +0 -1
- package/dist/engine/pipeline/indexing/index.d.ts +0 -14
- package/dist/engine/pipeline/indexing/index.js +0 -1217
- package/dist/engine/pipeline/indexing/index.js.map +0 -1
- package/dist/engine/pipeline/indexing/input-budget.d.ts +0 -2
- package/dist/engine/pipeline/indexing/input-budget.js +0 -51
- package/dist/engine/pipeline/indexing/input-budget.js.map +0 -1
- package/dist/engine/pipeline/indexing/root-paths.d.ts +0 -7
- package/dist/engine/pipeline/indexing/root-paths.js +0 -148
- package/dist/engine/pipeline/indexing/root-paths.js.map +0 -1
- package/dist/engine/pipeline/indexing/scanner/index.d.ts +0 -14
- package/dist/engine/pipeline/indexing/scanner/index.js +0 -776
- package/dist/engine/pipeline/indexing/scanner/index.js.map +0 -1
- package/dist/engine/pipeline/search/index.d.ts +0 -12
- package/dist/engine/pipeline/search/index.js +0 -811
- package/dist/engine/pipeline/search/index.js.map +0 -1
- package/dist/engine/service/index.d.ts +0 -3
- package/dist/engine/service/index.js +0 -2
- package/dist/engine/service/index.js.map +0 -1
- package/dist/engine/service/lexical.d.ts +0 -28
- package/dist/engine/service/lexical.js +0 -446
- package/dist/engine/service/lexical.js.map +0 -1
- package/dist/engine/service/root.d.ts +0 -15
- package/dist/engine/service/root.js +0 -57
- package/dist/engine/service/root.js.map +0 -1
- package/dist/engine/service/structure-enrichment.d.ts +0 -8
- package/dist/engine/service/structure-enrichment.js +0 -178
- package/dist/engine/service/structure-enrichment.js.map +0 -1
- package/dist/engine/service/types.d.ts +0 -210
- package/dist/engine/service/types.js +0 -2
- package/dist/engine/service/types.js.map +0 -1
- package/dist/engine/service/workspace-index.d.ts +0 -26
- package/dist/engine/service/workspace-index.js +0 -157
- package/dist/engine/service/workspace-index.js.map +0 -1
- package/dist/engine/service/zvec-grep.d.ts +0 -13
- package/dist/engine/service/zvec-grep.js +0 -1393
- package/dist/engine/service/zvec-grep.js.map +0 -1
- package/dist/engine/storage/index.d.ts +0 -53
- package/dist/engine/storage/index.js +0 -3
- package/dist/engine/storage/index.js.map +0 -1
- package/dist/engine/storage/layout.d.ts +0 -10
- package/dist/engine/storage/layout.js +0 -29
- package/dist/engine/storage/layout.js.map +0 -1
- package/dist/engine/storage/zvec.d.ts +0 -4
- package/dist/engine/storage/zvec.js +0 -976
- package/dist/engine/storage/zvec.js.map +0 -1
- package/dist/engine/types.d.ts +0 -303
- package/dist/engine/types.js +0 -14
- package/dist/engine/types.js.map +0 -1
- package/dist/engine/utils/atomic-file.d.ts +0 -3
- package/dist/engine/utils/atomic-file.js +0 -39
- package/dist/engine/utils/atomic-file.js.map +0 -1
- package/dist/engine/utils/daemon-lease.d.ts +0 -17
- package/dist/engine/utils/daemon-lease.js +0 -175
- package/dist/engine/utils/daemon-lease.js.map +0 -1
- package/dist/engine/utils/file-selection.d.ts +0 -10
- package/dist/engine/utils/file-selection.js +0 -157
- package/dist/engine/utils/file-selection.js.map +0 -1
- package/dist/engine/utils/glob.d.ts +0 -9
- package/dist/engine/utils/glob.js +0 -208
- package/dist/engine/utils/glob.js.map +0 -1
- package/dist/engine/utils/hash.d.ts +0 -2
- package/dist/engine/utils/hash.js +0 -8
- package/dist/engine/utils/hash.js.map +0 -1
- package/dist/engine/utils/json.d.ts +0 -8
- package/dist/engine/utils/json.js +0 -83
- package/dist/engine/utils/json.js.map +0 -1
- package/dist/engine/utils/lock.d.ts +0 -19
- package/dist/engine/utils/lock.js +0 -254
- package/dist/engine/utils/lock.js.map +0 -1
- package/dist/engine/utils/path.d.ts +0 -4
- package/dist/engine/utils/path.js +0 -18
- package/dist/engine/utils/path.js.map +0 -1
- package/dist/engine/utils/timing.d.ts +0 -19
- package/dist/engine/utils/timing.js +0 -87
- package/dist/engine/utils/timing.js.map +0 -1
- package/dist/index-progress.d.ts +0 -10
- package/dist/index-progress.js +0 -159
- package/dist/index-progress.js.map +0 -1
- package/dist/index.d.ts +0 -6
- package/dist/index.js +0 -4
- package/dist/index.js.map +0 -1
- package/dist/mcp/http-transport.d.ts +0 -27
- package/dist/mcp/http-transport.js +0 -182
- package/dist/mcp/http-transport.js.map +0 -1
- package/dist/mcp/input-normalization.d.ts +0 -38
- package/dist/mcp/input-normalization.js +0 -104
- package/dist/mcp/input-normalization.js.map +0 -1
- package/dist/mcp/progress-heartbeat.d.ts +0 -17
- package/dist/mcp/progress-heartbeat.js +0 -46
- package/dist/mcp/progress-heartbeat.js.map +0 -1
- package/dist/mcp/request-metadata.d.ts +0 -2
- package/dist/mcp/request-metadata.js +0 -11
- package/dist/mcp/request-metadata.js.map +0 -1
- package/dist/mcp/request-state.d.ts +0 -40
- package/dist/mcp/request-state.js +0 -210
- package/dist/mcp/request-state.js.map +0 -1
- package/dist/mcp/result-format.d.ts +0 -13
- package/dist/mcp/result-format.js +0 -75
- package/dist/mcp/result-format.js.map +0 -1
- package/dist/mcp/schemas.d.ts +0 -668
- package/dist/mcp/schemas.js +0 -512
- package/dist/mcp/schemas.js.map +0 -1
- package/dist/mcp/stdio-bridge.d.ts +0 -15
- package/dist/mcp/stdio-bridge.js +0 -190
- package/dist/mcp/stdio-bridge.js.map +0 -1
- package/dist/mcp/tools.d.ts +0 -153
- package/dist/mcp/tools.js +0 -488
- package/dist/mcp/tools.js.map +0 -1
- package/dist/mcp/toolset.d.ts +0 -5
- package/dist/mcp/toolset.js +0 -12
- package/dist/mcp/toolset.js.map +0 -1
- package/dist/observability/trace-context.d.ts +0 -11
- package/dist/observability/trace-context.js +0 -138
- package/dist/observability/trace-context.js.map +0 -1
- package/dist/prompts/zvec-grep-guidance.d.ts +0 -2
- package/dist/prompts/zvec-grep-guidance.js +0 -9
- package/dist/prompts/zvec-grep-guidance.js.map +0 -1
- package/docs/01-agents.md +0 -209
- package/docs/02-cli.md +0 -247
- package/docs/03-mcp.md +0 -185
- package/docs/04-pipeline.md +0 -226
- package/docs/05-architecture.md +0 -86
- package/docs/06-server.md +0 -233
- package/docs/07-embedding.md +0 -209
- package/docs/08-roadmap.md +0 -85
- package/docs/README.md +0 -53
|
@@ -1,696 +0,0 @@
|
|
|
1
|
-
import { EngineError } from "../../errors.js";
|
|
2
|
-
import { COMPONENT_CODE_FORMATS } from "../../code-formats.js";
|
|
3
|
-
import { makeEntityId } from "../ids.js";
|
|
4
|
-
import { validateSourceFile } from "../source.js";
|
|
5
|
-
import { hasGrammar } from "./tree-sitter/grammar.js";
|
|
6
|
-
import { withParser } from "./tree-sitter/parser.js";
|
|
7
|
-
import { extractPlainTextFragments } from "../text/extractor.js";
|
|
8
|
-
import { chunkOptionsForMetadata } from "../vector-content.js";
|
|
9
|
-
import { resolveAdapter } from "./adapter.js";
|
|
10
|
-
import { hasJavascriptTypescriptFunctionValue } from "./families/js-ts.js";
|
|
11
|
-
const DEFAULT_CODE_CHUNK_CHARS = 3600;
|
|
12
|
-
const DEFAULT_CODE_CHUNK_OVERLAP_CHARS = 540;
|
|
13
|
-
const COMPONENT_CODE_FORMAT_SET = new Set(COMPONENT_CODE_FORMATS);
|
|
14
|
-
export class CodeExtractor {
|
|
15
|
-
async extract(source, options = {}) {
|
|
16
|
-
return (await this.extractForIndexing(source, options)).map((item) => item.fragment);
|
|
17
|
-
}
|
|
18
|
-
async extractForIndexing(source, options = {}) {
|
|
19
|
-
if (source.kind !== "text" || source.file.kind !== "code") {
|
|
20
|
-
return [];
|
|
21
|
-
}
|
|
22
|
-
validateSourceFile(source);
|
|
23
|
-
const chunkOptions = resolveCodeChunkOptions(options);
|
|
24
|
-
if (isScriptBlockFormat(source.file.format)) {
|
|
25
|
-
const fragments = await this.extractScriptBlocks(source, chunkOptions);
|
|
26
|
-
return fragments.length > 0
|
|
27
|
-
? fragments
|
|
28
|
-
: this.fallback(source, chunkOptions);
|
|
29
|
-
}
|
|
30
|
-
const adapter = resolveAdapter(source.file.format);
|
|
31
|
-
if (!hasGrammar(source.file.format) || !adapter) {
|
|
32
|
-
return this.fallback(source, chunkOptions);
|
|
33
|
-
}
|
|
34
|
-
const extracted = await withParser(source.text, source.file.format, (tree) => {
|
|
35
|
-
const collected = [];
|
|
36
|
-
walkCodeNode(tree.rootNode, adapter, [], collected);
|
|
37
|
-
const output = [];
|
|
38
|
-
let entityIdIndex = 0;
|
|
39
|
-
const appendEntity = (entity) => {
|
|
40
|
-
const fragments = codeEntityToSearchFragments(source, adapter, entity, chunkOptions.maxChunkChars, chunkOptions.chunkOverlapChars);
|
|
41
|
-
const majorId = fragments[0]?.group === ""
|
|
42
|
-
? makeEntityId(source.file.id, entityIdIndex)
|
|
43
|
-
: null;
|
|
44
|
-
for (const item of fragments) {
|
|
45
|
-
const id = makeEntityId(source.file.id, entityIdIndex);
|
|
46
|
-
const { embeddingText, ...fragment } = item;
|
|
47
|
-
output.push({
|
|
48
|
-
fragment: {
|
|
49
|
-
id,
|
|
50
|
-
...fragment,
|
|
51
|
-
group: fragment.group === "" ? id : (majorId ?? fragment.group),
|
|
52
|
-
},
|
|
53
|
-
embeddingText,
|
|
54
|
-
});
|
|
55
|
-
entityIdIndex++;
|
|
56
|
-
}
|
|
57
|
-
};
|
|
58
|
-
for (const entity of collected) {
|
|
59
|
-
appendEntity(entity);
|
|
60
|
-
}
|
|
61
|
-
return output;
|
|
62
|
-
});
|
|
63
|
-
if (!extracted || extracted.length === 0) {
|
|
64
|
-
return this.fallback(source, chunkOptions);
|
|
65
|
-
}
|
|
66
|
-
return extracted;
|
|
67
|
-
}
|
|
68
|
-
fallback(source, options) {
|
|
69
|
-
return extractPlainTextFragments(source, options.maxChunkChars, options.chunkOverlapChars).map((fragment) => ({ fragment }));
|
|
70
|
-
}
|
|
71
|
-
async extractScriptBlocks(source, options) {
|
|
72
|
-
const fragments = [];
|
|
73
|
-
for (const block of findScriptBlocks(source.text)) {
|
|
74
|
-
const blockFile = {
|
|
75
|
-
...source.file,
|
|
76
|
-
format: block.format,
|
|
77
|
-
};
|
|
78
|
-
const blockFragments = await this.extractForIndexing({
|
|
79
|
-
kind: "text",
|
|
80
|
-
file: blockFile,
|
|
81
|
-
text: block.text,
|
|
82
|
-
}, options);
|
|
83
|
-
fragments.push(...remapScriptBlockFragments(source.file.id, blockFragments, fragments.length, block.startLine, block.startOffset));
|
|
84
|
-
}
|
|
85
|
-
return fragments;
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
function resolveCodeChunkOptions(options) {
|
|
89
|
-
const maxChunkChars = options.maxChunkChars ?? DEFAULT_CODE_CHUNK_CHARS;
|
|
90
|
-
const chunkOverlapChars = options.chunkOverlapChars ?? DEFAULT_CODE_CHUNK_OVERLAP_CHARS;
|
|
91
|
-
if (!Number.isInteger(maxChunkChars) || maxChunkChars <= 0) {
|
|
92
|
-
throw new EngineError("Code extractor requires a positive integer chunk size", {
|
|
93
|
-
code: "ZVEC_GREP.ENGINE.EXTRACTORS.CODE_INVALID_CHUNK_SIZE",
|
|
94
|
-
context: `maxChunkChars=${maxChunkChars}`,
|
|
95
|
-
});
|
|
96
|
-
}
|
|
97
|
-
if (!Number.isInteger(chunkOverlapChars) ||
|
|
98
|
-
chunkOverlapChars < 0 ||
|
|
99
|
-
chunkOverlapChars >= maxChunkChars) {
|
|
100
|
-
throw new EngineError("Code extractor requires overlap to be smaller than chunk size", {
|
|
101
|
-
code: "ZVEC_GREP.ENGINE.EXTRACTORS.CODE_INVALID_CHUNK_OVERLAP",
|
|
102
|
-
context: `maxChunkChars=${maxChunkChars} chunkOverlapChars=${chunkOverlapChars}`,
|
|
103
|
-
});
|
|
104
|
-
}
|
|
105
|
-
return { maxChunkChars, chunkOverlapChars };
|
|
106
|
-
}
|
|
107
|
-
function walkCodeNode(node, adapter, breadcrumb, out) {
|
|
108
|
-
for (const child of node.children) {
|
|
109
|
-
const isScope = adapter.scopeTypes.has(child.type) &&
|
|
110
|
-
adapter.shouldEnterScope?.(child) !== false;
|
|
111
|
-
const isEntity = adapter.entityTypes.has(child.type) &&
|
|
112
|
-
adapter.shouldIndexEntity?.(child) !== false;
|
|
113
|
-
if (isEntity) {
|
|
114
|
-
const entities = adapter.resolveEntities?.(child) ?? [
|
|
115
|
-
adapter.resolveEntity ? adapter.resolveEntity(child) : child,
|
|
116
|
-
];
|
|
117
|
-
for (const entity of entities) {
|
|
118
|
-
const name = adapter.extractName(entity);
|
|
119
|
-
const entityBreadcrumb = adapter.scopeBreadcrumb?.(entity, breadcrumb) ?? breadcrumb;
|
|
120
|
-
const symbolType = adapter.classifyNode?.(entity, entityBreadcrumb) ??
|
|
121
|
-
classifyCodeNode(entity, entityBreadcrumb);
|
|
122
|
-
out.push({
|
|
123
|
-
node: entity,
|
|
124
|
-
name,
|
|
125
|
-
symbolType,
|
|
126
|
-
breadcrumb: entityBreadcrumb,
|
|
127
|
-
signature: adapter.extractSignature?.(entity),
|
|
128
|
-
doc: adapter.extractDoc?.(entity),
|
|
129
|
-
modifiers: adapter.extractModifiers?.(entity) ?? [],
|
|
130
|
-
});
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
if (isScope) {
|
|
134
|
-
const name = adapter.extractName(child);
|
|
135
|
-
const scopeNode = adapter.enterScopeNode?.(child) ?? child;
|
|
136
|
-
walkCodeNode(scopeNode, adapter, name ? [...breadcrumb, name] : breadcrumb, out);
|
|
137
|
-
continue;
|
|
138
|
-
}
|
|
139
|
-
if (!isEntity) {
|
|
140
|
-
walkCodeNode(child, adapter, breadcrumb, out);
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
function codeEntityToSearchFragments(source, adapter, entity, maxChars, overlapChars) {
|
|
145
|
-
const metadata = codeEntityMetadata(entity);
|
|
146
|
-
const contentChunkOptions = chunkOptionsForMetadata({ maxChunkChars: maxChars, chunkOverlapChars: overlapChars }, metadata);
|
|
147
|
-
const contentMaxChars = contentChunkOptions.maxChunkChars;
|
|
148
|
-
if (entity.node.text.length <= contentMaxChars) {
|
|
149
|
-
return [
|
|
150
|
-
codeEntityWindowToFragment(source, entity, nodeToWindow(entity.node)),
|
|
151
|
-
];
|
|
152
|
-
}
|
|
153
|
-
const major = {
|
|
154
|
-
group: "",
|
|
155
|
-
fileId: source.file.id,
|
|
156
|
-
range: nodeToWindow(entity.node).range,
|
|
157
|
-
content: {
|
|
158
|
-
kind: "text",
|
|
159
|
-
text: codeEntityOutline(entity, adapter, contentMaxChars),
|
|
160
|
-
},
|
|
161
|
-
metadata,
|
|
162
|
-
};
|
|
163
|
-
return [
|
|
164
|
-
major,
|
|
165
|
-
...[
|
|
166
|
-
...splitLargeNode(entity.node, contentMaxChars, contentChunkOptions.chunkOverlapChars),
|
|
167
|
-
].map((window) => codeEntityWindowToFragment(source, entity, window)),
|
|
168
|
-
];
|
|
169
|
-
}
|
|
170
|
-
function codeEntityWindowToFragment(source, entity, window) {
|
|
171
|
-
return {
|
|
172
|
-
fileId: source.file.id,
|
|
173
|
-
range: window.range,
|
|
174
|
-
content: {
|
|
175
|
-
kind: "text",
|
|
176
|
-
text: window.text,
|
|
177
|
-
},
|
|
178
|
-
metadata: codeEntityMetadata(entity),
|
|
179
|
-
embeddingText: window.embeddingText,
|
|
180
|
-
};
|
|
181
|
-
}
|
|
182
|
-
function nodeToWindow(node) {
|
|
183
|
-
return {
|
|
184
|
-
text: node.text,
|
|
185
|
-
range: {
|
|
186
|
-
kind: "text",
|
|
187
|
-
startLine: node.startPosition.row + 1,
|
|
188
|
-
endLine: node.endPosition.row + 1,
|
|
189
|
-
startOffset: node.startIndex,
|
|
190
|
-
endOffset: node.endIndex,
|
|
191
|
-
},
|
|
192
|
-
};
|
|
193
|
-
}
|
|
194
|
-
function* splitLargeNode(node, maxChars, overlapChars) {
|
|
195
|
-
const body = node.childForFieldName("body") ?? node;
|
|
196
|
-
const statements = body.namedChildren;
|
|
197
|
-
if (statements.length <= 1) {
|
|
198
|
-
yield* splitTextByLines(node.text, maxChars, node.startPosition.row + 1, node.startIndex, overlapChars);
|
|
199
|
-
return;
|
|
200
|
-
}
|
|
201
|
-
const baseStart = node.startIndex;
|
|
202
|
-
const source = node.text;
|
|
203
|
-
let groupStart = 0;
|
|
204
|
-
let groupChars = 0;
|
|
205
|
-
for (let index = 0; index < statements.length; index++) {
|
|
206
|
-
const statement = statements[index];
|
|
207
|
-
const statementChars = statement.text.length;
|
|
208
|
-
if (statementChars > maxChars) {
|
|
209
|
-
if (index > groupStart) {
|
|
210
|
-
yield sliceStatements(source, baseStart, statements, groupStart, index - 1);
|
|
211
|
-
}
|
|
212
|
-
yield* splitTextByLines(statement.text, maxChars, statement.startPosition.row + 1, statement.startIndex, overlapChars);
|
|
213
|
-
groupStart = index + 1;
|
|
214
|
-
groupChars = 0;
|
|
215
|
-
continue;
|
|
216
|
-
}
|
|
217
|
-
const separatorChars = index > groupStart ? 1 : 0;
|
|
218
|
-
if (groupChars + separatorChars + statementChars > maxChars &&
|
|
219
|
-
index > groupStart) {
|
|
220
|
-
yield sliceStatements(source, baseStart, statements, groupStart, index - 1);
|
|
221
|
-
const overlapStart = computeOverlapStart(statements, groupStart, index - 1, overlapChars);
|
|
222
|
-
let candidateStart = overlapStart < index ? overlapStart : index;
|
|
223
|
-
let candidateChars = statementChars;
|
|
224
|
-
for (let previous = index - 1; previous >= candidateStart; previous--) {
|
|
225
|
-
const addedChars = statements[previous].text.length + 1;
|
|
226
|
-
if (candidateChars + addedChars > maxChars) {
|
|
227
|
-
candidateStart = previous + 1;
|
|
228
|
-
break;
|
|
229
|
-
}
|
|
230
|
-
candidateChars += addedChars;
|
|
231
|
-
}
|
|
232
|
-
groupStart = candidateStart;
|
|
233
|
-
groupChars = candidateChars;
|
|
234
|
-
continue;
|
|
235
|
-
}
|
|
236
|
-
groupChars += separatorChars + statementChars;
|
|
237
|
-
}
|
|
238
|
-
if (groupStart < statements.length) {
|
|
239
|
-
yield sliceStatements(source, baseStart, statements, groupStart, statements.length - 1);
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
function sliceStatements(source, baseStart, statements, startIndex, endIndex) {
|
|
243
|
-
const start = statements[startIndex].startIndex;
|
|
244
|
-
const end = statements[endIndex].endIndex;
|
|
245
|
-
return {
|
|
246
|
-
text: source.slice(start - baseStart, end - baseStart),
|
|
247
|
-
embeddingText: statements
|
|
248
|
-
.slice(startIndex, endIndex + 1)
|
|
249
|
-
.map((statement) => statement.text)
|
|
250
|
-
.join("\n"),
|
|
251
|
-
range: {
|
|
252
|
-
kind: "text",
|
|
253
|
-
startLine: statements[startIndex].startPosition.row + 1,
|
|
254
|
-
endLine: statements[endIndex].endPosition.row + 1,
|
|
255
|
-
startOffset: start,
|
|
256
|
-
endOffset: end,
|
|
257
|
-
},
|
|
258
|
-
};
|
|
259
|
-
}
|
|
260
|
-
function* splitTextByLines(text, maxChars, startLine, startOffset, overlapChars) {
|
|
261
|
-
const lines = text.split("\n");
|
|
262
|
-
let lineIndex = 0;
|
|
263
|
-
let offset = startOffset;
|
|
264
|
-
while (lineIndex < lines.length) {
|
|
265
|
-
if (lines[lineIndex].length > maxChars) {
|
|
266
|
-
yield* splitLongLineByChars(lines[lineIndex], maxChars, startLine + lineIndex, offset, overlapChars);
|
|
267
|
-
offset += lines[lineIndex].length + 1;
|
|
268
|
-
lineIndex++;
|
|
269
|
-
continue;
|
|
270
|
-
}
|
|
271
|
-
let endIndex = lineIndex;
|
|
272
|
-
let usedChars = 0;
|
|
273
|
-
while (endIndex < lines.length) {
|
|
274
|
-
const lineLength = lines[endIndex].length + 1;
|
|
275
|
-
if (usedChars + lineLength > maxChars && endIndex > lineIndex) {
|
|
276
|
-
break;
|
|
277
|
-
}
|
|
278
|
-
usedChars += lineLength;
|
|
279
|
-
endIndex++;
|
|
280
|
-
}
|
|
281
|
-
const chunk = lines.slice(lineIndex, endIndex).join("\n");
|
|
282
|
-
yield {
|
|
283
|
-
text: chunk,
|
|
284
|
-
range: {
|
|
285
|
-
kind: "text",
|
|
286
|
-
startLine: startLine + lineIndex,
|
|
287
|
-
endLine: startLine + endIndex - 1,
|
|
288
|
-
startOffset: offset,
|
|
289
|
-
endOffset: offset + chunk.length,
|
|
290
|
-
},
|
|
291
|
-
};
|
|
292
|
-
if (endIndex >= lines.length) {
|
|
293
|
-
break;
|
|
294
|
-
}
|
|
295
|
-
const overlapLines = computeLineOverlap(lines, lineIndex, endIndex, overlapChars);
|
|
296
|
-
const nextIndex = endIndex - overlapLines;
|
|
297
|
-
offset += lines.slice(lineIndex, nextIndex).join("\n").length;
|
|
298
|
-
if (nextIndex > lineIndex) {
|
|
299
|
-
offset += 1;
|
|
300
|
-
}
|
|
301
|
-
lineIndex = nextIndex;
|
|
302
|
-
}
|
|
303
|
-
}
|
|
304
|
-
function* splitLongLineByChars(text, maxChars, line, startOffset, overlapChars) {
|
|
305
|
-
let relativeStart = 0;
|
|
306
|
-
while (relativeStart < text.length) {
|
|
307
|
-
const rawEnd = Math.min(text.length, relativeStart + maxChars);
|
|
308
|
-
const relativeEnd = safeCharacterEnd(text, relativeStart, rawEnd);
|
|
309
|
-
yield {
|
|
310
|
-
text: text.slice(relativeStart, relativeEnd),
|
|
311
|
-
range: {
|
|
312
|
-
kind: "text",
|
|
313
|
-
startLine: line,
|
|
314
|
-
endLine: line,
|
|
315
|
-
startOffset: startOffset + relativeStart,
|
|
316
|
-
endOffset: startOffset + relativeEnd,
|
|
317
|
-
},
|
|
318
|
-
};
|
|
319
|
-
if (relativeEnd >= text.length) {
|
|
320
|
-
break;
|
|
321
|
-
}
|
|
322
|
-
const rawStart = Math.max(relativeStart + 1, relativeEnd - overlapChars);
|
|
323
|
-
relativeStart = safeCharacterStart(text, rawStart);
|
|
324
|
-
}
|
|
325
|
-
}
|
|
326
|
-
function safeCharacterEnd(text, start, end) {
|
|
327
|
-
if (end > start &&
|
|
328
|
-
end < text.length &&
|
|
329
|
-
isHighSurrogate(text.charCodeAt(end - 1)) &&
|
|
330
|
-
isLowSurrogate(text.charCodeAt(end))) {
|
|
331
|
-
return end - 1 > start ? end - 1 : end + 1;
|
|
332
|
-
}
|
|
333
|
-
return end;
|
|
334
|
-
}
|
|
335
|
-
function safeCharacterStart(text, start) {
|
|
336
|
-
if (start > 0 &&
|
|
337
|
-
start < text.length &&
|
|
338
|
-
isHighSurrogate(text.charCodeAt(start - 1)) &&
|
|
339
|
-
isLowSurrogate(text.charCodeAt(start))) {
|
|
340
|
-
return start + 1;
|
|
341
|
-
}
|
|
342
|
-
return start;
|
|
343
|
-
}
|
|
344
|
-
function isHighSurrogate(value) {
|
|
345
|
-
return value >= 0xd800 && value <= 0xdbff;
|
|
346
|
-
}
|
|
347
|
-
function isLowSurrogate(value) {
|
|
348
|
-
return value >= 0xdc00 && value <= 0xdfff;
|
|
349
|
-
}
|
|
350
|
-
function computeOverlapStart(statements, groupStart, groupEnd, overlapChars) {
|
|
351
|
-
if (overlapChars <= 0) {
|
|
352
|
-
return groupEnd + 1;
|
|
353
|
-
}
|
|
354
|
-
let chars = 0;
|
|
355
|
-
let index = groupEnd;
|
|
356
|
-
while (index >= groupStart && chars < overlapChars) {
|
|
357
|
-
chars += statements[index].text.length;
|
|
358
|
-
if (index < groupEnd) {
|
|
359
|
-
chars++;
|
|
360
|
-
}
|
|
361
|
-
index--;
|
|
362
|
-
}
|
|
363
|
-
return index + 1;
|
|
364
|
-
}
|
|
365
|
-
function computeLineOverlap(lines, startIndex, endIndex, overlapChars) {
|
|
366
|
-
if (overlapChars <= 0) {
|
|
367
|
-
return 0;
|
|
368
|
-
}
|
|
369
|
-
let chars = 0;
|
|
370
|
-
let count = 0;
|
|
371
|
-
for (let index = endIndex - 1; index >= startIndex; index--) {
|
|
372
|
-
chars += lines[index].length + 1;
|
|
373
|
-
if (chars > overlapChars) {
|
|
374
|
-
break;
|
|
375
|
-
}
|
|
376
|
-
count++;
|
|
377
|
-
}
|
|
378
|
-
return Math.min(count, Math.floor((endIndex - startIndex) / 2));
|
|
379
|
-
}
|
|
380
|
-
const STRUCTURAL_SYMBOL_TYPES = new Set([
|
|
381
|
-
"class",
|
|
382
|
-
"interface",
|
|
383
|
-
"module",
|
|
384
|
-
]);
|
|
385
|
-
const OUTLINE_MAX_MEMBERS = 32;
|
|
386
|
-
const OUTLINE_MAX_CALLS = 24;
|
|
387
|
-
const OUTLINE_MAX_LINE_CHARS = 180;
|
|
388
|
-
function codeEntityOutline(entity, adapter, maxChars) {
|
|
389
|
-
const header = extractCodeHeader(entity.node.text);
|
|
390
|
-
const lines = [
|
|
391
|
-
header.length > 0 ? header : (entity.name ?? entity.symbolType),
|
|
392
|
-
];
|
|
393
|
-
if (STRUCTURAL_SYMBOL_TYPES.has(entity.symbolType)) {
|
|
394
|
-
const members = collectStructureOutlineMembers(entity, adapter);
|
|
395
|
-
if (members.length > 0) {
|
|
396
|
-
lines.push("", "members:", ...members.map((member) => `- ${formatOutlineMember(member)}`));
|
|
397
|
-
}
|
|
398
|
-
}
|
|
399
|
-
else if (entity.symbolType === "function") {
|
|
400
|
-
const calls = collectFunctionCallNames(entity.node);
|
|
401
|
-
if (calls.length > 0) {
|
|
402
|
-
lines.push("", `calls: ${calls.join(", ")}`);
|
|
403
|
-
}
|
|
404
|
-
}
|
|
405
|
-
return truncateOutline(lines.join("\n").trim(), maxChars);
|
|
406
|
-
}
|
|
407
|
-
function truncateOutline(outline, maxChars) {
|
|
408
|
-
if (outline.length <= maxChars) {
|
|
409
|
-
return outline;
|
|
410
|
-
}
|
|
411
|
-
if (maxChars <= 3) {
|
|
412
|
-
return ".".repeat(maxChars);
|
|
413
|
-
}
|
|
414
|
-
return `${outline.slice(0, maxChars - 3).trimEnd()}...`;
|
|
415
|
-
}
|
|
416
|
-
function extractCodeHeader(text) {
|
|
417
|
-
const maxChars = 1200;
|
|
418
|
-
const maxLines = 24;
|
|
419
|
-
const lines = [];
|
|
420
|
-
for (const line of text.split(/\r?\n/)) {
|
|
421
|
-
lines.push(line);
|
|
422
|
-
if (line.includes("{") || lines.length >= maxLines) {
|
|
423
|
-
break;
|
|
424
|
-
}
|
|
425
|
-
}
|
|
426
|
-
const header = lines.join("\n").trim();
|
|
427
|
-
return header.length > maxChars
|
|
428
|
-
? `${header.slice(0, maxChars).trimEnd()}\n...`
|
|
429
|
-
: header;
|
|
430
|
-
}
|
|
431
|
-
function collectStructureOutlineMembers(entity, adapter) {
|
|
432
|
-
const members = [];
|
|
433
|
-
const seen = new Set();
|
|
434
|
-
const visit = (node, depth) => {
|
|
435
|
-
if (members.length >= OUTLINE_MAX_MEMBERS || depth > 12) {
|
|
436
|
-
return;
|
|
437
|
-
}
|
|
438
|
-
if (!sameNode(node, entity.node) && adapter.entityTypes.has(node.type)) {
|
|
439
|
-
if (adapter.shouldIndexEntity?.(node) !== false) {
|
|
440
|
-
const resolved = adapter.resolveEntities?.(node) ?? [
|
|
441
|
-
adapter.resolveEntity ? adapter.resolveEntity(node) : node,
|
|
442
|
-
];
|
|
443
|
-
for (const resolvedNode of resolved) {
|
|
444
|
-
if (members.length >= OUTLINE_MAX_MEMBERS ||
|
|
445
|
-
sameNode(resolvedNode, entity.node)) {
|
|
446
|
-
break;
|
|
447
|
-
}
|
|
448
|
-
const name = adapter.extractName(resolvedNode);
|
|
449
|
-
const symbolType = adapter.classifyNode?.(resolvedNode, entity.breadcrumb) ??
|
|
450
|
-
classifyCodeNode(resolvedNode, entity.breadcrumb);
|
|
451
|
-
const signature = adapter.extractSignature?.(resolvedNode);
|
|
452
|
-
const key = `${symbolType}:${name ?? ""}:${signature ?? ""}:${resolvedNode.startIndex}`;
|
|
453
|
-
if (!seen.has(key)) {
|
|
454
|
-
seen.add(key);
|
|
455
|
-
members.push({ symbolType, name, signature });
|
|
456
|
-
}
|
|
457
|
-
}
|
|
458
|
-
}
|
|
459
|
-
return;
|
|
460
|
-
}
|
|
461
|
-
for (const child of node.namedChildren) {
|
|
462
|
-
visit(child, depth + 1);
|
|
463
|
-
}
|
|
464
|
-
};
|
|
465
|
-
visit(entity.node, 0);
|
|
466
|
-
return members;
|
|
467
|
-
}
|
|
468
|
-
function formatOutlineMember(member) {
|
|
469
|
-
const name = member.name ?? "";
|
|
470
|
-
const signature = member.signature
|
|
471
|
-
? truncateOutlineLine(oneLine(member.signature))
|
|
472
|
-
: "";
|
|
473
|
-
if (signature.length > 0) {
|
|
474
|
-
return name.length > 0 && !signature.includes(name)
|
|
475
|
-
? `${member.symbolType} ${name}: ${signature}`
|
|
476
|
-
: `${member.symbolType} ${signature}`;
|
|
477
|
-
}
|
|
478
|
-
return name.length > 0 ? `${member.symbolType} ${name}` : member.symbolType;
|
|
479
|
-
}
|
|
480
|
-
function collectFunctionCallNames(node) {
|
|
481
|
-
const calls = [];
|
|
482
|
-
const seen = new Set();
|
|
483
|
-
const visit = (current) => {
|
|
484
|
-
if (calls.length >= OUTLINE_MAX_CALLS) {
|
|
485
|
-
return;
|
|
486
|
-
}
|
|
487
|
-
if (isCallNode(current)) {
|
|
488
|
-
const name = extractCallName(current);
|
|
489
|
-
if (name && !seen.has(name)) {
|
|
490
|
-
seen.add(name);
|
|
491
|
-
calls.push(name);
|
|
492
|
-
}
|
|
493
|
-
}
|
|
494
|
-
for (const child of current.namedChildren) {
|
|
495
|
-
visit(child);
|
|
496
|
-
}
|
|
497
|
-
};
|
|
498
|
-
visit(node);
|
|
499
|
-
return calls;
|
|
500
|
-
}
|
|
501
|
-
function isCallNode(node) {
|
|
502
|
-
return (node.type === "call" ||
|
|
503
|
-
node.type === "call_expression" ||
|
|
504
|
-
node.type === "function_call_expression" ||
|
|
505
|
-
node.type === "method_invocation" ||
|
|
506
|
-
node.type === "object_creation_expression" ||
|
|
507
|
-
node.type === "new_expression");
|
|
508
|
-
}
|
|
509
|
-
function extractCallName(node) {
|
|
510
|
-
const target = node.childForFieldName("function") ??
|
|
511
|
-
node.childForFieldName("name") ??
|
|
512
|
-
node.childForFieldName("constructor") ??
|
|
513
|
-
node.childForFieldName("type") ??
|
|
514
|
-
node.namedChildren[0];
|
|
515
|
-
if (!target) {
|
|
516
|
-
return undefined;
|
|
517
|
-
}
|
|
518
|
-
return normalizeCallName(target.text);
|
|
519
|
-
}
|
|
520
|
-
function normalizeCallName(value) {
|
|
521
|
-
const cleaned = value
|
|
522
|
-
.replace(/\s+/g, " ")
|
|
523
|
-
.replace(/^new\s+/, "")
|
|
524
|
-
.trim();
|
|
525
|
-
if (cleaned.length === 0 ||
|
|
526
|
-
cleaned.length > OUTLINE_MAX_LINE_CHARS ||
|
|
527
|
-
/[\n\r]/.test(cleaned) ||
|
|
528
|
-
!/[A-Za-z_$][A-Za-z0-9_$]*/.test(cleaned)) {
|
|
529
|
-
return undefined;
|
|
530
|
-
}
|
|
531
|
-
return cleaned;
|
|
532
|
-
}
|
|
533
|
-
function sameNode(left, right) {
|
|
534
|
-
return (left.startIndex === right.startIndex &&
|
|
535
|
-
left.endIndex === right.endIndex &&
|
|
536
|
-
left.type === right.type);
|
|
537
|
-
}
|
|
538
|
-
function oneLine(value) {
|
|
539
|
-
return value.replace(/\s+/g, " ").trim();
|
|
540
|
-
}
|
|
541
|
-
function truncateOutlineLine(value) {
|
|
542
|
-
return value.length > OUTLINE_MAX_LINE_CHARS
|
|
543
|
-
? `${value.slice(0, OUTLINE_MAX_LINE_CHARS - 3).trimEnd()}...`
|
|
544
|
-
: value;
|
|
545
|
-
}
|
|
546
|
-
function codeEntityMetadata(entity) {
|
|
547
|
-
return {
|
|
548
|
-
kind: "code",
|
|
549
|
-
symbolType: entity.symbolType,
|
|
550
|
-
symbolName: entity.name ?? null,
|
|
551
|
-
scope: entity.breadcrumb.length > 0 ? entity.breadcrumb.join("::") : null,
|
|
552
|
-
nodeType: entity.node.type,
|
|
553
|
-
signature: entity.signature ?? null,
|
|
554
|
-
doc: entity.doc ?? null,
|
|
555
|
-
modifiers: entity.modifiers,
|
|
556
|
-
};
|
|
557
|
-
}
|
|
558
|
-
function classifyCodeNode(node, breadcrumb) {
|
|
559
|
-
const nodeType = node.type;
|
|
560
|
-
if (nodeType === "decorated_definition") {
|
|
561
|
-
const inner = node.namedChildren.find((child) => child.type === "function_definition" ||
|
|
562
|
-
child.type === "class_definition");
|
|
563
|
-
return inner ? classifyCodeNode(inner, breadcrumb) : "value";
|
|
564
|
-
}
|
|
565
|
-
if ((nodeType === "field_definition" ||
|
|
566
|
-
nodeType === "public_field_definition" ||
|
|
567
|
-
nodeType === "variable_declarator") &&
|
|
568
|
-
hasJavascriptTypescriptFunctionValue(node)) {
|
|
569
|
-
return "function";
|
|
570
|
-
}
|
|
571
|
-
if (nodeType.includes("method") || nodeType.includes("constructor")) {
|
|
572
|
-
return "function";
|
|
573
|
-
}
|
|
574
|
-
if (breadcrumb.length > 0 &&
|
|
575
|
-
(nodeType.includes("function") ||
|
|
576
|
-
nodeType === "declaration" ||
|
|
577
|
-
nodeType === "function_item")) {
|
|
578
|
-
return "function";
|
|
579
|
-
}
|
|
580
|
-
if (nodeType.includes("function")) {
|
|
581
|
-
return "function";
|
|
582
|
-
}
|
|
583
|
-
if (nodeType === "declaration" || nodeType === "macro_type_specifier") {
|
|
584
|
-
return "function";
|
|
585
|
-
}
|
|
586
|
-
if (nodeType.includes("class") ||
|
|
587
|
-
nodeType.includes("struct") ||
|
|
588
|
-
nodeType.includes("impl") ||
|
|
589
|
-
nodeType.includes("enum") ||
|
|
590
|
-
nodeType.includes("union") ||
|
|
591
|
-
nodeType.includes("record")) {
|
|
592
|
-
return "class";
|
|
593
|
-
}
|
|
594
|
-
if (nodeType.includes("interface") ||
|
|
595
|
-
nodeType.includes("protocol") ||
|
|
596
|
-
nodeType.includes("trait")) {
|
|
597
|
-
return "interface";
|
|
598
|
-
}
|
|
599
|
-
if (nodeType.includes("module") ||
|
|
600
|
-
nodeType.includes("namespace") ||
|
|
601
|
-
nodeType === "mod_item") {
|
|
602
|
-
return "module";
|
|
603
|
-
}
|
|
604
|
-
if (nodeType.includes("alias") ||
|
|
605
|
-
nodeType.includes("typedef") ||
|
|
606
|
-
nodeType === "type_definition" ||
|
|
607
|
-
nodeType === "type_item") {
|
|
608
|
-
return "alias";
|
|
609
|
-
}
|
|
610
|
-
return "value";
|
|
611
|
-
}
|
|
612
|
-
function truncateInline(value, maxChars) {
|
|
613
|
-
const compact = value.replace(/\s+/g, " ").trim();
|
|
614
|
-
return compact.length > maxChars
|
|
615
|
-
? `${compact.slice(0, maxChars).trimEnd()}...`
|
|
616
|
-
: compact;
|
|
617
|
-
}
|
|
618
|
-
function isScriptBlockFormat(format) {
|
|
619
|
-
return COMPONENT_CODE_FORMAT_SET.has(format);
|
|
620
|
-
}
|
|
621
|
-
function findScriptBlocks(text) {
|
|
622
|
-
const blocks = [];
|
|
623
|
-
const scriptPattern = /<script(\s[^>]*)?>([\s\S]*?)<\/script>/gi;
|
|
624
|
-
for (const match of text.matchAll(scriptPattern)) {
|
|
625
|
-
const fullMatch = match[0];
|
|
626
|
-
const attrs = match[1] ?? "";
|
|
627
|
-
const blockText = match[2] ?? "";
|
|
628
|
-
const tagEndOffset = fullMatch.indexOf(">");
|
|
629
|
-
if (tagEndOffset < 0) {
|
|
630
|
-
continue;
|
|
631
|
-
}
|
|
632
|
-
const startOffset = match.index + tagEndOffset + 1;
|
|
633
|
-
blocks.push({
|
|
634
|
-
text: blockText,
|
|
635
|
-
format: scriptBlockFormat(attrs),
|
|
636
|
-
startLine: lineAtOffset(text, startOffset),
|
|
637
|
-
startOffset,
|
|
638
|
-
});
|
|
639
|
-
}
|
|
640
|
-
return blocks;
|
|
641
|
-
}
|
|
642
|
-
function scriptBlockFormat(attrs) {
|
|
643
|
-
const lang = attrs
|
|
644
|
-
.match(/\blang\s*=\s*["']?([A-Za-z0-9_-]+)/i)?.[1]
|
|
645
|
-
?.toLowerCase();
|
|
646
|
-
if (lang === "ts" || lang === "typescript") {
|
|
647
|
-
return "typescript";
|
|
648
|
-
}
|
|
649
|
-
if (lang === "tsx") {
|
|
650
|
-
return "tsx";
|
|
651
|
-
}
|
|
652
|
-
if (lang === "jsx") {
|
|
653
|
-
return "jsx";
|
|
654
|
-
}
|
|
655
|
-
return "javascript";
|
|
656
|
-
}
|
|
657
|
-
function lineAtOffset(text, offset) {
|
|
658
|
-
let line = 1;
|
|
659
|
-
for (let index = 0; index < offset; index++) {
|
|
660
|
-
if (text.charCodeAt(index) === 10) {
|
|
661
|
-
line++;
|
|
662
|
-
}
|
|
663
|
-
}
|
|
664
|
-
return line;
|
|
665
|
-
}
|
|
666
|
-
function remapScriptBlockFragments(fileId, fragments, startIndex, startLine, startOffset) {
|
|
667
|
-
const idMap = new Map();
|
|
668
|
-
for (const [index, item] of fragments.entries()) {
|
|
669
|
-
idMap.set(item.fragment.id, makeEntityId(fileId, startIndex + index));
|
|
670
|
-
}
|
|
671
|
-
return fragments.map((item) => ({
|
|
672
|
-
...item,
|
|
673
|
-
fragment: {
|
|
674
|
-
...item.fragment,
|
|
675
|
-
id: idMap.get(item.fragment.id) ?? item.fragment.id,
|
|
676
|
-
group: item.fragment.group
|
|
677
|
-
? (idMap.get(item.fragment.group) ?? item.fragment.group)
|
|
678
|
-
: undefined,
|
|
679
|
-
fileId,
|
|
680
|
-
range: remapScriptBlockRange(item.fragment.range, startLine, startOffset),
|
|
681
|
-
},
|
|
682
|
-
}));
|
|
683
|
-
}
|
|
684
|
-
function remapScriptBlockRange(range, startLine, startOffset) {
|
|
685
|
-
if (range.kind !== "text") {
|
|
686
|
-
return range;
|
|
687
|
-
}
|
|
688
|
-
return {
|
|
689
|
-
...range,
|
|
690
|
-
startLine: startLine + range.startLine - 1,
|
|
691
|
-
endLine: startLine + range.endLine - 1,
|
|
692
|
-
startOffset: startOffset + range.startOffset,
|
|
693
|
-
endOffset: startOffset + range.endOffset,
|
|
694
|
-
};
|
|
695
|
-
}
|
|
696
|
-
//# sourceMappingURL=extractor.js.map
|