@@ -10,12 +10,6 @@ import { QueryCapture } from "web-tree-sitter"
1010// Private constant
1111const DEFAULT_MIN_COMPONENT_LINES_VALUE = 4
1212
13- // Language-specific rules
14- const LANGUAGE_SKIP_RULES : Record < string , string [ ] > = {
15- java : [ "definition.method" ] ,
16- // Future languages can be added here
17- }
18-
1913// Getter function for MIN_COMPONENT_LINES (for easier testing)
2014let currentMinComponentLines = DEFAULT_MIN_COMPONENT_LINES_VALUE
2115
@@ -34,8 +28,8 @@ export function setMinComponentLines(value: number): void {
3428}
3529
3630function shouldSkipLineCountCheck ( lineCount : number , capture : QueryCapture , language : string ) {
37- const skipRules = LANGUAGE_SKIP_RULES [ language ]
38- if ( skipRules && skipRules . includes ( capture . name ) ) {
31+ if ( [ "definition.method" , "definition.method.start" ] . includes ( capture . name ) ) {
32+ // In object-oriented programming languages, method signatures are only one line and should not be ignored.
3933 return false
4034 }
4135 return lineCount < getMinComponentLines ( )
@@ -337,14 +331,8 @@ function processCaptures(captures: QueryCapture[], lines: string[], language: st
337331 return
338332 }
339333
340- let outputLineIdx = startLine
341- // For Java method definitions, find the actual method signature line
342- if ( language === "java" && name === "definition.method" ) {
343- outputLineIdx = findJavaMethodSignatureLine ( lines , startLine , endLine )
344- }
345-
346334 // Check if this is a valid component definition (not an HTML element)
347- const startLineContent = lines [ outputLineIdx ] . trim ( )
335+ const startLineContent = lines [ startLine ] . trim ( )
348336
349337 // Special handling for component name definitions
350338 if ( name . includes ( "name.definition" ) ) {
@@ -353,13 +341,13 @@ function processCaptures(captures: QueryCapture[], lines: string[], language: st
353341
354342 // Add component name to output regardless of HTML filtering
355343 if ( ! processedLines . has ( lineKey ) && componentName ) {
356- formattedOutput += `${ outputLineIdx + 1 } --${ endLine + 1 } | ${ lines [ outputLineIdx ] } \n`
344+ formattedOutput += `${ startLine + 1 } --${ endLine + 1 } | ${ lines [ startLine ] } \n`
357345 processedLines . add ( lineKey )
358346 }
359347 }
360348 // For other component definitions
361349 else if ( isNotHtmlElement ( startLineContent ) ) {
362- formattedOutput += `${ outputLineIdx + 1 } --${ endLine + 1 } | ${ lines [ outputLineIdx ] } \n`
350+ formattedOutput += `${ startLine + 1 } --${ endLine + 1 } | ${ lines [ startLine ] } \n`
363351 processedLines . add ( lineKey )
364352
365353 // If this is part of a larger definition, include its non-HTML context
@@ -433,45 +421,3 @@ async function parseFile(
433421 return null
434422 }
435423}
436-
437- /**
438- * Find the line containing the actual Java method signature
439- * by looking for lines that match method declaration patterns
440- *
441- * @param lines - Array of lines from the file
442- * @param startLine - Starting line index
443- * @param endLine - Ending line index
444- * @returns The line index of the method signature
445- */
446- function findJavaMethodSignatureLine ( lines : string [ ] , startLine : number , endLine : number ) : number {
447- // Java method signature pattern - avoiding backtracking issues
448- // Split into separate checks to avoid complex alternations
449- const accessModifiers = / ^ \s * (?: p u b l i c | p r i v a t e | p r o t e c t e d ) \s + /
450- const otherModifiers = / ^ \s * (?: s t a t i c | f i n a l | a b s t r a c t | s y n c h r o n i z e d | n a t i v e | s t r i c t f p ) \s + /
451- const methodPattern = / ^ \s * (?: \w + (?: \[ \] ) * (?: \s * < [ ^ > ] + > ) ? \s + ) + \w + \s * \( /
452-
453- for ( let i = startLine ; i <= endLine ; i ++ ) {
454- const line = lines [ i ] . trim ( )
455-
456- // Skip empty lines and annotation lines
457- if ( line . length === 0 || line . startsWith ( "@" ) ) {
458- continue
459- }
460-
461- // Check if this looks like a method signature using multiple simple patterns
462- // This avoids complex alternation that can cause backtracking
463- if ( accessModifiers . test ( line ) || otherModifiers . test ( line ) || methodPattern . test ( line ) ) {
464- return i
465- }
466- }
467-
468- // If no method signature found, return the first non-annotation, non-empty line
469- for ( let i = startLine ; i <= endLine ; i ++ ) {
470- const line = lines [ i ] . trim ( )
471- if ( line . length > 0 && ! line . startsWith ( "@" ) ) {
472- return i
473- }
474- }
475-
476- return startLine
477- }
0 commit comments