@@ -11,7 +11,7 @@ import {
1111} from 'vscode' ;
1212
1313import { Context } from '../Context.js' ;
14- import { isApexLogContent } from '../language/ApexLogLanguageDetector.js' ;
14+ import { APEXLOG_HEADER , isApexLogContent } from '../language/ApexLogLanguageDetector.js' ;
1515import { formatDuration , TIMESTAMP_REGEX } from '../log-utils.js' ;
1616
1717// Pattern to find EXECUTION_STARTED line
@@ -98,8 +98,13 @@ export class LogTimingDecoration {
9898
9999 const formattedDuration = formatDuration ( duration ) ;
100100
101- // Create decoration for line 0 (first line)
102- const line = document . lineAt ( 0 ) ;
101+ const startLine = this . findFirstLogLine ( document ) ;
102+ if ( startLine === null ) {
103+ editor . setDecorations ( decorationType , [ ] ) ;
104+ return ;
105+ }
106+
107+ const line = document . lineAt ( startLine ) ;
103108 const decoration : DecorationOptions = {
104109 range : line . range ,
105110 renderOptions : {
@@ -112,6 +117,17 @@ export class LogTimingDecoration {
112117 editor . setDecorations ( decorationType , [ decoration ] ) ;
113118 }
114119
120+ private findFirstLogLine ( doc : TextDocument ) : number | null {
121+ const limit = Math . min ( 1000 , doc . lineCount ) ;
122+ for ( let i = 0 ; i < limit ; i ++ ) {
123+ const text = doc . lineAt ( i ) . text ;
124+ if ( APEXLOG_HEADER . test ( text ) || TIMESTAMP_REGEX . test ( text ) ) {
125+ return i ;
126+ }
127+ }
128+ return null ;
129+ }
130+
115131 private calculateLogDuration ( document : TextDocument ) : number | null {
116132 const startTs = this . findTimestamp ( document , false , executionStartedRegex ) ;
117133 const endTs = this . findTimestamp ( document , true , TIMESTAMP_REGEX ) ;
0 commit comments