|
5 | 5 |
|
6 | 6 | import { Iterable } from 'vs/base/common/iterator'; |
7 | 7 | 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'; |
10 | 9 | 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'; |
14 | 13 | import { ILanguageService } from 'vs/editor/common/languages/language'; |
15 | 14 | import { localize } from 'vs/nls'; |
16 | 15 | import { MenuId, registerAction2 } from 'vs/platform/actions/common/actions'; |
| 16 | +import { ICommandService } from 'vs/platform/commands/common/commands'; |
17 | 17 | import { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey'; |
18 | 18 | import { ServicesAccessor } from 'vs/platform/instantiation/common/instantiation'; |
19 | | -import { ThemeIcon } from 'vs/base/common/themables'; |
20 | 19 | 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'; |
21 | 23 | 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'; |
24 | 25 | import { CellEditState, CellFocusMode, EXECUTE_CELL_COMMAND_ID } from 'vs/workbench/contrib/notebook/browser/notebookBrowser'; |
25 | 26 | import * as icons from 'vs/workbench/contrib/notebook/browser/notebookIcons'; |
26 | 27 | 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'; |
27 | 29 | import { NotebookEditorInput } from 'vs/workbench/contrib/notebook/common/notebookEditorInput'; |
28 | 30 | import { INotebookExecutionStateService } from 'vs/workbench/contrib/notebook/common/notebookExecutionStateService'; |
| 31 | +import { ICellRange } from 'vs/workbench/contrib/notebook/common/notebookRange'; |
29 | 32 | import { IEditorGroupsService } from 'vs/workbench/services/editor/common/editorGroupsService'; |
30 | 33 | 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'; |
38 | 34 |
|
39 | 35 | const EXECUTE_NOTEBOOK_COMMAND_ID = 'notebook.execute'; |
40 | 36 | const CANCEL_NOTEBOOK_COMMAND_ID = 'notebook.cancelExecution'; |
@@ -810,55 +806,18 @@ registerAction2(class FixCellErrorction extends NotebookCellAction<ICellRange> { |
810 | 806 | try { |
811 | 807 | err = <ErrorLike>JSON.parse(textDecoder.decode(output.data.buffer)); |
812 | 808 |
|
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) { |
825 | 810 | return; |
826 | 811 | } |
827 | 812 |
|
| 813 | + const errString = [err.name, err.message].filter(Boolean).join(': '); |
828 | 814 | context.notebookEditor.showProgress(); |
829 | 815 |
|
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 | + }); |
862 | 821 | context.notebookEditor.hideProgress(); |
863 | 822 | } catch (e) { |
864 | 823 | console.log(e); |
|
0 commit comments