@codingame/monaco-vscode-notebook-service-override 7.1.0 → 8.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -2
- package/vscode/src/vs/workbench/contrib/codeEditor/browser/emptyTextEditorHint/emptyTextEditorHint.js +14 -20
- package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/cellCommands/cellCommands.js +22 -23
- package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/cellDiagnostics/cellDiagnosticsActions.js +3 -4
- package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/cellDiagnostics/diagnosticCellStatusBarContrib.js +2 -3
- package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/cellStatusBar/statusBarProviders.js +5 -7
- package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/clipboard/notebookClipboard.js +7 -8
- package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/editorStatusBar/editorStatusBar.js +12 -13
- package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/find/notebookFind.js +3 -4
- package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/format/formatting.js +5 -6
- package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/gettingStarted/notebookGettingStarted.js +2 -3
- package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/layout/layoutActions.js +2 -3
- package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/navigation/arrow.js +16 -19
- package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/notebookVariables/notebookVariables.js +2 -3
- package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/notebookVariables/notebookVariablesDataSource.js +2 -3
- package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/notebookVariables/notebookVariablesTree.js +3 -4
- package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/notebookVariables/notebookVariablesView.js +4 -6
- package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/outline/notebookOutline.js +13 -17
- package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/profile/notebookProfile.js +2 -3
- package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/saveParticipants/saveParticipants.js +15 -18
- package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/troubleshoot/layout.js +4 -5
- package/vscode/src/vs/workbench/contrib/notebook/browser/controller/chat/cellChatActions.js +25 -26
- package/vscode/src/vs/workbench/contrib/notebook/browser/controller/chat/notebook.chat.contribution.js +3 -20
- package/vscode/src/vs/workbench/contrib/notebook/browser/controller/editActions.js +629 -0
- package/vscode/src/vs/workbench/contrib/notebook/browser/controller/executeActions.js +23 -24
- package/vscode/src/vs/workbench/contrib/notebook/browser/controller/insertCellActions.js +25 -26
- package/vscode/src/vs/workbench/contrib/notebook/browser/controller/layoutActions.js +18 -19
- package/vscode/src/vs/workbench/contrib/notebook/browser/controller/notebookIndentationActions.js +208 -0
- package/vscode/src/vs/workbench/contrib/notebook/browser/controller/sectionActions.js +13 -14
- package/vscode/src/vs/workbench/contrib/notebook/browser/diff/diffComponents.js +2 -3
- package/vscode/src/vs/workbench/contrib/notebook/browser/diff/diffElementOutputs.js +11 -15
- package/vscode/src/vs/workbench/contrib/notebook/browser/diff/notebookDiffActions.js +12 -13
- package/vscode/src/vs/workbench/contrib/notebook/browser/diff/notebookDiffEditor.js +2 -3
- package/vscode/src/vs/workbench/contrib/notebook/browser/notebook.contribution.js +95 -163
- package/vscode/src/vs/workbench/contrib/notebook/browser/notebookAccessibilityHelp.js +38 -50
- package/vscode/src/vs/workbench/contrib/notebook/browser/notebookAccessibleView.js +11 -12
- package/vscode/src/vs/workbench/contrib/notebook/browser/notebookExtensionPoint.js +43 -53
- package/vscode/src/vs/workbench/contrib/notebook/browser/services/notebookExecutionServiceImpl.js +2 -7
- package/vscode/src/vs/workbench/contrib/notebook/browser/services/notebookKernelHistoryServiceImpl.js +2 -3
- package/vscode/src/vs/workbench/contrib/notebook/browser/services/notebookKeymapServiceImpl.js +5 -7
- package/vscode/src/vs/workbench/contrib/notebook/browser/services/notebookLoggingServiceImpl.js +2 -3
- package/vscode/src/vs/workbench/contrib/notebook/browser/services/notebookServiceImpl.js +2 -3
- package/vscode/src/vs/workbench/services/workingCopy/common/fileWorkingCopyManager.js +16 -20
- package/vscode/src/vs/workbench/services/workingCopy/common/storedFileWorkingCopyManager.js +2 -3
|
@@ -0,0 +1,629 @@
|
|
|
1
|
+
import { KeyCode, KeyMod } from 'vscode/vscode/vs/base/common/keyCodes';
|
|
2
|
+
import { Mimes } from 'vscode/vscode/vs/base/common/mime';
|
|
3
|
+
import { URI } from 'vscode/vscode/vs/base/common/uri';
|
|
4
|
+
import { EditorOption } from 'vscode/vscode/vs/editor/common/config/editorOptions';
|
|
5
|
+
import { Selection } from 'vscode/vscode/vs/editor/common/core/selection';
|
|
6
|
+
import { EditorContextKeys } from 'vscode/vscode/vs/editor/common/editorContextKeys';
|
|
7
|
+
import { ILanguageService } from 'vscode/vscode/vs/editor/common/languages/language';
|
|
8
|
+
import { ILanguageConfigurationService } from 'vscode/vscode/vs/editor/common/languages/languageConfigurationRegistry';
|
|
9
|
+
import { getIconClasses } from 'vscode/vscode/vs/editor/common/services/getIconClasses';
|
|
10
|
+
import { IModelService } from 'vscode/vscode/vs/editor/common/services/model';
|
|
11
|
+
import { LineCommentCommand, Type } from 'vscode/vscode/vs/editor/contrib/comment/browser/lineCommentCommand';
|
|
12
|
+
import { localize, localize2 } from 'vscode/vscode/vs/nls';
|
|
13
|
+
import { registerAction2, MenuId } from 'vscode/vscode/vs/platform/actions/common/actions';
|
|
14
|
+
import { IConfigurationService } from 'vscode/vscode/vs/platform/configuration/common/configuration.service';
|
|
15
|
+
import { ContextKeyExpr } from 'vscode/vscode/vs/platform/contextkey/common/contextkey';
|
|
16
|
+
import { InputFocusedContextKey, InputFocusedContext } from 'vscode/vscode/vs/platform/contextkey/common/contextkeys';
|
|
17
|
+
import { IDialogService } from 'vscode/vscode/vs/platform/dialogs/common/dialogs.service';
|
|
18
|
+
import { IInstantiationService } from 'vscode/vscode/vs/platform/instantiation/common/instantiation';
|
|
19
|
+
import { KeybindingWeight } from 'vscode/vscode/vs/platform/keybinding/common/keybindingsRegistry';
|
|
20
|
+
import { INotificationService } from 'vscode/vscode/vs/platform/notification/common/notification.service';
|
|
21
|
+
import { IQuickInputService } from 'vscode/vscode/vs/platform/quickinput/common/quickInput.service';
|
|
22
|
+
import { InlineChatController } from 'vscode/vscode/vs/workbench/contrib/inlineChat/browser/inlineChatController';
|
|
23
|
+
import { CTX_INLINE_CHAT_FOCUSED } from 'vscode/vscode/vs/workbench/contrib/inlineChat/common/inlineChat';
|
|
24
|
+
import { runDeleteAction, changeCellToKind } from 'vscode/vscode/vs/workbench/contrib/notebook/browser/controller/cellOperations';
|
|
25
|
+
import { NotebookCellAction, CellToolbarOrder, CELL_TITLE_CELL_GROUP_ID, findTargetCellEditor, NOTEBOOK_EDITOR_WIDGET_ACTION_WEIGHT, executeNotebookCondition, CELL_TITLE_OUTPUT_GROUP_ID, NotebookAction, NotebookMultiCellAction } from 'vscode/vscode/vs/workbench/contrib/notebook/browser/controller/coreActions';
|
|
26
|
+
import { NotebookIndentUsingTabs, NotebookIndentUsingSpaces, NotebookChangeTabDisplaySize, NotebookIndentationToTabsAction, NotebookIndentationToSpacesAction } from './notebookIndentationActions.js';
|
|
27
|
+
import { QUIT_EDIT_CELL_COMMAND_ID, CellEditState, CHANGE_CELL_LANGUAGE, DETECT_CELL_LANGUAGE, getNotebookEditorFromEditorPane } from 'vscode/vscode/vs/workbench/contrib/notebook/browser/notebookBrowser';
|
|
28
|
+
import { editIcon, stopEditIcon, deleteCellIcon, clearIcon } from 'vscode/vscode/vs/workbench/contrib/notebook/browser/notebookIcons';
|
|
29
|
+
import { CellKind, NotebookCellExecutionState, NotebookSetting, CellEditType } from 'vscode/vscode/vs/workbench/contrib/notebook/common/notebookCommon';
|
|
30
|
+
import { NOTEBOOK_CELL_LIST_FOCUSED, NOTEBOOK_EDITOR_EDITABLE, NOTEBOOK_OUTPUT_INPUT_FOCUSED, NOTEBOOK_CELL_TYPE, NOTEBOOK_CELL_MARKDOWN_EDIT_MODE, NOTEBOOK_CELL_EDITABLE, NOTEBOOK_EDITOR_FOCUSED, NOTEBOOK_OUTPUT_FOCUSED, NOTEBOOK_CELL_HAS_OUTPUTS, NOTEBOOK_USE_CONSOLIDATED_OUTPUT_BUTTON, NOTEBOOK_CELL_IS_FIRST_OUTPUT, NOTEBOOK_HAS_OUTPUTS, NOTEBOOK_IS_ACTIVE_EDITOR } from 'vscode/vscode/vs/workbench/contrib/notebook/common/notebookContextKeys';
|
|
31
|
+
import { INotebookExecutionStateService } from 'vscode/vscode/vs/workbench/contrib/notebook/common/notebookExecutionStateService.service';
|
|
32
|
+
import { INotebookKernelService } from 'vscode/vscode/vs/workbench/contrib/notebook/common/notebookKernelService.service';
|
|
33
|
+
import { IEditorService } from 'vscode/vscode/vs/workbench/services/editor/common/editorService.service';
|
|
34
|
+
import { ILanguageDetectionService } from 'vscode/vscode/vs/workbench/services/languageDetection/common/languageDetectionWorkerService.service';
|
|
35
|
+
|
|
36
|
+
const CLEAR_ALL_CELLS_OUTPUTS_COMMAND_ID = 'notebook.clearAllCellsOutputs';
|
|
37
|
+
const EDIT_CELL_COMMAND_ID = 'notebook.cell.edit';
|
|
38
|
+
const DELETE_CELL_COMMAND_ID = 'notebook.cell.delete';
|
|
39
|
+
const CLEAR_CELL_OUTPUTS_COMMAND_ID = 'notebook.cell.clearOutputs';
|
|
40
|
+
const SELECT_NOTEBOOK_INDENTATION_ID = 'notebook.selectIndentation';
|
|
41
|
+
const COMMENT_SELECTED_CELLS_ID = 'notebook.commentSelectedCells';
|
|
42
|
+
registerAction2(class EditCellAction extends NotebookCellAction {
|
|
43
|
+
constructor() {
|
|
44
|
+
super({
|
|
45
|
+
id: EDIT_CELL_COMMAND_ID,
|
|
46
|
+
title: ( localize(7862, "Edit Cell")),
|
|
47
|
+
keybinding: {
|
|
48
|
+
when: ( (ContextKeyExpr.and(
|
|
49
|
+
NOTEBOOK_CELL_LIST_FOCUSED,
|
|
50
|
+
ContextKeyExpr.not(InputFocusedContextKey),
|
|
51
|
+
(NOTEBOOK_EDITOR_EDITABLE.isEqualTo(true)),
|
|
52
|
+
(EditorContextKeys.hoverFocused.toNegated()),
|
|
53
|
+
(NOTEBOOK_OUTPUT_INPUT_FOCUSED.toNegated())
|
|
54
|
+
))),
|
|
55
|
+
primary: KeyCode.Enter,
|
|
56
|
+
weight: KeybindingWeight.WorkbenchContrib
|
|
57
|
+
},
|
|
58
|
+
menu: {
|
|
59
|
+
id: MenuId.NotebookCellTitle,
|
|
60
|
+
when: ( (ContextKeyExpr.and(
|
|
61
|
+
(NOTEBOOK_EDITOR_EDITABLE.isEqualTo(true)),
|
|
62
|
+
(NOTEBOOK_CELL_TYPE.isEqualTo('markup')),
|
|
63
|
+
(NOTEBOOK_CELL_MARKDOWN_EDIT_MODE.toNegated()),
|
|
64
|
+
NOTEBOOK_CELL_EDITABLE
|
|
65
|
+
))),
|
|
66
|
+
order: CellToolbarOrder.EditCell,
|
|
67
|
+
group: CELL_TITLE_CELL_GROUP_ID
|
|
68
|
+
},
|
|
69
|
+
icon: editIcon,
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
async runWithContext(accessor, context) {
|
|
73
|
+
if (!context.notebookEditor.hasModel() || context.notebookEditor.isReadOnly) {
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
await context.notebookEditor.focusNotebookCell(context.cell, 'editor');
|
|
77
|
+
const foundEditor = context.cell ? findTargetCellEditor(context, context.cell) : undefined;
|
|
78
|
+
if (foundEditor && foundEditor.hasTextFocus() && InlineChatController.get(foundEditor)?.getWidgetPosition()?.lineNumber === foundEditor.getPosition()?.lineNumber) {
|
|
79
|
+
InlineChatController.get(foundEditor)?.focus();
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
const quitEditCondition = ( (ContextKeyExpr.and(
|
|
84
|
+
NOTEBOOK_EDITOR_FOCUSED,
|
|
85
|
+
InputFocusedContext,
|
|
86
|
+
(CTX_INLINE_CHAT_FOCUSED.toNegated())
|
|
87
|
+
)));
|
|
88
|
+
registerAction2(class QuitEditCellAction extends NotebookCellAction {
|
|
89
|
+
constructor() {
|
|
90
|
+
super({
|
|
91
|
+
id: QUIT_EDIT_CELL_COMMAND_ID,
|
|
92
|
+
title: ( localize(7863, "Stop Editing Cell")),
|
|
93
|
+
menu: {
|
|
94
|
+
id: MenuId.NotebookCellTitle,
|
|
95
|
+
when: ( (ContextKeyExpr.and(
|
|
96
|
+
(NOTEBOOK_CELL_TYPE.isEqualTo('markup')),
|
|
97
|
+
NOTEBOOK_CELL_MARKDOWN_EDIT_MODE,
|
|
98
|
+
NOTEBOOK_CELL_EDITABLE
|
|
99
|
+
))),
|
|
100
|
+
order: CellToolbarOrder.SaveCell,
|
|
101
|
+
group: CELL_TITLE_CELL_GROUP_ID
|
|
102
|
+
},
|
|
103
|
+
icon: stopEditIcon,
|
|
104
|
+
keybinding: [
|
|
105
|
+
{
|
|
106
|
+
when: ( (ContextKeyExpr.and(
|
|
107
|
+
quitEditCondition,
|
|
108
|
+
(EditorContextKeys.hoverVisible.toNegated()),
|
|
109
|
+
(EditorContextKeys.hasNonEmptySelection.toNegated()),
|
|
110
|
+
(EditorContextKeys.hasMultipleSelections.toNegated())
|
|
111
|
+
))),
|
|
112
|
+
primary: KeyCode.Escape,
|
|
113
|
+
weight: NOTEBOOK_EDITOR_WIDGET_ACTION_WEIGHT - 5
|
|
114
|
+
},
|
|
115
|
+
{
|
|
116
|
+
when: ( (ContextKeyExpr.and(NOTEBOOK_EDITOR_FOCUSED, NOTEBOOK_OUTPUT_FOCUSED))),
|
|
117
|
+
primary: KeyCode.Escape,
|
|
118
|
+
weight: KeybindingWeight.WorkbenchContrib + 5
|
|
119
|
+
},
|
|
120
|
+
{
|
|
121
|
+
when: ( (ContextKeyExpr.and(quitEditCondition, (NOTEBOOK_CELL_TYPE.isEqualTo('markup'))))),
|
|
122
|
+
primary: KeyMod.WinCtrl | KeyCode.Enter,
|
|
123
|
+
win: {
|
|
124
|
+
primary: KeyMod.CtrlCmd | KeyMod.Alt | KeyCode.Enter
|
|
125
|
+
},
|
|
126
|
+
weight: NOTEBOOK_EDITOR_WIDGET_ACTION_WEIGHT - 5
|
|
127
|
+
},
|
|
128
|
+
]
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
async runWithContext(accessor, context) {
|
|
132
|
+
if (context.cell.cellKind === CellKind.Markup) {
|
|
133
|
+
context.cell.updateEditState(CellEditState.Preview, QUIT_EDIT_CELL_COMMAND_ID);
|
|
134
|
+
}
|
|
135
|
+
await context.notebookEditor.focusNotebookCell(context.cell, 'container', { skipReveal: true });
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
registerAction2(class DeleteCellAction extends NotebookCellAction {
|
|
139
|
+
constructor() {
|
|
140
|
+
super({
|
|
141
|
+
id: DELETE_CELL_COMMAND_ID,
|
|
142
|
+
title: ( localize(7864, "Delete Cell")),
|
|
143
|
+
keybinding: {
|
|
144
|
+
primary: KeyCode.Delete,
|
|
145
|
+
mac: {
|
|
146
|
+
primary: KeyMod.CtrlCmd | KeyCode.Backspace
|
|
147
|
+
},
|
|
148
|
+
when: ( (ContextKeyExpr.and(
|
|
149
|
+
NOTEBOOK_EDITOR_FOCUSED,
|
|
150
|
+
ContextKeyExpr.not(InputFocusedContextKey),
|
|
151
|
+
(NOTEBOOK_OUTPUT_INPUT_FOCUSED.toNegated())
|
|
152
|
+
))),
|
|
153
|
+
weight: KeybindingWeight.WorkbenchContrib
|
|
154
|
+
},
|
|
155
|
+
menu: [
|
|
156
|
+
{
|
|
157
|
+
id: MenuId.NotebookCellDelete,
|
|
158
|
+
when: NOTEBOOK_EDITOR_EDITABLE,
|
|
159
|
+
group: CELL_TITLE_CELL_GROUP_ID
|
|
160
|
+
},
|
|
161
|
+
{
|
|
162
|
+
id: MenuId.InteractiveCellDelete,
|
|
163
|
+
group: CELL_TITLE_CELL_GROUP_ID
|
|
164
|
+
}
|
|
165
|
+
],
|
|
166
|
+
icon: deleteCellIcon
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
async runWithContext(accessor, context) {
|
|
170
|
+
if (!context.notebookEditor.hasModel()) {
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
let confirmation;
|
|
174
|
+
const notebookExecutionStateService = accessor.get(INotebookExecutionStateService);
|
|
175
|
+
const runState = notebookExecutionStateService.getCellExecution(context.cell.uri)?.state;
|
|
176
|
+
const configService = accessor.get(IConfigurationService);
|
|
177
|
+
if (runState === NotebookCellExecutionState.Executing && configService.getValue(NotebookSetting.confirmDeleteRunningCell)) {
|
|
178
|
+
const dialogService = accessor.get(IDialogService);
|
|
179
|
+
const primaryButton = ( localize(7865, "Delete"));
|
|
180
|
+
confirmation = await dialogService.confirm({
|
|
181
|
+
type: 'question',
|
|
182
|
+
message: ( localize(7866, "This cell is running, are you sure you want to delete it?")),
|
|
183
|
+
primaryButton: primaryButton,
|
|
184
|
+
checkbox: {
|
|
185
|
+
label: ( localize(7867, "Do not ask me again"))
|
|
186
|
+
}
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
else {
|
|
190
|
+
confirmation = { confirmed: true };
|
|
191
|
+
}
|
|
192
|
+
if (!confirmation.confirmed) {
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
if (confirmation.checkboxChecked === true) {
|
|
196
|
+
await configService.updateValue(NotebookSetting.confirmDeleteRunningCell, false);
|
|
197
|
+
}
|
|
198
|
+
runDeleteAction(context.notebookEditor, context.cell);
|
|
199
|
+
}
|
|
200
|
+
});
|
|
201
|
+
registerAction2(class ClearCellOutputsAction extends NotebookCellAction {
|
|
202
|
+
constructor() {
|
|
203
|
+
super({
|
|
204
|
+
id: CLEAR_CELL_OUTPUTS_COMMAND_ID,
|
|
205
|
+
title: ( localize(7868, 'Clear Cell Outputs')),
|
|
206
|
+
menu: [
|
|
207
|
+
{
|
|
208
|
+
id: MenuId.NotebookCellTitle,
|
|
209
|
+
when: ( (ContextKeyExpr.and(
|
|
210
|
+
(NOTEBOOK_CELL_TYPE.isEqualTo('code')),
|
|
211
|
+
executeNotebookCondition,
|
|
212
|
+
NOTEBOOK_CELL_HAS_OUTPUTS,
|
|
213
|
+
NOTEBOOK_EDITOR_EDITABLE,
|
|
214
|
+
NOTEBOOK_CELL_EDITABLE,
|
|
215
|
+
(NOTEBOOK_USE_CONSOLIDATED_OUTPUT_BUTTON.toNegated())
|
|
216
|
+
))),
|
|
217
|
+
order: CellToolbarOrder.ClearCellOutput,
|
|
218
|
+
group: CELL_TITLE_OUTPUT_GROUP_ID
|
|
219
|
+
},
|
|
220
|
+
{
|
|
221
|
+
id: MenuId.NotebookOutputToolbar,
|
|
222
|
+
when: ( (ContextKeyExpr.and(
|
|
223
|
+
NOTEBOOK_CELL_HAS_OUTPUTS,
|
|
224
|
+
NOTEBOOK_EDITOR_EDITABLE,
|
|
225
|
+
NOTEBOOK_CELL_EDITABLE,
|
|
226
|
+
NOTEBOOK_CELL_IS_FIRST_OUTPUT,
|
|
227
|
+
NOTEBOOK_USE_CONSOLIDATED_OUTPUT_BUTTON
|
|
228
|
+
)))
|
|
229
|
+
},
|
|
230
|
+
],
|
|
231
|
+
keybinding: {
|
|
232
|
+
when: ( (ContextKeyExpr.and(
|
|
233
|
+
NOTEBOOK_EDITOR_FOCUSED,
|
|
234
|
+
ContextKeyExpr.not(InputFocusedContextKey),
|
|
235
|
+
NOTEBOOK_CELL_HAS_OUTPUTS,
|
|
236
|
+
NOTEBOOK_EDITOR_EDITABLE,
|
|
237
|
+
NOTEBOOK_CELL_EDITABLE
|
|
238
|
+
))),
|
|
239
|
+
primary: KeyMod.Alt | KeyCode.Delete,
|
|
240
|
+
weight: KeybindingWeight.WorkbenchContrib
|
|
241
|
+
},
|
|
242
|
+
icon: clearIcon
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
async runWithContext(accessor, context) {
|
|
246
|
+
const notebookExecutionStateService = accessor.get(INotebookExecutionStateService);
|
|
247
|
+
const editor = context.notebookEditor;
|
|
248
|
+
if (!editor.hasModel() || !editor.textModel.length) {
|
|
249
|
+
return;
|
|
250
|
+
}
|
|
251
|
+
const cell = context.cell;
|
|
252
|
+
const index = editor.textModel.cells.indexOf(cell.model);
|
|
253
|
+
if (index < 0) {
|
|
254
|
+
return;
|
|
255
|
+
}
|
|
256
|
+
const computeUndoRedo = !editor.isReadOnly;
|
|
257
|
+
editor.textModel.applyEdits([{ editType: CellEditType.Output, index, outputs: [] }], true, undefined, () => undefined, undefined, computeUndoRedo);
|
|
258
|
+
const runState = notebookExecutionStateService.getCellExecution(context.cell.uri)?.state;
|
|
259
|
+
if (runState !== NotebookCellExecutionState.Executing) {
|
|
260
|
+
context.notebookEditor.textModel.applyEdits([{
|
|
261
|
+
editType: CellEditType.PartialInternalMetadata, index, internalMetadata: {
|
|
262
|
+
runStartTime: null,
|
|
263
|
+
runStartTimeAdjustment: null,
|
|
264
|
+
runEndTime: null,
|
|
265
|
+
executionOrder: null,
|
|
266
|
+
lastRunSuccess: null
|
|
267
|
+
}
|
|
268
|
+
}], true, undefined, () => undefined, undefined, computeUndoRedo);
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
});
|
|
272
|
+
registerAction2(class ClearAllCellOutputsAction extends NotebookAction {
|
|
273
|
+
constructor() {
|
|
274
|
+
super({
|
|
275
|
+
id: CLEAR_ALL_CELLS_OUTPUTS_COMMAND_ID,
|
|
276
|
+
title: ( localize(7869, 'Clear All Outputs')),
|
|
277
|
+
precondition: NOTEBOOK_HAS_OUTPUTS,
|
|
278
|
+
menu: [
|
|
279
|
+
{
|
|
280
|
+
id: MenuId.EditorTitle,
|
|
281
|
+
when: ( (ContextKeyExpr.and(
|
|
282
|
+
NOTEBOOK_IS_ACTIVE_EDITOR,
|
|
283
|
+
(ContextKeyExpr.notEquals('config.notebook.globalToolbar', true))
|
|
284
|
+
))),
|
|
285
|
+
group: 'navigation',
|
|
286
|
+
order: 0
|
|
287
|
+
},
|
|
288
|
+
{
|
|
289
|
+
id: MenuId.NotebookToolbar,
|
|
290
|
+
when: ( (ContextKeyExpr.and(
|
|
291
|
+
executeNotebookCondition,
|
|
292
|
+
(ContextKeyExpr.equals('config.notebook.globalToolbar', true))
|
|
293
|
+
))),
|
|
294
|
+
group: 'navigation/execute',
|
|
295
|
+
order: 10
|
|
296
|
+
}
|
|
297
|
+
],
|
|
298
|
+
icon: clearIcon
|
|
299
|
+
});
|
|
300
|
+
}
|
|
301
|
+
async runWithContext(accessor, context) {
|
|
302
|
+
const notebookExecutionStateService = accessor.get(INotebookExecutionStateService);
|
|
303
|
+
const editor = context.notebookEditor;
|
|
304
|
+
if (!editor.hasModel() || !editor.textModel.length) {
|
|
305
|
+
return;
|
|
306
|
+
}
|
|
307
|
+
const computeUndoRedo = !editor.isReadOnly;
|
|
308
|
+
editor.textModel.applyEdits(( (editor.textModel.cells.map((cell, index) => ({
|
|
309
|
+
editType: CellEditType.Output, index, outputs: []
|
|
310
|
+
})))), true, undefined, () => undefined, undefined, computeUndoRedo);
|
|
311
|
+
const clearExecutionMetadataEdits = ( (editor.textModel.cells.map((cell, index) => {
|
|
312
|
+
const runState = notebookExecutionStateService.getCellExecution(cell.uri)?.state;
|
|
313
|
+
if (runState !== NotebookCellExecutionState.Executing) {
|
|
314
|
+
return {
|
|
315
|
+
editType: CellEditType.PartialInternalMetadata, index, internalMetadata: {
|
|
316
|
+
runStartTime: null,
|
|
317
|
+
runStartTimeAdjustment: null,
|
|
318
|
+
runEndTime: null,
|
|
319
|
+
executionOrder: null,
|
|
320
|
+
lastRunSuccess: null
|
|
321
|
+
}
|
|
322
|
+
};
|
|
323
|
+
}
|
|
324
|
+
else {
|
|
325
|
+
return undefined;
|
|
326
|
+
}
|
|
327
|
+
}))).filter(edit => !!edit);
|
|
328
|
+
if (clearExecutionMetadataEdits.length) {
|
|
329
|
+
context.notebookEditor.textModel.applyEdits(clearExecutionMetadataEdits, true, undefined, () => undefined, undefined, computeUndoRedo);
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
});
|
|
333
|
+
registerAction2(class ChangeCellLanguageAction extends NotebookCellAction {
|
|
334
|
+
constructor() {
|
|
335
|
+
super({
|
|
336
|
+
id: CHANGE_CELL_LANGUAGE,
|
|
337
|
+
title: ( localize(7870, 'Change Cell Language')),
|
|
338
|
+
metadata: {
|
|
339
|
+
description: ( localize(7870, 'Change Cell Language')),
|
|
340
|
+
args: [
|
|
341
|
+
{
|
|
342
|
+
name: 'range',
|
|
343
|
+
description: 'The cell range',
|
|
344
|
+
schema: {
|
|
345
|
+
'type': 'object',
|
|
346
|
+
'required': ['start', 'end'],
|
|
347
|
+
'properties': {
|
|
348
|
+
'start': {
|
|
349
|
+
'type': 'number'
|
|
350
|
+
},
|
|
351
|
+
'end': {
|
|
352
|
+
'type': 'number'
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
},
|
|
357
|
+
{
|
|
358
|
+
name: 'language',
|
|
359
|
+
description: 'The target cell language',
|
|
360
|
+
schema: {
|
|
361
|
+
'type': 'string'
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
]
|
|
365
|
+
}
|
|
366
|
+
});
|
|
367
|
+
}
|
|
368
|
+
getCellContextFromArgs(accessor, context, ...additionalArgs) {
|
|
369
|
+
if (!context || typeof context.start !== 'number' || typeof context.end !== 'number' || context.start >= context.end) {
|
|
370
|
+
return;
|
|
371
|
+
}
|
|
372
|
+
const language = additionalArgs.length && typeof additionalArgs[0] === 'string' ? additionalArgs[0] : undefined;
|
|
373
|
+
const activeEditorContext = this.getEditorContextFromArgsOrActive(accessor);
|
|
374
|
+
if (!activeEditorContext || !activeEditorContext.notebookEditor.hasModel() || context.start >= activeEditorContext.notebookEditor.getLength()) {
|
|
375
|
+
return;
|
|
376
|
+
}
|
|
377
|
+
return {
|
|
378
|
+
notebookEditor: activeEditorContext.notebookEditor,
|
|
379
|
+
cell: activeEditorContext.notebookEditor.cellAt(context.start),
|
|
380
|
+
language
|
|
381
|
+
};
|
|
382
|
+
}
|
|
383
|
+
async runWithContext(accessor, context) {
|
|
384
|
+
if (context.language) {
|
|
385
|
+
await this.setLanguage(context, context.language);
|
|
386
|
+
}
|
|
387
|
+
else {
|
|
388
|
+
await this.showLanguagePicker(accessor, context);
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
async showLanguagePicker(accessor, context) {
|
|
392
|
+
const topItems = [];
|
|
393
|
+
const mainItems = [];
|
|
394
|
+
const languageService = accessor.get(ILanguageService);
|
|
395
|
+
const modelService = accessor.get(IModelService);
|
|
396
|
+
const quickInputService = accessor.get(IQuickInputService);
|
|
397
|
+
const languageDetectionService = accessor.get(ILanguageDetectionService);
|
|
398
|
+
const kernelService = accessor.get(INotebookKernelService);
|
|
399
|
+
let languages = context.notebookEditor.activeKernel?.supportedLanguages;
|
|
400
|
+
if (!languages) {
|
|
401
|
+
const matchResult = kernelService.getMatchingKernel(context.notebookEditor.textModel);
|
|
402
|
+
const allSupportedLanguages = matchResult.all.flatMap(kernel => kernel.supportedLanguages);
|
|
403
|
+
languages = allSupportedLanguages.length > 0 ? allSupportedLanguages : languageService.getRegisteredLanguageIds();
|
|
404
|
+
}
|
|
405
|
+
const providerLanguages = ( (new Set([
|
|
406
|
+
...languages,
|
|
407
|
+
'markdown'
|
|
408
|
+
])));
|
|
409
|
+
providerLanguages.forEach(languageId => {
|
|
410
|
+
let description;
|
|
411
|
+
if (context.cell.cellKind === CellKind.Markup ? (languageId === 'markdown') : (languageId === context.cell.language)) {
|
|
412
|
+
description = ( localize(7871, "({0}) - Current Language", languageId));
|
|
413
|
+
}
|
|
414
|
+
else {
|
|
415
|
+
description = ( localize(7872, "({0})", languageId));
|
|
416
|
+
}
|
|
417
|
+
const languageName = languageService.getLanguageName(languageId);
|
|
418
|
+
if (!languageName) {
|
|
419
|
+
return;
|
|
420
|
+
}
|
|
421
|
+
const item = {
|
|
422
|
+
label: languageName,
|
|
423
|
+
iconClasses: getIconClasses(modelService, languageService, this.getFakeResource(languageName, languageService)),
|
|
424
|
+
description,
|
|
425
|
+
languageId
|
|
426
|
+
};
|
|
427
|
+
if (languageId === 'markdown' || languageId === context.cell.language) {
|
|
428
|
+
topItems.push(item);
|
|
429
|
+
}
|
|
430
|
+
else {
|
|
431
|
+
mainItems.push(item);
|
|
432
|
+
}
|
|
433
|
+
});
|
|
434
|
+
mainItems.sort((a, b) => {
|
|
435
|
+
return a.description.localeCompare(b.description);
|
|
436
|
+
});
|
|
437
|
+
const autoDetectMode = {
|
|
438
|
+
label: ( localize(7873, "Auto Detect"))
|
|
439
|
+
};
|
|
440
|
+
const picks = [
|
|
441
|
+
autoDetectMode,
|
|
442
|
+
{ type: 'separator', label: ( localize(7874, "languages (identifier)")) },
|
|
443
|
+
...topItems,
|
|
444
|
+
{ type: 'separator' },
|
|
445
|
+
...mainItems
|
|
446
|
+
];
|
|
447
|
+
const selection = await quickInputService.pick(picks, { placeHolder: ( localize(7875, "Select Language Mode")) });
|
|
448
|
+
const languageId = selection === autoDetectMode
|
|
449
|
+
? await languageDetectionService.detectLanguage(context.cell.uri)
|
|
450
|
+
: selection?.languageId;
|
|
451
|
+
if (languageId) {
|
|
452
|
+
await this.setLanguage(context, languageId);
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
async setLanguage(context, languageId) {
|
|
456
|
+
await setCellToLanguage(languageId, context);
|
|
457
|
+
}
|
|
458
|
+
getFakeResource(lang, languageService) {
|
|
459
|
+
let fakeResource;
|
|
460
|
+
const languageId = languageService.getLanguageIdByLanguageName(lang);
|
|
461
|
+
if (languageId) {
|
|
462
|
+
const extensions = languageService.getExtensions(languageId);
|
|
463
|
+
if (extensions.length) {
|
|
464
|
+
fakeResource = URI.file(extensions[0]);
|
|
465
|
+
}
|
|
466
|
+
else {
|
|
467
|
+
const filenames = languageService.getFilenames(languageId);
|
|
468
|
+
if (filenames.length) {
|
|
469
|
+
fakeResource = URI.file(filenames[0]);
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
return fakeResource;
|
|
474
|
+
}
|
|
475
|
+
});
|
|
476
|
+
registerAction2(class DetectCellLanguageAction extends NotebookCellAction {
|
|
477
|
+
constructor() {
|
|
478
|
+
super({
|
|
479
|
+
id: DETECT_CELL_LANGUAGE,
|
|
480
|
+
title: ( localize2(7876, "Accept Detected Language for Cell")),
|
|
481
|
+
f1: true,
|
|
482
|
+
precondition: ( (ContextKeyExpr.and(NOTEBOOK_EDITOR_EDITABLE, NOTEBOOK_CELL_EDITABLE))),
|
|
483
|
+
keybinding: { primary: KeyCode.KeyD | KeyMod.Alt | KeyMod.Shift, weight: KeybindingWeight.WorkbenchContrib }
|
|
484
|
+
});
|
|
485
|
+
}
|
|
486
|
+
async runWithContext(accessor, context) {
|
|
487
|
+
const languageDetectionService = accessor.get(ILanguageDetectionService);
|
|
488
|
+
const notificationService = accessor.get(INotificationService);
|
|
489
|
+
const kernelService = accessor.get(INotebookKernelService);
|
|
490
|
+
const kernel = kernelService.getSelectedOrSuggestedKernel(context.notebookEditor.textModel);
|
|
491
|
+
const providerLanguages = [...(kernel?.supportedLanguages ?? [])];
|
|
492
|
+
providerLanguages.push('markdown');
|
|
493
|
+
const detection = await languageDetectionService.detectLanguage(context.cell.uri, providerLanguages);
|
|
494
|
+
if (detection) {
|
|
495
|
+
setCellToLanguage(detection, context);
|
|
496
|
+
}
|
|
497
|
+
else {
|
|
498
|
+
notificationService.warn(( localize(7877, "Unable to detect cell language")));
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
});
|
|
502
|
+
async function setCellToLanguage(languageId, context) {
|
|
503
|
+
if (languageId === 'markdown' && context.cell?.language !== 'markdown') {
|
|
504
|
+
const idx = context.notebookEditor.getCellIndex(context.cell);
|
|
505
|
+
await changeCellToKind(CellKind.Markup, { cell: context.cell, notebookEditor: context.notebookEditor, ui: true }, 'markdown', Mimes.markdown);
|
|
506
|
+
const newCell = context.notebookEditor.cellAt(idx);
|
|
507
|
+
if (newCell) {
|
|
508
|
+
await context.notebookEditor.focusNotebookCell(newCell, 'editor');
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
else if (languageId !== 'markdown' && context.cell?.cellKind === CellKind.Markup) {
|
|
512
|
+
await changeCellToKind(CellKind.Code, { cell: context.cell, notebookEditor: context.notebookEditor, ui: true }, languageId);
|
|
513
|
+
}
|
|
514
|
+
else {
|
|
515
|
+
const index = context.notebookEditor.textModel.cells.indexOf(context.cell.model);
|
|
516
|
+
context.notebookEditor.textModel.applyEdits([{ editType: CellEditType.CellLanguage, index, language: languageId }], true, undefined, () => undefined, undefined, !context.notebookEditor.isReadOnly);
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
registerAction2(class SelectNotebookIndentation extends NotebookAction {
|
|
520
|
+
constructor() {
|
|
521
|
+
super({
|
|
522
|
+
id: SELECT_NOTEBOOK_INDENTATION_ID,
|
|
523
|
+
title: ( localize2(7878, 'Select Indentation')),
|
|
524
|
+
f1: true,
|
|
525
|
+
precondition: ( (ContextKeyExpr.and(
|
|
526
|
+
NOTEBOOK_IS_ACTIVE_EDITOR,
|
|
527
|
+
NOTEBOOK_EDITOR_EDITABLE,
|
|
528
|
+
NOTEBOOK_CELL_EDITABLE
|
|
529
|
+
))),
|
|
530
|
+
});
|
|
531
|
+
}
|
|
532
|
+
async runWithContext(accessor, context) {
|
|
533
|
+
await this.showNotebookIndentationPicker(accessor, context);
|
|
534
|
+
}
|
|
535
|
+
async showNotebookIndentationPicker(accessor, context) {
|
|
536
|
+
const quickInputService = accessor.get(IQuickInputService);
|
|
537
|
+
const editorService = accessor.get(IEditorService);
|
|
538
|
+
const instantiationService = accessor.get(IInstantiationService);
|
|
539
|
+
const activeNotebook = getNotebookEditorFromEditorPane(editorService.activeEditorPane);
|
|
540
|
+
if (!activeNotebook || activeNotebook.isDisposed) {
|
|
541
|
+
return quickInputService.pick([{ label: ( localize(7879, "No notebook editor active at this time")) }]);
|
|
542
|
+
}
|
|
543
|
+
if (activeNotebook.isReadOnly) {
|
|
544
|
+
return quickInputService.pick([{ label: ( localize(7880, "The active notebook editor is read-only.")) }]);
|
|
545
|
+
}
|
|
546
|
+
const picks = ( ([
|
|
547
|
+
(
|
|
548
|
+
(new NotebookIndentUsingTabs())),
|
|
549
|
+
(
|
|
550
|
+
(new NotebookIndentUsingSpaces())),
|
|
551
|
+
(
|
|
552
|
+
(new NotebookChangeTabDisplaySize())),
|
|
553
|
+
(
|
|
554
|
+
(new NotebookIndentationToTabsAction())),
|
|
555
|
+
(
|
|
556
|
+
(new NotebookIndentationToSpacesAction()))
|
|
557
|
+
].map(item => {
|
|
558
|
+
return {
|
|
559
|
+
id: item.desc.id,
|
|
560
|
+
label: ( (item.desc.title.toString())),
|
|
561
|
+
run: () => {
|
|
562
|
+
instantiationService.invokeFunction(item.run);
|
|
563
|
+
}
|
|
564
|
+
};
|
|
565
|
+
})));
|
|
566
|
+
picks.splice(3, 0, { type: 'separator', label: ( localize(7881, "convert file")) });
|
|
567
|
+
picks.unshift({ type: 'separator', label: ( localize(7882, "change view")) });
|
|
568
|
+
const action = await quickInputService.pick(picks, { placeHolder: ( localize(7883, "Select Action")), matchOnDetail: true });
|
|
569
|
+
if (!action) {
|
|
570
|
+
return;
|
|
571
|
+
}
|
|
572
|
+
action.run();
|
|
573
|
+
context.notebookEditor.focus();
|
|
574
|
+
return;
|
|
575
|
+
}
|
|
576
|
+
});
|
|
577
|
+
registerAction2(class CommentSelectedCellsAction extends NotebookMultiCellAction {
|
|
578
|
+
constructor() {
|
|
579
|
+
super({
|
|
580
|
+
id: COMMENT_SELECTED_CELLS_ID,
|
|
581
|
+
title: ( localize(7884, "Comment Selected Cells")),
|
|
582
|
+
keybinding: {
|
|
583
|
+
when: ( (ContextKeyExpr.and(
|
|
584
|
+
NOTEBOOK_EDITOR_FOCUSED,
|
|
585
|
+
NOTEBOOK_EDITOR_EDITABLE,
|
|
586
|
+
ContextKeyExpr.not(InputFocusedContextKey)
|
|
587
|
+
))),
|
|
588
|
+
primary: KeyMod.CtrlCmd | KeyCode.Slash,
|
|
589
|
+
weight: KeybindingWeight.WorkbenchContrib
|
|
590
|
+
}
|
|
591
|
+
});
|
|
592
|
+
}
|
|
593
|
+
async runWithContext(accessor, context) {
|
|
594
|
+
const languageConfigurationService = accessor.get(ILanguageConfigurationService);
|
|
595
|
+
const selectedCellEditors = [];
|
|
596
|
+
context.selectedCells.forEach(cell => {
|
|
597
|
+
const findContext = { notebookEditor: context.notebookEditor, cell };
|
|
598
|
+
const foundEditor = findTargetCellEditor(findContext, cell);
|
|
599
|
+
if (foundEditor) {
|
|
600
|
+
selectedCellEditors.push(foundEditor);
|
|
601
|
+
}
|
|
602
|
+
});
|
|
603
|
+
selectedCellEditors.forEach(editor => {
|
|
604
|
+
if (!editor.hasModel()) {
|
|
605
|
+
return;
|
|
606
|
+
}
|
|
607
|
+
const model = editor.getModel();
|
|
608
|
+
const commands = [];
|
|
609
|
+
const modelOptions = model.getOptions();
|
|
610
|
+
const commentsOptions = editor.getOption(EditorOption.comments);
|
|
611
|
+
const selection = editor.getSelection();
|
|
612
|
+
commands.push(( (new LineCommentCommand(
|
|
613
|
+
languageConfigurationService,
|
|
614
|
+
(new Selection(1, 1, model.getLineCount(), model.getLineMaxColumn(model.getLineCount()))),
|
|
615
|
+
modelOptions.indentSize,
|
|
616
|
+
Type.Toggle,
|
|
617
|
+
commentsOptions.insertSpace,
|
|
618
|
+
commentsOptions.ignoreEmptyLines,
|
|
619
|
+
false
|
|
620
|
+
))));
|
|
621
|
+
editor.pushUndoStop();
|
|
622
|
+
editor.executeCommands(COMMENT_SELECTED_CELLS_ID, commands);
|
|
623
|
+
editor.pushUndoStop();
|
|
624
|
+
editor.setSelection(selection);
|
|
625
|
+
});
|
|
626
|
+
}
|
|
627
|
+
});
|
|
628
|
+
|
|
629
|
+
export { CLEAR_CELL_OUTPUTS_COMMAND_ID, COMMENT_SELECTED_CELLS_ID, SELECT_NOTEBOOK_INDENTATION_ID };
|