MCPcopy Create free account
hub / github.com/Effect-TS/effect / snippets

Function snippets

packages/tools/doctest/src/Source.ts:50–71  ·  view source on GitHub ↗
(
  text: string,
  offset: number,
  lineAt: (offset: number) => number,
  jsdoc = false
)

Source from the content-addressed store, hash-verified

48}
49
50const snippets = (
51 text: string,
52 offset: number,
53 lineAt: (offset: number) => number,
54 jsdoc = false
55): ReadonlyArray<Snippet> => {
56 return Array.from(text.matchAll(fencePattern)).flatMap((match) => {
57 const metadata = match[1].toLowerCase()
58 if ((!metadata.startsWith("ts") && !metadata.startsWith("typescript")) || !metadata.includes(runnableMarker)) {
59 return []
60 }
61
62 const name = namePattern.exec(match[1])
63 const source = jsdoc ? match[2].replace(/^[ \t]*\* ?/gm, "").trim() : match[2].trim()
64
65 return [{
66 source,
67 line: lineAt(offset + (match.index ?? 0)),
68 name: name?.[1] ?? name?.[2] ?? name?.[3]
69 }]
70 })
71}
72
73/**
74 * Extracts marked TypeScript code snippets from documentation text.

Callers 1

extractFunction · 0.85

Calls 2

execMethod · 0.80
replaceMethod · 0.45

Tested by

no test coverage detected