-
Notifications
You must be signed in to change notification settings - Fork 34.8k
Update confirmations to use new proposed terminal style #260770
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
e8cd3e6
df1ce23
041dd57
75d3635
0c6da45
b4b07a0
ba2ec76
0b413e0
ab95f94
2443ee5
f7d919f
3bd5689
67b78f4
a5d813d
152f679
afabd39
3ffb2fa
19e3d7f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,9 @@ | |
*--------------------------------------------------------------------------------------------*/ | ||
|
||
import * as dom from '../../../../../../base/browser/dom.js'; | ||
import { HoverPosition } from '../../../../../../base/browser/ui/hover/hoverWidget.js'; | ||
import { asArray } from '../../../../../../base/common/arrays.js'; | ||
import { Codicon } from '../../../../../../base/common/codicons.js'; | ||
import { ErrorNoTelemetry } from '../../../../../../base/common/errors.js'; | ||
import { MarkdownString, type IMarkdownString } from '../../../../../../base/common/htmlContent.js'; | ||
import { thenIfNotDisposed } from '../../../../../../base/common/lifecycle.js'; | ||
|
@@ -15,9 +17,11 @@ import { generateUuid } from '../../../../../../base/common/uuid.js'; | |
import { MarkdownRenderer } from '../../../../../../editor/browser/widget/markdownRenderer/browser/markdownRenderer.js'; | ||
import { ILanguageService } from '../../../../../../editor/common/languages/language.js'; | ||
import { IModelService } from '../../../../../../editor/common/services/model.js'; | ||
import { ITextModelService } from '../../../../../../editor/common/services/resolverService.js'; | ||
import { localize } from '../../../../../../nls.js'; | ||
import { ConfigurationTarget, IConfigurationService } from '../../../../../../platform/configuration/common/configuration.js'; | ||
import { IContextKeyService } from '../../../../../../platform/contextkey/common/contextkey.js'; | ||
import { IHoverService } from '../../../../../../platform/hover/browser/hover.js'; | ||
import { IInstantiationService } from '../../../../../../platform/instantiation/common/instantiation.js'; | ||
import { IKeybindingService } from '../../../../../../platform/keybinding/common/keybinding.js'; | ||
import { IPreferencesService } from '../../../../../services/preferences/common/preferences.js'; | ||
|
@@ -30,11 +34,13 @@ import { CancelChatActionId } from '../../actions/chatExecuteActions.js'; | |
import { AcceptToolConfirmationActionId } from '../../actions/chatToolActions.js'; | ||
import { IChatCodeBlockInfo, IChatWidgetService } from '../../chat.js'; | ||
import { ICodeBlockRenderOptions } from '../../codeBlockPart.js'; | ||
import { ChatCustomConfirmationWidget, IChatConfirmationButton } from '../chatConfirmationWidget.js'; | ||
import { ChatCustomConfirmationWidget2, IChatConfirmationButton } from '../chatConfirmationWidget.js'; | ||
import { IChatContentPartRenderContext } from '../chatContentParts.js'; | ||
import { ChatMarkdownContentPart, EditorPool } from '../chatMarkdownContentPart.js'; | ||
import { BaseChatToolInvocationSubPart } from './chatToolInvocationSubPart.js'; | ||
|
||
const $ = dom.$; | ||
|
||
export interface ITerminalNewAutoApproveRule { | ||
key: string; | ||
value: boolean | { | ||
|
@@ -48,7 +54,7 @@ export type TerminalNewAutoApproveButtonData = ( | |
{ type: 'newRule'; rule: ITerminalNewAutoApproveRule | ITerminalNewAutoApproveRule[] } | ||
); | ||
|
||
export class TerminalConfirmationWidgetSubPart extends BaseChatToolInvocationSubPart { | ||
export class ChatTerminalToolConfirmationSubPart extends BaseChatToolInvocationSubPart { | ||
public readonly domNode: HTMLElement; | ||
public readonly codeblocks: IChatCodeBlockInfo[] = []; | ||
|
||
|
@@ -69,6 +75,8 @@ export class TerminalConfirmationWidgetSubPart extends BaseChatToolInvocationSub | |
@IContextKeyService private readonly contextKeyService: IContextKeyService, | ||
@IChatWidgetService private readonly chatWidgetService: IChatWidgetService, | ||
@IPreferencesService private readonly preferencesService: IPreferencesService, | ||
@ITextModelService textModelService: ITextModelService, | ||
@IHoverService hoverService: IHoverService, | ||
) { | ||
super(toolInvocation); | ||
|
||
|
@@ -98,11 +106,8 @@ export class TerminalConfirmationWidgetSubPart extends BaseChatToolInvocationSub | |
data: false, | ||
isSecondary: true, | ||
tooltip: cancelTooltip, | ||
}]; | ||
const renderedMessage = this._register(this.renderer.render( | ||
typeof message === 'string' ? new MarkdownString(message) : message, | ||
{ asyncRenderCallback: () => this._onDidChangeHeight.fire() } | ||
)); | ||
} | ||
]; | ||
const codeBlockRenderOptions: ICodeBlockRenderOptions = { | ||
hideToolbar: true, | ||
reserveWidth: 19, | ||
|
@@ -114,19 +119,26 @@ export class TerminalConfirmationWidgetSubPart extends BaseChatToolInvocationSub | |
ariaLabel: typeof title === 'string' ? title : title.value | ||
} | ||
}; | ||
const langId = this.languageService.getLanguageIdByLanguageName(terminalData.language ?? 'sh') ?? 'shellscript'; | ||
const languageId = this.languageService.getLanguageIdByLanguageName(terminalData.language ?? 'sh') ?? 'shellscript'; | ||
const model = this.modelService.createModel( | ||
terminalData.commandLine.toolEdited ?? terminalData.commandLine.original, | ||
this.languageService.createById(langId), | ||
this.languageService.createById(languageId), | ||
this._getUniqueCodeBlockUri(), | ||
true | ||
); | ||
textModelService.createModelReference(model.uri).then(ref => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See my helper There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The fact that we have to do this is confusing. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think I can use that since I need to call There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point. There could probably be a helper that covers what you want to do There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added helper, created #261211 to adopt after this PR is merged. |
||
if (this._store.isDisposed) { | ||
ref.dispose(); | ||
} else { | ||
this._register(ref); | ||
} | ||
}); | ||
const editor = this._register(this.editorPool.get()); | ||
const renderPromise = editor.object.render({ | ||
codeBlockIndex: this.codeBlockStartIndex, | ||
codeBlockPartIndex: 0, | ||
element: this.context.element, | ||
languageId: langId, | ||
languageId, | ||
renderOptions: codeBlockRenderOptions, | ||
textModel: Promise.resolve(model), | ||
chatSessionId: this.context.element.sessionId | ||
|
@@ -150,17 +162,26 @@ export class TerminalConfirmationWidgetSubPart extends BaseChatToolInvocationSub | |
this._register(model.onDidChangeContent(e => { | ||
terminalData.commandLine.userEdited = model.getValue(); | ||
})); | ||
const element = dom.$(''); | ||
dom.append(element, editor.object.element); | ||
dom.append(element, renderedMessage.element); | ||
const messageElement = $(''); | ||
dom.append(messageElement, editor.object.element); | ||
this._register(hoverService.setupDelayedHover(messageElement, { | ||
content: message, | ||
position: { hoverPosition: HoverPosition.BELOW }, | ||
appearance: { showPointer: true } | ||
})); | ||
const confirmWidget = this._register(this.instantiationService.createInstance( | ||
ChatCustomConfirmationWidget, | ||
ChatCustomConfirmationWidget2, | ||
this.context.container, | ||
{ title, message: element, buttons }, | ||
{ | ||
title, | ||
icon: Codicon.terminal, | ||
message: messageElement, | ||
buttons | ||
}, | ||
)); | ||
|
||
if (disclaimer) { | ||
this._appendMarkdownPart(element, disclaimer, codeBlockRenderOptions); | ||
this._appendMarkdownPart(messageElement, disclaimer, codeBlockRenderOptions); | ||
} | ||
|
||
ChatContextKeys.Editing.hasToolConfirmation.bindTo(this.contextKeyService).set(true); | ||
|
@@ -217,6 +238,7 @@ export class TerminalConfirmationWidgetSubPart extends BaseChatToolInvocationSub | |
ChatContextKeys.Editing.hasToolConfirmation.bindTo(this.contextKeyService).set(false); | ||
this._onNeedsRerender.fire(); | ||
}); | ||
|
||
this.domNode = confirmWidget.domNode; | ||
} | ||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.