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,15 @@
|
|
|
1
|
+
import type { IEmbedder, ILogger } from '../../interfaces';
|
|
2
|
+
import type { ChunkRow, SearchResult } from '../../interfaces/IChunkSearch';
|
|
3
|
+
import type { SearchPlan } from './search-plan';
|
|
4
|
+
export declare function rerankDocument(row: ChunkRow): string;
|
|
5
|
+
export interface RerankOutcome {
|
|
6
|
+
reranked: SearchResult[];
|
|
7
|
+
rerankFailed: boolean;
|
|
8
|
+
rerankMs: number;
|
|
9
|
+
}
|
|
10
|
+
export declare class RerankStage {
|
|
11
|
+
private embedder;
|
|
12
|
+
private logger;
|
|
13
|
+
constructor(embedder: IEmbedder, logger: ILogger);
|
|
14
|
+
run(query: string, candidates: SearchResult[], vector: SearchResult[], plan: SearchPlan, startedAt: number): Promise<RerankOutcome>;
|
|
15
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RerankStage = void 0;
|
|
4
|
+
exports.rerankDocument = rerankDocument;
|
|
5
|
+
const result_shaping_1 = require("../result-shaping");
|
|
6
|
+
function rerankDocument(row) {
|
|
7
|
+
const symbol = row.ownerPath ? ` | Symbol: ${oneLine(row.ownerPath)}` : '';
|
|
8
|
+
return `File: ${oneLine(row.filePath)}${symbol}\n${row.content}`;
|
|
9
|
+
}
|
|
10
|
+
function oneLine(text) {
|
|
11
|
+
return text.replace(/\s+/g, ' ').trim();
|
|
12
|
+
}
|
|
13
|
+
class RerankStage {
|
|
14
|
+
embedder;
|
|
15
|
+
logger;
|
|
16
|
+
constructor(embedder, logger) {
|
|
17
|
+
this.embedder = embedder;
|
|
18
|
+
this.logger = logger;
|
|
19
|
+
}
|
|
20
|
+
async run(query, candidates, vector, plan, startedAt) {
|
|
21
|
+
if (candidates.length === 0)
|
|
22
|
+
return { reranked: [], rerankFailed: false, rerankMs: 0 };
|
|
23
|
+
const tRerank0 = Date.now();
|
|
24
|
+
try {
|
|
25
|
+
const topN = plan.perFileActive ? candidates.length : plan.limit;
|
|
26
|
+
const indices = await this.embedder.rerank(query, candidates.map(rerankDocument), topN);
|
|
27
|
+
const rerankMs = Date.now() - tRerank0;
|
|
28
|
+
this.logger.debug('RerankStage: searchChunks rerank done', { indices, ms: Date.now() - startedAt });
|
|
29
|
+
const order = indices.filter(i => i >= 0 && i < candidates.length).map(i => candidates[i]);
|
|
30
|
+
return { reranked: (0, result_shaping_1.limitPerFile)(order, plan.limit, plan.perFile), rerankFailed: false, rerankMs };
|
|
31
|
+
}
|
|
32
|
+
catch (err) {
|
|
33
|
+
const rerankMs = Date.now() - tRerank0;
|
|
34
|
+
this.logger.warn('RerankStage: rerank failed, falling back to vector order', {
|
|
35
|
+
err,
|
|
36
|
+
ms: Date.now() - startedAt,
|
|
37
|
+
});
|
|
38
|
+
return { reranked: vector, rerankFailed: true, rerankMs };
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
exports.RerankStage = RerankStage;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { ResolvedThreshold } from '../../constants';
|
|
2
|
+
import type { SearchResult } from '../../interfaces/IChunkSearch';
|
|
3
|
+
export interface SearchMetricsInput {
|
|
4
|
+
fetchLimit: number;
|
|
5
|
+
candidates: SearchResult[];
|
|
6
|
+
results: SearchResult[];
|
|
7
|
+
poolSaturated: boolean;
|
|
8
|
+
indexParams: {
|
|
9
|
+
efSearch: number;
|
|
10
|
+
iterativeScan: string;
|
|
11
|
+
};
|
|
12
|
+
threshold: ResolvedThreshold;
|
|
13
|
+
embedMs: number;
|
|
14
|
+
dbMs: number;
|
|
15
|
+
rerankMs: number;
|
|
16
|
+
totalMs: number;
|
|
17
|
+
}
|
|
18
|
+
export declare function searchMetrics(query: string, m: SearchMetricsInput): Record<string, unknown>;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.searchMetrics = searchMetrics;
|
|
4
|
+
function searchMetrics(query, m) {
|
|
5
|
+
const { candidates, results } = m;
|
|
6
|
+
const contentIndex = new Map(candidates.map((c, i) => [c, i]));
|
|
7
|
+
const maxCosineRankSurvived = results.reduce((max, r) => Math.max(max, contentIndex.get(r) ?? -1), -1);
|
|
8
|
+
const fileCounts = new Map();
|
|
9
|
+
for (const r of results)
|
|
10
|
+
fileCounts.set(r.filePath, (fileCounts.get(r.filePath) ?? 0) + 1);
|
|
11
|
+
const topFileCount = results.length ? Math.max(...fileCounts.values()) : 0;
|
|
12
|
+
return {
|
|
13
|
+
query: query.slice(0, 120),
|
|
14
|
+
fetchLimit: m.fetchLimit,
|
|
15
|
+
candidatesReturned: candidates.length,
|
|
16
|
+
poolSaturated: m.poolSaturated,
|
|
17
|
+
maxCosineRankSurvived,
|
|
18
|
+
resultCount: results.length,
|
|
19
|
+
distinctFilesInResult: fileCounts.size,
|
|
20
|
+
topFileShare: results.length ? +(topFileCount / results.length).toFixed(3) : 0,
|
|
21
|
+
bestResultScore: results.length ? Math.min(...results.map(r => r.score)) : null,
|
|
22
|
+
worstResultScore: results.length ? Math.max(...results.map(r => r.score)) : null,
|
|
23
|
+
efSearch: m.indexParams.efSearch,
|
|
24
|
+
iterativeScan: m.indexParams.iterativeScan,
|
|
25
|
+
threshold: m.threshold.value,
|
|
26
|
+
thresholdSource: m.threshold.source,
|
|
27
|
+
embedMs: m.embedMs,
|
|
28
|
+
rerankMs: m.rerankMs,
|
|
29
|
+
dbMs: m.dbMs,
|
|
30
|
+
totalMs: m.totalMs,
|
|
31
|
+
};
|
|
32
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { Config } from '../../config';
|
|
2
|
+
import { type ResolvedThreshold } from '../../constants';
|
|
3
|
+
export interface SearchPlan {
|
|
4
|
+
limit: number;
|
|
5
|
+
perFile: number;
|
|
6
|
+
threshold: ResolvedThreshold;
|
|
7
|
+
reranking: boolean;
|
|
8
|
+
perFileActive: boolean;
|
|
9
|
+
fetchLimit: number;
|
|
10
|
+
dbLimit: number;
|
|
11
|
+
}
|
|
12
|
+
export declare function planSearch(call: {
|
|
13
|
+
limit: number;
|
|
14
|
+
perFile: number;
|
|
15
|
+
threshold?: number;
|
|
16
|
+
rerankOverride?: boolean;
|
|
17
|
+
rerankAvailable: boolean;
|
|
18
|
+
}, config: Config): SearchPlan;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.planSearch = planSearch;
|
|
4
|
+
const constants_1 = require("../../constants");
|
|
5
|
+
function planSearch(call, config) {
|
|
6
|
+
const { limit, perFile, threshold, rerankOverride } = call;
|
|
7
|
+
const resolvedThreshold = (0, constants_1.resolveThreshold)({
|
|
8
|
+
callValue: threshold,
|
|
9
|
+
configValue: config.search.similarityThreshold,
|
|
10
|
+
model: config.embedding.model,
|
|
11
|
+
});
|
|
12
|
+
const reranking = rerankOverride === false ? false : call.rerankAvailable;
|
|
13
|
+
const perFileActive = perFile < limit;
|
|
14
|
+
const fetchLimit = reranking || perFileActive
|
|
15
|
+
? Math.min(Math.max(limit * config.reranker.overfetch, config.reranker.candidateFloor), 200)
|
|
16
|
+
: limit;
|
|
17
|
+
const dbLimit = fetchLimit + 1;
|
|
18
|
+
return { limit, perFile, threshold: resolvedThreshold, reranking, perFileActive, fetchLimit, dbLimit };
|
|
19
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { Config } from '../config';
|
|
2
|
+
import type { IDatabase, IEmbedder, ILogger, IProjectDiscovery } from '../interfaces';
|
|
3
|
+
import { type WorkspaceFs } from '../workspace/fs-access';
|
|
4
|
+
import { ProjectRoots } from '../workspace/ProjectRoots';
|
|
5
|
+
import { ToolPaths } from '../workspace/ToolPaths';
|
|
6
|
+
import { WorkspaceFiles } from '../workspace/WorkspaceFiles';
|
|
7
|
+
import { GrepRunner } from '../workspace/GrepRunner';
|
|
8
|
+
import { SymbolLookup } from './SymbolLookup';
|
|
9
|
+
import { CallGraph } from './CallGraph';
|
|
10
|
+
import { DependencyGraph } from './DependencyGraph';
|
|
11
|
+
import { IndexIdentityGuard } from './IndexIdentityGuard';
|
|
12
|
+
import { ChunkSearch } from './ChunkSearch';
|
|
13
|
+
import { ProjectCatalog } from './ProjectCatalog';
|
|
14
|
+
export interface SearchServices {
|
|
15
|
+
readonly roots: ProjectRoots;
|
|
16
|
+
readonly paths: ToolPaths;
|
|
17
|
+
readonly files: WorkspaceFiles;
|
|
18
|
+
readonly grep: GrepRunner;
|
|
19
|
+
readonly symbols: SymbolLookup;
|
|
20
|
+
readonly calls: CallGraph;
|
|
21
|
+
readonly dependencies: DependencyGraph;
|
|
22
|
+
readonly identity: IndexIdentityGuard;
|
|
23
|
+
readonly chunks: ChunkSearch;
|
|
24
|
+
readonly catalog: ProjectCatalog;
|
|
25
|
+
}
|
|
26
|
+
export declare function createSearchServices(db: IDatabase, embedder: IEmbedder, discovery: IProjectDiscovery, config: Config, logger?: ILogger, fsDeps?: Partial<WorkspaceFs>): SearchServices;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createSearchServices = createSearchServices;
|
|
4
|
+
const LoggerService_1 = require("../services/LoggerService");
|
|
5
|
+
const fs_access_1 = require("../workspace/fs-access");
|
|
6
|
+
const ProjectRoots_1 = require("../workspace/ProjectRoots");
|
|
7
|
+
const ToolPaths_1 = require("../workspace/ToolPaths");
|
|
8
|
+
const WorkspaceFiles_1 = require("../workspace/WorkspaceFiles");
|
|
9
|
+
const GrepRunner_1 = require("../workspace/GrepRunner");
|
|
10
|
+
const SymbolLookup_1 = require("./SymbolLookup");
|
|
11
|
+
const CallGraph_1 = require("./CallGraph");
|
|
12
|
+
const DependencyGraph_1 = require("./DependencyGraph");
|
|
13
|
+
const IndexIdentityGuard_1 = require("./IndexIdentityGuard");
|
|
14
|
+
const ChunkSearch_1 = require("./ChunkSearch");
|
|
15
|
+
const ProjectCatalog_1 = require("./ProjectCatalog");
|
|
16
|
+
function createSearchServices(db, embedder, discovery, config, logger = LoggerService_1.LoggerService.silent(), fsDeps = {}) {
|
|
17
|
+
const fs = { ...fs_access_1.NODE_FS, ...fsDeps };
|
|
18
|
+
const roots = new ProjectRoots_1.ProjectRoots(discovery, config);
|
|
19
|
+
const paths = new ToolPaths_1.ToolPaths(db, roots, logger, fs);
|
|
20
|
+
const files = new WorkspaceFiles_1.WorkspaceFiles(paths, roots, logger, fs);
|
|
21
|
+
const grep = new GrepRunner_1.GrepRunner(logger);
|
|
22
|
+
const symbols = new SymbolLookup_1.SymbolLookup(db, grep, roots, paths, config, logger);
|
|
23
|
+
const calls = new CallGraph_1.CallGraph(db, logger);
|
|
24
|
+
const dependencies = new DependencyGraph_1.DependencyGraph(db, roots, config, logger);
|
|
25
|
+
const identity = new IndexIdentityGuard_1.IndexIdentityGuard(db, embedder, config);
|
|
26
|
+
const chunks = new ChunkSearch_1.ChunkSearch(db, embedder, identity, config, logger);
|
|
27
|
+
const catalog = new ProjectCatalog_1.ProjectCatalog(db, roots, fs);
|
|
28
|
+
return { roots, paths, files, grep, symbols, calls, dependencies, identity, chunks, catalog };
|
|
29
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const OUTSIDE_WORKSPACE_VALUE: (col: string) => string;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DEFAULT_PER_FILE = void 0;
|
|
4
|
+
exports.limitPerFile = limitPerFile;
|
|
5
|
+
exports.DEFAULT_PER_FILE = 2;
|
|
6
|
+
function limitPerFile(ranked, limit, perFile) {
|
|
7
|
+
const taken = [];
|
|
8
|
+
const perFileCount = new Map();
|
|
9
|
+
for (const entry of ranked) {
|
|
10
|
+
if (taken.length >= limit)
|
|
11
|
+
break;
|
|
12
|
+
const count = perFileCount.get(entry.filePath) ?? 0;
|
|
13
|
+
if (count >= perFile)
|
|
14
|
+
continue;
|
|
15
|
+
perFileCount.set(entry.filePath, count + 1);
|
|
16
|
+
taken.push(entry);
|
|
17
|
+
}
|
|
18
|
+
return taken;
|
|
19
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { IDatabase } from '../interfaces';
|
|
2
|
+
import type { SymbolKind } from '../interfaces/ISymbolLookup';
|
|
3
|
+
export declare function symbolMatch(name: string, container: string | null, params: unknown[]): {
|
|
4
|
+
filter: string;
|
|
5
|
+
exactRank: string | null;
|
|
6
|
+
};
|
|
7
|
+
export declare const QUALIFIED_SQL = "COALESCE(container || '.', '') || name";
|
|
8
|
+
export declare const SIMILAR_NAMES_LIMIT = 5;
|
|
9
|
+
export declare function similarSymbolNames(db: IDatabase, name: string, project: string | null, exactFirst: boolean): Promise<{
|
|
10
|
+
names: string[];
|
|
11
|
+
truncated: boolean;
|
|
12
|
+
}>;
|
|
13
|
+
export declare function symbolIndexedElsewhere(db: IDatabase, name: string, project: string | null, kind: SymbolKind): Promise<boolean>;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SIMILAR_NAMES_LIMIT = exports.QUALIFIED_SQL = void 0;
|
|
4
|
+
exports.symbolMatch = symbolMatch;
|
|
5
|
+
exports.similarSymbolNames = similarSymbolNames;
|
|
6
|
+
exports.symbolIndexedElsewhere = symbolIndexedElsewhere;
|
|
7
|
+
const symbol_name_1 = require("../symbol-name");
|
|
8
|
+
function symbolMatch(name, container, params) {
|
|
9
|
+
params.push(name);
|
|
10
|
+
const nameFilter = `name = $${params.length}`;
|
|
11
|
+
if (container === null)
|
|
12
|
+
return { filter: nameFilter, exactRank: null };
|
|
13
|
+
params.push(container);
|
|
14
|
+
const exactParam = params.length;
|
|
15
|
+
params.push(`%.${(0, symbol_name_1.escapeLike)(container)}`);
|
|
16
|
+
const suffixParam = params.length;
|
|
17
|
+
return {
|
|
18
|
+
filter: `${nameFilter} AND (container = $${exactParam} OR container LIKE $${suffixParam} ESCAPE '\\')`,
|
|
19
|
+
exactRank: `(CASE WHEN container = $${exactParam} THEN 0 ELSE 1 END)`,
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
exports.QUALIFIED_SQL = `COALESCE(container || '.', '') || name`;
|
|
23
|
+
exports.SIMILAR_NAMES_LIMIT = 5;
|
|
24
|
+
async function similarSymbolNames(db, name, project, exactFirst) {
|
|
25
|
+
const params = [];
|
|
26
|
+
let projectFilter = '';
|
|
27
|
+
if (project !== null) {
|
|
28
|
+
params.push(project);
|
|
29
|
+
projectFilter = `project = $${params.length} AND `;
|
|
30
|
+
}
|
|
31
|
+
params.push(`${(0, symbol_name_1.escapeLike)(name)}%`);
|
|
32
|
+
const likeParam = params.length;
|
|
33
|
+
let exactRank = '';
|
|
34
|
+
if (exactFirst) {
|
|
35
|
+
params.push(name);
|
|
36
|
+
exactRank = `(CASE WHEN name = $${params.length} THEN 0 ELSE 1 END), `;
|
|
37
|
+
}
|
|
38
|
+
params.push(exports.SIMILAR_NAMES_LIMIT + 1);
|
|
39
|
+
const rows = await db.query(`SELECT qualified
|
|
40
|
+
FROM (
|
|
41
|
+
SELECT DISTINCT name, ${exports.QUALIFIED_SQL} AS qualified
|
|
42
|
+
FROM code_symbol
|
|
43
|
+
WHERE ${projectFilter}name ILIKE $${likeParam} ESCAPE '\\'
|
|
44
|
+
) AS suggestions
|
|
45
|
+
ORDER BY ${exactRank}name COLLATE "C", qualified COLLATE "C"
|
|
46
|
+
LIMIT $${params.length}`, params);
|
|
47
|
+
return {
|
|
48
|
+
names: rows.slice(0, exports.SIMILAR_NAMES_LIMIT).map(r => r.qualified),
|
|
49
|
+
truncated: rows.length > exports.SIMILAR_NAMES_LIMIT,
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
async function symbolIndexedElsewhere(db, name, project, kind) {
|
|
53
|
+
const params = [name];
|
|
54
|
+
let projectFilter = '';
|
|
55
|
+
if (project) {
|
|
56
|
+
params.push(project);
|
|
57
|
+
projectFilter = `AND project = $${params.length}`;
|
|
58
|
+
}
|
|
59
|
+
let kindFilter = '';
|
|
60
|
+
if (kind !== 'all') {
|
|
61
|
+
params.push(kind);
|
|
62
|
+
kindFilter = `AND kind = $${params.length}`;
|
|
63
|
+
}
|
|
64
|
+
const rows = await db.query(`SELECT EXISTS (SELECT 1 FROM code_symbol WHERE name = $1 ${projectFilter} ${kindFilter}) AS present`, params);
|
|
65
|
+
return !!rows[0]?.present;
|
|
66
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { Config } from '../../config';
|
|
2
|
+
import type { ILogger } from '../../interfaces';
|
|
3
|
+
import type { FindSymbolGrep, SymbolHit, SymbolKind } from '../../interfaces/ISymbolLookup';
|
|
4
|
+
import type { FindSymbolQuery } from '../../symbol-name';
|
|
5
|
+
import type { GrepRunner } from '../../workspace/GrepRunner';
|
|
6
|
+
import type { ToolPaths } from '../../workspace/ToolPaths';
|
|
7
|
+
export type GrepFindResult = {
|
|
8
|
+
hits: SymbolHit[];
|
|
9
|
+
truncated: boolean;
|
|
10
|
+
grep: FindSymbolGrep;
|
|
11
|
+
};
|
|
12
|
+
export declare class SymbolGrepFallback {
|
|
13
|
+
private grep;
|
|
14
|
+
private paths;
|
|
15
|
+
private config;
|
|
16
|
+
private logger;
|
|
17
|
+
constructor(grep: GrepRunner, paths: ToolPaths, config: Config, logger: ILogger);
|
|
18
|
+
run(parsed: FindSymbolQuery, project: string | null, kind: SymbolKind): Promise<GrepFindResult>;
|
|
19
|
+
}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.SymbolGrepFallback = void 0;
|
|
37
|
+
const path = __importStar(require("path"));
|
|
38
|
+
const find_symbol_constants_1 = require("./find-symbol-constants");
|
|
39
|
+
const grep_args_1 = require("./grep-args");
|
|
40
|
+
const grep_patterns_1 = require("./grep-patterns");
|
|
41
|
+
const FIND_SYMBOL_RAW_LIMIT = find_symbol_constants_1.FIND_SYMBOL_LIMIT * 10;
|
|
42
|
+
class SymbolGrepFallback {
|
|
43
|
+
grep;
|
|
44
|
+
paths;
|
|
45
|
+
config;
|
|
46
|
+
logger;
|
|
47
|
+
constructor(grep, paths, config, logger) {
|
|
48
|
+
this.grep = grep;
|
|
49
|
+
this.paths = paths;
|
|
50
|
+
this.config = config;
|
|
51
|
+
this.logger = logger;
|
|
52
|
+
}
|
|
53
|
+
async run(parsed, project, kind) {
|
|
54
|
+
const t0 = Date.now();
|
|
55
|
+
const grepName = parsed.name;
|
|
56
|
+
this.logger.debug('SymbolGrepFallback: findSymbol', { grepName, project, kind, source: 'grep' });
|
|
57
|
+
const pattern = (0, grep_patterns_1.buildFindSymbolPattern)(grepName, kind);
|
|
58
|
+
if (pattern === null)
|
|
59
|
+
return { hits: [], truncated: false, grep: find_symbol_constants_1.COMPLETE };
|
|
60
|
+
const searchDir = project ? await this.paths.grepSearchDir(project) : this.config.workspaceRoot;
|
|
61
|
+
if (searchDir === null)
|
|
62
|
+
return { hits: [], truncated: false, grep: { outcome: 'no-project-directory' } };
|
|
63
|
+
const result = await this.grep.run([
|
|
64
|
+
'-rn', '-E',
|
|
65
|
+
grep_args_1.GREP_BINARY_AS_TEXT,
|
|
66
|
+
'-m', String(FIND_SYMBOL_RAW_LIMIT),
|
|
67
|
+
...grep_args_1.SOURCE_INCLUDES,
|
|
68
|
+
...grep_args_1.GREP_EXCLUDE_DIRS,
|
|
69
|
+
pattern,
|
|
70
|
+
searchDir,
|
|
71
|
+
]);
|
|
72
|
+
if (!result.ok)
|
|
73
|
+
this.logger.warn('SymbolGrepFallback: findSymbol grep failed', { grepName, project, failure: result.failure });
|
|
74
|
+
const parsedHits = [];
|
|
75
|
+
for (const raw of (result.output ?? '').split('\n').slice(0, -1)) {
|
|
76
|
+
const m = raw.match(/^(.+?):(\d+):(.*)$/s);
|
|
77
|
+
if (!m)
|
|
78
|
+
continue;
|
|
79
|
+
const [, absFile, lineNumStr, matchedLine] = m;
|
|
80
|
+
const lineNum = parseInt(lineNumStr, 10);
|
|
81
|
+
if (isNaN(lineNum))
|
|
82
|
+
continue;
|
|
83
|
+
const col = (0, grep_patterns_1.wholeWordIndex)(matchedLine, grepName);
|
|
84
|
+
if (col === -1)
|
|
85
|
+
continue;
|
|
86
|
+
parsedHits.push({
|
|
87
|
+
filePath: path.relative(this.config.workspaceRoot, absFile),
|
|
88
|
+
line: lineNum,
|
|
89
|
+
column: col + 1,
|
|
90
|
+
kind: (0, grep_patterns_1.inferKind)(matchedLine, grepName),
|
|
91
|
+
signature: matchedLine.trim(),
|
|
92
|
+
qualified: grepName,
|
|
93
|
+
isStatic: false,
|
|
94
|
+
source: 'grep',
|
|
95
|
+
target: null,
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
const truncated = parsedHits.length > find_symbol_constants_1.FIND_SYMBOL_LIMIT;
|
|
99
|
+
this.logger.debug('SymbolGrepFallback: findSymbol result', { source: 'grep', hits: Math.min(parsedHits.length, find_symbol_constants_1.FIND_SYMBOL_LIMIT), truncated, partial: !result.ok, ms: Date.now() - t0 });
|
|
100
|
+
let grep = find_symbol_constants_1.COMPLETE;
|
|
101
|
+
if (!result.ok)
|
|
102
|
+
grep = parsedHits.length > 0 ? { outcome: 'partial' } : { outcome: 'failed', cause: result.failure ?? 'unknown' };
|
|
103
|
+
return { hits: parsedHits.slice(0, find_symbol_constants_1.FIND_SYMBOL_LIMIT), truncated, grep };
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
exports.SymbolGrepFallback = SymbolGrepFallback;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { IDatabase } from '../../interfaces';
|
|
2
|
+
import type { SymbolHit, SymbolKind } from '../../interfaces/ISymbolLookup';
|
|
3
|
+
import type { FindSymbolQuery } from '../../symbol-name';
|
|
4
|
+
import type { TargetColumnGate } from './TargetColumnGate';
|
|
5
|
+
export interface IndexedSymbols {
|
|
6
|
+
hits: SymbolHit[];
|
|
7
|
+
truncated: boolean;
|
|
8
|
+
}
|
|
9
|
+
export declare class SymbolIndexQuery {
|
|
10
|
+
private db;
|
|
11
|
+
private gate;
|
|
12
|
+
constructor(db: IDatabase, gate: TargetColumnGate);
|
|
13
|
+
query(parsed: FindSymbolQuery, project: string | null, kind: SymbolKind): Promise<IndexedSymbols>;
|
|
14
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SymbolIndexQuery = void 0;
|
|
4
|
+
const symbol_sql_1 = require("../symbol-sql");
|
|
5
|
+
const find_symbol_constants_1 = require("./find-symbol-constants");
|
|
6
|
+
class SymbolIndexQuery {
|
|
7
|
+
db;
|
|
8
|
+
gate;
|
|
9
|
+
constructor(db, gate) {
|
|
10
|
+
this.db = db;
|
|
11
|
+
this.gate = gate;
|
|
12
|
+
}
|
|
13
|
+
async query(parsed, project, kind) {
|
|
14
|
+
const container = 'container' in parsed ? parsed.container : null;
|
|
15
|
+
const hasTarget = await this.gate.present();
|
|
16
|
+
const params = [];
|
|
17
|
+
const { filter: nameFilter, exactRank } = (0, symbol_sql_1.symbolMatch)(parsed.name, container, params);
|
|
18
|
+
const orderPrefix = exactRank ? `${exactRank}, ` : '';
|
|
19
|
+
let projectFilter = '';
|
|
20
|
+
if (project) {
|
|
21
|
+
params.push(project);
|
|
22
|
+
projectFilter = `AND project = $${params.length}`;
|
|
23
|
+
}
|
|
24
|
+
let kindFilter = '';
|
|
25
|
+
if (kind !== 'all') {
|
|
26
|
+
params.push(kind);
|
|
27
|
+
kindFilter = `AND kind = $${params.length}`;
|
|
28
|
+
}
|
|
29
|
+
params.push(find_symbol_constants_1.FIND_SYMBOL_LIMIT + 1);
|
|
30
|
+
const targetSelect = hasTarget ? '"target"' : 'NULL AS target';
|
|
31
|
+
const rows = await this.db.query(`SELECT "filePath", name, kind, signature, line, col, container, "isStatic", ${targetSelect}
|
|
32
|
+
FROM code_symbol
|
|
33
|
+
WHERE ${nameFilter} ${projectFilter} ${kindFilter}
|
|
34
|
+
ORDER BY ${orderPrefix}project, "filePath", line, col, kind COLLATE "C", container COLLATE "C" NULLS FIRST
|
|
35
|
+
LIMIT $${params.length}`, params);
|
|
36
|
+
return {
|
|
37
|
+
truncated: rows.length > find_symbol_constants_1.FIND_SYMBOL_LIMIT,
|
|
38
|
+
hits: rows.slice(0, find_symbol_constants_1.FIND_SYMBOL_LIMIT).map(row => ({
|
|
39
|
+
filePath: row.filePath,
|
|
40
|
+
line: row.line ?? 1,
|
|
41
|
+
column: row.col ?? 1,
|
|
42
|
+
kind: row.kind,
|
|
43
|
+
signature: row.signature ?? row.name,
|
|
44
|
+
qualified: row.container ? `${row.container}.${row.name}` : row.name,
|
|
45
|
+
isStatic: !!row.isStatic,
|
|
46
|
+
source: 'index',
|
|
47
|
+
target: row.target ?? null,
|
|
48
|
+
})),
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
exports.SymbolIndexQuery = SymbolIndexQuery;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Config } from '../../config';
|
|
2
|
+
import type { ILogger } from '../../interfaces';
|
|
3
|
+
import type { GrepSymbolResult } from '../../interfaces/ISymbolLookup';
|
|
4
|
+
import type { GrepRunner } from '../../workspace/GrepRunner';
|
|
5
|
+
import type { ProjectRoots } from '../../workspace/ProjectRoots';
|
|
6
|
+
export declare class SymbolTextSearch {
|
|
7
|
+
private grep;
|
|
8
|
+
private roots;
|
|
9
|
+
private config;
|
|
10
|
+
private logger;
|
|
11
|
+
constructor(grep: GrepRunner, roots: ProjectRoots, config: Config, logger: ILogger);
|
|
12
|
+
search(symbol: string, rootDir: string, excludeFile: string): Promise<GrepSymbolResult>;
|
|
13
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.SymbolTextSearch = void 0;
|
|
37
|
+
const path = __importStar(require("path"));
|
|
38
|
+
const grep_args_1 = require("./grep-args");
|
|
39
|
+
const GREP_MAX_RESULTS = 200;
|
|
40
|
+
const GREP_RAW_LIMIT = GREP_MAX_RESULTS * 5;
|
|
41
|
+
class SymbolTextSearch {
|
|
42
|
+
grep;
|
|
43
|
+
roots;
|
|
44
|
+
config;
|
|
45
|
+
logger;
|
|
46
|
+
constructor(grep, roots, config, logger) {
|
|
47
|
+
this.grep = grep;
|
|
48
|
+
this.roots = roots;
|
|
49
|
+
this.config = config;
|
|
50
|
+
this.logger = logger;
|
|
51
|
+
}
|
|
52
|
+
async search(symbol, rootDir, excludeFile) {
|
|
53
|
+
const t0 = Date.now();
|
|
54
|
+
this.logger.debug('SymbolTextSearch: grepSymbol', { symbol, rootDir, excludeFile });
|
|
55
|
+
if (symbol.includes('\n'))
|
|
56
|
+
return { ok: true, matches: [], truncated: false, partial: false };
|
|
57
|
+
const result = await this.grep.run([
|
|
58
|
+
'-rn', '-F', '-w',
|
|
59
|
+
grep_args_1.GREP_BINARY_AS_TEXT,
|
|
60
|
+
'-m', String(GREP_RAW_LIMIT),
|
|
61
|
+
...grep_args_1.SOURCE_INCLUDES,
|
|
62
|
+
...grep_args_1.GREP_EXCLUDE_DIRS,
|
|
63
|
+
'--',
|
|
64
|
+
symbol,
|
|
65
|
+
this.roots.toAbs(rootDir),
|
|
66
|
+
]);
|
|
67
|
+
const excludeAbsPath = path.join(this.config.workspaceRoot, excludeFile);
|
|
68
|
+
const all = (result.output ?? '').split('\n').flatMap(line => {
|
|
69
|
+
const match = line.match(/^(.+?):(\d+):/);
|
|
70
|
+
if (!match)
|
|
71
|
+
return [];
|
|
72
|
+
const [, absFile, lineNum] = match;
|
|
73
|
+
if (absFile === excludeAbsPath)
|
|
74
|
+
return [];
|
|
75
|
+
return [{ filePath: path.relative(this.config.workspaceRoot, absFile), line: parseInt(lineNum, 10) }];
|
|
76
|
+
});
|
|
77
|
+
if (!result.ok && all.length === 0)
|
|
78
|
+
return { ok: false };
|
|
79
|
+
const truncated = all.length > GREP_MAX_RESULTS;
|
|
80
|
+
this.logger.debug('SymbolTextSearch: grepSymbol result', { matches: Math.min(all.length, GREP_MAX_RESULTS), truncated, partial: !result.ok, ms: Date.now() - t0 });
|
|
81
|
+
return { ok: true, matches: all.slice(0, GREP_MAX_RESULTS), truncated, partial: !result.ok };
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
exports.SymbolTextSearch = SymbolTextSearch;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TargetColumnGate = void 0;
|
|
4
|
+
class TargetColumnGate {
|
|
5
|
+
db;
|
|
6
|
+
targetColumnPresent = false;
|
|
7
|
+
constructor(db) {
|
|
8
|
+
this.db = db;
|
|
9
|
+
}
|
|
10
|
+
async present() {
|
|
11
|
+
if (this.targetColumnPresent)
|
|
12
|
+
return true;
|
|
13
|
+
const rows = await this.db.query(`SELECT EXISTS (
|
|
14
|
+
SELECT 1 FROM information_schema.columns
|
|
15
|
+
WHERE table_schema = 'public' AND table_name = 'code_symbol' AND column_name = 'target'
|
|
16
|
+
) AS present`);
|
|
17
|
+
const present = !!rows[0]?.present;
|
|
18
|
+
if (present)
|
|
19
|
+
this.targetColumnPresent = true;
|
|
20
|
+
return present;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
exports.TargetColumnGate = TargetColumnGate;
|