Skip to content

Commit 4ba3d65

Browse files
authored
Generate cell for all chat users. (microsoft#210487)
1 parent 0ddd487 commit 4ba3d65

File tree

1 file changed

+26
-9
lines changed

1 file changed

+26
-9
lines changed

src/vs/workbench/contrib/notebook/browser/controller/chat/cellChatActions.ts

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import { EditorContextKeys } from 'vs/editor/common/editorContextKeys';
99
import { localize, localize2 } from 'vs/nls';
1010
import { CONTEXT_ACCESSIBILITY_MODE_ENABLED } from 'vs/platform/accessibility/common/accessibility';
1111
import { MenuId, MenuRegistry, registerAction2 } from 'vs/platform/actions/common/actions';
12+
import { ICommandService } from 'vs/platform/commands/common/commands';
13+
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
1214
import { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey';
1315
import { InputFocusedContextKey } from 'vs/platform/contextkey/common/contextkeys';
1416
import { ServicesAccessor } from 'vs/platform/instantiation/common/instantiation';
@@ -17,6 +19,7 @@ import { CTX_INLINE_CHAT_FOCUSED, CTX_INLINE_CHAT_HAS_PROVIDER, CTX_INLINE_CHAT_
1719
import { CTX_NOTEBOOK_CELL_CHAT_FOCUSED, CTX_NOTEBOOK_CHAT_HAS_ACTIVE_REQUEST, CTX_NOTEBOOK_CHAT_OUTER_FOCUS_POSITION, CTX_NOTEBOOK_CHAT_USER_DID_EDIT, MENU_CELL_CHAT_INPUT, MENU_CELL_CHAT_WIDGET, MENU_CELL_CHAT_WIDGET_FEEDBACK, MENU_CELL_CHAT_WIDGET_STATUS } from 'vs/workbench/contrib/notebook/browser/controller/chat/notebookChatContext';
1820
import { NotebookChatController } from 'vs/workbench/contrib/notebook/browser/controller/chat/notebookChatController';
1921
import { CELL_TITLE_CELL_GROUP_ID, INotebookActionContext, INotebookCellActionContext, NotebookAction, NotebookCellAction, getEditorFromArgsOrActivePane } from 'vs/workbench/contrib/notebook/browser/controller/coreActions';
22+
import { insertNewCell } from 'vs/workbench/contrib/notebook/browser/controller/insertCellActions';
2023
import { CellEditState } from 'vs/workbench/contrib/notebook/browser/notebookBrowser';
2124
import { CellKind, NOTEBOOK_EDITOR_CURSOR_BOUNDARY, NotebookSetting } from 'vs/workbench/contrib/notebook/common/notebookCommon';
2225
import { NOTEBOOK_CELL_EDITOR_FOCUSED, NOTEBOOK_CELL_GENERATED_BY_CHAT, NOTEBOOK_EDITOR_EDITABLE, NOTEBOOK_EDITOR_FOCUSED } from 'vs/workbench/contrib/notebook/common/notebookContextKeys';
@@ -364,6 +367,26 @@ interface IInsertCellWithChatArgs extends INotebookActionContext {
364367
autoSend?: boolean;
365368
}
366369

370+
async function startChat(accessor: ServicesAccessor, context: INotebookActionContext, index: number, input?: string, autoSend?: boolean) {
371+
const configurationService = accessor.get(IConfigurationService);
372+
const commandService = accessor.get(ICommandService);
373+
374+
if (configurationService.getValue<boolean>(NotebookSetting.cellChat)) {
375+
context.notebookEditor.focusContainer();
376+
NotebookChatController.get(context.notebookEditor)?.run(index, input, autoSend);
377+
} else {
378+
const newCell = await insertNewCell(accessor, context, CellKind.Code, 'below', true);
379+
if (newCell) {
380+
await context.notebookEditor.revealFirstLineIfOutsideViewport(newCell);
381+
const codeEditor = context.notebookEditor.codeEditors.find(ce => ce[0] === newCell)?.[1];
382+
if (codeEditor) {
383+
codeEditor.focus();
384+
commandService.executeCommand('inlineChat.start');
385+
}
386+
}
387+
}
388+
}
389+
367390
registerAction2(class extends NotebookAction {
368391
constructor() {
369392
super(
@@ -404,7 +427,6 @@ registerAction2(class extends NotebookAction {
404427
NOTEBOOK_EDITOR_EDITABLE.isEqualTo(true),
405428
ContextKeyExpr.not(InputFocusedContextKey),
406429
CTX_INLINE_CHAT_HAS_PROVIDER,
407-
ContextKeyExpr.equals(`config.${NotebookSetting.cellChat}`, true)
408430
),
409431
weight: KeybindingWeight.WorkbenchContrib,
410432
primary: KeyMod.CtrlCmd | KeyCode.KeyI,
@@ -418,7 +440,6 @@ registerAction2(class extends NotebookAction {
418440
when: ContextKeyExpr.and(
419441
NOTEBOOK_EDITOR_EDITABLE.isEqualTo(true),
420442
CTX_INLINE_CHAT_HAS_PROVIDER,
421-
ContextKeyExpr.equals(`config.${NotebookSetting.cellChat}`, true)
422443
)
423444
}
424445
]
@@ -467,8 +488,7 @@ registerAction2(class extends NotebookAction {
467488

468489
async runWithContext(accessor: ServicesAccessor, context: IInsertCellWithChatArgs) {
469490
const index = Math.max(0, context.cell ? context.notebookEditor.getCellIndex(context.cell) + 1 : 0);
470-
context.notebookEditor.focusContainer();
471-
NotebookChatController.get(context.notebookEditor)?.run(index, context.input, context.autoSend);
491+
await startChat(accessor, context, index, context.input, context.autoSend);
472492
}
473493
});
474494

@@ -490,17 +510,15 @@ registerAction2(class extends NotebookAction {
490510
order: -1,
491511
when: ContextKeyExpr.and(
492512
NOTEBOOK_EDITOR_EDITABLE.isEqualTo(true),
493-
CTX_INLINE_CHAT_HAS_PROVIDER,
494-
ContextKeyExpr.equals(`config.${NotebookSetting.cellChat}`, true)
513+
CTX_INLINE_CHAT_HAS_PROVIDER
495514
)
496515
},
497516
]
498517
});
499518
}
500519

501520
async runWithContext(accessor: ServicesAccessor, context: INotebookActionContext) {
502-
context.notebookEditor.focusContainer();
503-
NotebookChatController.get(context.notebookEditor)?.run(0, '', false);
521+
await startChat(accessor, context, 0, '', false);
504522
}
505523
});
506524

@@ -518,7 +536,6 @@ MenuRegistry.appendMenuItem(MenuId.NotebookToolbar, {
518536
ContextKeyExpr.notEquals('config.notebook.insertToolbarLocation', 'betweenCells'),
519537
ContextKeyExpr.notEquals('config.notebook.insertToolbarLocation', 'hidden'),
520538
CTX_INLINE_CHAT_HAS_PROVIDER,
521-
ContextKeyExpr.equals(`config.${NotebookSetting.cellChat}`, true)
522539
)
523540
});
524541

0 commit comments

Comments
 (0)