@@ -6,6 +6,8 @@ import { fileExistsAtPath } from "../../utils/fs"
66import { parseMarkdown } from "./markdownParser"
77import { RooIgnoreController } from "../../core/ignore/RooIgnoreController"
88
9+ const MIN_COMPONENT_LINES = 4
10+
911const extensions = [
1012 "tla" ,
1113 "js" ,
@@ -104,7 +106,7 @@ export async function parseSourceCodeDefinitionsForFile(
104106 const markdownCaptures = parseMarkdown ( fileContent )
105107
106108 // Process the captures
107- const markdownDefinitions = processCaptures ( markdownCaptures , lines , "markdown" , 4 )
109+ const markdownDefinitions = processCaptures ( markdownCaptures , lines , "markdown" )
108110
109111 if ( markdownDefinitions ) {
110112 return `# ${ path . basename ( filePath ) } \n${ markdownDefinitions } `
@@ -180,7 +182,7 @@ export async function parseSourceCodeForDefinitionsTopLevel(
180182 const markdownCaptures = parseMarkdown ( fileContent )
181183
182184 // Process the captures
183- const markdownDefinitions = processCaptures ( markdownCaptures , lines , "markdown" , 4 )
185+ const markdownDefinitions = processCaptures ( markdownCaptures , lines , "markdown" )
184186
185187 if ( markdownDefinitions ) {
186188 result += `# ${ path . relative ( dirPath , file ) . toPosix ( ) } \n${ markdownDefinitions } \n`
@@ -240,12 +242,7 @@ This approach allows us to focus on the most relevant parts of the code (defined
240242 * @param minComponentLines - Minimum number of lines for a component to be included
241243 * @returns A formatted string with definitions
242244 */
243- function processCaptures (
244- captures : any [ ] ,
245- lines : string [ ] ,
246- language : string ,
247- minComponentLines : number = 4 ,
248- ) : string | null {
245+ function processCaptures ( captures : any [ ] , lines : string [ ] , language : string ) : string | null {
249246 // Determine if HTML filtering is needed for this language
250247 const needsHtmlFiltering = [ "jsx" , "tsx" ] . includes ( language )
251248
@@ -290,7 +287,7 @@ function processCaptures(
290287 const lineCount = endLine - startLine + 1
291288
292289 // Skip components that don't span enough lines
293- if ( lineCount < minComponentLines ) {
290+ if ( lineCount < MIN_COMPONENT_LINES ) {
294291 return
295292 }
296293
@@ -328,7 +325,7 @@ function processCaptures(
328325 const contextSpan = contextEnd - node . parent . startPosition . row + 1
329326
330327 // Only include context if it spans multiple lines
331- if ( contextSpan >= minComponentLines ) {
328+ if ( contextSpan >= MIN_COMPONENT_LINES ) {
332329 // Add the full range first
333330 const rangeKey = `${ node . parent . startPosition . row } -${ contextEnd } `
334331 if ( ! processedLines . has ( rangeKey ) ) {
@@ -360,9 +357,6 @@ async function parseFile(
360357 languageParsers : LanguageParser ,
361358 rooIgnoreController ?: RooIgnoreController ,
362359) : Promise < string | null > {
363- // Minimum number of lines for a component to be included
364- const MIN_COMPONENT_LINES = 4
365-
366360 // Check if we have permission to access this file
367361 if ( rooIgnoreController && ! rooIgnoreController . validateAccess ( filePath ) ) {
368362 return null
@@ -389,7 +383,7 @@ async function parseFile(
389383 const lines = fileContent . split ( "\n" )
390384
391385 // Process the captures
392- return processCaptures ( captures , lines , extLang , MIN_COMPONENT_LINES )
386+ return processCaptures ( captures , lines , extLang )
393387 } catch ( error ) {
394388 console . log ( `Error parsing file: ${ error } \n` )
395389 // Return null on parsing error to avoid showing error messages in the output
0 commit comments