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

Function codeOf

src/graph/symbol-references.ts:195–224  ·  view source on GitHub ↗

`line` with its comments and strings blanked, given the block `state` it starts in.

(line: string, syntax: Syntax, state: { close: string | null })

Source from the content-addressed store, hash-verified

193
194/** `line` with its comments and strings blanked, given the block `state` it starts in. */
195function codeOf(line: string, syntax: Syntax, state: { close: string | null }): string {
196 let out = '';
197 let i = 0;
198 scan: while (i < line.length) {
199 if (state.close !== null) {
200 const end = line.indexOf(state.close, i);
201 if (end < 0) return out;
202 i = end + state.close.length;
203 state.close = null;
204 out += ' ';
205 continue;
206 }
207 for (const [open, close] of syntax.block) {
208 if (line.startsWith(open, i)) { state.close = close; i += open.length; continue scan; }
209 }
210 for (const opener of syntax.line) if (line.startsWith(opener, i)) return out;
211 const ch = line[i]!;
212 if (syntax.quotes.includes(ch)) {
213 let j = i + 1;
214 while (j < line.length && line[j] !== ch) j += line[j] === '\\' ? 2 : 1;
215 if (j >= line.length) return out; // an unclosed string runs to the end of the line
216 i = j + 1;
217 out += ' ';
218 continue;
219 }
220 out += ch;
221 i++;
222 }
223 return out;
224}
225
226/** `name` as a whole word: not inside a longer identifier, in any script. */
227export function wholeNamePattern(name: string): RegExp {

Callers 1

codeMentionLinesFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected