Skip to content

Commit 68e4514

Browse files
committed
feat: add log duration on first valid log line
This will probably be the log levels line ut if not present will be placed on the first line with timestamp.
1 parent 4b305a1 commit 68e4514

2 files changed

Lines changed: 20 additions & 4 deletions

File tree

lana/src/decorations/LogTimingDecoration.ts

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
} from 'vscode';
1212

1313
import { Context } from '../Context.js';
14-
import { isApexLogContent } from '../language/ApexLogLanguageDetector.js';
14+
import { APEXLOG_HEADER, isApexLogContent } from '../language/ApexLogLanguageDetector.js';
1515
import { 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);

lana/src/language/ApexLogLanguageDetector.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import {
1616

1717
import { Context } from '../Context.js';
1818

19-
const APEXLOG_HEADER = /^(\d\d\.\d.+?)?APEX_CODE,\w.+$/;
19+
export const APEXLOG_HEADER = /^(\d\d\.\d.+?)?APEX_CODE,\w.+$/;
2020
const EXECUTION_STARTED = /^\d{2}:\d{2}:\d{2}\.\d{1,} \(\d+\)\|EXECUTION_STARTED$/;
2121
const USER_INFO = /^\d{2}:\d{2}:\d{2}\.\d{1,} \(\d+\)\|USER_INFO\|/;
2222
const DETECT_EXTENSIONS = new Set(['.log', '.txt']);

0 commit comments

Comments
 (0)