Skip to content
Merged

👁️ #231521

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
*--------------------------------------------------------------------------------------------*/

import * as dom from '../../../../../base/browser/dom.js';
import { StandardKeyboardEvent } from '../../../../../base/browser/keyboardEvent.js';
import { Button } from '../../../../../base/browser/ui/button/button.js';
import { getDefaultHoverDelegate } from '../../../../../base/browser/ui/hover/hoverDelegateFactory.js';
import { Codicon } from '../../../../../base/common/codicons.js';
import { KeyCode } from '../../../../../base/common/keyCodes.js';
import { Disposable, DisposableStore } from '../../../../../base/common/lifecycle.js';
import { basename, dirname } from '../../../../../base/common/resources.js';
import { URI } from '../../../../../base/common/uri.js';
import { localize } from '../../../../../nls.js';
import { FileKind } from '../../../../../platform/files/common/files.js';
import { IHoverService } from '../../../../../platform/hover/browser/hover.js';
import { ILabelService } from '../../../../../platform/label/common/label.js';
import { ResourceLabels } from '../../../../browser/labels.js';
import { IChatRequestImplicitVariableEntry } from '../../common/chatModel.js';
Expand All @@ -26,6 +26,7 @@ export class ImplicitContextAttachmentWidget extends Disposable {
private readonly attachment: IChatRequestImplicitVariableEntry,
private readonly resourceLabels: ResourceLabels,
@ILabelService private readonly labelService: ILabelService,
@IHoverService private readonly hoverService: IHoverService,
) {
super();

Expand All @@ -48,37 +49,27 @@ export class ImplicitContextAttachmentWidget extends Disposable {
const ariaLabel = range ? localize('chat.fileAttachmentWithRange', "Attached file, {0}, line {1} to line {2}", friendlyName, range.startLineNumber, range.endLineNumber) : localize('chat.fileAttachment', "Attached file, {0}", friendlyName);

const uriLabel = this.labelService.getUriLabel(file, { relative: true });
const currentFile = localize('openEditor', "Current File");
const inactive = localize('enableHint', "click to enable");
const currentFile = localize('openEditor', "Current file context");
const inactive = localize('enableHint', "disabled");
const currentFileHint = currentFile + (this.attachment.enabled ? '' : ` (${inactive})`);
const tip = localize('tip', "This context may or may not be used by a chat participant, and it may use other kinds of context automatically");
const title = `${currentFileHint}\n${uriLabel}`;
label.setFile(file, {
fileKind: FileKind.FILE,
hidePath: true,
range,
title: `${currentFileHint}\n${uriLabel}\n${tip}`,
title
});
this.domNode.ariaLabel = ariaLabel;
this.domNode.tabIndex = 0;
this.domNode.appendChild(dom.$('span.chat-implicit-hint', undefined, 'Current file'));
const hintElement = dom.append(this.domNode, dom.$('span.chat-implicit-hint', undefined, 'Current file'));
this._register(this.hoverService.setupManagedHover(getDefaultHoverDelegate('element'), hintElement, title));

if (this.attachment.enabled) {
const clearButton = this.renderDisposables.add(new Button(this.domNode, { supportIcons: true }));
clearButton.icon = Codicon.close;
this.renderDisposables.add(clearButton.onDidClick((e) => {
e.stopPropagation(); // prevent it from triggering the click handler on the parent immediately after rerendering
this.attachment.enabled = !this.attachment.enabled;
}));
} else {
this.renderDisposables.add(dom.addDisposableListener(this.domNode, dom.EventType.CLICK, () => {
this.attachment.enabled = !this.attachment.enabled;
}));
this.renderDisposables.add(dom.addDisposableListener(this.domNode, dom.EventType.KEY_UP, e => {
const keyboardEvent = new StandardKeyboardEvent(e);
if (keyboardEvent.equals(KeyCode.Space) || keyboardEvent.equals(KeyCode.Enter)) {
this.attachment.enabled = !this.attachment.enabled;
}
}));
}
const buttonMsg = this.attachment.enabled ? localize('disable', "Disable current file context") : localize('enable', "Enable current file context");
const toggleButton = this.renderDisposables.add(new Button(this.domNode, { supportIcons: true, title: buttonMsg }));
toggleButton.icon = this.attachment.enabled ? Codicon.eye : Codicon.eyeClosed;
this.renderDisposables.add(toggleButton.onDidClick((e) => {
e.stopPropagation(); // prevent it from triggering the click handler on the parent immediately after rerendering
this.attachment.enabled = !this.attachment.enabled;
}));
}
}
5 changes: 0 additions & 5 deletions src/vs/workbench/contrib/chat/browser/chatInputPart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1231,11 +1231,6 @@ class ModelPickerActionViewItem extends MenuEntryActionViewItem {
}));
}

// TODO need extra context tooltip?
// protected override getTooltip(): string {
// return super.getTooltip() + '\n' + localize('modelPickerHint', "A chat participant may or may not choose to use the selected model");
// }

override async onClick(event: MouseEvent): Promise<void> {
this._openContextMenu();
}
Expand Down
10 changes: 4 additions & 6 deletions src/vs/workbench/contrib/chat/browser/media/chat.css
Original file line number Diff line number Diff line change
Expand Up @@ -873,21 +873,19 @@ have to be updated for changes to the rules above, or to support more deeply nes
font-size: .9em;
}

.interactive-session .chat-attached-context .chat-attached-context-attachment.implicit.disabled .chat-implicit-hint {
font-style: italic;
}

.interactive-session .chat-attached-context .chat-attached-context-attachment.implicit.disabled {
border-style: dashed;
cursor: pointer;
padding-right: 26px;
}

.interactive-session .chat-attached-context .chat-attached-context-attachment.implicit.disabled:focus {
outline: none;
border-color: var(--vscode-focusBorder);
}

.interactive-session .chat-attached-context .chat-attached-context-attachment.implicit.disabled:hover {
background-color: var(--vscode-toolbar-hoverBackground);
}

.interactive-session .chat-attached-context .chat-attached-context-attachment.implicit.disabled .monaco-icon-label .label-name {
text-decoration: line-through;
font-style: italic;
Expand Down