Skip to content

Commit 9a61ab7

Browse files
committed
Add duration to the terminal command SI tooltip
1 parent b3b84b5 commit 9a61ab7

File tree

5 files changed

+30
-3
lines changed

5 files changed

+30
-3
lines changed

src/vs/platform/terminal/common/capabilities/capabilities.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@ interface IBaseTerminalCommand {
242242
command: string;
243243
isTrusted: boolean;
244244
timestamp: number;
245+
duration: number;
245246

246247
// Optional serializable
247248
cwd: string | undefined;

src/vs/platform/terminal/common/capabilities/commandDetection/terminalCommand.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export interface ITerminalCommandProperties {
1414
command: string;
1515
isTrusted: boolean;
1616
timestamp: number;
17+
duration: number;
1718
marker: IXtermMarker | undefined;
1819
cwd: string | undefined;
1920
exitCode: number | undefined;
@@ -34,6 +35,7 @@ export class TerminalCommand implements ITerminalCommand {
3435
get command() { return this._properties.command; }
3536
get isTrusted() { return this._properties.isTrusted; }
3637
get timestamp() { return this._properties.timestamp; }
38+
get duration() { return this._properties.duration; }
3739
get promptStartMarker() { return this._properties.promptStartMarker; }
3840
get marker() { return this._properties.marker; }
3941
get endMarker() { return this._properties.endMarker; }
@@ -77,6 +79,7 @@ export class TerminalCommand implements ITerminalCommand {
7779
executedMarker,
7880
executedX: serialized.executedX,
7981
timestamp: serialized.timestamp,
82+
duration: serialized.duration,
8083
cwd: serialized.cwd,
8184
commandStartLineContent: serialized.commandStartLineContent,
8285
exitCode: serialized.exitCode,
@@ -101,6 +104,7 @@ export class TerminalCommand implements ITerminalCommand {
101104
exitCode: this.exitCode,
102105
commandStartLineContent: this.commandStartLineContent,
103106
timestamp: this.timestamp,
107+
duration: this.duration,
104108
markProperties: this.markProperties,
105109
};
106110
}
@@ -251,6 +255,9 @@ export class PartialTerminalCommand implements ICurrentPartialCommand {
251255
commandExecutedMarker?: IMarker;
252256
commandExecutedX?: number;
253257

258+
private commandExecutedTimestamp?: number;
259+
private commandDuration?: number;
260+
254261
commandFinishedMarker?: IMarker;
255262

256263
currentContinuationMarker?: IMarker;
@@ -284,6 +291,7 @@ export class PartialTerminalCommand implements ICurrentPartialCommand {
284291
exitCode: undefined,
285292
commandStartLineContent: undefined,
286293
timestamp: 0,
294+
duration: 0,
287295
markProperties: undefined
288296
};
289297
}
@@ -305,6 +313,7 @@ export class PartialTerminalCommand implements ICurrentPartialCommand {
305313
executedMarker: this.commandExecutedMarker,
306314
executedX: this.commandExecutedX,
307315
timestamp: Date.now(),
316+
duration: this.commandDuration || 0,
308317
cwd,
309318
exitCode,
310319
commandStartLineContent: this.commandStartLineContent,
@@ -315,6 +324,18 @@ export class PartialTerminalCommand implements ICurrentPartialCommand {
315324
return undefined;
316325
}
317326

327+
markExecutedTime() {
328+
if (this.commandExecutedTimestamp === undefined) {
329+
this.commandExecutedTimestamp = Date.now();
330+
}
331+
}
332+
333+
markFinishedTime() {
334+
if (this.commandDuration === undefined && this.commandExecutedTimestamp !== undefined) {
335+
this.commandDuration = Date.now() - this.commandExecutedTimestamp;
336+
}
337+
}
338+
318339
getPromptRowCount(): number {
319340
return getPromptRowCount(this, this._xterm.buffer.active);
320341
}

src/vs/platform/terminal/common/capabilities/commandDetectionCapability.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,9 +303,11 @@ export class CommandDetectionCapability extends Disposable implements ICommandDe
303303

304304
handleCommandExecuted(options?: IHandleCommandOptions): void {
305305
this._ptyHeuristics.value.handleCommandExecuted(options);
306+
this._currentCommand.markExecutedTime();
306307
}
307308

308309
handleCommandFinished(exitCode: number | undefined, options?: IHandleCommandOptions): void {
310+
this._currentCommand.markFinishedTime();
309311
this._ptyHeuristics.value.preHandleCommandFinished?.();
310312

311313
this._logService.debug('CommandDetectionCapability#handleCommandFinished', this._terminal.buffer.active.cursorX, options?.marker?.line, this._currentCommand.command, this._currentCommand);

src/vs/workbench/contrib/terminal/browser/xterm/decorationStyles.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,12 @@ export class TerminalDecorationHoverManager extends Disposable {
7373
}
7474
} else if (command.exitCode) {
7575
if (command.exitCode === -1) {
76-
hoverContent += localize('terminalPromptCommandFailed', 'Command executed {0} and failed', fromNow(command.timestamp, true));
76+
hoverContent += localize('terminalPromptCommandFailed', 'Command executed {0} for {1} ms and failed', fromNow(command.timestamp, true), command.duration);
7777
} else {
78-
hoverContent += localize('terminalPromptCommandFailedWithExitCode', 'Command executed {0} and failed (Exit Code {1})', fromNow(command.timestamp, true), command.exitCode);
78+
hoverContent += localize('terminalPromptCommandFailedWithExitCode', 'Command executed {0} for {2} ms and failed (Exit Code {1})', fromNow(command.timestamp, true), command.exitCode, command.duration);
7979
}
8080
} else {
81-
hoverContent += localize('terminalPromptCommandSuccess', 'Command executed {0}', fromNow(command.timestamp, true));
81+
hoverContent += localize('terminalPromptCommandSuccess', 'Command executed {0} for {1} ms', fromNow(command.timestamp, true), command.duration);
8282
}
8383
this._hoverService.showHover({ content: new MarkdownString(hoverContent), target: element });
8484
});

src/vs/workbench/contrib/terminalContrib/links/test/browser/terminalLinkOpeners.test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ suite('Workbench - TerminalLinkOpeners', () => {
142142
isTrusted: true,
143143
cwd: '/initial/cwd',
144144
timestamp: 0,
145+
duration: 0,
145146
executedX: undefined,
146147
startX: undefined,
147148
marker: {
@@ -279,6 +280,7 @@ suite('Workbench - TerminalLinkOpeners', () => {
279280
isTrusted: true,
280281
cwd,
281282
timestamp: 0,
283+
duration: 0,
282284
executedX: undefined,
283285
startX: undefined,
284286
marker: {
@@ -374,6 +376,7 @@ suite('Workbench - TerminalLinkOpeners', () => {
374376
executedX: undefined,
375377
startX: undefined,
376378
timestamp: 0,
379+
duration: 0,
377380
marker: {
378381
line: 0
379382
} as Partial<IXtermMarker> as any,

0 commit comments

Comments
 (0)