MCPcopy Index your code
hub / github.com/colbymchenry/codegraph / extractCodeBlocks

Method extractCodeBlocks

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

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

()

Source from the content-addressed store, hash-verified

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

Callers 1

processCodeBlocksMethod · 0.95

Calls 2

matchBraceMethod · 0.95
execMethod · 0.65

Tested by

no test coverage detected