codesearch-mcp 0.2.3-alpha → 0.4.0-alpha
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/CHANGELOG.md +88 -5
- package/LICENSE +661 -21
- package/README.md +76 -40
- package/dist/app.js +17 -38
- package/dist/src/ast/CallExtractor.d.ts +8 -0
- package/dist/src/ast/CallExtractor.js +68 -0
- package/dist/src/ast/GraphqlNameExtractor.d.ts +22 -0
- package/dist/src/ast/GraphqlNameExtractor.js +240 -0
- package/dist/src/ast/ImportEdgeExtractor.d.ts +11 -0
- package/dist/src/ast/ImportEdgeExtractor.js +129 -0
- package/dist/src/ast/IndexedNodeResolver.d.ts +14 -0
- package/dist/src/ast/IndexedNodeResolver.js +217 -0
- package/dist/src/ast/MemberExtractor.d.ts +8 -0
- package/dist/src/ast/MemberExtractor.js +129 -0
- package/dist/src/ast/TopLevelSymbolExtractor.d.ts +5 -0
- package/dist/src/ast/TopLevelSymbolExtractor.js +86 -0
- package/dist/src/ast/graphql-grammar.d.ts +24 -0
- package/dist/src/ast/graphql-grammar.js +93 -0
- package/dist/src/ast/node-helpers.d.ts +11 -0
- package/dist/src/ast/node-helpers.js +55 -0
- package/dist/src/chunking/AstChunker.d.ts +12 -0
- package/dist/src/chunking/AstChunker.js +30 -0
- package/dist/src/chunking/CharacterChunkStrategy.d.ts +8 -0
- package/dist/src/chunking/CharacterChunkStrategy.js +15 -0
- package/dist/src/chunking/DeclarationChunkStrategy.d.ts +15 -0
- package/dist/src/chunking/DeclarationChunkStrategy.js +87 -0
- package/dist/src/chunking/FragmentMerger.d.ts +11 -0
- package/dist/src/chunking/FragmentMerger.js +61 -0
- package/dist/src/chunking/ImportOnlyFilter.d.ts +5 -0
- package/dist/src/chunking/ImportOnlyFilter.js +14 -0
- package/dist/src/chunking/LangchainTextSplitter.d.ts +21 -0
- package/dist/src/chunking/LangchainTextSplitter.js +133 -0
- package/dist/src/chunking/MinSizeSplitPolicy.d.ts +9 -0
- package/dist/src/chunking/MinSizeSplitPolicy.js +18 -0
- package/dist/src/chunking/RunPacker.d.ts +12 -0
- package/dist/src/chunking/RunPacker.js +84 -0
- package/dist/src/chunking/create-chunker.d.ts +3 -0
- package/dist/src/chunking/create-chunker.js +15 -0
- package/dist/src/chunking/interfaces.d.ts +27 -0
- package/dist/src/commands/ConfigCommand.js +1 -9
- package/dist/src/commands/EvalCommand.d.ts +10 -5
- package/dist/src/commands/EvalCommand.js +60 -149
- package/dist/src/commands/IndexCommand.d.ts +10 -4
- package/dist/src/commands/IndexCommand.js +52 -146
- package/dist/src/commands/McpCommand.d.ts +6 -3
- package/dist/src/commands/McpCommand.js +19 -20
- package/dist/src/commands/WebCommand.d.ts +9 -3
- package/dist/src/commands/WebCommand.js +17 -11
- package/dist/src/commands/eval/baseline-comparison.d.ts +6 -0
- package/dist/src/commands/eval/baseline-comparison.js +54 -0
- package/dist/src/commands/eval/eval-args.d.ts +6 -0
- package/dist/src/commands/eval/eval-args.js +71 -0
- package/dist/src/commands/eval/eval-corpora.d.ts +6 -0
- package/dist/src/commands/eval/eval-corpora.js +76 -0
- package/dist/src/commands/eval/eval-metadata.d.ts +17 -0
- package/dist/src/commands/eval/eval-metadata.js +75 -0
- package/dist/src/commands/eval/index-inspector.d.ts +3 -0
- package/dist/src/commands/eval/index-inspector.js +21 -0
- package/dist/src/commands/eval/staged-search.d.ts +3 -0
- package/dist/src/commands/eval/staged-search.js +20 -0
- package/dist/src/commands/eval/suite-loader.d.ts +8 -0
- package/dist/src/commands/eval/suite-loader.js +52 -0
- package/dist/src/commands/index/backend-probe.d.ts +2 -0
- package/dist/src/commands/index/backend-probe.js +15 -0
- package/dist/src/commands/index/embedding-setup.d.ts +3 -0
- package/dist/src/commands/index/embedding-setup.js +16 -0
- package/dist/src/commands/index/index-summary.d.ts +2 -0
- package/dist/src/commands/index/index-summary.js +22 -0
- package/dist/src/commands/index/legacy-ollama-guard.d.ts +3 -0
- package/dist/src/commands/index/legacy-ollama-guard.js +23 -0
- package/dist/src/commands/index/prune-step.d.ts +3 -0
- package/dist/src/commands/index/prune-step.js +22 -0
- package/dist/src/commands/index/scan-targets.d.ts +8 -0
- package/dist/src/commands/index/scan-targets.js +107 -0
- package/dist/src/config-error.d.ts +0 -4
- package/dist/src/config-error.js +0 -4
- package/dist/src/config-store.d.ts +1 -55
- package/dist/src/config-store.js +11 -73
- package/dist/src/config.d.ts +9 -18
- package/dist/src/config.js +36 -35
- package/dist/src/constants.d.ts +17 -28
- package/dist/src/constants.js +35 -29
- package/dist/src/container.d.ts +10 -2
- package/dist/src/container.js +19 -8
- package/dist/src/db/drizzle-types.d.ts +7 -0
- package/dist/src/db/drizzle-types.js +2 -0
- package/dist/src/db/index.d.ts +1 -0
- package/dist/src/db/schema-steps.d.ts +8 -0
- package/dist/src/db/schema-steps.js +105 -0
- package/dist/src/db/schema.d.ts +17 -0
- package/dist/src/db/schema.js +1 -6
- package/dist/src/declarations/DeclarationTree.d.ts +19 -0
- package/dist/src/declarations/DeclarationTree.js +66 -0
- package/dist/src/declarations/DeclarationTreeBuilder.d.ts +22 -0
- package/dist/src/declarations/DeclarationTreeBuilder.js +179 -0
- package/dist/src/declarations/SourceLines.d.ts +37 -0
- package/dist/src/declarations/SourceLines.js +415 -0
- package/dist/src/dependency-traversal.d.ts +0 -6
- package/dist/src/dependency-traversal.js +0 -6
- package/dist/src/enriched-prompt.d.ts +0 -6
- package/dist/src/enriched-prompt.js +0 -6
- package/dist/src/error-record.d.ts +12 -0
- package/dist/src/error-record.js +248 -0
- package/dist/src/eval-corpus.d.ts +16 -0
- package/dist/src/eval-corpus.js +169 -0
- package/dist/src/eval-results.d.ts +6 -3
- package/dist/src/eval-results.js +323 -26
- package/dist/src/eval-vector-index.d.ts +5 -0
- package/dist/src/eval-vector-index.js +60 -0
- package/dist/src/file-utils.d.ts +0 -5
- package/dist/src/file-utils.js +0 -5
- package/dist/src/graph.d.ts +0 -25
- package/dist/src/graph.js +0 -28
- package/dist/src/help.js +9 -1
- package/dist/src/hnsw-settings.d.ts +3 -0
- package/dist/src/hnsw-settings.js +24 -0
- package/dist/src/index-args.d.ts +13 -0
- package/dist/src/index-args.js +48 -0
- package/dist/src/indexing/AnalysisBatcher.d.ts +12 -0
- package/dist/src/indexing/AnalysisBatcher.js +28 -0
- package/dist/src/indexing/ChunkEmbedder.d.ts +24 -0
- package/dist/src/indexing/ChunkEmbedder.js +37 -0
- package/dist/src/indexing/ConsoleScanReporter.d.ts +10 -0
- package/dist/src/indexing/ConsoleScanReporter.js +73 -0
- package/dist/src/indexing/EmbeddingSchemaPreparer.d.ts +14 -0
- package/dist/src/indexing/EmbeddingSchemaPreparer.js +66 -0
- package/dist/src/indexing/FileIngestor.d.ts +22 -0
- package/dist/src/indexing/FileIngestor.js +116 -0
- package/dist/src/indexing/IndexStore.d.ts +24 -0
- package/dist/src/indexing/IndexStore.js +69 -0
- package/dist/src/indexing/StaleFilePruner.d.ts +8 -0
- package/dist/src/indexing/StaleFilePruner.js +55 -0
- package/dist/src/indexing/analysis-rows.d.ts +4 -0
- package/dist/src/indexing/analysis-rows.js +65 -0
- package/dist/src/indexing/project-notices.d.ts +2 -0
- package/dist/src/indexing/project-notices.js +63 -0
- package/dist/src/interfaces/IAstParser.d.ts +4 -40
- package/dist/src/interfaces/ICallGraph.d.ts +28 -0
- package/dist/src/interfaces/ICallGraph.js +2 -0
- package/dist/src/interfaces/IChunkSearch.d.ts +42 -0
- package/dist/src/interfaces/IChunkSearch.js +2 -0
- package/dist/src/interfaces/IChunker.d.ts +3 -12
- package/dist/src/interfaces/ICorpusInspector.d.ts +7 -0
- package/dist/src/interfaces/ICorpusInspector.js +2 -0
- package/dist/src/interfaces/IDatabase.d.ts +8 -24
- package/dist/src/interfaces/IDependencyGraph.d.ts +24 -0
- package/dist/src/interfaces/IDependencyGraph.js +2 -0
- package/dist/src/interfaces/IEmbedder.d.ts +0 -9
- package/dist/src/interfaces/IIndexIdentityGuard.d.ts +3 -0
- package/dist/src/interfaces/IIndexIdentityGuard.js +2 -0
- package/dist/src/interfaces/IIndexedNodeResolver.d.ts +10 -0
- package/dist/src/interfaces/IIndexedNodeResolver.js +2 -0
- package/dist/src/interfaces/ILogger.d.ts +1 -11
- package/dist/src/interfaces/IMcpReadiness.d.ts +12 -0
- package/dist/src/interfaces/IMcpReadiness.js +2 -0
- package/dist/src/interfaces/IMcpToolHandler.d.ts +0 -5
- package/dist/src/interfaces/IMonorepoResolver.d.ts +0 -22
- package/dist/src/interfaces/IProjectCatalog.d.ts +13 -0
- package/dist/src/interfaces/IProjectCatalog.js +2 -0
- package/dist/src/interfaces/IProjectDiscovery.d.ts +0 -17
- package/dist/src/interfaces/IProjectRoots.d.ts +3 -0
- package/dist/src/interfaces/IProjectRoots.js +2 -0
- package/dist/src/interfaces/IRetrievalEvaluator.d.ts +153 -12
- package/dist/src/interfaces/IScanReporter.d.ts +13 -0
- package/dist/src/interfaces/IScanReporter.js +2 -0
- package/dist/src/interfaces/ISymbolLookup.d.ts +49 -0
- package/dist/src/interfaces/ISymbolLookup.js +2 -0
- package/dist/src/interfaces/IToolPaths.d.ts +62 -0
- package/dist/src/interfaces/IToolPaths.js +2 -0
- package/dist/src/interfaces/IWorkspaceFiles.d.ts +28 -0
- package/dist/src/interfaces/IWorkspaceFiles.js +2 -0
- package/dist/src/interfaces/SymbolKind.d.ts +1 -0
- package/dist/src/interfaces/SymbolKind.js +2 -0
- package/dist/src/interfaces/index.d.ts +12 -1
- package/dist/src/interrupt.js +0 -2
- package/dist/src/owner-path.d.ts +9 -10
- package/dist/src/owner-path.js +11 -23
- package/dist/src/project-scope.d.ts +1 -12
- package/dist/src/project-scope.js +5 -12
- package/dist/src/project-selector.d.ts +0 -5
- package/dist/src/project-selector.js +0 -11
- package/dist/src/retrieval-eval.d.ts +15 -6
- package/dist/src/retrieval-eval.js +388 -59
- package/dist/src/search/CallGraph.d.ts +9 -0
- package/dist/src/search/CallGraph.js +84 -0
- package/dist/src/search/ChunkSearch.d.ts +23 -0
- package/dist/src/search/ChunkSearch.js +115 -0
- package/dist/src/search/DependencyGraph.d.ts +19 -0
- package/dist/src/search/DependencyGraph.js +180 -0
- package/dist/src/search/IndexIdentityGuard.d.ts +11 -0
- package/dist/src/search/IndexIdentityGuard.js +37 -0
- package/dist/src/search/ProjectCatalog.d.ts +11 -0
- package/dist/src/search/ProjectCatalog.js +38 -0
- package/dist/src/search/SymbolLookup.d.ts +24 -0
- package/dist/src/search/SymbolLookup.js +97 -0
- package/dist/src/search/chunks/CandidateFetcher.d.ts +19 -0
- package/dist/src/search/chunks/CandidateFetcher.js +40 -0
- package/dist/src/search/chunks/IterativeScanGate.d.ts +10 -0
- package/dist/src/search/chunks/IterativeScanGate.js +42 -0
- package/dist/src/search/chunks/RerankStage.d.ts +15 -0
- package/dist/src/search/chunks/RerankStage.js +42 -0
- package/dist/src/search/chunks/search-metrics.d.ts +18 -0
- package/dist/src/search/chunks/search-metrics.js +32 -0
- package/dist/src/search/chunks/search-plan.d.ts +18 -0
- package/dist/src/search/chunks/search-plan.js +19 -0
- package/dist/src/search/create-search-services.d.ts +26 -0
- package/dist/src/search/create-search-services.js +29 -0
- package/dist/src/search/index-paths.d.ts +1 -0
- package/dist/src/search/index-paths.js +5 -0
- package/dist/src/search/result-shaping.d.ts +4 -0
- package/dist/src/search/result-shaping.js +19 -0
- package/dist/src/search/symbol-sql.d.ts +13 -0
- package/dist/src/search/symbol-sql.js +66 -0
- package/dist/src/search/symbols/SymbolGrepFallback.d.ts +19 -0
- package/dist/src/search/symbols/SymbolGrepFallback.js +106 -0
- package/dist/src/search/symbols/SymbolIndexQuery.d.ts +14 -0
- package/dist/src/search/symbols/SymbolIndexQuery.js +52 -0
- package/dist/src/search/symbols/SymbolTextSearch.d.ts +13 -0
- package/dist/src/search/symbols/SymbolTextSearch.js +84 -0
- package/dist/src/search/symbols/TargetColumnGate.d.ts +7 -0
- package/dist/src/search/symbols/TargetColumnGate.js +23 -0
- package/dist/src/search/symbols/find-symbol-constants.d.ts +4 -0
- package/dist/src/search/symbols/find-symbol-constants.js +8 -0
- package/dist/src/search/symbols/grep-args.d.ts +3 -0
- package/dist/src/search/symbols/grep-args.js +7 -0
- package/dist/src/search/symbols/grep-patterns.d.ts +4 -0
- package/dist/src/search/symbols/grep-patterns.js +60 -0
- package/dist/src/services/AstParserService.d.ts +10 -106
- package/dist/src/services/AstParserService.js +37 -1068
- package/dist/src/services/DatabaseService.d.ts +10 -17
- package/dist/src/services/DatabaseService.js +71 -115
- package/dist/src/services/EmbedderFactory.d.ts +0 -4
- package/dist/src/services/EmbedderFactory.js +0 -5
- package/dist/src/services/IndexerService.d.ts +7 -26
- package/dist/src/services/IndexerService.js +38 -286
- package/dist/src/services/InfinityEmbedder.d.ts +0 -21
- package/dist/src/services/InfinityEmbedder.js +0 -15
- package/dist/src/services/LoggerService.d.ts +7 -5
- package/dist/src/services/LoggerService.js +37 -41
- package/dist/src/services/McpReadiness.d.ts +18 -0
- package/dist/src/services/McpReadiness.js +73 -0
- package/dist/src/services/McpServer.d.ts +50 -19
- package/dist/src/services/McpServer.js +132 -62
- package/dist/src/services/MonorepoAwareDiscoveryService.d.ts +1 -45
- package/dist/src/services/MonorepoAwareDiscoveryService.js +1 -51
- package/dist/src/services/NxMonorepoResolver.d.ts +0 -29
- package/dist/src/services/NxMonorepoResolver.js +5 -56
- package/dist/src/services/OpenAICompatibleEmbedder.d.ts +0 -6
- package/dist/src/services/OpenAICompatibleEmbedder.js +0 -14
- package/dist/src/services/ProjectDiscoveryService.d.ts +0 -4
- package/dist/src/services/ProjectDiscoveryService.js +0 -4
- package/dist/src/services/VoyageEmbedder.d.ts +0 -6
- package/dist/src/services/VoyageEmbedder.js +0 -6
- package/dist/src/services/WebServerService.d.ts +5 -56
- package/dist/src/services/WebServerService.js +25 -63
- package/dist/src/services/http-retry.d.ts +0 -7
- package/dist/src/services/http-retry.js +1 -10
- package/dist/src/services/infinity-provisioning.d.ts +0 -74
- package/dist/src/services/infinity-provisioning.js +5 -88
- package/dist/src/services/legacy-ollama-index.d.ts +0 -16
- package/dist/src/services/legacy-ollama-index.js +0 -23
- package/dist/src/services/reranker.d.ts +0 -9
- package/dist/src/services/reranker.js +46 -12
- package/dist/src/setup.d.ts +24 -24
- package/dist/src/setup.js +205 -103
- package/dist/src/symbol-name.d.ts +1 -12
- package/dist/src/symbol-name.js +16 -25
- package/dist/src/symbol-rows.d.ts +0 -14
- package/dist/src/symbol-rows.js +0 -14
- package/dist/src/tool-call-log.d.ts +2 -0
- package/dist/src/tool-call-log.js +24 -0
- package/dist/src/tools/FindSymbolTool.d.ts +17 -7
- package/dist/src/tools/FindSymbolTool.js +54 -35
- package/dist/src/tools/GetCallersTool.d.ts +16 -8
- package/dist/src/tools/GetCallersTool.js +65 -35
- package/dist/src/tools/GetDependenciesTool.d.ts +16 -8
- package/dist/src/tools/GetDependenciesTool.js +36 -29
- package/dist/src/tools/GetDependentsTool.d.ts +20 -8
- package/dist/src/tools/GetDependentsTool.js +48 -34
- package/dist/src/tools/ListFilesTool.d.ts +16 -8
- package/dist/src/tools/ListFilesTool.js +20 -26
- package/dist/src/tools/ListProjectsTool.d.ts +11 -7
- package/dist/src/tools/ListProjectsTool.js +13 -11
- package/dist/src/tools/McpTool.d.ts +17 -0
- package/dist/src/tools/McpTool.js +28 -0
- package/dist/src/tools/ReadFileRangeTool.d.ts +16 -8
- package/dist/src/tools/ReadFileRangeTool.js +23 -25
- package/dist/src/tools/ReadFileTool.d.ts +15 -8
- package/dist/src/tools/ReadFileTool.js +19 -24
- package/dist/src/tools/SearchCodebaseTool.d.ts +22 -10
- package/dist/src/tools/SearchCodebaseTool.js +71 -50
- package/dist/src/tools/format-helpers.d.ts +9 -9
- package/dist/src/tools/format-helpers.js +146 -28
- package/dist/src/tools/tool-args.d.ts +38 -0
- package/dist/src/tools/tool-args.js +95 -0
- package/dist/src/web/dashboard.d.ts +0 -8
- package/dist/src/web/dashboard.js +7 -10
- package/dist/src/workspace/GrepRunner.d.ts +15 -0
- package/dist/src/workspace/GrepRunner.js +104 -0
- package/dist/src/workspace/ProjectRoots.d.ts +22 -0
- package/dist/src/workspace/ProjectRoots.js +102 -0
- package/dist/src/workspace/ToolPaths.d.ts +31 -0
- package/dist/src/workspace/ToolPaths.js +312 -0
- package/dist/src/workspace/WorkspaceFiles.d.ts +19 -0
- package/dist/src/workspace/WorkspaceFiles.js +285 -0
- package/dist/src/workspace/fs-access.d.ts +9 -0
- package/dist/src/workspace/fs-access.js +47 -0
- package/dist/src/workspace/path-helpers.d.ts +3 -0
- package/dist/src/workspace/path-helpers.js +43 -0
- package/package.json +5 -4
- package/dist/src/interfaces/ISearcher.d.ts +0 -35
- package/dist/src/services/AstChunker.d.ts +0 -42
- package/dist/src/services/AstChunker.js +0 -158
- package/dist/src/services/SearcherService.d.ts +0 -342
- package/dist/src/services/SearcherService.js +0 -1199
- package/docs/web-dashboard.md +0 -206
- /package/dist/src/{interfaces/ISearcher.js → chunking/interfaces.js} +0 -0
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MemberExtractor = void 0;
|
|
4
|
+
const ts_morph_1 = require("ts-morph");
|
|
5
|
+
const node_helpers_1 = require("./node-helpers");
|
|
6
|
+
class MemberExtractor {
|
|
7
|
+
resolver;
|
|
8
|
+
constructor(resolver) {
|
|
9
|
+
this.resolver = resolver;
|
|
10
|
+
}
|
|
11
|
+
extractMembers(sourceFile, filePath, serviceName) {
|
|
12
|
+
const candidates = [];
|
|
13
|
+
const sourceLines = sourceFile.getFullText().split('\n');
|
|
14
|
+
const lineAt = (node) => (0, node_helpers_1.lineTextAt)(sourceLines, sourceFile, node);
|
|
15
|
+
const push = (declNode, posNode, name, kind, container, isStatic, hasBody) => {
|
|
16
|
+
const { line, col } = (0, node_helpers_1.getPos)(sourceFile, posNode);
|
|
17
|
+
candidates.push({
|
|
18
|
+
declNode,
|
|
19
|
+
entry: {
|
|
20
|
+
project: serviceName, filePath, name, kind,
|
|
21
|
+
signature: lineAt(posNode),
|
|
22
|
+
line, endLine: declNode.getEndLineNumber(), col,
|
|
23
|
+
container: container.length ? container.join('.') : null,
|
|
24
|
+
isStatic, hasBody,
|
|
25
|
+
},
|
|
26
|
+
});
|
|
27
|
+
};
|
|
28
|
+
for (const cls of [
|
|
29
|
+
...sourceFile.getDescendantsOfKind(ts_morph_1.SyntaxKind.ClassDeclaration),
|
|
30
|
+
...sourceFile.getDescendantsOfKind(ts_morph_1.SyntaxKind.ClassExpression),
|
|
31
|
+
]) {
|
|
32
|
+
if (ts_morph_1.Node.isClassDeclaration(cls) && cls.getName() && ts_morph_1.Node.isSourceFile(cls.getParent()))
|
|
33
|
+
continue;
|
|
34
|
+
const described = this.resolver.describeIndexedNode(cls);
|
|
35
|
+
if (!described)
|
|
36
|
+
continue;
|
|
37
|
+
const posNode = (ts_morph_1.Node.isClassDeclaration(cls) ? cls.getNameNode() : undefined) ?? cls;
|
|
38
|
+
push(cls, posNode, described.name, 'class', described.container, false, true);
|
|
39
|
+
}
|
|
40
|
+
for (const m of sourceFile.getDescendantsOfKind(ts_morph_1.SyntaxKind.MethodDeclaration)) {
|
|
41
|
+
const described = this.resolver.describeIndexedNode(m);
|
|
42
|
+
if (!described)
|
|
43
|
+
continue;
|
|
44
|
+
push(m, m.getNameNode(), described.name, 'method', described.container, m.isStatic(), m.getBody() !== undefined);
|
|
45
|
+
}
|
|
46
|
+
for (const a of sourceFile.getDescendantsOfKind(ts_morph_1.SyntaxKind.GetAccessor)) {
|
|
47
|
+
const described = this.resolver.describeIndexedNode(a);
|
|
48
|
+
if (!described)
|
|
49
|
+
continue;
|
|
50
|
+
push(a, a.getNameNode(), described.name, 'get_accessor', described.container, a.isStatic(), true);
|
|
51
|
+
}
|
|
52
|
+
for (const a of sourceFile.getDescendantsOfKind(ts_morph_1.SyntaxKind.SetAccessor)) {
|
|
53
|
+
const described = this.resolver.describeIndexedNode(a);
|
|
54
|
+
if (!described)
|
|
55
|
+
continue;
|
|
56
|
+
push(a, a.getNameNode(), described.name, 'set_accessor', described.container, a.isStatic(), true);
|
|
57
|
+
}
|
|
58
|
+
for (const c of sourceFile.getDescendantsOfKind(ts_morph_1.SyntaxKind.Constructor)) {
|
|
59
|
+
const described = this.resolver.describeIndexedNode(c);
|
|
60
|
+
if (!described)
|
|
61
|
+
continue;
|
|
62
|
+
const kw = c.getFirstChildByKind(ts_morph_1.SyntaxKind.ConstructorKeyword) ?? c;
|
|
63
|
+
push(c, kw, described.name, 'constructor', described.container, false, c.getBody() !== undefined);
|
|
64
|
+
}
|
|
65
|
+
for (const p of sourceFile.getDescendantsOfKind(ts_morph_1.SyntaxKind.PropertyDeclaration)) {
|
|
66
|
+
const described = this.resolver.describeIndexedNode(p);
|
|
67
|
+
if (!described)
|
|
68
|
+
continue;
|
|
69
|
+
push(p, p.getNameNode(), described.name, 'function_property', described.container, p.isStatic(), true);
|
|
70
|
+
}
|
|
71
|
+
for (const p of sourceFile.getDescendantsOfKind(ts_morph_1.SyntaxKind.PropertyAssignment)) {
|
|
72
|
+
const described = this.resolver.describeIndexedNode(p);
|
|
73
|
+
if (!described)
|
|
74
|
+
continue;
|
|
75
|
+
push(p, p.getNameNode(), described.name, 'function_property', described.container, false, true);
|
|
76
|
+
}
|
|
77
|
+
for (const s of sourceFile.getDescendantsOfKind(ts_morph_1.SyntaxKind.MethodSignature)) {
|
|
78
|
+
const described = this.resolver.describeIndexedNode(s);
|
|
79
|
+
if (!described)
|
|
80
|
+
continue;
|
|
81
|
+
push(s, s.getNameNode(), described.name, 'method_signature', described.container, false, false);
|
|
82
|
+
}
|
|
83
|
+
for (const s of sourceFile.getDescendantsOfKind(ts_morph_1.SyntaxKind.PropertySignature)) {
|
|
84
|
+
const described = this.resolver.describeIndexedNode(s);
|
|
85
|
+
if (!described)
|
|
86
|
+
continue;
|
|
87
|
+
push(s, s.getNameNode(), described.name, 'method_signature', described.container, false, false);
|
|
88
|
+
}
|
|
89
|
+
for (const fn of sourceFile.getDescendantsOfKind(ts_morph_1.SyntaxKind.FunctionDeclaration)) {
|
|
90
|
+
if (!ts_morph_1.Node.isModuleBlock(fn.getParent()))
|
|
91
|
+
continue;
|
|
92
|
+
const described = this.resolver.describeIndexedNode(fn);
|
|
93
|
+
if (!described)
|
|
94
|
+
continue;
|
|
95
|
+
const nameNode = fn.getNameNode();
|
|
96
|
+
if (!nameNode)
|
|
97
|
+
continue;
|
|
98
|
+
push(fn, nameNode, described.name, 'function', described.container, false, fn.getBody() !== undefined);
|
|
99
|
+
}
|
|
100
|
+
for (const iface of sourceFile.getDescendantsOfKind(ts_morph_1.SyntaxKind.InterfaceDeclaration)) {
|
|
101
|
+
if (!ts_morph_1.Node.isModuleBlock(iface.getParent()))
|
|
102
|
+
continue;
|
|
103
|
+
const described = this.resolver.describeIndexedNode(iface);
|
|
104
|
+
if (!described)
|
|
105
|
+
continue;
|
|
106
|
+
push(iface, iface.getNameNode(), described.name, 'interface', described.container, false, true);
|
|
107
|
+
}
|
|
108
|
+
for (const ta of sourceFile.getDescendantsOfKind(ts_morph_1.SyntaxKind.TypeAliasDeclaration)) {
|
|
109
|
+
if (!ts_morph_1.Node.isModuleBlock(ta.getParent()))
|
|
110
|
+
continue;
|
|
111
|
+
const described = this.resolver.describeIndexedNode(ta);
|
|
112
|
+
if (!described)
|
|
113
|
+
continue;
|
|
114
|
+
push(ta, ta.getNameNode(), described.name, 'type', described.container, false, true);
|
|
115
|
+
}
|
|
116
|
+
for (const stmt of sourceFile.getDescendantsOfKind(ts_morph_1.SyntaxKind.VariableStatement)) {
|
|
117
|
+
if (!ts_morph_1.Node.isModuleBlock(stmt.getParent()))
|
|
118
|
+
continue;
|
|
119
|
+
for (const decl of stmt.getDeclarations()) {
|
|
120
|
+
const described = this.resolver.describeIndexedNode(decl);
|
|
121
|
+
if (!described)
|
|
122
|
+
continue;
|
|
123
|
+
push(decl, decl.getNameNode(), described.name, 'variable', described.container, false, true);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
return candidates;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
exports.MemberExtractor = MemberExtractor;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { SourceFile } from 'ts-morph';
|
|
2
|
+
import type { DeclarationCandidate } from '../declarations/DeclarationTreeBuilder';
|
|
3
|
+
export declare class TopLevelSymbolExtractor {
|
|
4
|
+
extractSymbols(sourceFile: SourceFile, filePath: string, serviceName: string): DeclarationCandidate[];
|
|
5
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TopLevelSymbolExtractor = void 0;
|
|
4
|
+
const node_helpers_1 = require("./node-helpers");
|
|
5
|
+
class TopLevelSymbolExtractor {
|
|
6
|
+
extractSymbols(sourceFile, filePath, serviceName) {
|
|
7
|
+
const candidates = [];
|
|
8
|
+
const sourceLines = sourceFile.getFullText().split('\n');
|
|
9
|
+
const lineAt = (node) => (0, node_helpers_1.lineTextAt)(sourceLines, sourceFile, node);
|
|
10
|
+
for (const cls of sourceFile.getClasses()) {
|
|
11
|
+
const name = cls.getName();
|
|
12
|
+
if (!name)
|
|
13
|
+
continue;
|
|
14
|
+
const nameNode = cls.getNameNode() ?? cls;
|
|
15
|
+
const { line, col } = (0, node_helpers_1.getPos)(sourceFile, nameNode);
|
|
16
|
+
candidates.push({
|
|
17
|
+
declNode: cls,
|
|
18
|
+
entry: {
|
|
19
|
+
project: serviceName, filePath, name, kind: 'class',
|
|
20
|
+
signature: lineAt(nameNode),
|
|
21
|
+
line, endLine: cls.getEndLineNumber(), col,
|
|
22
|
+
container: null, isStatic: false,
|
|
23
|
+
},
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
for (const fn of sourceFile.getFunctions()) {
|
|
27
|
+
const name = fn.getName();
|
|
28
|
+
if (!name)
|
|
29
|
+
continue;
|
|
30
|
+
const nameNode = fn.getNameNode() ?? fn;
|
|
31
|
+
const { line, col } = (0, node_helpers_1.getPos)(sourceFile, nameNode);
|
|
32
|
+
candidates.push({
|
|
33
|
+
declNode: fn,
|
|
34
|
+
entry: {
|
|
35
|
+
project: serviceName, filePath, name, kind: 'function',
|
|
36
|
+
signature: lineAt(nameNode),
|
|
37
|
+
line, endLine: fn.getEndLineNumber(), col,
|
|
38
|
+
container: null, isStatic: false, hasBody: fn.getBody() !== undefined,
|
|
39
|
+
},
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
for (const iface of sourceFile.getInterfaces()) {
|
|
43
|
+
const nameNode = iface.getNameNode();
|
|
44
|
+
const { line, col } = (0, node_helpers_1.getPos)(sourceFile, nameNode);
|
|
45
|
+
candidates.push({
|
|
46
|
+
declNode: iface,
|
|
47
|
+
entry: {
|
|
48
|
+
project: serviceName, filePath, name: iface.getName(), kind: 'interface',
|
|
49
|
+
signature: lineAt(nameNode),
|
|
50
|
+
line, endLine: iface.getEndLineNumber(), col,
|
|
51
|
+
container: null, isStatic: false,
|
|
52
|
+
},
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
for (const ta of sourceFile.getTypeAliases()) {
|
|
56
|
+
const nameNode = ta.getNameNode();
|
|
57
|
+
const { line, col } = (0, node_helpers_1.getPos)(sourceFile, nameNode);
|
|
58
|
+
candidates.push({
|
|
59
|
+
declNode: ta,
|
|
60
|
+
entry: {
|
|
61
|
+
project: serviceName, filePath, name: ta.getName(), kind: 'type',
|
|
62
|
+
signature: lineAt(nameNode),
|
|
63
|
+
line, endLine: ta.getEndLineNumber(), col,
|
|
64
|
+
container: null, isStatic: false,
|
|
65
|
+
},
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
for (const stmt of sourceFile.getVariableStatements()) {
|
|
69
|
+
for (const decl of stmt.getDeclarations()) {
|
|
70
|
+
const nameNode = decl.getNameNode();
|
|
71
|
+
const { line, col } = (0, node_helpers_1.getPos)(sourceFile, nameNode);
|
|
72
|
+
candidates.push({
|
|
73
|
+
declNode: decl,
|
|
74
|
+
entry: {
|
|
75
|
+
project: serviceName, filePath, name: decl.getName(), kind: 'variable',
|
|
76
|
+
signature: lineAt(nameNode),
|
|
77
|
+
line, endLine: stmt.getEndLineNumber(), col,
|
|
78
|
+
container: null, isStatic: false,
|
|
79
|
+
},
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return candidates;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
exports.TopLevelSymbolExtractor = TopLevelSymbolExtractor;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Node, type Decorator, type ObjectLiteralExpression, type PropertyAssignment, type ShorthandPropertyAssignment } from 'ts-morph';
|
|
2
|
+
import type { SymbolKind } from '../interfaces/IAstParser';
|
|
3
|
+
export declare const GRAPHQL_MODULE = "@nestjs/graphql";
|
|
4
|
+
export declare const GRAPHQL_TYPE_DECORATORS: Set<string>;
|
|
5
|
+
export declare const GRAPHQL_OPERATION_KIND: Record<string, SymbolKind>;
|
|
6
|
+
export declare const GRAPHQL_NAME_RE: RegExp;
|
|
7
|
+
export type GraphqlNameResult = {
|
|
8
|
+
ok: true;
|
|
9
|
+
name: string;
|
|
10
|
+
} | {
|
|
11
|
+
ok: false;
|
|
12
|
+
reason: 'non-literal-name' | 'invalid-name';
|
|
13
|
+
value?: string;
|
|
14
|
+
};
|
|
15
|
+
export declare function decoratorIdentifier(dec: Decorator): Node | undefined;
|
|
16
|
+
export declare function literalStringValue(node: Node): string | null;
|
|
17
|
+
export declare function checkGraphqlGrammar(name: string): GraphqlNameResult;
|
|
18
|
+
export declare function isAbstractGraphqlType(args: Node[]): boolean;
|
|
19
|
+
export declare function findNameProperty(obj: ObjectLiteralExpression): PropertyAssignment | ShorthandPropertyAssignment | undefined;
|
|
20
|
+
export declare function peekThroughWrapper(node: Node): {
|
|
21
|
+
inner: Node;
|
|
22
|
+
wrapped: boolean;
|
|
23
|
+
};
|
|
24
|
+
export declare function extractResolverIdentifier(argNode: Node): Node | null;
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GRAPHQL_NAME_RE = exports.GRAPHQL_OPERATION_KIND = exports.GRAPHQL_TYPE_DECORATORS = exports.GRAPHQL_MODULE = void 0;
|
|
4
|
+
exports.decoratorIdentifier = decoratorIdentifier;
|
|
5
|
+
exports.literalStringValue = literalStringValue;
|
|
6
|
+
exports.checkGraphqlGrammar = checkGraphqlGrammar;
|
|
7
|
+
exports.isAbstractGraphqlType = isAbstractGraphqlType;
|
|
8
|
+
exports.findNameProperty = findNameProperty;
|
|
9
|
+
exports.peekThroughWrapper = peekThroughWrapper;
|
|
10
|
+
exports.extractResolverIdentifier = extractResolverIdentifier;
|
|
11
|
+
const ts_morph_1 = require("ts-morph");
|
|
12
|
+
exports.GRAPHQL_MODULE = '@nestjs/graphql';
|
|
13
|
+
exports.GRAPHQL_TYPE_DECORATORS = new Set(['ObjectType', 'InputType', 'InterfaceType']);
|
|
14
|
+
exports.GRAPHQL_OPERATION_KIND = {
|
|
15
|
+
Query: 'graphql_query', Mutation: 'graphql_mutation', Subscription: 'graphql_subscription',
|
|
16
|
+
};
|
|
17
|
+
exports.GRAPHQL_NAME_RE = /^[_A-Za-z][_0-9A-Za-z]*$/;
|
|
18
|
+
function decoratorIdentifier(dec) {
|
|
19
|
+
const expr = dec.getExpression();
|
|
20
|
+
if (ts_morph_1.Node.isCallExpression(expr)) {
|
|
21
|
+
const callee = expr.getExpression();
|
|
22
|
+
return ts_morph_1.Node.isIdentifier(callee) ? callee : undefined;
|
|
23
|
+
}
|
|
24
|
+
return ts_morph_1.Node.isIdentifier(expr) ? expr : undefined;
|
|
25
|
+
}
|
|
26
|
+
function literalStringValue(node) {
|
|
27
|
+
if (ts_morph_1.Node.isStringLiteral(node) || ts_morph_1.Node.isNoSubstitutionTemplateLiteral(node))
|
|
28
|
+
return node.getLiteralValue();
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
function checkGraphqlGrammar(name) {
|
|
32
|
+
return exports.GRAPHQL_NAME_RE.test(name) ? { ok: true, name } : { ok: false, reason: 'invalid-name', value: name };
|
|
33
|
+
}
|
|
34
|
+
function isAbstractGraphqlType(args) {
|
|
35
|
+
return args.some((arg) => {
|
|
36
|
+
if (!ts_morph_1.Node.isObjectLiteralExpression(arg))
|
|
37
|
+
return false;
|
|
38
|
+
const prop = arg.getProperties().find((p) => {
|
|
39
|
+
if (!ts_morph_1.Node.isPropertyAssignment(p))
|
|
40
|
+
return false;
|
|
41
|
+
const nameNode = p.getNameNode();
|
|
42
|
+
if (ts_morph_1.Node.isIdentifier(nameNode))
|
|
43
|
+
return nameNode.getText() === 'isAbstract';
|
|
44
|
+
if (ts_morph_1.Node.isStringLiteral(nameNode))
|
|
45
|
+
return nameNode.getLiteralValue() === 'isAbstract';
|
|
46
|
+
return false;
|
|
47
|
+
});
|
|
48
|
+
const init = prop?.getInitializer();
|
|
49
|
+
return init !== undefined && ts_morph_1.Node.isTrueLiteral(init);
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
function findNameProperty(obj) {
|
|
53
|
+
return obj.getProperties().find((p) => {
|
|
54
|
+
if (!ts_morph_1.Node.isPropertyAssignment(p) && !ts_morph_1.Node.isShorthandPropertyAssignment(p))
|
|
55
|
+
return false;
|
|
56
|
+
const nameNode = p.getNameNode();
|
|
57
|
+
if (ts_morph_1.Node.isIdentifier(nameNode))
|
|
58
|
+
return nameNode.getText() === 'name';
|
|
59
|
+
if (ts_morph_1.Node.isStringLiteral(nameNode))
|
|
60
|
+
return nameNode.getLiteralValue() === 'name';
|
|
61
|
+
return false;
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
function peekThroughWrapper(node) {
|
|
65
|
+
let current = node;
|
|
66
|
+
let wrapped = false;
|
|
67
|
+
while (true) {
|
|
68
|
+
if (ts_morph_1.Node.isParenthesizedExpression(current) || ts_morph_1.Node.isAsExpression(current) || ts_morph_1.Node.isSatisfiesExpression(current) || ts_morph_1.Node.isNonNullExpression(current)) {
|
|
69
|
+
current = current.getExpression();
|
|
70
|
+
wrapped = true;
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
break;
|
|
74
|
+
}
|
|
75
|
+
return { inner: current, wrapped };
|
|
76
|
+
}
|
|
77
|
+
function extractResolverIdentifier(argNode) {
|
|
78
|
+
let target = argNode;
|
|
79
|
+
if (ts_morph_1.Node.isArrowFunction(target)) {
|
|
80
|
+
const body = target.getBody();
|
|
81
|
+
if (ts_morph_1.Node.isBlock(body))
|
|
82
|
+
return null;
|
|
83
|
+
target = body;
|
|
84
|
+
}
|
|
85
|
+
if (ts_morph_1.Node.isIdentifier(target))
|
|
86
|
+
return target;
|
|
87
|
+
if (ts_morph_1.Node.isArrayLiteralExpression(target)) {
|
|
88
|
+
const elements = target.getElements();
|
|
89
|
+
if (elements.length === 1 && ts_morph_1.Node.isIdentifier(elements[0]))
|
|
90
|
+
return elements[0];
|
|
91
|
+
}
|
|
92
|
+
return null;
|
|
93
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Node, type SourceFile } from 'ts-morph';
|
|
2
|
+
export type ResolveDeclaration = (identifier: Node) => Node | undefined;
|
|
3
|
+
export declare function getPos(sourceFile: SourceFile, node: Node): {
|
|
4
|
+
line: number;
|
|
5
|
+
col: number;
|
|
6
|
+
};
|
|
7
|
+
export declare function lineTextAt(sourceLines: string[], sourceFile: SourceFile, node: Node): string;
|
|
8
|
+
export declare function memberName(nameNode: Node | undefined): string | null;
|
|
9
|
+
export declare function unwrapExpr(node: Node): Node;
|
|
10
|
+
export declare function unwrapParent(node: Node): Node | undefined;
|
|
11
|
+
export declare function defaultResolveDeclaration(identifier: Node): Node | undefined;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getPos = getPos;
|
|
4
|
+
exports.lineTextAt = lineTextAt;
|
|
5
|
+
exports.memberName = memberName;
|
|
6
|
+
exports.unwrapExpr = unwrapExpr;
|
|
7
|
+
exports.unwrapParent = unwrapParent;
|
|
8
|
+
exports.defaultResolveDeclaration = defaultResolveDeclaration;
|
|
9
|
+
const ts_morph_1 = require("ts-morph");
|
|
10
|
+
function getPos(sourceFile, node) {
|
|
11
|
+
const { line, character } = sourceFile.compilerNode
|
|
12
|
+
.getLineAndCharacterOfPosition(node.getStart());
|
|
13
|
+
return { line: line + 1, col: character + 1 };
|
|
14
|
+
}
|
|
15
|
+
function lineTextAt(sourceLines, sourceFile, node) {
|
|
16
|
+
const { line } = getPos(sourceFile, node);
|
|
17
|
+
return (sourceLines[line - 1] ?? node.getText().split('\n')[0]).trim();
|
|
18
|
+
}
|
|
19
|
+
function memberName(nameNode) {
|
|
20
|
+
if (!nameNode)
|
|
21
|
+
return null;
|
|
22
|
+
if (ts_morph_1.Node.isPrivateIdentifier(nameNode))
|
|
23
|
+
return nameNode.getText();
|
|
24
|
+
if (ts_morph_1.Node.isIdentifier(nameNode))
|
|
25
|
+
return nameNode.getText();
|
|
26
|
+
if (ts_morph_1.Node.isStringLiteral(nameNode))
|
|
27
|
+
return nameNode.getLiteralValue();
|
|
28
|
+
if (ts_morph_1.Node.isNumericLiteral(nameNode))
|
|
29
|
+
return nameNode.getText();
|
|
30
|
+
if (ts_morph_1.Node.isComputedPropertyName(nameNode))
|
|
31
|
+
return nameNode.getText().replace(/\s+/g, '');
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
function unwrapExpr(node) {
|
|
35
|
+
let current = node;
|
|
36
|
+
while (ts_morph_1.Node.isParenthesizedExpression(current) || ts_morph_1.Node.isAsExpression(current) || ts_morph_1.Node.isSatisfiesExpression(current)) {
|
|
37
|
+
current = current.getExpression();
|
|
38
|
+
}
|
|
39
|
+
return current;
|
|
40
|
+
}
|
|
41
|
+
function unwrapParent(node) {
|
|
42
|
+
let current = node.getParent();
|
|
43
|
+
while (current && (ts_morph_1.Node.isParenthesizedExpression(current) || ts_morph_1.Node.isAsExpression(current) || ts_morph_1.Node.isSatisfiesExpression(current))) {
|
|
44
|
+
current = current.getParent();
|
|
45
|
+
}
|
|
46
|
+
return current;
|
|
47
|
+
}
|
|
48
|
+
function defaultResolveDeclaration(identifier) {
|
|
49
|
+
const sym = identifier.getSymbol();
|
|
50
|
+
if (!sym)
|
|
51
|
+
return undefined;
|
|
52
|
+
const firstDecl = sym.getDeclarations()?.[0];
|
|
53
|
+
const resolved = firstDecl && ts_morph_1.Node.isImportSpecifier(firstDecl) ? (sym.getAliasedSymbol() ?? sym) : sym;
|
|
54
|
+
return resolved.getDeclarations()?.[0];
|
|
55
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Config } from '../config';
|
|
2
|
+
import type { IChunker, ChunkPiece, ChunkOpts } from '../interfaces/IChunker';
|
|
3
|
+
import type { IChunkPostProcessor, IChunkStrategy } from './interfaces';
|
|
4
|
+
export declare class AstChunker implements IChunker {
|
|
5
|
+
private readonly declarationStrategy;
|
|
6
|
+
private readonly characterStrategy;
|
|
7
|
+
private readonly postProcessors;
|
|
8
|
+
private readonly declarationPostProcessors;
|
|
9
|
+
private readonly chunkSize;
|
|
10
|
+
constructor(declarationStrategy: IChunkStrategy, characterStrategy: IChunkStrategy, postProcessors: IChunkPostProcessor[], declarationPostProcessors: IChunkPostProcessor[], config: Config);
|
|
11
|
+
chunk(code: string, opts: ChunkOpts): Promise<ChunkPiece[]>;
|
|
12
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AstChunker = void 0;
|
|
4
|
+
const DeclarationTree_1 = require("../declarations/DeclarationTree");
|
|
5
|
+
const SourceLines_1 = require("../declarations/SourceLines");
|
|
6
|
+
class AstChunker {
|
|
7
|
+
declarationStrategy;
|
|
8
|
+
characterStrategy;
|
|
9
|
+
postProcessors;
|
|
10
|
+
declarationPostProcessors;
|
|
11
|
+
chunkSize;
|
|
12
|
+
constructor(declarationStrategy, characterStrategy, postProcessors, declarationPostProcessors, config) {
|
|
13
|
+
this.declarationStrategy = declarationStrategy;
|
|
14
|
+
this.characterStrategy = characterStrategy;
|
|
15
|
+
this.postProcessors = postProcessors;
|
|
16
|
+
this.declarationPostProcessors = declarationPostProcessors;
|
|
17
|
+
this.chunkSize = config.indexer.chunkSize;
|
|
18
|
+
}
|
|
19
|
+
async chunk(code, opts) {
|
|
20
|
+
const declarations = opts.declarations ?? DeclarationTree_1.DeclarationTree.EMPTY;
|
|
21
|
+
const ctx = { lines: new SourceLines_1.SourceLines(code, { jsx: opts.jsx }), declarations, chunkSize: this.chunkSize, removed: [], splitPoints: [], characterSplit: [] };
|
|
22
|
+
const byDeclarations = !opts.isSchemaFile && opts.strategy !== 'character' && declarations.roots.length > 0;
|
|
23
|
+
let pieces = await (byDeclarations ? this.declarationStrategy : this.characterStrategy).chunk(ctx, opts);
|
|
24
|
+
const processors = byDeclarations ? [...this.postProcessors, ...this.declarationPostProcessors] : this.postProcessors;
|
|
25
|
+
for (const processor of processors)
|
|
26
|
+
pieces = processor.process(pieces, ctx);
|
|
27
|
+
return pieces;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
exports.AstChunker = AstChunker;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ChunkOpts, ChunkPiece } from '../interfaces/IChunker';
|
|
2
|
+
import type { ChunkContext, IChunkStrategy, ITextSplitter } from './interfaces';
|
|
3
|
+
export declare class CharacterChunkStrategy implements IChunkStrategy {
|
|
4
|
+
private readonly jsSplitter;
|
|
5
|
+
private readonly schemaSplitter;
|
|
6
|
+
constructor(jsSplitter: ITextSplitter, schemaSplitter: ITextSplitter);
|
|
7
|
+
chunk(ctx: ChunkContext, opts: ChunkOpts): Promise<ChunkPiece[]>;
|
|
8
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CharacterChunkStrategy = void 0;
|
|
4
|
+
class CharacterChunkStrategy {
|
|
5
|
+
jsSplitter;
|
|
6
|
+
schemaSplitter;
|
|
7
|
+
constructor(jsSplitter, schemaSplitter) {
|
|
8
|
+
this.jsSplitter = jsSplitter;
|
|
9
|
+
this.schemaSplitter = schemaSplitter;
|
|
10
|
+
}
|
|
11
|
+
chunk(ctx, opts) {
|
|
12
|
+
return (opts.isSchemaFile ? this.schemaSplitter : this.jsSplitter).split(ctx.lines.text, 1);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
exports.CharacterChunkStrategy = CharacterChunkStrategy;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { ChunkPiece } from '../interfaces/IChunker';
|
|
2
|
+
import type { ChunkContext, IChunkStrategy, ISplitPolicy } from './interfaces';
|
|
3
|
+
import { RunPacker } from './RunPacker';
|
|
4
|
+
export declare class DeclarationChunkStrategy implements IChunkStrategy {
|
|
5
|
+
private readonly policy;
|
|
6
|
+
private readonly packer;
|
|
7
|
+
constructor(policy: ISplitPolicy, packer: RunPacker);
|
|
8
|
+
chunk(ctx: ChunkContext): Promise<ChunkPiece[]>;
|
|
9
|
+
private splitNode;
|
|
10
|
+
private coversParent;
|
|
11
|
+
private splitLevel;
|
|
12
|
+
private packRuns;
|
|
13
|
+
private static isShortPrologue;
|
|
14
|
+
private static gaps;
|
|
15
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DeclarationChunkStrategy = void 0;
|
|
4
|
+
const FragmentMerger_1 = require("./FragmentMerger");
|
|
5
|
+
const RunPacker_1 = require("./RunPacker");
|
|
6
|
+
class DeclarationChunkStrategy {
|
|
7
|
+
policy;
|
|
8
|
+
packer;
|
|
9
|
+
constructor(policy, packer) {
|
|
10
|
+
this.policy = policy;
|
|
11
|
+
this.packer = packer;
|
|
12
|
+
}
|
|
13
|
+
async chunk(ctx) {
|
|
14
|
+
const roots = ctx.declarations.roots;
|
|
15
|
+
const removed = DeclarationChunkStrategy.gaps({ start: 1, end: ctx.lines.count }, roots)
|
|
16
|
+
.flatMap(gap => ctx.lines.importRegions(gap.start, gap.end));
|
|
17
|
+
if (removed.length > 0 && DeclarationChunkStrategy.isShortPrologue(removed[0].start - 1, ctx.lines)) {
|
|
18
|
+
removed[0] = { start: 1, end: removed[0].end };
|
|
19
|
+
}
|
|
20
|
+
ctx.removed.push(...removed);
|
|
21
|
+
return this.splitLevel({ start: 1, end: ctx.lines.count }, roots, null, removed, ctx);
|
|
22
|
+
}
|
|
23
|
+
async splitNode(node, ctx) {
|
|
24
|
+
if (ctx.lines.length(node.start, node.end) <= ctx.chunkSize)
|
|
25
|
+
return RunPacker_1.RunPacker.piece(node, ctx.lines);
|
|
26
|
+
let children = node.children;
|
|
27
|
+
while (children.length === 1 && this.coversParent(children[0], node, ctx))
|
|
28
|
+
children = children[0].children;
|
|
29
|
+
return this.splitLevel(node, children, node, [], ctx);
|
|
30
|
+
}
|
|
31
|
+
coversParent(child, parent, ctx) {
|
|
32
|
+
if (child.end !== parent.end || child.start < parent.start)
|
|
33
|
+
return false;
|
|
34
|
+
for (let n = parent.start; n < child.start; n++) {
|
|
35
|
+
if (!ctx.lines.isBlank(n) && !ctx.lines.isCommentOnly(n))
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
return true;
|
|
39
|
+
}
|
|
40
|
+
async splitLevel(range, children, boundary, removed, ctx) {
|
|
41
|
+
const splitPoints = children.filter(c => this.policy.isSplitPoint(c, children, boundary, ctx.lines));
|
|
42
|
+
const packed = children.filter(c => !splitPoints.includes(c));
|
|
43
|
+
ctx.splitPoints.push(...splitPoints);
|
|
44
|
+
const pieces = [];
|
|
45
|
+
let cursor = range.start;
|
|
46
|
+
for (const sp of splitPoints) {
|
|
47
|
+
if (cursor < sp.start)
|
|
48
|
+
pieces.push(...await this.packRuns({ start: cursor, end: sp.start - 1 }, packed, boundary, removed, ctx));
|
|
49
|
+
pieces.push(...await this.splitNode(sp, ctx));
|
|
50
|
+
cursor = sp.end + 1;
|
|
51
|
+
}
|
|
52
|
+
if (cursor <= range.end)
|
|
53
|
+
pieces.push(...await this.packRuns({ start: cursor, end: range.end }, packed, boundary, removed, ctx));
|
|
54
|
+
return pieces;
|
|
55
|
+
}
|
|
56
|
+
async packRuns(span, children, owner, removed, ctx) {
|
|
57
|
+
const pieces = [];
|
|
58
|
+
for (const run of DeclarationChunkStrategy.gaps(span, removed)) {
|
|
59
|
+
pieces.push(...await this.packer.pack(run, children, ctx.lines, ctx.chunkSize, ctx.characterSplit, owner));
|
|
60
|
+
}
|
|
61
|
+
return pieces;
|
|
62
|
+
}
|
|
63
|
+
static isShortPrologue(end, lines) {
|
|
64
|
+
if (end < 1)
|
|
65
|
+
return false;
|
|
66
|
+
for (let n = lines.line(1).startsWith('#!') ? 2 : 1; n <= end; n++) {
|
|
67
|
+
if (!lines.isBlank(n) && !lines.isCommentOnly(n) && !lines.isDirective(n))
|
|
68
|
+
return false;
|
|
69
|
+
}
|
|
70
|
+
return lines.slice(1, end).replace(/\s+/g, '').length < FragmentMerger_1.MIN_FRAGMENT_CHARS;
|
|
71
|
+
}
|
|
72
|
+
static gaps(span, taken) {
|
|
73
|
+
const out = [];
|
|
74
|
+
let cursor = span.start;
|
|
75
|
+
for (const t of [...taken].sort((a, b) => a.start - b.start)) {
|
|
76
|
+
if (t.end < cursor || t.start > span.end)
|
|
77
|
+
continue;
|
|
78
|
+
if (cursor < t.start)
|
|
79
|
+
out.push({ start: cursor, end: t.start - 1 });
|
|
80
|
+
cursor = Math.max(cursor, t.end + 1);
|
|
81
|
+
}
|
|
82
|
+
if (cursor <= span.end)
|
|
83
|
+
out.push({ start: cursor, end: span.end });
|
|
84
|
+
return out;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
exports.DeclarationChunkStrategy = DeclarationChunkStrategy;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { ChunkPiece } from '../interfaces/IChunker';
|
|
2
|
+
import type { ChunkContext, IChunkPostProcessor } from './interfaces';
|
|
3
|
+
export declare const MIN_FRAGMENT_CHARS = 60;
|
|
4
|
+
export declare class FragmentMerger implements IChunkPostProcessor {
|
|
5
|
+
process(pieces: ChunkPiece[], ctx: ChunkContext): ChunkPiece[];
|
|
6
|
+
private isFragment;
|
|
7
|
+
private canMerge;
|
|
8
|
+
private static scope;
|
|
9
|
+
private static within;
|
|
10
|
+
private static merge;
|
|
11
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FragmentMerger = exports.MIN_FRAGMENT_CHARS = void 0;
|
|
4
|
+
const owner_path_1 = require("../owner-path");
|
|
5
|
+
exports.MIN_FRAGMENT_CHARS = 60;
|
|
6
|
+
class FragmentMerger {
|
|
7
|
+
process(pieces, ctx) {
|
|
8
|
+
const queue = [...pieces].sort((a, b) => a.startLine - b.startLine);
|
|
9
|
+
const out = [];
|
|
10
|
+
for (let i = 0; i < queue.length; i++) {
|
|
11
|
+
const piece = queue[i];
|
|
12
|
+
if (!this.isFragment(piece, ctx)) {
|
|
13
|
+
out.push(piece);
|
|
14
|
+
continue;
|
|
15
|
+
}
|
|
16
|
+
const scope = FragmentMerger.scope(piece, ctx);
|
|
17
|
+
const prev = out[out.length - 1];
|
|
18
|
+
if (prev && FragmentMerger.within(prev, scope) && this.canMerge(prev, piece, ctx)) {
|
|
19
|
+
out[out.length - 1] = FragmentMerger.merge(prev, piece, ctx);
|
|
20
|
+
continue;
|
|
21
|
+
}
|
|
22
|
+
const next = queue[i + 1];
|
|
23
|
+
if (next && FragmentMerger.within(next, scope) && this.canMerge(piece, next, ctx)) {
|
|
24
|
+
queue[i + 1] = FragmentMerger.merge(piece, next, ctx);
|
|
25
|
+
continue;
|
|
26
|
+
}
|
|
27
|
+
out.push(piece);
|
|
28
|
+
}
|
|
29
|
+
return out;
|
|
30
|
+
}
|
|
31
|
+
isFragment(piece, ctx) {
|
|
32
|
+
return ctx.lines.significantLength(piece.startLine, piece.endLine) < exports.MIN_FRAGMENT_CHARS
|
|
33
|
+
&& (0, owner_path_1.ownedLines)(piece, ctx.declarations, ctx.lines).length === 0;
|
|
34
|
+
}
|
|
35
|
+
canMerge(first, second, ctx) {
|
|
36
|
+
const start = Math.min(first.startLine, second.startLine);
|
|
37
|
+
const end = Math.max(first.endLine, second.endLine);
|
|
38
|
+
if (ctx.removed.some(r => r.start > first.endLine && r.end < second.startLine))
|
|
39
|
+
return false;
|
|
40
|
+
return ctx.lines.length(start, end) <= ctx.chunkSize;
|
|
41
|
+
}
|
|
42
|
+
static scope(piece, ctx) {
|
|
43
|
+
let best = null;
|
|
44
|
+
for (const sp of [...ctx.splitPoints, ...ctx.characterSplit]) {
|
|
45
|
+
if (sp.start > piece.startLine || sp.end < piece.endLine)
|
|
46
|
+
continue;
|
|
47
|
+
if (!best || sp.end - sp.start < best.end - best.start)
|
|
48
|
+
best = sp;
|
|
49
|
+
}
|
|
50
|
+
return best;
|
|
51
|
+
}
|
|
52
|
+
static within(piece, scope) {
|
|
53
|
+
return !scope || (scope.start <= piece.startLine && piece.endLine <= scope.end);
|
|
54
|
+
}
|
|
55
|
+
static merge(first, second, ctx) {
|
|
56
|
+
const startLine = Math.min(first.startLine, second.startLine);
|
|
57
|
+
const endLine = Math.max(first.endLine, second.endLine);
|
|
58
|
+
return { content: ctx.lines.slice(startLine, endLine), startLine, endLine };
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
exports.FragmentMerger = FragmentMerger;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { ChunkPiece } from '../interfaces/IChunker';
|
|
2
|
+
import type { ChunkContext, IChunkPostProcessor } from './interfaces';
|
|
3
|
+
export declare class ImportOnlyFilter implements IChunkPostProcessor {
|
|
4
|
+
process(pieces: ChunkPiece[], ctx: ChunkContext): ChunkPiece[];
|
|
5
|
+
}
|