Skip to content

Commit e858db0

Browse files
authored
terminal command attachment follow-ups (microsoft#273187)
1 parent bd2aa0c commit e858db0

File tree

5 files changed

+9
-12
lines changed

5 files changed

+9
-12
lines changed

src/vs/workbench/contrib/chat/browser/actions/chatContext.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ export class TerminalContext implements IChatContextValueItem {
269269
constructor(private readonly _resource: URI, @ITerminalService private readonly _terminalService: ITerminalService) {
270270

271271
}
272-
async isEnabled(widget: IChatWidget) {
272+
isEnabled(widget: IChatWidget) {
273273
const terminal = this._terminalService.getInstanceFromResource(this._resource);
274274
return !!widget.attachmentCapabilities.supportsTerminalAttachments && terminal?.isDisposed === false;
275275
}
@@ -279,7 +279,7 @@ export class TerminalContext implements IChatContextValueItem {
279279
return;
280280
}
281281

282-
const command = terminal.capabilities.get(TerminalCapability.CommandDetection)?.commands.find(cmd => cmd.id === this._resource.query);
282+
const command = terminal.capabilities.get(TerminalCapability.CommandDetection)?.commands.find(cmd => cmd.id === this._resource.query.replace('command=', ''));
283283
if (!command) {
284284
return;
285285
}

src/vs/workbench/contrib/chat/browser/chatAttachmentWidgets.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -280,9 +280,6 @@ export class TerminalCommandAttachmentWidget extends AbstractChatAttachmentWidge
280280
this._register(createTerminalCommandElements(this.element, attachment, ariaLabel, this.hoverService, clickHandler));
281281

282282
this._register(dom.addDisposableListener(this.element, dom.EventType.KEY_DOWN, async (e: KeyboardEvent) => {
283-
if ((e.target as HTMLElement | null)?.closest('.monaco-button')) {
284-
return;
285-
}
286283
const event = new StandardKeyboardEvent(e);
287284
if (event.equals(KeyCode.Enter) || event.equals(KeyCode.Space)) {
288285
dom.EventHelper.stop(e, true);
@@ -307,15 +304,14 @@ function createTerminalCommandElements(
307304
element.ariaLabel = ariaLabel;
308305
element.style.cursor = 'pointer';
309306

310-
const pillIcon = dom.$('div.chat-attached-context-pill', {}, dom.$('span.codicon.codicon-terminal'));
307+
const terminalIconSpan = dom.$('span');
308+
terminalIconSpan.classList.add(...ThemeIcon.asClassNameArray(Codicon.terminal));
309+
const pillIcon = dom.$('div.chat-attached-context-pill', {}, terminalIconSpan);
311310
const textLabel = dom.$('span.chat-attached-context-custom-text', {}, attachment.command);
312311
element.appendChild(pillIcon);
313312
element.appendChild(textLabel);
314313

315314
disposable.add(dom.addDisposableListener(element, dom.EventType.CLICK, e => {
316-
if ((e.target as HTMLElement | null)?.closest('.monaco-button')) {
317-
return;
318-
}
319315
void clickHandler();
320316
}));
321317

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -775,7 +775,7 @@ export class TerminalService extends Disposable implements ITerminalService {
775775
if (instance) {
776776
this.revealTerminal(instance);
777777
const commands = instance.capabilities.get(TerminalCapability.CommandDetection)?.commands;
778-
const relevantCommand = commands?.find(c => c.id === resource.query);
778+
const relevantCommand = commands?.find(c => c.id === resource.query.replace('command=', ''));
779779
if (relevantCommand) {
780780
instance.xterm?.markTracker.revealCommand(relevantCommand);
781781
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export function getTerminalUri(workspaceId: string, instanceId: number, title?:
2727
scheme: Schemas.vscodeTerminal,
2828
path: `/${workspaceId}/${instanceId}`,
2929
fragment: title || undefined,
30-
query: commandId
30+
query: `command=${commandId}`
3131
});
3232
}
3333

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,8 +405,9 @@ export class DecorationAddon extends Disposable implements ITerminalAddon, IDeco
405405
}),
406406
dom.addDisposableListener(element, dom.EventType.CONTEXT_MENU, async (e) => {
407407
e.stopImmediatePropagation();
408+
const chatActions = await this._getCommandActions(command);
408409
const actions = this._getContextMenuActions();
409-
this._contextMenuService.showContextMenu({ getAnchor: () => element, getActions: () => actions });
410+
this._contextMenuService.showContextMenu({ getAnchor: () => element, getActions: () => [...actions, ...chatActions] });
410411
}),
411412
];
412413
}

0 commit comments

Comments
 (0)