@codingame/monaco-vscode-interactive-service-override 2.2.0-next.1
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/external/rollup-plugin-styles/dist/runtime/inject-css.js +3 -0
- package/external/tslib/tslib.es6.js +11 -0
- package/index.d.ts +1 -0
- package/index.js +1 -0
- package/interactive.d.ts +5 -0
- package/interactive.js +13 -0
- package/package.json +24 -0
- package/vscode/src/vs/workbench/contrib/interactive/browser/interactive.contribution.js +703 -0
- package/vscode/src/vs/workbench/contrib/interactive/browser/interactiveCommon.js +8 -0
- package/vscode/src/vs/workbench/contrib/interactive/browser/interactiveEditor.css.js +6 -0
- package/vscode/src/vs/workbench/contrib/interactive/browser/interactiveEditor.js +585 -0
- package/vscode/src/vs/workbench/contrib/interactive/browser/media/interactive.css.js +6 -0
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { RawContextKey } from 'vscode/vscode/vs/platform/contextkey/common/contextkey';
|
|
2
|
+
|
|
3
|
+
const INTERACTIVE_INPUT_CURSOR_BOUNDARY = ( new RawContextKey('interactiveInputCursorAtBoundary', 'none'));
|
|
4
|
+
const InteractiveWindowSetting = {
|
|
5
|
+
interactiveWindowAlwaysScrollOnNewCell: 'interactiveWindow.alwaysScrollOnNewCell'
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
export { INTERACTIVE_INPUT_CURSOR_BOUNDARY, InteractiveWindowSetting };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import n from '../../../../../../../external/rollup-plugin-styles/dist/runtime/inject-css.js';
|
|
2
|
+
|
|
3
|
+
var css = ".interactive-editor .input-cell-container:focus-within .input-editor-container .monaco-editor{outline:solid 1px var(--vscode-notebook-focusedCellBorder)}.interactive-editor .input-cell-container .input-editor-container .monaco-editor{outline:solid 1px var(--vscode-notebook-inactiveFocusedCellBorder)}.interactive-editor .input-cell-container .input-focus-indicator{top:8px}.interactive-editor .input-cell-container .margin-view-overlays,.interactive-editor .input-cell-container .monaco-editor-background{background-color:var(--vscode-notebook-cellEditorBackground,var(--vscode-editor-background))}";
|
|
4
|
+
n(css,{});
|
|
5
|
+
|
|
6
|
+
export { css, css as default };
|
|
@@ -0,0 +1,585 @@
|
|
|
1
|
+
import { __decorate, __param } from '../../../../../../../external/tslib/tslib.es6.js';
|
|
2
|
+
import './media/interactive.css.js';
|
|
3
|
+
import { localizeWithPath } from 'vscode/vscode/vs/nls';
|
|
4
|
+
import { append, $, createStyleSheet, getWindow, Dimension } from 'vscode/vscode/vs/base/browser/dom';
|
|
5
|
+
import { Emitter } from 'vscode/vscode/vs/base/common/event';
|
|
6
|
+
import { DisposableStore } from 'vscode/vscode/vs/base/common/lifecycle';
|
|
7
|
+
import { ICodeEditorService } from 'vscode/vscode/vs/editor/browser/services/codeEditorService';
|
|
8
|
+
import { CodeEditorWidget } from 'vscode/vscode/vs/editor/browser/widget/codeEditorWidget';
|
|
9
|
+
import { IContextKeyService } from 'vscode/vscode/vs/platform/contextkey/common/contextkey';
|
|
10
|
+
import { IInstantiationService } from 'vscode/vscode/vs/platform/instantiation/common/instantiation';
|
|
11
|
+
import { IStorageService } from 'vscode/vscode/vs/platform/storage/common/storage';
|
|
12
|
+
import { ITelemetryService } from 'vscode/vscode/vs/platform/telemetry/common/telemetry';
|
|
13
|
+
import { resolveColorValue, editorForeground } from 'vscode/vscode/vs/platform/theme/common/colorRegistry';
|
|
14
|
+
import { IThemeService } from 'vscode/vscode/vs/platform/theme/common/themeService';
|
|
15
|
+
import { EditorPane } from 'vscode/vscode/vs/workbench/browser/parts/editor/editorPane';
|
|
16
|
+
import { getSimpleEditorOptions } from 'vscode/vscode/vs/workbench/contrib/codeEditor/browser/simpleEditorOptions';
|
|
17
|
+
import { InteractiveEditorInput } from 'vscode/vscode/vs/workbench/contrib/interactive/browser/interactiveEditorInput';
|
|
18
|
+
import { NotebookEditorExtensionsRegistry } from 'vscode/vscode/vs/workbench/contrib/notebook/browser/notebookEditorExtensions';
|
|
19
|
+
import { INotebookEditorService } from 'vscode/vscode/vs/workbench/contrib/notebook/browser/services/notebookEditorService';
|
|
20
|
+
import { IEditorGroupsService } from 'vscode/vscode/vs/workbench/services/editor/common/editorGroupsService';
|
|
21
|
+
import { ExecutionStateCellStatusBarContrib, TimerCellStatusBarContrib } from 'vscode/vscode/vs/workbench/contrib/notebook/browser/contrib/cellStatusBar/executionStatusBarItemController';
|
|
22
|
+
import { INotebookKernelService } from 'vscode/vscode/vs/workbench/contrib/notebook/common/notebookKernelService';
|
|
23
|
+
import { PLAINTEXT_LANGUAGE_ID } from 'vscode/vscode/vs/editor/common/languages/modesRegistry';
|
|
24
|
+
import { ILanguageService } from 'vscode/vscode/vs/editor/common/languages/language';
|
|
25
|
+
import { MenuId, IMenuService } from 'vscode/vscode/vs/platform/actions/common/actions';
|
|
26
|
+
import { IKeybindingService } from 'vscode/vscode/vs/platform/keybinding/common/keybinding';
|
|
27
|
+
import { INTERACTIVE_INPUT_CURSOR_BOUNDARY, InteractiveWindowSetting } from './interactiveCommon.js';
|
|
28
|
+
import { IConfigurationService } from 'vscode/vscode/vs/platform/configuration/common/configuration';
|
|
29
|
+
import { NotebookOptions } from 'vscode/vscode/vs/workbench/contrib/notebook/browser/notebookOptions';
|
|
30
|
+
import { ToolBar } from 'vscode/vscode/vs/base/browser/ui/toolbar/toolbar';
|
|
31
|
+
import { IContextMenuService } from 'vscode/vscode/vs/platform/contextview/browser/contextView';
|
|
32
|
+
import { createActionViewItem, createAndFillInActionBarActions } from 'vscode/vscode/vs/platform/actions/browser/menuEntryActionViewItem';
|
|
33
|
+
import { EditorExtensionsRegistry } from 'vscode/vscode/vs/editor/browser/editorExtensions';
|
|
34
|
+
import { ParameterHintsController } from 'vscode/vscode/vs/editor/contrib/parameterHints/browser/parameterHints';
|
|
35
|
+
import { MenuPreventer } from 'vscode/vscode/vs/workbench/contrib/codeEditor/browser/menuPreventer';
|
|
36
|
+
import { SelectionClipboardContributionID } from 'vscode/vscode/vs/workbench/contrib/codeEditor/browser/selectionClipboard';
|
|
37
|
+
import { ContextMenuController } from 'vscode/vscode/vs/editor/contrib/contextmenu/browser/contextmenu';
|
|
38
|
+
import { SuggestController } from 'vscode/vscode/vs/editor/contrib/suggest/browser/suggestController';
|
|
39
|
+
import { SnippetController2 } from 'vscode/vscode/vs/editor/contrib/snippet/browser/snippetController2';
|
|
40
|
+
import { TabCompletionController } from 'vscode/vscode/vs/workbench/contrib/snippets/browser/tabCompletion';
|
|
41
|
+
import { HoverController } from 'vscode/vscode/vs/editor/contrib/hover/browser/hover';
|
|
42
|
+
import { MarkerController } from 'vscode/vscode/vs/editor/contrib/gotoError/browser/gotoError';
|
|
43
|
+
import { ITextResourceConfigurationService } from 'vscode/vscode/vs/editor/common/services/textResourceConfiguration';
|
|
44
|
+
import { NotebookExecutionType, INotebookExecutionStateService } from 'vscode/vscode/vs/workbench/contrib/notebook/common/notebookExecutionStateService';
|
|
45
|
+
import { NOTEBOOK_KERNEL } from 'vscode/vscode/vs/workbench/contrib/notebook/common/notebookContextKeys';
|
|
46
|
+
import { IExtensionService } from 'vscode/vscode/vs/workbench/services/extensions/common/extensions';
|
|
47
|
+
import { isEqual } from 'vscode/vscode/vs/base/common/resources';
|
|
48
|
+
import { NotebookFindContrib } from 'vscode/vscode/vs/workbench/contrib/notebook/browser/contrib/find/notebookFindWidget';
|
|
49
|
+
import { INTERACTIVE_WINDOW_EDITOR_ID } from 'vscode/vscode/vs/workbench/contrib/notebook/common/notebookCommon';
|
|
50
|
+
import './interactiveEditor.css.js';
|
|
51
|
+
import { deepClone } from 'vscode/vscode/vs/base/common/objects';
|
|
52
|
+
import { mainWindow } from 'vscode/vscode/vs/base/browser/window';
|
|
53
|
+
|
|
54
|
+
const DECORATION_KEY = 'interactiveInputDecoration';
|
|
55
|
+
const INTERACTIVE_EDITOR_VIEW_STATE_PREFERENCE_KEY = 'InteractiveEditorViewState';
|
|
56
|
+
const INPUT_CELL_VERTICAL_PADDING = 8;
|
|
57
|
+
const INPUT_CELL_HORIZONTAL_PADDING_RIGHT = 10;
|
|
58
|
+
const INPUT_EDITOR_PADDING = 8;
|
|
59
|
+
let InteractiveEditor = class InteractiveEditor extends EditorPane {
|
|
60
|
+
get onDidFocus() { return this._onDidFocusWidget.event; }
|
|
61
|
+
constructor(telemetryService, themeService, storageService, instantiationService, notebookWidgetService, contextKeyService, codeEditorService, notebookKernelService, languageService, keybindingService, configurationService, menuService, contextMenuService, editorGroupService, textResourceConfigurationService, notebookExecutionStateService, extensionService) {
|
|
62
|
+
super(INTERACTIVE_WINDOW_EDITOR_ID, telemetryService, themeService, storageService);
|
|
63
|
+
this._notebookWidget = { value: undefined };
|
|
64
|
+
this._widgetDisposableStore = this._register(( new DisposableStore()));
|
|
65
|
+
this._groupListener = this._register(( new DisposableStore()));
|
|
66
|
+
this._onDidFocusWidget = this._register(( new Emitter()));
|
|
67
|
+
this._onDidChangeSelection = this._register(( new Emitter()));
|
|
68
|
+
this.onDidChangeSelection = this._onDidChangeSelection.event;
|
|
69
|
+
this._instantiationService = instantiationService;
|
|
70
|
+
this._notebookWidgetService = notebookWidgetService;
|
|
71
|
+
this._contextKeyService = contextKeyService;
|
|
72
|
+
this._configurationService = configurationService;
|
|
73
|
+
this._notebookKernelService = notebookKernelService;
|
|
74
|
+
this._languageService = languageService;
|
|
75
|
+
this._keybindingService = keybindingService;
|
|
76
|
+
this._menuService = menuService;
|
|
77
|
+
this._contextMenuService = contextMenuService;
|
|
78
|
+
this._editorGroupService = editorGroupService;
|
|
79
|
+
this._notebookExecutionStateService = notebookExecutionStateService;
|
|
80
|
+
this._extensionService = extensionService;
|
|
81
|
+
this._editorOptions = this._computeEditorOptions();
|
|
82
|
+
this._register(this._configurationService.onDidChangeConfiguration(e => {
|
|
83
|
+
if (e.affectsConfiguration('editor') || e.affectsConfiguration('notebook')) {
|
|
84
|
+
this._editorOptions = this._computeEditorOptions();
|
|
85
|
+
}
|
|
86
|
+
}));
|
|
87
|
+
this._notebookOptions = ( new NotebookOptions(
|
|
88
|
+
configurationService,
|
|
89
|
+
notebookExecutionStateService,
|
|
90
|
+
true,
|
|
91
|
+
{ cellToolbarInteraction: 'hover', globalToolbar: true, stickyScrollEnabled: false, dragAndDropEnabled: false }
|
|
92
|
+
));
|
|
93
|
+
this._editorMemento = this.getEditorMemento(editorGroupService, textResourceConfigurationService, INTERACTIVE_EDITOR_VIEW_STATE_PREFERENCE_KEY);
|
|
94
|
+
codeEditorService.registerDecorationType('interactive-decoration', DECORATION_KEY, {});
|
|
95
|
+
this._register(this._keybindingService.onDidUpdateKeybindings(this._updateInputDecoration, this));
|
|
96
|
+
this._register(this._notebookExecutionStateService.onDidChangeExecution((e) => {
|
|
97
|
+
if (e.type === NotebookExecutionType.cell && isEqual(e.notebook, this._notebookWidget.value?.viewModel?.notebookDocument.uri)) {
|
|
98
|
+
const cell = this._notebookWidget.value?.getCellByHandle(e.cellHandle);
|
|
99
|
+
if (cell && e.changed?.state) {
|
|
100
|
+
this._scrollIfNecessary(cell);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}));
|
|
104
|
+
}
|
|
105
|
+
get inputCellContainerHeight() {
|
|
106
|
+
return 19 + 2 + INPUT_CELL_VERTICAL_PADDING * 2 + INPUT_EDITOR_PADDING * 2;
|
|
107
|
+
}
|
|
108
|
+
get inputCellEditorHeight() {
|
|
109
|
+
return 19 + INPUT_EDITOR_PADDING * 2;
|
|
110
|
+
}
|
|
111
|
+
createEditor(parent) {
|
|
112
|
+
this._rootElement = append(parent, $('.interactive-editor'));
|
|
113
|
+
this._rootElement.style.position = 'relative';
|
|
114
|
+
this._notebookEditorContainer = append(this._rootElement, $('.notebook-editor-container'));
|
|
115
|
+
this._inputCellContainer = append(this._rootElement, $('.input-cell-container'));
|
|
116
|
+
this._inputCellContainer.style.position = 'absolute';
|
|
117
|
+
this._inputCellContainer.style.height = `${this.inputCellContainerHeight}px`;
|
|
118
|
+
this._inputFocusIndicator = append(this._inputCellContainer, $('.input-focus-indicator'));
|
|
119
|
+
this._inputRunButtonContainer = append(this._inputCellContainer, $('.run-button-container'));
|
|
120
|
+
this._setupRunButtonToolbar(this._inputRunButtonContainer);
|
|
121
|
+
this._inputEditorContainer = append(this._inputCellContainer, $('.input-editor-container'));
|
|
122
|
+
this._createLayoutStyles();
|
|
123
|
+
}
|
|
124
|
+
_setupRunButtonToolbar(runButtonContainer) {
|
|
125
|
+
const menu = this._register(this._menuService.createMenu(MenuId.InteractiveInputExecute, this._contextKeyService));
|
|
126
|
+
this._runbuttonToolbar = this._register(( new ToolBar(runButtonContainer, this._contextMenuService, {
|
|
127
|
+
getKeyBinding: action => this._keybindingService.lookupKeybinding(action.id),
|
|
128
|
+
actionViewItemProvider: action => {
|
|
129
|
+
return createActionViewItem(this._instantiationService, action);
|
|
130
|
+
},
|
|
131
|
+
renderDropdownAsChildElement: true
|
|
132
|
+
})));
|
|
133
|
+
const primary = [];
|
|
134
|
+
const secondary = [];
|
|
135
|
+
const result = { primary, secondary };
|
|
136
|
+
createAndFillInActionBarActions(menu, { shouldForwardArgs: true }, result);
|
|
137
|
+
this._runbuttonToolbar.setActions([...primary, ...secondary]);
|
|
138
|
+
}
|
|
139
|
+
_createLayoutStyles() {
|
|
140
|
+
this._styleElement = createStyleSheet(this._rootElement);
|
|
141
|
+
const styleSheets = [];
|
|
142
|
+
const { codeCellLeftMargin, cellRunGutter } = this._notebookOptions.getLayoutConfiguration();
|
|
143
|
+
const { focusIndicator } = this._notebookOptions.getDisplayOptions();
|
|
144
|
+
const leftMargin = this._notebookOptions.getCellEditorContainerLeftMargin();
|
|
145
|
+
styleSheets.push(`
|
|
146
|
+
.interactive-editor .input-cell-container {
|
|
147
|
+
padding: ${INPUT_CELL_VERTICAL_PADDING}px ${INPUT_CELL_HORIZONTAL_PADDING_RIGHT}px ${INPUT_CELL_VERTICAL_PADDING}px ${leftMargin}px;
|
|
148
|
+
}
|
|
149
|
+
`);
|
|
150
|
+
if (focusIndicator === 'gutter') {
|
|
151
|
+
styleSheets.push(`
|
|
152
|
+
.interactive-editor .input-cell-container:focus-within .input-focus-indicator::before {
|
|
153
|
+
border-color: var(--vscode-notebook-focusedCellBorder) !important;
|
|
154
|
+
}
|
|
155
|
+
.interactive-editor .input-focus-indicator::before {
|
|
156
|
+
border-color: var(--vscode-notebook-inactiveFocusedCellBorder) !important;
|
|
157
|
+
}
|
|
158
|
+
.interactive-editor .input-cell-container .input-focus-indicator {
|
|
159
|
+
display: block;
|
|
160
|
+
top: ${INPUT_CELL_VERTICAL_PADDING}px;
|
|
161
|
+
}
|
|
162
|
+
.interactive-editor .input-cell-container {
|
|
163
|
+
border-top: 1px solid var(--vscode-notebook-inactiveFocusedCellBorder);
|
|
164
|
+
}
|
|
165
|
+
`);
|
|
166
|
+
}
|
|
167
|
+
else {
|
|
168
|
+
styleSheets.push(`
|
|
169
|
+
.interactive-editor .input-cell-container {
|
|
170
|
+
border-top: 1px solid var(--vscode-notebook-inactiveFocusedCellBorder);
|
|
171
|
+
}
|
|
172
|
+
.interactive-editor .input-cell-container .input-focus-indicator {
|
|
173
|
+
display: none;
|
|
174
|
+
}
|
|
175
|
+
`);
|
|
176
|
+
}
|
|
177
|
+
styleSheets.push(`
|
|
178
|
+
.interactive-editor .input-cell-container .run-button-container {
|
|
179
|
+
width: ${cellRunGutter}px;
|
|
180
|
+
left: ${codeCellLeftMargin}px;
|
|
181
|
+
margin-top: ${INPUT_EDITOR_PADDING - 2}px;
|
|
182
|
+
}
|
|
183
|
+
`);
|
|
184
|
+
this._styleElement.textContent = styleSheets.join('\n');
|
|
185
|
+
}
|
|
186
|
+
_computeEditorOptions() {
|
|
187
|
+
let overrideIdentifier = undefined;
|
|
188
|
+
if (this._codeEditorWidget) {
|
|
189
|
+
overrideIdentifier = this._codeEditorWidget.getModel()?.getLanguageId();
|
|
190
|
+
}
|
|
191
|
+
const editorOptions = deepClone(this._configurationService.getValue('editor', { overrideIdentifier }));
|
|
192
|
+
const editorOptionsOverride = getSimpleEditorOptions(this._configurationService);
|
|
193
|
+
const computed = ( Object.freeze({
|
|
194
|
+
...editorOptions,
|
|
195
|
+
...editorOptionsOverride,
|
|
196
|
+
...{
|
|
197
|
+
glyphMargin: true,
|
|
198
|
+
padding: {
|
|
199
|
+
top: INPUT_EDITOR_PADDING,
|
|
200
|
+
bottom: INPUT_EDITOR_PADDING
|
|
201
|
+
},
|
|
202
|
+
hover: {
|
|
203
|
+
enabled: true
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
}));
|
|
207
|
+
return computed;
|
|
208
|
+
}
|
|
209
|
+
saveState() {
|
|
210
|
+
this._saveEditorViewState(this.input);
|
|
211
|
+
super.saveState();
|
|
212
|
+
}
|
|
213
|
+
getViewState() {
|
|
214
|
+
const input = this.input;
|
|
215
|
+
if (!(input instanceof InteractiveEditorInput)) {
|
|
216
|
+
return undefined;
|
|
217
|
+
}
|
|
218
|
+
this._saveEditorViewState(input);
|
|
219
|
+
return this._loadNotebookEditorViewState(input);
|
|
220
|
+
}
|
|
221
|
+
_saveEditorViewState(input) {
|
|
222
|
+
if (this.group && this._notebookWidget.value && input instanceof InteractiveEditorInput) {
|
|
223
|
+
if (this._notebookWidget.value.isDisposed) {
|
|
224
|
+
return;
|
|
225
|
+
}
|
|
226
|
+
const state = this._notebookWidget.value.getEditorViewState();
|
|
227
|
+
const editorState = this._codeEditorWidget.saveViewState();
|
|
228
|
+
this._editorMemento.saveEditorState(this.group, input.notebookEditorInput.resource, {
|
|
229
|
+
notebook: state,
|
|
230
|
+
input: editorState
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
_loadNotebookEditorViewState(input) {
|
|
235
|
+
let result;
|
|
236
|
+
if (this.group) {
|
|
237
|
+
result = this._editorMemento.loadEditorState(this.group, input.notebookEditorInput.resource);
|
|
238
|
+
}
|
|
239
|
+
if (result) {
|
|
240
|
+
return result;
|
|
241
|
+
}
|
|
242
|
+
for (const group of this._editorGroupService.getGroups(1 )) {
|
|
243
|
+
if (group.activeEditorPane !== this && group.activeEditorPane === this && group.activeEditor?.matches(input)) {
|
|
244
|
+
const notebook = this._notebookWidget.value?.getEditorViewState();
|
|
245
|
+
const input = this._codeEditorWidget.saveViewState();
|
|
246
|
+
return {
|
|
247
|
+
notebook,
|
|
248
|
+
input
|
|
249
|
+
};
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
return;
|
|
253
|
+
}
|
|
254
|
+
async setInput(input, options, context, token) {
|
|
255
|
+
const group = this.group;
|
|
256
|
+
const notebookInput = input.notebookEditorInput;
|
|
257
|
+
this._notebookWidget.value?.onWillHide();
|
|
258
|
+
this._codeEditorWidget?.dispose();
|
|
259
|
+
this._widgetDisposableStore.clear();
|
|
260
|
+
this._notebookWidget = this._instantiationService.invokeFunction(this._notebookWidgetService.retrieveWidget, group, notebookInput, {
|
|
261
|
+
isEmbedded: true,
|
|
262
|
+
isReadOnly: true,
|
|
263
|
+
contributions: NotebookEditorExtensionsRegistry.getSomeEditorContributions([
|
|
264
|
+
ExecutionStateCellStatusBarContrib.id,
|
|
265
|
+
TimerCellStatusBarContrib.id,
|
|
266
|
+
NotebookFindContrib.id
|
|
267
|
+
]),
|
|
268
|
+
menuIds: {
|
|
269
|
+
notebookToolbar: MenuId.InteractiveToolbar,
|
|
270
|
+
cellTitleToolbar: MenuId.InteractiveCellTitle,
|
|
271
|
+
cellDeleteToolbar: MenuId.InteractiveCellDelete,
|
|
272
|
+
cellInsertToolbar: MenuId.NotebookCellBetween,
|
|
273
|
+
cellTopInsertToolbar: MenuId.NotebookCellListTop,
|
|
274
|
+
cellExecuteToolbar: MenuId.InteractiveCellExecute,
|
|
275
|
+
cellExecutePrimary: undefined
|
|
276
|
+
},
|
|
277
|
+
cellEditorContributions: EditorExtensionsRegistry.getSomeEditorContributions([
|
|
278
|
+
SelectionClipboardContributionID,
|
|
279
|
+
ContextMenuController.ID,
|
|
280
|
+
HoverController.ID,
|
|
281
|
+
MarkerController.ID
|
|
282
|
+
]),
|
|
283
|
+
options: this._notebookOptions
|
|
284
|
+
}, undefined, this._rootElement ? getWindow(this._rootElement) : mainWindow);
|
|
285
|
+
this._codeEditorWidget = this._instantiationService.createInstance(CodeEditorWidget, this._inputEditorContainer, this._editorOptions, {
|
|
286
|
+
...{
|
|
287
|
+
isSimpleWidget: false,
|
|
288
|
+
contributions: EditorExtensionsRegistry.getSomeEditorContributions([
|
|
289
|
+
MenuPreventer.ID,
|
|
290
|
+
SelectionClipboardContributionID,
|
|
291
|
+
ContextMenuController.ID,
|
|
292
|
+
SuggestController.ID,
|
|
293
|
+
ParameterHintsController.ID,
|
|
294
|
+
SnippetController2.ID,
|
|
295
|
+
TabCompletionController.ID,
|
|
296
|
+
HoverController.ID,
|
|
297
|
+
MarkerController.ID
|
|
298
|
+
])
|
|
299
|
+
}
|
|
300
|
+
});
|
|
301
|
+
if (this._lastLayoutDimensions) {
|
|
302
|
+
this._notebookEditorContainer.style.height = `${this._lastLayoutDimensions.dimension.height - this.inputCellContainerHeight}px`;
|
|
303
|
+
this._notebookWidget.value.layout(new Dimension(this._lastLayoutDimensions.dimension.width, this._lastLayoutDimensions.dimension.height - this.inputCellContainerHeight), this._notebookEditorContainer);
|
|
304
|
+
const leftMargin = this._notebookOptions.getCellEditorContainerLeftMargin();
|
|
305
|
+
const maxHeight = Math.min(this._lastLayoutDimensions.dimension.height / 2, this.inputCellEditorHeight);
|
|
306
|
+
this._codeEditorWidget.layout(this._validateDimension(this._lastLayoutDimensions.dimension.width - leftMargin - INPUT_CELL_HORIZONTAL_PADDING_RIGHT, maxHeight));
|
|
307
|
+
this._inputFocusIndicator.style.height = `${this.inputCellEditorHeight}px`;
|
|
308
|
+
this._inputCellContainer.style.top = `${this._lastLayoutDimensions.dimension.height - this.inputCellContainerHeight}px`;
|
|
309
|
+
this._inputCellContainer.style.width = `${this._lastLayoutDimensions.dimension.width}px`;
|
|
310
|
+
}
|
|
311
|
+
await super.setInput(input, options, context, token);
|
|
312
|
+
const model = await input.resolve();
|
|
313
|
+
if (this._runbuttonToolbar) {
|
|
314
|
+
this._runbuttonToolbar.context = input.resource;
|
|
315
|
+
}
|
|
316
|
+
if (model === null) {
|
|
317
|
+
throw new Error('The Interactive Window model could not be resolved');
|
|
318
|
+
}
|
|
319
|
+
this._notebookWidget.value?.setParentContextKeyService(this._contextKeyService);
|
|
320
|
+
const viewState = options?.viewState ?? this._loadNotebookEditorViewState(input);
|
|
321
|
+
await this._extensionService.whenInstalledExtensionsRegistered();
|
|
322
|
+
await this._notebookWidget.value.setModel(model.notebook, viewState?.notebook);
|
|
323
|
+
model.notebook.setCellCollapseDefault(this._notebookOptions.getCellCollapseDefault());
|
|
324
|
+
this._notebookWidget.value.setOptions({
|
|
325
|
+
isReadOnly: true
|
|
326
|
+
});
|
|
327
|
+
this._widgetDisposableStore.add(this._notebookWidget.value.onDidResizeOutput((cvm) => {
|
|
328
|
+
this._scrollIfNecessary(cvm);
|
|
329
|
+
}));
|
|
330
|
+
this._widgetDisposableStore.add(this._notebookWidget.value.onDidFocusWidget(() => this._onDidFocusWidget.fire()));
|
|
331
|
+
this._widgetDisposableStore.add(this._notebookOptions.onDidChangeOptions(e => {
|
|
332
|
+
if (e.compactView || e.focusIndicator) {
|
|
333
|
+
this._styleElement?.remove();
|
|
334
|
+
this._createLayoutStyles();
|
|
335
|
+
}
|
|
336
|
+
if (this._lastLayoutDimensions && this.isVisible()) {
|
|
337
|
+
this.layout(this._lastLayoutDimensions.dimension, this._lastLayoutDimensions.position);
|
|
338
|
+
}
|
|
339
|
+
if (e.interactiveWindowCollapseCodeCells) {
|
|
340
|
+
model.notebook.setCellCollapseDefault(this._notebookOptions.getCellCollapseDefault());
|
|
341
|
+
}
|
|
342
|
+
}));
|
|
343
|
+
const languageId = this._notebookWidget.value?.activeKernel?.supportedLanguages[0] ?? input.language ?? PLAINTEXT_LANGUAGE_ID;
|
|
344
|
+
const editorModel = await input.resolveInput(languageId);
|
|
345
|
+
editorModel.setLanguage(languageId);
|
|
346
|
+
this._codeEditorWidget.setModel(editorModel);
|
|
347
|
+
if (viewState?.input) {
|
|
348
|
+
this._codeEditorWidget.restoreViewState(viewState.input);
|
|
349
|
+
}
|
|
350
|
+
this._editorOptions = this._computeEditorOptions();
|
|
351
|
+
this._codeEditorWidget.updateOptions(this._editorOptions);
|
|
352
|
+
this._widgetDisposableStore.add(this._codeEditorWidget.onDidFocusEditorWidget(() => this._onDidFocusWidget.fire()));
|
|
353
|
+
this._widgetDisposableStore.add(this._codeEditorWidget.onDidContentSizeChange(e => {
|
|
354
|
+
if (!e.contentHeightChanged) {
|
|
355
|
+
return;
|
|
356
|
+
}
|
|
357
|
+
if (this._lastLayoutDimensions) {
|
|
358
|
+
this._layoutWidgets(this._lastLayoutDimensions.dimension, this._lastLayoutDimensions.position);
|
|
359
|
+
}
|
|
360
|
+
}));
|
|
361
|
+
this._widgetDisposableStore.add(this._codeEditorWidget.onDidChangeCursorPosition(e => this._onDidChangeSelection.fire({ reason: this._toEditorPaneSelectionChangeReason(e) })));
|
|
362
|
+
this._widgetDisposableStore.add(this._codeEditorWidget.onDidChangeModelContent(() => this._onDidChangeSelection.fire({ reason: 3 })));
|
|
363
|
+
this._widgetDisposableStore.add(this._notebookKernelService.onDidChangeNotebookAffinity(this._syncWithKernel, this));
|
|
364
|
+
this._widgetDisposableStore.add(this._notebookKernelService.onDidChangeSelectedNotebooks(this._syncWithKernel, this));
|
|
365
|
+
this._widgetDisposableStore.add(this.themeService.onDidColorThemeChange(() => {
|
|
366
|
+
if (this.isVisible()) {
|
|
367
|
+
this._updateInputDecoration();
|
|
368
|
+
}
|
|
369
|
+
}));
|
|
370
|
+
this._widgetDisposableStore.add(this._codeEditorWidget.onDidChangeModelContent(() => {
|
|
371
|
+
if (this.isVisible()) {
|
|
372
|
+
this._updateInputDecoration();
|
|
373
|
+
}
|
|
374
|
+
}));
|
|
375
|
+
const cursorAtBoundaryContext = INTERACTIVE_INPUT_CURSOR_BOUNDARY.bindTo(this._contextKeyService);
|
|
376
|
+
if (input.resource && ( input.historyService.has(input.resource))) {
|
|
377
|
+
cursorAtBoundaryContext.set('top');
|
|
378
|
+
}
|
|
379
|
+
else {
|
|
380
|
+
cursorAtBoundaryContext.set('none');
|
|
381
|
+
}
|
|
382
|
+
this._widgetDisposableStore.add(this._codeEditorWidget.onDidChangeCursorPosition(({ position }) => {
|
|
383
|
+
const viewModel = this._codeEditorWidget._getViewModel();
|
|
384
|
+
const lastLineNumber = viewModel.getLineCount();
|
|
385
|
+
const lastLineCol = viewModel.getLineLength(lastLineNumber) + 1;
|
|
386
|
+
const viewPosition = viewModel.coordinatesConverter.convertModelPositionToViewPosition(position);
|
|
387
|
+
const firstLine = viewPosition.lineNumber === 1 && viewPosition.column === 1;
|
|
388
|
+
const lastLine = viewPosition.lineNumber === lastLineNumber && viewPosition.column === lastLineCol;
|
|
389
|
+
if (firstLine) {
|
|
390
|
+
if (lastLine) {
|
|
391
|
+
cursorAtBoundaryContext.set('both');
|
|
392
|
+
}
|
|
393
|
+
else {
|
|
394
|
+
cursorAtBoundaryContext.set('top');
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
else {
|
|
398
|
+
if (lastLine) {
|
|
399
|
+
cursorAtBoundaryContext.set('bottom');
|
|
400
|
+
}
|
|
401
|
+
else {
|
|
402
|
+
cursorAtBoundaryContext.set('none');
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
}));
|
|
406
|
+
this._widgetDisposableStore.add(editorModel.onDidChangeContent(() => {
|
|
407
|
+
const value = editorModel.getValue();
|
|
408
|
+
if (this.input?.resource && value !== '') {
|
|
409
|
+
this.input.historyService.replaceLast(this.input.resource, value);
|
|
410
|
+
}
|
|
411
|
+
}));
|
|
412
|
+
this._syncWithKernel();
|
|
413
|
+
}
|
|
414
|
+
setOptions(options) {
|
|
415
|
+
this._notebookWidget.value?.setOptions(options);
|
|
416
|
+
super.setOptions(options);
|
|
417
|
+
}
|
|
418
|
+
_toEditorPaneSelectionChangeReason(e) {
|
|
419
|
+
switch (e.source) {
|
|
420
|
+
case "api" : return 1 ;
|
|
421
|
+
case "code.navigation" : return 4 ;
|
|
422
|
+
case "code.jump" : return 5 ;
|
|
423
|
+
default: return 2 ;
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
_cellAtBottom(cell) {
|
|
427
|
+
const visibleRanges = this._notebookWidget.value?.visibleRanges || [];
|
|
428
|
+
const cellIndex = this._notebookWidget.value?.getCellIndex(cell);
|
|
429
|
+
if (cellIndex === Math.max(...( visibleRanges.map(range => range.end - 1)))) {
|
|
430
|
+
return true;
|
|
431
|
+
}
|
|
432
|
+
return false;
|
|
433
|
+
}
|
|
434
|
+
_scrollIfNecessary(cvm) {
|
|
435
|
+
const index = this._notebookWidget.value.getCellIndex(cvm);
|
|
436
|
+
if (index === this._notebookWidget.value.getLength() - 1) {
|
|
437
|
+
if (this._configurationService.getValue(InteractiveWindowSetting.interactiveWindowAlwaysScrollOnNewCell) || this._cellAtBottom(cvm)) {
|
|
438
|
+
this._notebookWidget.value.scrollToBottom();
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
_syncWithKernel() {
|
|
443
|
+
const notebook = this._notebookWidget.value?.textModel;
|
|
444
|
+
const textModel = this._codeEditorWidget.getModel();
|
|
445
|
+
if (notebook && textModel) {
|
|
446
|
+
const info = this._notebookKernelService.getMatchingKernel(notebook);
|
|
447
|
+
const selectedOrSuggested = info.selected
|
|
448
|
+
?? (info.suggestions.length === 1 ? info.suggestions[0] : undefined)
|
|
449
|
+
?? (info.all.length === 1 ? info.all[0] : undefined);
|
|
450
|
+
if (selectedOrSuggested) {
|
|
451
|
+
const language = selectedOrSuggested.supportedLanguages[0];
|
|
452
|
+
if (language && language !== 'plaintext') {
|
|
453
|
+
const newMode = this._languageService.createById(language).languageId;
|
|
454
|
+
textModel.setLanguage(newMode);
|
|
455
|
+
}
|
|
456
|
+
NOTEBOOK_KERNEL.bindTo(this._contextKeyService).set(selectedOrSuggested.id);
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
this._updateInputDecoration();
|
|
460
|
+
}
|
|
461
|
+
layout(dimension, position) {
|
|
462
|
+
this._rootElement.classList.toggle('mid-width', dimension.width < 1000 && dimension.width >= 600);
|
|
463
|
+
this._rootElement.classList.toggle('narrow-width', dimension.width < 600);
|
|
464
|
+
const editorHeightChanged = dimension.height !== this._lastLayoutDimensions?.dimension.height;
|
|
465
|
+
this._lastLayoutDimensions = { dimension, position };
|
|
466
|
+
if (!this._notebookWidget.value) {
|
|
467
|
+
return;
|
|
468
|
+
}
|
|
469
|
+
if (editorHeightChanged && this._codeEditorWidget) {
|
|
470
|
+
SuggestController.get(this._codeEditorWidget)?.cancelSuggestWidget();
|
|
471
|
+
}
|
|
472
|
+
this._notebookEditorContainer.style.height = `${this._lastLayoutDimensions.dimension.height - this.inputCellContainerHeight}px`;
|
|
473
|
+
this._layoutWidgets(dimension, position);
|
|
474
|
+
}
|
|
475
|
+
_layoutWidgets(dimension, position) {
|
|
476
|
+
const contentHeight = this._codeEditorWidget.hasModel() ? this._codeEditorWidget.getContentHeight() : this.inputCellEditorHeight;
|
|
477
|
+
const maxHeight = Math.min(dimension.height / 2, contentHeight);
|
|
478
|
+
const leftMargin = this._notebookOptions.getCellEditorContainerLeftMargin();
|
|
479
|
+
const inputCellContainerHeight = maxHeight + INPUT_CELL_VERTICAL_PADDING * 2;
|
|
480
|
+
this._notebookEditorContainer.style.height = `${dimension.height - inputCellContainerHeight}px`;
|
|
481
|
+
this._notebookWidget.value.layout(dimension.with(dimension.width, dimension.height - inputCellContainerHeight), this._notebookEditorContainer, position);
|
|
482
|
+
this._codeEditorWidget.layout(this._validateDimension(dimension.width - leftMargin - INPUT_CELL_HORIZONTAL_PADDING_RIGHT, maxHeight));
|
|
483
|
+
this._inputFocusIndicator.style.height = `${contentHeight}px`;
|
|
484
|
+
this._inputCellContainer.style.top = `${dimension.height - inputCellContainerHeight}px`;
|
|
485
|
+
this._inputCellContainer.style.width = `${dimension.width}px`;
|
|
486
|
+
}
|
|
487
|
+
_validateDimension(width, height) {
|
|
488
|
+
return new Dimension(Math.max(0, width), Math.max(0, height));
|
|
489
|
+
}
|
|
490
|
+
_updateInputDecoration() {
|
|
491
|
+
if (!this._codeEditorWidget) {
|
|
492
|
+
return;
|
|
493
|
+
}
|
|
494
|
+
if (!this._codeEditorWidget.hasModel()) {
|
|
495
|
+
return;
|
|
496
|
+
}
|
|
497
|
+
const model = this._codeEditorWidget.getModel();
|
|
498
|
+
const decorations = [];
|
|
499
|
+
if (model?.getValueLength() === 0) {
|
|
500
|
+
const transparentForeground = resolveColorValue(editorForeground, this.themeService.getColorTheme())?.transparent(0.4);
|
|
501
|
+
const languageId = model.getLanguageId();
|
|
502
|
+
const keybinding = this._keybindingService.lookupKeybinding('interactive.execute', this._contextKeyService)?.getLabel();
|
|
503
|
+
const text = ( localizeWithPath(
|
|
504
|
+
'vs/workbench/contrib/interactive/browser/interactiveEditor',
|
|
505
|
+
'interactiveInputPlaceHolder',
|
|
506
|
+
"Type '{0}' code here and press {1} to run",
|
|
507
|
+
languageId,
|
|
508
|
+
keybinding ?? 'ctrl+enter'
|
|
509
|
+
));
|
|
510
|
+
decorations.push({
|
|
511
|
+
range: {
|
|
512
|
+
startLineNumber: 0,
|
|
513
|
+
endLineNumber: 0,
|
|
514
|
+
startColumn: 0,
|
|
515
|
+
endColumn: 1
|
|
516
|
+
},
|
|
517
|
+
renderOptions: {
|
|
518
|
+
after: {
|
|
519
|
+
contentText: text,
|
|
520
|
+
color: transparentForeground ? ( transparentForeground.toString()) : undefined
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
});
|
|
524
|
+
}
|
|
525
|
+
this._codeEditorWidget.setDecorationsByType('interactive-decoration', DECORATION_KEY, decorations);
|
|
526
|
+
}
|
|
527
|
+
focus() {
|
|
528
|
+
super.focus();
|
|
529
|
+
this._notebookWidget.value?.onShow();
|
|
530
|
+
this._codeEditorWidget.focus();
|
|
531
|
+
}
|
|
532
|
+
focusHistory() {
|
|
533
|
+
this._notebookWidget.value.focus();
|
|
534
|
+
}
|
|
535
|
+
setEditorVisible(visible, group) {
|
|
536
|
+
super.setEditorVisible(visible, group);
|
|
537
|
+
if (group) {
|
|
538
|
+
this._groupListener.clear();
|
|
539
|
+
this._groupListener.add(group.onWillCloseEditor(e => this._saveEditorViewState(e.editor)));
|
|
540
|
+
}
|
|
541
|
+
if (!visible) {
|
|
542
|
+
this._saveEditorViewState(this.input);
|
|
543
|
+
if (this.input && this._notebookWidget.value) {
|
|
544
|
+
this._notebookWidget.value.onWillHide();
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
clearInput() {
|
|
549
|
+
if (this._notebookWidget.value) {
|
|
550
|
+
this._saveEditorViewState(this.input);
|
|
551
|
+
this._notebookWidget.value.onWillHide();
|
|
552
|
+
}
|
|
553
|
+
this._codeEditorWidget?.dispose();
|
|
554
|
+
this._notebookWidget = { value: undefined };
|
|
555
|
+
this._widgetDisposableStore.clear();
|
|
556
|
+
super.clearInput();
|
|
557
|
+
}
|
|
558
|
+
getControl() {
|
|
559
|
+
return {
|
|
560
|
+
notebookEditor: this._notebookWidget.value,
|
|
561
|
+
codeEditor: this._codeEditorWidget
|
|
562
|
+
};
|
|
563
|
+
}
|
|
564
|
+
};
|
|
565
|
+
InteractiveEditor = ( __decorate([
|
|
566
|
+
( __param(0, ITelemetryService)),
|
|
567
|
+
( __param(1, IThemeService)),
|
|
568
|
+
( __param(2, IStorageService)),
|
|
569
|
+
( __param(3, IInstantiationService)),
|
|
570
|
+
( __param(4, INotebookEditorService)),
|
|
571
|
+
( __param(5, IContextKeyService)),
|
|
572
|
+
( __param(6, ICodeEditorService)),
|
|
573
|
+
( __param(7, INotebookKernelService)),
|
|
574
|
+
( __param(8, ILanguageService)),
|
|
575
|
+
( __param(9, IKeybindingService)),
|
|
576
|
+
( __param(10, IConfigurationService)),
|
|
577
|
+
( __param(11, IMenuService)),
|
|
578
|
+
( __param(12, IContextMenuService)),
|
|
579
|
+
( __param(13, IEditorGroupsService)),
|
|
580
|
+
( __param(14, ITextResourceConfigurationService)),
|
|
581
|
+
( __param(15, INotebookExecutionStateService)),
|
|
582
|
+
( __param(16, IExtensionService))
|
|
583
|
+
], InteractiveEditor));
|
|
584
|
+
|
|
585
|
+
export { InteractiveEditor };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import n from '../../../../../../../../external/rollup-plugin-styles/dist/runtime/inject-css.js';
|
|
2
|
+
|
|
3
|
+
var css = ".interactive-editor .input-cell-container{box-sizing:border-box}.interactive-editor .input-cell-container .input-focus-indicator{height:19px;left:0;position:absolute}.interactive-editor .input-cell-container .input-focus-indicator:before{border-left:3px solid transparent;border-radius:2px;content:\"\";height:100%;left:0;margin-left:4px;position:absolute;top:0;width:0;z-index:10}.interactive-editor .input-cell-container .run-button-container{position:absolute}.interactive-editor .input-cell-container .run-button-container .monaco-toolbar .actions-container{justify-content:center}";
|
|
4
|
+
n(css,{});
|
|
5
|
+
|
|
6
|
+
export { css, css as default };
|