Skip to content

Commit dc80eeb

Browse files
authored
Adopt interactive command in notebook execution errors (microsoft#182141)
1 parent 7fb686d commit dc80eeb

File tree

1 file changed

+18
-59
lines changed

1 file changed

+18
-59
lines changed

src/vs/workbench/contrib/notebook/browser/controller/executeActions.ts

Lines changed: 18 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -5,36 +5,32 @@
55

66
import { Iterable } from 'vs/base/common/iterator';
77
import { KeyCode, KeyMod } from 'vs/base/common/keyCodes';
8-
import { URI, UriComponents } from 'vs/base/common/uri';
9-
import { CancellationTokenSource } from 'vs/base/common/cancellation';
8+
import { Schemas } from 'vs/base/common/network';
109
import { isEqual } from 'vs/base/common/resources';
11-
import { ITextModel } from 'vs/editor/common/model';
12-
import { Range } from 'vs/editor/common/core/range';
13-
import { ISelection } from 'vs/editor/common/core/selection';
10+
import { ThemeIcon } from 'vs/base/common/themables';
11+
import { URI, UriComponents } from 'vs/base/common/uri';
12+
import { ICodeEditor } from 'vs/editor/browser/editorBrowser';
1413
import { ILanguageService } from 'vs/editor/common/languages/language';
1514
import { localize } from 'vs/nls';
1615
import { MenuId, registerAction2 } from 'vs/platform/actions/common/actions';
16+
import { ICommandService } from 'vs/platform/commands/common/commands';
1717
import { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey';
1818
import { ServicesAccessor } from 'vs/platform/instantiation/common/instantiation';
19-
import { ThemeIcon } from 'vs/base/common/themables';
2019
import { EditorsOrder } from 'vs/workbench/common/editor';
20+
import { IDebugService } from 'vs/workbench/contrib/debug/common/debug';
21+
import { InteractiveEditorController } from 'vs/workbench/contrib/interactiveEditor/browser/interactiveEditorController';
22+
import { CTX_INTERACTIVE_EDITOR_FOCUSED } from 'vs/workbench/contrib/interactiveEditor/common/interactiveEditor';
2123
import { insertCell } from 'vs/workbench/contrib/notebook/browser/controller/cellOperations';
22-
import { cellExecutionArgs, CellToolbarOrder, CELL_TITLE_CELL_GROUP_ID, executeNotebookCondition, getContextFromActiveEditor, getContextFromUri, INotebookActionContext, INotebookCellActionContext, INotebookCellToolbarActionContext, INotebookCommandContext, NotebookAction, NotebookCellAction, NotebookMultiCellAction, NOTEBOOK_EDITOR_WIDGET_ACTION_WEIGHT, parseMultiCellExecutionArgs } from 'vs/workbench/contrib/notebook/browser/controller/coreActions';
23-
import { NOTEBOOK_CELL_EXECUTING, NOTEBOOK_CELL_EXECUTION_STATE, NOTEBOOK_CELL_LIST_FOCUSED, NOTEBOOK_CELL_TYPE, NOTEBOOK_HAS_RUNNING_CELL, NOTEBOOK_HAS_SOMETHING_RUNNING, NOTEBOOK_INTERRUPTIBLE_KERNEL, NOTEBOOK_IS_ACTIVE_EDITOR, NOTEBOOK_KERNEL_COUNT, NOTEBOOK_KERNEL_SOURCE_COUNT, NOTEBOOK_LAST_CELL_FAILED, NOTEBOOK_MISSING_KERNEL_EXTENSION } from 'vs/workbench/contrib/notebook/common/notebookContextKeys';
24+
import { CELL_TITLE_CELL_GROUP_ID, CellToolbarOrder, INotebookActionContext, INotebookCellActionContext, INotebookCellToolbarActionContext, INotebookCommandContext, NOTEBOOK_EDITOR_WIDGET_ACTION_WEIGHT, NotebookAction, NotebookCellAction, NotebookMultiCellAction, cellExecutionArgs, executeNotebookCondition, getContextFromActiveEditor, getContextFromUri, parseMultiCellExecutionArgs } from 'vs/workbench/contrib/notebook/browser/controller/coreActions';
2425
import { CellEditState, CellFocusMode, EXECUTE_CELL_COMMAND_ID } from 'vs/workbench/contrib/notebook/browser/notebookBrowser';
2526
import * as icons from 'vs/workbench/contrib/notebook/browser/notebookIcons';
2627
import { CellKind, CellUri, NotebookSetting } from 'vs/workbench/contrib/notebook/common/notebookCommon';
28+
import { NOTEBOOK_CELL_EXECUTING, NOTEBOOK_CELL_EXECUTION_STATE, NOTEBOOK_CELL_LIST_FOCUSED, NOTEBOOK_CELL_TYPE, NOTEBOOK_HAS_RUNNING_CELL, NOTEBOOK_HAS_SOMETHING_RUNNING, NOTEBOOK_INTERRUPTIBLE_KERNEL, NOTEBOOK_IS_ACTIVE_EDITOR, NOTEBOOK_KERNEL_COUNT, NOTEBOOK_KERNEL_SOURCE_COUNT, NOTEBOOK_LAST_CELL_FAILED, NOTEBOOK_MISSING_KERNEL_EXTENSION } from 'vs/workbench/contrib/notebook/common/notebookContextKeys';
2729
import { NotebookEditorInput } from 'vs/workbench/contrib/notebook/common/notebookEditorInput';
2830
import { INotebookExecutionStateService } from 'vs/workbench/contrib/notebook/common/notebookExecutionStateService';
31+
import { ICellRange } from 'vs/workbench/contrib/notebook/common/notebookRange';
2932
import { IEditorGroupsService } from 'vs/workbench/services/editor/common/editorGroupsService';
3033
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
31-
import { Schemas } from 'vs/base/common/network';
32-
import { IDebugService } from 'vs/workbench/contrib/debug/common/debug';
33-
import { CTX_INTERACTIVE_EDITOR_FOCUSED, IInteractiveEditorRequest, IInteractiveEditorService } from 'vs/workbench/contrib/interactiveEditor/common/interactiveEditor';
34-
import { ICellRange } from 'vs/workbench/contrib/notebook/common/notebookRange';
35-
import { ICodeEditor } from 'vs/editor/browser/editorBrowser';
36-
import { InteractiveEditorController } from 'vs/workbench/contrib/interactiveEditor/browser/interactiveEditorController';
37-
import { EditOperation } from 'vs/editor/common/core/editOperation';
3834

3935
const EXECUTE_NOTEBOOK_COMMAND_ID = 'notebook.execute';
4036
const CANCEL_NOTEBOOK_COMMAND_ID = 'notebook.cancelExecution';
@@ -810,55 +806,18 @@ registerAction2(class FixCellErrorction extends NotebookCellAction<ICellRange> {
810806
try {
811807
err = <ErrorLike>JSON.parse(textDecoder.decode(output.data.buffer));
812808

813-
if (!err.message) {
814-
return;
815-
}
816-
const textModel = context.notebookEditor.activeCodeEditor?.getModel() as ITextModel | null;
817-
818-
if (!textModel) {
819-
return;
820-
}
821-
822-
const interactiveEditorService = accessor.get(IInteractiveEditorService);
823-
const provider = Iterable.first(interactiveEditorService.getAllProvider());
824-
if (!provider) {
809+
if (!err.name && !err.message) {
825810
return;
826811
}
827812

813+
const errString = [err.name, err.message].filter(Boolean).join(': ');
828814
context.notebookEditor.showProgress();
829815

830-
const _ctsSession: CancellationTokenSource = new CancellationTokenSource();
831-
832-
const range = textModel.getFullModelRange();
833-
const selection: ISelection = {
834-
selectionStartLineNumber: range.startLineNumber,
835-
selectionStartColumn: range.startColumn,
836-
positionLineNumber: range.endLineNumber,
837-
positionColumn: range.endColumn
838-
};
839-
840-
const session = await provider.prepareInteractiveEditorSession(textModel, selection, _ctsSession.token);
841-
842-
if (!session) {
843-
context.notebookEditor.hideProgress();
844-
return;
845-
}
846-
847-
const request: IInteractiveEditorRequest = {
848-
prompt: `/fix ${err.message}`,
849-
selection: selection,
850-
wholeRange: textModel.getFullModelRange()
851-
};
852-
853-
const reply = await provider.provideResponse(session, request, _ctsSession.token);
854-
855-
if (reply && reply.type === 'editorEdit') {
856-
textModel.pushStackElement();
857-
const edits = reply.edits.map(edit => EditOperation.replace(Range.lift(edit.range), edit.text));
858-
textModel.pushEditOperations(null, edits, () => null);
859-
textModel.pushStackElement();
860-
}
861-
816+
const commandService = accessor.get(ICommandService);
817+
await commandService.executeCommand('interactiveEditor.start', {
818+
autoSend: true,
819+
message: `/fix ${errString}`,
820+
});
862821
context.notebookEditor.hideProgress();
863822
} catch (e) {
864823
console.log(e);

0 commit comments

Comments
 (0)