MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / extractQueryPaths

Function extractQueryPaths

src/search/query-paths.ts:294–540  ·  view source on GitHub ↗
(
  query: string,
  indexedPaths: readonly string[],
  opts: {
    maxPins?: number;
    maxMatchesPerSpan?: number;
    /**
     * Does this repo-relative span name a real FILE in the project? Optional,
     * injected by the caller (see the module docstring): it is the only way to
     * tell a dotless path the index simply doesn't hold (`scripts/deploy`)
     * from slashed prose (`and/or`), and it must stay out of this module.
     * Must not throw — the caller absorbs fs errors and returns false.
     */
    existsOnDisk?: (relPath: string) => boolean;
    /**
     * Which indexed files define a symbol spelled like this query token
     * (`clampedInt`, `SQLCompiler.as_sql`)? Optional, injected by the caller
     * for the same reason as `existsOnDisk`: the answer lives in the index,
     * and this module stays DB-free. Consulted only when a span matches
     * several files (a basename two directories share): the matches that
     * define a symbol the query also names are pinned, the rest set aside.
     * Must not throw — the caller absorbs lookup errors and returns nothing.
     */
    symbolFiles?: (symbol: string) => Iterable<string>;
  } = {},
)

Source from the content-addressed store, hash-verified

292}
293
294export function extractQueryPaths(
295 query: string,
296 indexedPaths: readonly string[],
297 opts: {
298 maxPins?: number;
299 maxMatchesPerSpan?: number;
300 /**
301 * Does this repo-relative span name a real FILE in the project? Optional,
302 * injected by the caller (see the module docstring): it is the only way to
303 * tell a dotless path the index simply doesn't hold (`scripts/deploy`)
304 * from slashed prose (`and/or`), and it must stay out of this module.
305 * Must not throw — the caller absorbs fs errors and returns false.
306 */
307 existsOnDisk?: (relPath: string) => boolean;
308 /**
309 * Which indexed files define a symbol spelled like this query token
310 * (`clampedInt`, `SQLCompiler.as_sql`)? Optional, injected by the caller
311 * for the same reason as `existsOnDisk`: the answer lives in the index,
312 * and this module stays DB-free. Consulted only when a span matches
313 * several files (a basename two directories share): the matches that
314 * define a symbol the query also names are pinned, the rest set aside.
315 * Must not throw — the caller absorbs lookup errors and returns nothing.
316 */
317 symbolFiles?: (symbol: string) => Iterable<string>;
318 } = {},
319): QueryPathExtraction {
320 const maxPins = Math.max(1, opts.maxPins ?? 8);
321 const maxMatchesPerSpan = Math.max(1, opts.maxMatchesPerSpan ?? 3);
322
323 const passthrough: QueryPathExtraction = {
324 strippedQuery: query,
325 pinnedFiles: [],
326 unresolvedPathSpans: [],
327 lineAnchors: [],
328 setAsideMatches: [],
329 };
330 if (!query.trim() || indexedPaths.length === 0) return passthrough;
331
332 // Lowercase view of the index, built once per call. Last writer wins on a
333 // case-colliding pair, which is the existing file-view behavior too.
334 const lowerToOriginal = new Map<string, string>();
335 for (const p of indexedPaths) lowerToOriginal.set(p.toLowerCase(), p);
336
337 const tokens = query.split(/\s+/).filter(Boolean);
338 const consumed = new Set<number>();
339 const pinned: string[] = [];
340 const pinnedSeen = new Set<string>();
341 const unresolved: string[] = [];
342 const anchors: QueryLineAnchor[] = [];
343 const setAside: QuerySetAsideMatch[] = [];
344 /** Token index → the ONE file it pinned, for binding prose line ranges. */
345 const singleFileAt = new Map<number, string>();
346 let candidatesExamined = 0;
347
348 // A bare basename two directories share (`editorOptions.ts` is both vscode's
349 // editor option registry and a workbench helper) used to pin EVERY match,
350 // and the matches split the pinned reservation — so a query that also named
351 // three functions in one of them got half the room for them it would have

Callers 3

handleExploreMethod · 0.90
anchorFunction · 0.90

Calls 15

stripWrappingFunction · 0.85
normalizeSpanFunction · 0.85
resolveSpanFunction · 0.85
pinnableMatchesFunction · 0.85
isClearlyPathShapedFunction · 0.85
buildBasenameStemsFunction · 0.85
lineSpanFunction · 0.85
nearestFileFunction · 0.85
hasMethod · 0.80
pushMethod · 0.80
mapMethod · 0.80

Tested by 1

anchorFunction · 0.72