Skip to content

Commit 2a5d381

Browse files
authored
only show output button when a command's markers haven't been disposed of (microsoft#154220)
* fix microsoft#154215 * make hasOutput a function * fix test * Update src/vs/workbench/contrib/terminal/browser/terminalProfileService.ts * actually fix tests
1 parent 22f3f60 commit 2a5d381

File tree

7 files changed

+13
-13
lines changed

7 files changed

+13
-13
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ export interface ITerminalCommand {
198198
executedMarker?: IXtermMarker;
199199
commandStartLineContent?: string;
200200
getOutput(): string | undefined;
201-
hasOutput: boolean;
201+
hasOutput(): boolean;
202202
genericMarkProperties?: IGenericMarkProperties;
203203
}
204204

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ export class CommandDetectionCapability implements ICommandDetectionCapability {
457457
cwd: this._cwd,
458458
exitCode: this._exitCode,
459459
commandStartLineContent: this._currentCommand.commandStartLineContent,
460-
hasOutput: !!(executedMarker && endMarker && executedMarker?.line < endMarker!.line),
460+
hasOutput: () => !executedMarker?.isDisposed && !endMarker?.isDisposed && !!(executedMarker && endMarker && executedMarker?.line < endMarker!.line),
461461
getOutput: () => getOutputForCommand(executedMarker, endMarker, buffer),
462462
genericMarkProperties: options?.genericMarkProperties
463463
};
@@ -579,7 +579,7 @@ export class CommandDetectionCapability implements ICommandDetectionCapability {
579579
cwd: e.cwd,
580580
commandStartLineContent: e.commandStartLineContent,
581581
exitCode: e.exitCode,
582-
hasOutput: !!(executedMarker && endMarker && executedMarker.line < endMarker.line),
582+
hasOutput: () => !executedMarker?.isDisposed && !endMarker?.isDisposed && !!(executedMarker && endMarker && executedMarker.line < endMarker.line),
583583
getOutput: () => getOutputForCommand(executedMarker, endMarker, buffer),
584584
genericMarkProperties: e.genericMarkProperties
585585
};

src/vs/workbench/contrib/terminal/browser/terminalInstance.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -877,7 +877,7 @@ export class TerminalInstance extends Disposable implements ITerminalInstance {
877877
description,
878878
id: entry.timestamp.toString(),
879879
command: entry,
880-
buttons: entry.hasOutput ? buttons : undefined
880+
buttons: entry.hasOutput() ? buttons : undefined
881881
});
882882
commandMap.add(label);
883883
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ export class DecorationAddon extends Disposable implements ITerminalAddon {
365365
run: () => this._clipboardService.writeText(command.command)
366366
});
367367
}
368-
if (command.hasOutput) {
368+
if (command.hasOutput()) {
369369
if (actions.length > 0) {
370370
actions.push(new Separator());
371371
}

src/vs/workbench/contrib/terminal/common/terminal.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ export interface ITerminalCommand {
341341
cwd?: string;
342342
exitCode?: number;
343343
marker?: IXtermMarker;
344-
hasOutput: boolean;
344+
hasOutput(): boolean;
345345
getOutput(): string | undefined;
346346
genericMarkProperties?: IGenericMarkProperties;
347347
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ suite('Workbench - TerminalLinkOpeners', () => {
110110
marker: {
111111
line: 0
112112
} as Partial<IXtermMarker> as any,
113-
hasOutput: true
113+
hasOutput() { return true; }
114114
}]);
115115
fileService.setFiles([
116116
URI.from({ scheme: Schemas.file, path: '/initial/cwd/foo/bar.txt' }),
@@ -188,7 +188,7 @@ suite('Workbench - TerminalLinkOpeners', () => {
188188
marker: {
189189
line: 0
190190
} as Partial<IXtermMarker> as any,
191-
hasOutput: true
191+
hasOutput() { return true; }
192192
}]);
193193
await opener.open({
194194
text: 'file.txt',
@@ -237,7 +237,7 @@ suite('Workbench - TerminalLinkOpeners', () => {
237237
marker: {
238238
line: 0
239239
} as Partial<IXtermMarker> as any,
240-
hasOutput: true
240+
hasOutput() { return true; }
241241
}]);
242242
await opener.open({
243243
text: 'file.txt',

src/vs/workbench/contrib/terminal/test/browser/xterm/decorationAddon.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,21 +56,21 @@ suite('DecorationAddon', () => {
5656

5757
suite('registerDecoration', async () => {
5858
test('should throw when command has no marker', async () => {
59-
throws(() => decorationAddon.registerCommandDecoration({ command: 'cd src', timestamp: Date.now(), hasOutput: false } as ITerminalCommand));
59+
throws(() => decorationAddon.registerCommandDecoration({ command: 'cd src', timestamp: Date.now(), hasOutput: () => false } as ITerminalCommand));
6060
});
6161
test('should return undefined when marker has been disposed of', async () => {
6262
const marker = xterm.registerMarker(1);
6363
marker?.dispose();
64-
strictEqual(decorationAddon.registerCommandDecoration({ command: 'cd src', marker, timestamp: Date.now(), hasOutput: false } as ITerminalCommand), undefined);
64+
strictEqual(decorationAddon.registerCommandDecoration({ command: 'cd src', marker, timestamp: Date.now(), hasOutput: () => false } as ITerminalCommand), undefined);
6565
});
6666
test('should return undefined when command is just empty chars', async () => {
6767
const marker = xterm.registerMarker(1);
6868
marker?.dispose();
69-
strictEqual(decorationAddon.registerCommandDecoration({ command: ' ', marker, timestamp: Date.now(), hasOutput: false } as ITerminalCommand), undefined);
69+
strictEqual(decorationAddon.registerCommandDecoration({ command: ' ', marker, timestamp: Date.now(), hasOutput: () => false } as ITerminalCommand), undefined);
7070
});
7171
test('should return decoration when marker has not been disposed of', async () => {
7272
const marker = xterm.registerMarker(2);
73-
notEqual(decorationAddon.registerCommandDecoration({ command: 'cd src', marker, timestamp: Date.now(), hasOutput: false } as ITerminalCommand), undefined);
73+
notEqual(decorationAddon.registerCommandDecoration({ command: 'cd src', marker, timestamp: Date.now(), hasOutput: () => false } as ITerminalCommand), undefined);
7474
});
7575
});
7676
});

0 commit comments

Comments
 (0)