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

Method extractCodeBlocks

src/extraction/razor-extractor.ts:234–250  ·  view source on GitHub ↗

`@code { … }` / `@functions { … }` (Blazor) and `@{ … }` (Razor) C# blocks.

()

Source from the content-addressed store, hash-verified

232
233 /** `@code { … }` / `@functions { … }` (Blazor) and `@{ … }` (Razor) C# blocks. */
234 private extractCodeBlocks(): Array<{ content: string; lineOffset: number }> {
235 const blocks: Array<{ content: string; lineOffset: number }> = [];
236 const re = /@(?:code|functions)\b\s*\{|@\{/g;
237 let m: RegExpExecArray | null;
238 while ((m = re.exec(this.source)) !== null) {
239 const openIdx = this.source.indexOf('{', m.index);
240 if (openIdx < 0) continue;
241 const close = this.matchBrace(this.source, openIdx);
242 if (close < 0) continue;
243 const content = this.source.slice(openIdx + 1, close);
244 // newlines before the content's first char → 0-indexed line of content start
245 const lineOffset = (this.source.slice(0, openIdx + 1).match(/\n/g) || []).length;
246 blocks.push({ content, lineOffset });
247 re.lastIndex = close;
248 }
249 return blocks;
250 }
251
252 /**
253 * Delegate each `@code`/`@functions`/`@{` block's C# to the tree-sitter C#

Callers 1

processCodeBlocksMethod · 0.95

Calls 3

matchBraceMethod · 0.95
pushMethod · 0.80
execMethod · 0.65

Tested by

no test coverage detected