MCPcopy
hub / github.com/colbymchenry/codegraph / deriveProjectNameTokens

Function deriveProjectNameTokens

src/search/query-utils.ts:29–54  ·  view source on GitHub ↗
(projectRoot: string)

Source from the content-addressed store, hash-verified

27 * safely down-weight.
28 */
29export function deriveProjectNameTokens(projectRoot: string): Set<string> {
30 const tokens = new Set<string>();
31 const add = (raw: string | undefined | null): void => {
32 if (!raw) return;
33 const norm = normalizeNameToken(raw);
34 if (norm.length >= 5) tokens.add(norm);
35 };
36
37 // go.mod module last segment (the most reliable signal for Go repos).
38 try {
39 const gomod = fs.readFileSync(path.join(projectRoot, 'go.mod'), 'utf-8');
40 const m = gomod.match(/^\s*module\s+(\S+)/m);
41 if (m && m[1]) add(m[1].split('/').pop());
42 } catch { /* no go.mod */ }
43
44 // package.json name (strip an `@scope/` prefix).
45 try {
46 const pkg = JSON.parse(fs.readFileSync(path.join(projectRoot, 'package.json'), 'utf-8'));
47 if (typeof pkg.name === 'string') add(pkg.name.replace(/^@[^/]+\//, ''));
48 } catch { /* no / invalid package.json */ }
49
50 // Repo root directory name — a fallback when neither manifest names the project.
51 add(path.basename(path.resolve(projectRoot)));
52
53 return tokens;
54}
55
56/**
57 * Common stop words to filter from search queries.

Callers 2

wireLayersMethod · 0.90

Calls 3

joinMethod · 0.80
resolveMethod · 0.80
addFunction · 0.70

Tested by

no test coverage detected