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

Function findAnnotation

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

Source from the content-addressed store, hash-verified

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