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

Function findAnnotation

packages/tools/utils/src/Codegen.ts:33–58  ·  view source on GitHub ↗
(content: string)

Source from the content-addressed store, hash-verified

31}> {}
32
33const findAnnotation = (content: string): { pattern: string; offset: number } | undefined => {
34 const lines = content.split("\n")
35
36 // Find the line containing the annotation
37 let annotationLine = -1
38 let pattern: string | undefined
39 for (let i = 0; i < lines.length; i++) {
40 pattern = parseAnnotation(lines[i])
41 if (pattern !== undefined) {
42 annotationLine = i
43 break
44 }
45 }
46
47 if (annotationLine === -1 || pattern === undefined) {
48 return undefined
49 }
50
51 // Walk forwards to find the end of the comment block
52 let commentEnd = annotationLine
53 while (commentEnd < lines.length - 1 && lines[commentEnd + 1].trimStart().startsWith("//")) {
54 commentEnd++
55 }
56
57 return { pattern, offset: commentEnd + 1 }
58}
59
60const parseAnnotation = (line: string): string | undefined => {
61 const match = line.match(/^\/\/\s*@barrel(?:\((.+?)\))?/)

Callers 1

Codegen.tsFile · 0.85

Calls 2

parseAnnotationFunction · 0.70
splitMethod · 0.45

Tested by

no test coverage detected