diff --git a/src/vs/workbench/contrib/inlineChat/browser/inlineChatController.ts b/src/vs/workbench/contrib/inlineChat/browser/inlineChatController.ts index eb264de31db..c26f84ea791 100644 --- a/src/vs/workbench/contrib/inlineChat/browser/inlineChatController.ts +++ b/src/vs/workbench/contrib/inlineChat/browser/inlineChatController.ts @@ -63,6 +63,7 @@ import { IFileService } from '../../../../platform/files/common/files.js'; import { IChatAttachmentResolveService } from '../../chat/browser/chatAttachmentResolveService.js'; import { INotebookService } from '../../notebook/common/notebookService.js'; import { ICellEditOperation } from '../../notebook/common/notebookCommon.js'; +import { INotebookEditor } from '../../notebook/browser/notebookBrowser.js'; export const enum State { CREATE_SESSION = 'CREATE_SESSION', @@ -242,16 +243,18 @@ export class InlineChatController1 implements IEditorContribution { // check if this editor is part of a notebook editor // and iff so, use the notebook location but keep the resolveData // talk about editor data - for (const notebookEditor of notebookEditorService.listNotebookEditors()) { - for (const [, codeEditor] of notebookEditor.codeEditors) { + let notebookEditor: INotebookEditor | undefined; + for (const editor of notebookEditorService.listNotebookEditors()) { + for (const [, codeEditor] of editor.codeEditors) { if (codeEditor === this._editor) { + notebookEditor = editor; location.location = ChatAgentLocation.Notebook; break; } } } - const zone = _instaService.createInstance(InlineChatZoneWidget, location, undefined, this._editor); + const zone = _instaService.createInstance(InlineChatZoneWidget, location, undefined, { editor: this._editor, notebookEditor }); this._store.add(zone); this._store.add(zone.widget.chatWidget.onDidClear(async () => { const r = this.joinCurrentRun(); @@ -1260,12 +1263,13 @@ export class InlineChatController2 implements IEditorContribution { // inline chat in notebooks // check if this editor is part of a notebook editor - // and iff so, use the notebook location but keep the resolveData - // talk about editor data - for (const notebookEditor of this._notebookEditorService.listNotebookEditors()) { - for (const [, codeEditor] of notebookEditor.codeEditors) { + // if so, update the location and use the notebook specific widget + let notebookEditor: INotebookEditor | undefined; + for (const editor of this._notebookEditorService.listNotebookEditors()) { + for (const [, codeEditor] of editor.codeEditors) { if (codeEditor === this._editor) { location.location = ChatAgentLocation.Notebook; + notebookEditor = editor; break; } } @@ -1279,7 +1283,7 @@ export class InlineChatController2 implements IEditorContribution { renderTextEditsAsSummary: _uri => true } }, - this._editor + { editor: this._editor, notebookEditor }, ); result.domNode.classList.add('inline-chat-2'); diff --git a/src/vs/workbench/contrib/inlineChat/browser/inlineChatZoneWidget.ts b/src/vs/workbench/contrib/inlineChat/browser/inlineChatZoneWidget.ts index 83836042939..85a7c8b047b 100644 --- a/src/vs/workbench/contrib/inlineChat/browser/inlineChatZoneWidget.ts +++ b/src/vs/workbench/contrib/inlineChat/browser/inlineChatZoneWidget.ts @@ -22,6 +22,7 @@ import { ILogService } from '../../../../platform/log/common/log.js'; import { IChatWidgetViewOptions } from '../../chat/browser/chat.js'; import { IChatWidgetLocationOptions } from '../../chat/browser/chatWidget.js'; import { isResponseVM } from '../../chat/common/chatViewModel.js'; +import { INotebookEditor } from '../../notebook/browser/notebookBrowser.js'; import { ACTION_REGENERATE_RESPONSE, ACTION_REPORT_ISSUE, ACTION_TOGGLE_DIFF, CTX_INLINE_CHAT_OUTER_CURSOR_POSITION, MENU_INLINE_CHAT_SIDE, MENU_INLINE_CHAT_WIDGET_SECONDARY, MENU_INLINE_CHAT_WIDGET_STATUS } from '../common/inlineChat.js'; import { EditorBasedInlineChatWidget } from './inlineChatWidget.js'; @@ -45,16 +46,18 @@ export class InlineChatZoneWidget extends ZoneWidget { private readonly _scrollUp = this._disposables.add(new ScrollUpState(this.editor)); private readonly _ctxCursorPosition: IContextKey<'above' | 'below' | ''>; private _dimension?: Dimension; + private notebookEditor?: INotebookEditor; constructor( location: IChatWidgetLocationOptions, options: IChatWidgetViewOptions | undefined, - editor: ICodeEditor, + editors: { editor: ICodeEditor; notebookEditor?: INotebookEditor }, @IInstantiationService private readonly _instaService: IInstantiationService, @ILogService private _logService: ILogService, @IContextKeyService contextKeyService: IContextKeyService, ) { - super(editor, InlineChatZoneWidget._options); + super(editors.editor, InlineChatZoneWidget._options); + this.notebookEditor = editors.notebookEditor; this._ctxCursorPosition = CTX_INLINE_CHAT_OUTER_CURSOR_POSITION.bindTo(contextKeyService); @@ -87,7 +90,7 @@ export class InlineChatZoneWidget extends ZoneWidget { rendererOptions: { renderTextEditsAsSummary: (uri) => { // render when dealing with the current file in the editor - return isEqual(uri, editor.getModel()?.uri); + return isEqual(uri, editors.editor.getModel()?.uri); }, renderDetectedCommandsWithRequest: true, ...options?.rendererOptions @@ -165,7 +168,7 @@ export class InlineChatZoneWidget extends ZoneWidget { private _computeHeight(): { linesValue: number; pixelsValue: number } { const chatContentHeight = this.widget.contentHeight; - const editorHeight = this.editor.getLayoutInfo().height; + const editorHeight = this.notebookEditor?.getLayoutInfo().height ?? this.editor.getLayoutInfo().height; const contentHeight = this._decoratingElementsHeight() + Math.min(chatContentHeight, Math.max(this.widget.minHeight, editorHeight * 0.42)); const heightInLines = contentHeight / this.editor.getOption(EditorOption.lineHeight);