@theia/monaco 1.53.0-next.5 → 1.53.0-next.55

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.
Files changed (96) hide show
  1. package/README.md +100 -100
  2. package/data/monaco-nls.json +1379 -1379
  3. package/data/monaco-themes/vscode/dark_plus.json +201 -201
  4. package/data/monaco-themes/vscode/dark_theia.json +5 -5
  5. package/data/monaco-themes/vscode/dark_vs.json +393 -393
  6. package/data/monaco-themes/vscode/hc_black.json +457 -457
  7. package/data/monaco-themes/vscode/hc_light.json +590 -590
  8. package/data/monaco-themes/vscode/hc_theia.json +5 -5
  9. package/data/monaco-themes/vscode/hc_theia_light.json +5 -5
  10. package/data/monaco-themes/vscode/light_plus.json +202 -202
  11. package/data/monaco-themes/vscode/light_theia.json +10 -10
  12. package/data/monaco-themes/vscode/light_vs.json +421 -421
  13. package/lib/browser/monaco-context-key-service.js +1 -1
  14. package/lib/browser/monaco-context-key-service.js.map +1 -1
  15. package/lib/browser/monaco-editor-model.d.ts +11 -5
  16. package/lib/browser/monaco-editor-model.d.ts.map +1 -1
  17. package/lib/browser/monaco-editor-model.js +2 -1
  18. package/lib/browser/monaco-editor-model.js.map +1 -1
  19. package/lib/browser/monaco-editor-service.js +1 -1
  20. package/lib/browser/monaco-editor-service.js.map +1 -1
  21. package/lib/browser/monaco-editor-zone-widget.js +1 -1
  22. package/lib/browser/monaco-editor.d.ts +5 -4
  23. package/lib/browser/monaco-editor.d.ts.map +1 -1
  24. package/lib/browser/monaco-editor.js +5 -2
  25. package/lib/browser/monaco-editor.js.map +1 -1
  26. package/lib/browser/monaco-frontend-application-contribution.js +25 -25
  27. package/lib/browser/monaco-quick-input-service.d.ts.map +1 -1
  28. package/lib/browser/monaco-quick-input-service.js +15 -15
  29. package/lib/browser/monaco-quick-input-service.js.map +1 -1
  30. package/lib/browser/monaco-text-model-service.d.ts +0 -10
  31. package/lib/browser/monaco-text-model-service.d.ts.map +1 -1
  32. package/lib/browser/monaco-text-model-service.js +0 -36
  33. package/lib/browser/monaco-text-model-service.js.map +1 -1
  34. package/lib/browser/monaco-to-protocol-converter.d.ts +2 -0
  35. package/lib/browser/monaco-to-protocol-converter.d.ts.map +1 -1
  36. package/lib/browser/monaco-to-protocol-converter.js +10 -0
  37. package/lib/browser/monaco-to-protocol-converter.js.map +1 -1
  38. package/package.json +9 -9
  39. package/src/browser/index.ts +17 -17
  40. package/src/browser/markdown-renderer/monaco-markdown-renderer.ts +109 -109
  41. package/src/browser/monaco-bulk-edit-service.ts +64 -64
  42. package/src/browser/monaco-color-registry.ts +73 -73
  43. package/src/browser/monaco-command-registry.ts +85 -85
  44. package/src/browser/monaco-command-service.ts +90 -90
  45. package/src/browser/monaco-command.ts +303 -303
  46. package/src/browser/monaco-context-key-service.ts +144 -144
  47. package/src/browser/monaco-context-menu.ts +112 -112
  48. package/src/browser/monaco-diff-editor.ts +141 -141
  49. package/src/browser/monaco-diff-navigator-factory.ts +39 -39
  50. package/src/browser/monaco-editor-model.ts +693 -685
  51. package/src/browser/monaco-editor-peek-view-widget.ts +233 -233
  52. package/src/browser/monaco-editor-provider.ts +455 -455
  53. package/src/browser/monaco-editor-service.ts +152 -152
  54. package/src/browser/monaco-editor-zone-widget.ts +250 -250
  55. package/src/browser/monaco-editor.ts +733 -729
  56. package/src/browser/monaco-formatting-conflicts.ts +116 -116
  57. package/src/browser/monaco-frontend-application-contribution.ts +182 -182
  58. package/src/browser/monaco-frontend-module.ts +319 -319
  59. package/src/browser/monaco-gotoline-quick-access.ts +47 -47
  60. package/src/browser/monaco-gotosymbol-quick-access.ts +53 -53
  61. package/src/browser/monaco-icon-registry.ts +49 -49
  62. package/src/browser/monaco-indexed-db.ts +130 -130
  63. package/src/browser/monaco-init.ts +134 -134
  64. package/src/browser/monaco-keybinding.ts +111 -111
  65. package/src/browser/monaco-keycode-map.ts +171 -171
  66. package/src/browser/monaco-languages.ts +177 -177
  67. package/src/browser/monaco-marker-collection.ts +83 -83
  68. package/src/browser/monaco-menu.ts +147 -147
  69. package/src/browser/monaco-mime-service.ts +71 -71
  70. package/src/browser/monaco-outline-contribution.ts +404 -404
  71. package/src/browser/monaco-outline-decorator.ts +66 -66
  72. package/src/browser/monaco-quick-access-registry.ts +112 -112
  73. package/src/browser/monaco-quick-input-service.ts +701 -702
  74. package/src/browser/monaco-resolved-keybinding.ts +162 -162
  75. package/src/browser/monaco-snippet-suggest-provider.ts +306 -306
  76. package/src/browser/monaco-standalone-theme-service.ts +51 -51
  77. package/src/browser/monaco-status-bar-contribution.ts +110 -110
  78. package/src/browser/monaco-text-model-service.ts +157 -199
  79. package/src/browser/monaco-theming-service.ts +204 -204
  80. package/src/browser/monaco-to-protocol-converter.ts +82 -71
  81. package/src/browser/monaco-undo-redo-handler.ts +64 -64
  82. package/src/browser/monaco-workspace.ts +416 -416
  83. package/src/browser/protocol-to-monaco-converter.ts +158 -158
  84. package/src/browser/simple-monaco-editor.ts +216 -216
  85. package/src/browser/style/index.css +266 -266
  86. package/src/browser/textmate/index.ts +20 -20
  87. package/src/browser/textmate/monaco-textmate-frontend-bindings.ts +90 -90
  88. package/src/browser/textmate/monaco-textmate-service.ts +187 -187
  89. package/src/browser/textmate/monaco-theme-registry.ts +176 -176
  90. package/src/browser/textmate/monaco-theme-types.ts +37 -37
  91. package/src/browser/textmate/textmate-contribution.ts +29 -29
  92. package/src/browser/textmate/textmate-registry.ts +129 -129
  93. package/src/browser/textmate/textmate-snippet-completion-provider.ts +73 -73
  94. package/src/browser/textmate/textmate-tokenizer.ts +84 -84
  95. package/src/browser/workspace-symbol-command.ts +196 -196
  96. package/src/package.spec.ts +28 -28
@@ -1,455 +1,455 @@
1
- // *****************************************************************************
2
- // Copyright (C) 2018 TypeFox and others.
3
- //
4
- // This program and the accompanying materials are made available under the
5
- // terms of the Eclipse Public License v. 2.0 which is available at
6
- // http://www.eclipse.org/legal/epl-2.0.
7
- //
8
- // This Source Code may also be made available under the following Secondary
9
- // Licenses when the conditions for such availability set forth in the Eclipse
10
- // Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
- // with the GNU Classpath Exception which is available at
12
- // https://www.gnu.org/software/classpath/license.html.
13
- //
14
- // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
15
- // *****************************************************************************
16
-
17
- /* eslint-disable @typescript-eslint/no-explicit-any */
18
- import URI from '@theia/core/lib/common/uri';
19
- import { EditorPreferenceChange, EditorPreferences, TextEditor, DiffNavigator } from '@theia/editor/lib/browser';
20
- import { DiffUris } from '@theia/core/lib/browser/diff-uris';
21
- import { inject, injectable, named } from '@theia/core/shared/inversify';
22
- import { DisposableCollection, deepClone, Disposable } from '@theia/core/lib/common';
23
- import { TextDocumentSaveReason } from '@theia/core/shared/vscode-languageserver-protocol';
24
- import { MonacoDiffEditor } from './monaco-diff-editor';
25
- import { MonacoDiffNavigatorFactory } from './monaco-diff-navigator-factory';
26
- import { EditorServiceOverrides, MonacoEditor, MonacoEditorServices } from './monaco-editor';
27
- import { MonacoEditorModel, WillSaveMonacoModelEvent } from './monaco-editor-model';
28
- import { MonacoWorkspace } from './monaco-workspace';
29
- import { ContributionProvider } from '@theia/core';
30
- import { KeybindingRegistry, OpenerService, open, WidgetOpenerOptions, FormatType } from '@theia/core/lib/browser';
31
- import { MonacoResolvedKeybinding } from './monaco-resolved-keybinding';
32
- import { HttpOpenHandlerOptions } from '@theia/core/lib/browser/http-open-handler';
33
- import { MonacoToProtocolConverter } from './monaco-to-protocol-converter';
34
- import { ProtocolToMonacoConverter } from './protocol-to-monaco-converter';
35
- import { FileSystemPreferences } from '@theia/filesystem/lib/browser';
36
- import * as monaco from '@theia/monaco-editor-core';
37
- import { StandaloneServices } from '@theia/monaco-editor-core/esm/vs/editor/standalone/browser/standaloneServices';
38
- import { IOpenerService, OpenExternalOptions, OpenInternalOptions } from '@theia/monaco-editor-core/esm/vs/platform/opener/common/opener';
39
- import { IKeybindingService } from '@theia/monaco-editor-core/esm/vs/platform/keybinding/common/keybinding';
40
- import { timeoutReject } from '@theia/core/lib/common/promise-util';
41
- import { IContextMenuService } from '@theia/monaco-editor-core/esm/vs/platform/contextview/browser/contextView';
42
- import { KeyCodeChord } from '@theia/monaco-editor-core/esm/vs/base/common/keybindings';
43
- import { IContextKeyService } from '@theia/monaco-editor-core/esm/vs/platform/contextkey/common/contextkey';
44
- import { ITextModelService } from '@theia/monaco-editor-core/esm/vs/editor/common/services/resolverService';
45
- import { IReference } from '@theia/monaco-editor-core/esm/vs/base/common/lifecycle';
46
- import { MarkdownString } from '@theia/core/lib/common/markdown-rendering';
47
-
48
- export const MonacoEditorFactory = Symbol('MonacoEditorFactory');
49
- export interface MonacoEditorFactory {
50
- readonly scheme: string;
51
- create(model: MonacoEditorModel, defaultOptions: MonacoEditor.IOptions, defaultOverrides: EditorServiceOverrides): MonacoEditor;
52
- }
53
-
54
- @injectable()
55
- export class MonacoEditorProvider {
56
-
57
- @inject(ContributionProvider)
58
- @named(MonacoEditorFactory)
59
- protected readonly factories: ContributionProvider<MonacoEditorFactory>;
60
-
61
- @inject(MonacoEditorServices)
62
- protected readonly services: MonacoEditorServices;
63
-
64
- @inject(KeybindingRegistry)
65
- protected readonly keybindingRegistry: KeybindingRegistry;
66
-
67
- @inject(OpenerService)
68
- protected readonly openerService: OpenerService;
69
-
70
- @inject(FileSystemPreferences)
71
- protected readonly filePreferences: FileSystemPreferences;
72
-
73
- protected _current: MonacoEditor | undefined;
74
- /**
75
- * Returns the last focused MonacoEditor.
76
- * It takes into account inline editors as well.
77
- * If you are interested only in standalone editors then use `MonacoEditor.getCurrent(EditorManager)`
78
- */
79
- get current(): MonacoEditor | undefined {
80
- return this._current;
81
- }
82
-
83
- constructor(
84
- @inject(MonacoToProtocolConverter) protected readonly m2p: MonacoToProtocolConverter,
85
- @inject(ProtocolToMonacoConverter) protected readonly p2m: ProtocolToMonacoConverter,
86
- @inject(MonacoWorkspace) protected readonly workspace: MonacoWorkspace,
87
- @inject(EditorPreferences) protected readonly editorPreferences: EditorPreferences,
88
- @inject(MonacoDiffNavigatorFactory) protected readonly diffNavigatorFactory: MonacoDiffNavigatorFactory,
89
- ) {
90
- }
91
-
92
- protected async getModel(uri: URI, toDispose: DisposableCollection): Promise<MonacoEditorModel> {
93
- const reference = await StandaloneServices.get(ITextModelService).createModelReference(monaco.Uri.from(uri.toComponents())) as IReference<MonacoEditorModel>;
94
- // if document is invalid makes sure that all events from underlying resource are processed before throwing invalid model
95
- if (!reference.object.valid) {
96
- await reference.object.sync();
97
- }
98
- if (!reference.object.valid) {
99
- reference.dispose();
100
- throw Object.assign(new Error(`'${uri.toString()}' is invalid`), { code: 'MODEL_IS_INVALID' });
101
- }
102
- toDispose.push(reference);
103
- return reference.object;
104
- }
105
-
106
- async get(uri: URI): Promise<MonacoEditor> {
107
- await this.editorPreferences.ready;
108
- return this.doCreateEditor(uri, (override, toDispose) => this.createEditor(uri, override, toDispose));
109
- }
110
-
111
- protected async doCreateEditor(uri: URI, factory: (
112
- override: EditorServiceOverrides, toDispose: DisposableCollection) => Promise<MonacoEditor>
113
- ): Promise<MonacoEditor> {
114
- const domNode = document.createElement('div');
115
- const contextKeyService = StandaloneServices.get(IContextKeyService).createScoped(domNode);
116
- StandaloneServices.get(IOpenerService).registerOpener({
117
- open: (u, options) => this.interceptOpen(u, options)
118
- });
119
- const overrides: EditorServiceOverrides = [
120
- [IContextKeyService, contextKeyService],
121
- ];
122
- const toDispose = new DisposableCollection();
123
- const editor = await factory(overrides, toDispose);
124
- editor.onDispose(() => toDispose.dispose());
125
-
126
- this.injectKeybindingResolver(editor);
127
-
128
- toDispose.push(editor.onFocusChanged(focused => {
129
- if (focused) {
130
- this._current = editor;
131
- }
132
- }));
133
- toDispose.push(Disposable.create(() => {
134
- if (this._current === editor) {
135
- this._current = undefined;
136
- }
137
- }));
138
-
139
- return editor;
140
- }
141
-
142
- /**
143
- * Intercept internal Monaco open calls and delegate to OpenerService.
144
- */
145
- protected async interceptOpen(monacoUri: monaco.Uri | string, monacoOptions?: OpenInternalOptions | OpenExternalOptions): Promise<boolean> {
146
- let options = undefined;
147
- if (monacoOptions) {
148
- if ('openToSide' in monacoOptions && monacoOptions.openToSide) {
149
- options = Object.assign(options || {}, <WidgetOpenerOptions>{
150
- widgetOptions: {
151
- mode: 'split-right'
152
- }
153
- });
154
- }
155
- if ('openExternal' in monacoOptions && monacoOptions.openExternal) {
156
- options = Object.assign(options || {}, <HttpOpenHandlerOptions>{
157
- openExternal: true
158
- });
159
- }
160
- }
161
- const uri = new URI(monacoUri.toString());
162
- try {
163
- await open(this.openerService, uri, options);
164
- return true;
165
- } catch (e) {
166
- console.error(`Fail to open '${uri.toString()}':`, e);
167
- return false;
168
- }
169
- }
170
-
171
- protected injectKeybindingResolver(editor: MonacoEditor): void {
172
- const keybindingService = StandaloneServices.get(IKeybindingService);
173
- keybindingService.resolveKeybinding = keybinding => [new MonacoResolvedKeybinding(MonacoResolvedKeybinding.keySequence(keybinding.chords), this.keybindingRegistry)];
174
- keybindingService.resolveKeyboardEvent = keyboardEvent => {
175
- const keybinding = new KeyCodeChord(
176
- keyboardEvent.ctrlKey,
177
- keyboardEvent.shiftKey,
178
- keyboardEvent.altKey,
179
- keyboardEvent.metaKey,
180
- keyboardEvent.keyCode
181
- );
182
- return new MonacoResolvedKeybinding(MonacoResolvedKeybinding.keySequence([keybinding]), this.keybindingRegistry);
183
- };
184
- }
185
-
186
- protected createEditor(uri: URI, override: EditorServiceOverrides, toDispose: DisposableCollection): Promise<MonacoEditor> {
187
- if (DiffUris.isDiffUri(uri)) {
188
- return this.createMonacoDiffEditor(uri, override, toDispose);
189
- }
190
- return this.createMonacoEditor(uri, override, toDispose);
191
- }
192
-
193
- protected get preferencePrefixes(): string[] {
194
- return ['editor.'];
195
- }
196
- async createMonacoEditor(uri: URI, override: EditorServiceOverrides, toDispose: DisposableCollection): Promise<MonacoEditor> {
197
- const model = await this.getModel(uri, toDispose);
198
- const options = this.createMonacoEditorOptions(model);
199
- const factory = this.factories.getContributions().find(({ scheme }) => uri.scheme === scheme);
200
- const editor = factory
201
- ? factory.create(model, options, override)
202
- : new MonacoEditor(uri, model, document.createElement('div'), this.services, options, override);
203
- toDispose.push(this.editorPreferences.onPreferenceChanged(event => {
204
- if (event.affects(uri.toString(), model.languageId)) {
205
- this.updateMonacoEditorOptions(editor, event);
206
- }
207
- }));
208
- toDispose.push(editor.onLanguageChanged(() => this.updateMonacoEditorOptions(editor)));
209
- toDispose.push(editor.onDidChangeReadOnly(() => this.updateReadOnlyMessage(options, model.readOnly)));
210
- editor.document.onWillSaveModel(event => event.waitUntil(this.formatOnSave(editor, event)));
211
- return editor;
212
- }
213
-
214
- protected updateReadOnlyMessage(options: MonacoEditor.IOptions, readOnly: boolean | MarkdownString): void {
215
- options.readOnlyMessage = MarkdownString.is(readOnly) ? readOnly : undefined;
216
- }
217
-
218
- protected createMonacoEditorOptions(model: MonacoEditorModel): MonacoEditor.IOptions {
219
- const options = this.createOptions(this.preferencePrefixes, model.uri, model.languageId);
220
- options.model = model.textEditorModel;
221
- options.readOnly = model.readOnly;
222
- this.updateReadOnlyMessage(options, model.readOnly);
223
- options.lineNumbersMinChars = model.lineNumbersMinChars;
224
- return options;
225
- }
226
- protected updateMonacoEditorOptions(editor: MonacoEditor, event?: EditorPreferenceChange): void {
227
- if (event) {
228
- const preferenceName = event.preferenceName;
229
- const overrideIdentifier = editor.document.languageId;
230
- const newValue = this.editorPreferences.get({ preferenceName, overrideIdentifier }, undefined, editor.uri.toString());
231
- editor.getControl().updateOptions(this.setOption(preferenceName, newValue, this.preferencePrefixes));
232
- } else {
233
- const options = this.createMonacoEditorOptions(editor.document);
234
- delete options.model;
235
- editor.getControl().updateOptions(options);
236
- }
237
- }
238
-
239
- protected shouldFormat(editor: MonacoEditor, event: WillSaveMonacoModelEvent): boolean {
240
- if (event.reason !== TextDocumentSaveReason.Manual) {
241
- return false;
242
- }
243
- if (event.options?.formatType) {
244
- switch (event.options.formatType) {
245
- case FormatType.ON: return true;
246
- case FormatType.OFF: return false;
247
- case FormatType.DIRTY: return editor.document.dirty;
248
- }
249
- }
250
- return true;
251
- }
252
-
253
- protected async formatOnSave(editor: MonacoEditor, event: WillSaveMonacoModelEvent): Promise<monaco.editor.IIdentifiedSingleEditOperation[]> {
254
- if (!this.shouldFormat(editor, event)) {
255
- return [];
256
- }
257
- const overrideIdentifier = editor.document.languageId;
258
- const uri = editor.uri.toString();
259
- const formatOnSave = this.editorPreferences.get({ preferenceName: 'editor.formatOnSave', overrideIdentifier }, undefined, uri);
260
- if (formatOnSave) {
261
- const formatOnSaveTimeout = this.editorPreferences.get({ preferenceName: 'editor.formatOnSaveTimeout', overrideIdentifier }, undefined, uri)!;
262
- await Promise.race([
263
- timeoutReject(formatOnSaveTimeout, `Aborted format on save after ${formatOnSaveTimeout}ms`),
264
- editor.runAction('editor.action.formatDocument')
265
- ]);
266
- }
267
- const shouldRemoveWhiteSpace = this.filePreferences.get({ preferenceName: 'files.trimTrailingWhitespace', overrideIdentifier }, undefined, uri);
268
- if (shouldRemoveWhiteSpace) {
269
- await editor.runAction('editor.action.trimTrailingWhitespace');
270
- }
271
- return [];
272
- }
273
-
274
- protected get diffPreferencePrefixes(): string[] {
275
- return [...this.preferencePrefixes, 'diffEditor.'];
276
- }
277
- protected async createMonacoDiffEditor(uri: URI, override: EditorServiceOverrides, toDispose: DisposableCollection): Promise<MonacoDiffEditor> {
278
- const [original, modified] = DiffUris.decode(uri);
279
-
280
- const [originalModel, modifiedModel] = await Promise.all([this.getModel(original, toDispose), this.getModel(modified, toDispose)]);
281
-
282
- const options = this.createMonacoDiffEditorOptions(originalModel, modifiedModel);
283
- const editor = new MonacoDiffEditor(
284
- uri,
285
- document.createElement('div'),
286
- originalModel, modifiedModel,
287
- this.services,
288
- this.diffNavigatorFactory,
289
- options,
290
- override);
291
- toDispose.push(this.editorPreferences.onPreferenceChanged(event => {
292
- const originalFileUri = original.withoutQuery().withScheme('file').toString();
293
- if (event.affects(originalFileUri, editor.document.languageId)) {
294
- this.updateMonacoDiffEditorOptions(editor, event, originalFileUri);
295
- }
296
- }));
297
- toDispose.push(editor.onLanguageChanged(() => this.updateMonacoDiffEditorOptions(editor)));
298
- return editor;
299
- }
300
- protected createMonacoDiffEditorOptions(original: MonacoEditorModel, modified: MonacoEditorModel): MonacoDiffEditor.IOptions {
301
- const options = this.createOptions(this.diffPreferencePrefixes, modified.uri, modified.languageId);
302
- options.originalEditable = !original.readOnly;
303
- options.readOnly = modified.readOnly;
304
- options.readOnlyMessage = MarkdownString.is(modified.readOnly) ? modified.readOnly : undefined;
305
- return options;
306
- }
307
- protected updateMonacoDiffEditorOptions(editor: MonacoDiffEditor, event?: EditorPreferenceChange, resourceUri?: string): void {
308
- if (event) {
309
- const preferenceName = event.preferenceName;
310
- const overrideIdentifier = editor.document.languageId;
311
- const newValue = this.editorPreferences.get({ preferenceName, overrideIdentifier }, undefined, resourceUri);
312
- editor.diffEditor.updateOptions(this.setOption(preferenceName, newValue, this.diffPreferencePrefixes));
313
- } else {
314
- const options = this.createMonacoDiffEditorOptions(editor.originalModel, editor.modifiedModel);
315
- editor.diffEditor.updateOptions(options);
316
- }
317
- }
318
-
319
- /** @deprecated always pass a language as an overrideIdentifier */
320
- protected createOptions(prefixes: string[], uri: string): Record<string, any>;
321
- protected createOptions(prefixes: string[], uri: string, overrideIdentifier: string): Record<string, any>;
322
- protected createOptions(prefixes: string[], uri: string, overrideIdentifier?: string): Record<string, any> {
323
- const flat: Record<string, any> = {};
324
- for (const preferenceName of Object.keys(this.editorPreferences)) {
325
- flat[preferenceName] = (<any>this.editorPreferences).get({ preferenceName, overrideIdentifier }, undefined, uri);
326
- }
327
- return Object.entries(flat).reduce((tree, [preferenceName, value]) => this.setOption(preferenceName, deepClone(value), prefixes, tree), {});
328
- }
329
-
330
- protected setOption(preferenceName: string, value: any, prefixes: string[], options: Record<string, any> = {}): {
331
- [name: string]: any;
332
- } {
333
- const optionName = this.toOptionName(preferenceName, prefixes);
334
- this.doSetOption(options, value, optionName.split('.'));
335
- return options;
336
- }
337
- protected toOptionName(preferenceName: string, prefixes: string[]): string {
338
- for (const prefix of prefixes) {
339
- if (preferenceName.startsWith(prefix)) {
340
- return preferenceName.substring(prefix.length);
341
- }
342
- }
343
- return preferenceName;
344
- }
345
- protected doSetOption(obj: Record<string, any>, value: any, names: string[]): void {
346
- for (let i = 0; i < names.length - 1; i++) {
347
- const name = names[i];
348
- if (obj[name] === undefined) {
349
- obj = obj[name] = {};
350
- } else if (typeof obj[name] !== 'object' || obj[name] === null) { // eslint-disable-line no-null/no-null
351
- console.warn(`Preference (diff)editor.${names.join('.')} conflicts with another preference name.`);
352
- obj = obj[name] = {};
353
- } else {
354
- obj = obj[name];
355
- }
356
- }
357
- obj[names[names.length - 1]] = value;
358
- }
359
-
360
- getDiffNavigator(editor: TextEditor): DiffNavigator {
361
- if (editor instanceof MonacoDiffEditor) {
362
- return editor.diffNavigator;
363
- }
364
- return MonacoDiffNavigatorFactory.nullNavigator;
365
- }
366
-
367
- async createInline(uri: URI, node: HTMLElement, options?: MonacoEditor.IOptions): Promise<MonacoEditor> {
368
- return this.doCreateEditor(uri, async (override, toDispose) => {
369
- const overrides = override ? Array.from(override) : [];
370
- overrides.push([IContextMenuService, { showContextMenu: () => {/** no op! */ } }]);
371
- const document = new MonacoEditorModel({
372
- uri,
373
- readContents: async () => '',
374
- dispose: () => { }
375
- }, this.m2p, this.p2m);
376
- toDispose.push(document);
377
- const model = (await document.load()).textEditorModel;
378
- return new MonacoEditor(
379
- uri,
380
- document,
381
- node,
382
- this.services,
383
- Object.assign({
384
- model,
385
- isSimpleWidget: true,
386
- autoSizing: false,
387
- minHeight: 1,
388
- maxHeight: 1
389
- }, MonacoEditorProvider.inlineOptions, options),
390
- overrides
391
- );
392
- });
393
- }
394
-
395
- static inlineOptions: monaco.editor.IEditorConstructionOptions = {
396
- wordWrap: 'on',
397
- overviewRulerLanes: 0,
398
- glyphMargin: false,
399
- lineNumbers: 'off',
400
- folding: false,
401
- selectOnLineNumbers: false,
402
- hideCursorInOverviewRuler: true,
403
- selectionHighlight: false,
404
- scrollbar: {
405
- horizontal: 'hidden'
406
- },
407
- lineDecorationsWidth: 0,
408
- overviewRulerBorder: false,
409
- scrollBeyondLastLine: false,
410
- renderLineHighlight: 'none',
411
- fixedOverflowWidgets: true,
412
- acceptSuggestionOnEnter: 'smart',
413
- minimap: {
414
- enabled: false
415
- }
416
- };
417
-
418
- async createEmbeddedDiffEditor(parentEditor: MonacoEditor, node: HTMLElement, originalUri: URI, modifiedUri: URI = parentEditor.uri,
419
- options?: MonacoDiffEditor.IOptions): Promise<MonacoDiffEditor> {
420
- options = {
421
- scrollBeyondLastLine: true,
422
- overviewRulerLanes: 2,
423
- fixedOverflowWidgets: true,
424
- minimap: { enabled: false },
425
- renderSideBySide: false,
426
- readOnly: true,
427
- renderIndicators: false,
428
- diffAlgorithm: 'advanced',
429
- stickyScroll: { enabled: false },
430
- ...options,
431
- scrollbar: {
432
- verticalScrollbarSize: 14,
433
- horizontal: 'auto',
434
- useShadows: true,
435
- verticalHasArrows: false,
436
- horizontalHasArrows: false,
437
- ...options?.scrollbar
438
- }
439
- };
440
- const uri = DiffUris.encode(originalUri, modifiedUri);
441
- return await this.doCreateEditor(uri, async (override, toDispose) =>
442
- new MonacoDiffEditor(
443
- uri,
444
- node,
445
- await this.getModel(originalUri, toDispose),
446
- await this.getModel(modifiedUri, toDispose),
447
- this.services,
448
- this.diffNavigatorFactory,
449
- options,
450
- override,
451
- parentEditor
452
- )
453
- ) as MonacoDiffEditor;
454
- }
455
- }
1
+ // *****************************************************************************
2
+ // Copyright (C) 2018 TypeFox and others.
3
+ //
4
+ // This program and the accompanying materials are made available under the
5
+ // terms of the Eclipse Public License v. 2.0 which is available at
6
+ // http://www.eclipse.org/legal/epl-2.0.
7
+ //
8
+ // This Source Code may also be made available under the following Secondary
9
+ // Licenses when the conditions for such availability set forth in the Eclipse
10
+ // Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
+ // with the GNU Classpath Exception which is available at
12
+ // https://www.gnu.org/software/classpath/license.html.
13
+ //
14
+ // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
15
+ // *****************************************************************************
16
+
17
+ /* eslint-disable @typescript-eslint/no-explicit-any */
18
+ import URI from '@theia/core/lib/common/uri';
19
+ import { EditorPreferenceChange, EditorPreferences, TextEditor, DiffNavigator } from '@theia/editor/lib/browser';
20
+ import { DiffUris } from '@theia/core/lib/browser/diff-uris';
21
+ import { inject, injectable, named } from '@theia/core/shared/inversify';
22
+ import { DisposableCollection, deepClone, Disposable } from '@theia/core/lib/common';
23
+ import { TextDocumentSaveReason } from '@theia/core/shared/vscode-languageserver-protocol';
24
+ import { MonacoDiffEditor } from './monaco-diff-editor';
25
+ import { MonacoDiffNavigatorFactory } from './monaco-diff-navigator-factory';
26
+ import { EditorServiceOverrides, MonacoEditor, MonacoEditorServices } from './monaco-editor';
27
+ import { MonacoEditorModel, WillSaveMonacoModelEvent } from './monaco-editor-model';
28
+ import { MonacoWorkspace } from './monaco-workspace';
29
+ import { ContributionProvider } from '@theia/core';
30
+ import { KeybindingRegistry, OpenerService, open, WidgetOpenerOptions, FormatType } from '@theia/core/lib/browser';
31
+ import { MonacoResolvedKeybinding } from './monaco-resolved-keybinding';
32
+ import { HttpOpenHandlerOptions } from '@theia/core/lib/browser/http-open-handler';
33
+ import { MonacoToProtocolConverter } from './monaco-to-protocol-converter';
34
+ import { ProtocolToMonacoConverter } from './protocol-to-monaco-converter';
35
+ import { FileSystemPreferences } from '@theia/filesystem/lib/browser';
36
+ import * as monaco from '@theia/monaco-editor-core';
37
+ import { StandaloneServices } from '@theia/monaco-editor-core/esm/vs/editor/standalone/browser/standaloneServices';
38
+ import { IOpenerService, OpenExternalOptions, OpenInternalOptions } from '@theia/monaco-editor-core/esm/vs/platform/opener/common/opener';
39
+ import { IKeybindingService } from '@theia/monaco-editor-core/esm/vs/platform/keybinding/common/keybinding';
40
+ import { timeoutReject } from '@theia/core/lib/common/promise-util';
41
+ import { IContextMenuService } from '@theia/monaco-editor-core/esm/vs/platform/contextview/browser/contextView';
42
+ import { KeyCodeChord } from '@theia/monaco-editor-core/esm/vs/base/common/keybindings';
43
+ import { IContextKeyService } from '@theia/monaco-editor-core/esm/vs/platform/contextkey/common/contextkey';
44
+ import { ITextModelService } from '@theia/monaco-editor-core/esm/vs/editor/common/services/resolverService';
45
+ import { IReference } from '@theia/monaco-editor-core/esm/vs/base/common/lifecycle';
46
+ import { MarkdownString } from '@theia/core/lib/common/markdown-rendering';
47
+
48
+ export const MonacoEditorFactory = Symbol('MonacoEditorFactory');
49
+ export interface MonacoEditorFactory {
50
+ readonly scheme: string;
51
+ create(model: MonacoEditorModel, defaultOptions: MonacoEditor.IOptions, defaultOverrides: EditorServiceOverrides): MonacoEditor;
52
+ }
53
+
54
+ @injectable()
55
+ export class MonacoEditorProvider {
56
+
57
+ @inject(ContributionProvider)
58
+ @named(MonacoEditorFactory)
59
+ protected readonly factories: ContributionProvider<MonacoEditorFactory>;
60
+
61
+ @inject(MonacoEditorServices)
62
+ protected readonly services: MonacoEditorServices;
63
+
64
+ @inject(KeybindingRegistry)
65
+ protected readonly keybindingRegistry: KeybindingRegistry;
66
+
67
+ @inject(OpenerService)
68
+ protected readonly openerService: OpenerService;
69
+
70
+ @inject(FileSystemPreferences)
71
+ protected readonly filePreferences: FileSystemPreferences;
72
+
73
+ protected _current: MonacoEditor | undefined;
74
+ /**
75
+ * Returns the last focused MonacoEditor.
76
+ * It takes into account inline editors as well.
77
+ * If you are interested only in standalone editors then use `MonacoEditor.getCurrent(EditorManager)`
78
+ */
79
+ get current(): MonacoEditor | undefined {
80
+ return this._current;
81
+ }
82
+
83
+ constructor(
84
+ @inject(MonacoToProtocolConverter) protected readonly m2p: MonacoToProtocolConverter,
85
+ @inject(ProtocolToMonacoConverter) protected readonly p2m: ProtocolToMonacoConverter,
86
+ @inject(MonacoWorkspace) protected readonly workspace: MonacoWorkspace,
87
+ @inject(EditorPreferences) protected readonly editorPreferences: EditorPreferences,
88
+ @inject(MonacoDiffNavigatorFactory) protected readonly diffNavigatorFactory: MonacoDiffNavigatorFactory,
89
+ ) {
90
+ }
91
+
92
+ protected async getModel(uri: URI, toDispose: DisposableCollection): Promise<MonacoEditorModel> {
93
+ const reference = await StandaloneServices.get(ITextModelService).createModelReference(monaco.Uri.from(uri.toComponents())) as IReference<MonacoEditorModel>;
94
+ // if document is invalid makes sure that all events from underlying resource are processed before throwing invalid model
95
+ if (!reference.object.valid) {
96
+ await reference.object.sync();
97
+ }
98
+ if (!reference.object.valid) {
99
+ reference.dispose();
100
+ throw Object.assign(new Error(`'${uri.toString()}' is invalid`), { code: 'MODEL_IS_INVALID' });
101
+ }
102
+ toDispose.push(reference);
103
+ return reference.object;
104
+ }
105
+
106
+ async get(uri: URI): Promise<MonacoEditor> {
107
+ await this.editorPreferences.ready;
108
+ return this.doCreateEditor(uri, (override, toDispose) => this.createEditor(uri, override, toDispose));
109
+ }
110
+
111
+ protected async doCreateEditor(uri: URI, factory: (
112
+ override: EditorServiceOverrides, toDispose: DisposableCollection) => Promise<MonacoEditor>
113
+ ): Promise<MonacoEditor> {
114
+ const domNode = document.createElement('div');
115
+ const contextKeyService = StandaloneServices.get(IContextKeyService).createScoped(domNode);
116
+ StandaloneServices.get(IOpenerService).registerOpener({
117
+ open: (u, options) => this.interceptOpen(u, options)
118
+ });
119
+ const overrides: EditorServiceOverrides = [
120
+ [IContextKeyService, contextKeyService],
121
+ ];
122
+ const toDispose = new DisposableCollection();
123
+ const editor = await factory(overrides, toDispose);
124
+ editor.onDispose(() => toDispose.dispose());
125
+
126
+ this.injectKeybindingResolver(editor);
127
+
128
+ toDispose.push(editor.onFocusChanged(focused => {
129
+ if (focused) {
130
+ this._current = editor;
131
+ }
132
+ }));
133
+ toDispose.push(Disposable.create(() => {
134
+ if (this._current === editor) {
135
+ this._current = undefined;
136
+ }
137
+ }));
138
+
139
+ return editor;
140
+ }
141
+
142
+ /**
143
+ * Intercept internal Monaco open calls and delegate to OpenerService.
144
+ */
145
+ protected async interceptOpen(monacoUri: monaco.Uri | string, monacoOptions?: OpenInternalOptions | OpenExternalOptions): Promise<boolean> {
146
+ let options = undefined;
147
+ if (monacoOptions) {
148
+ if ('openToSide' in monacoOptions && monacoOptions.openToSide) {
149
+ options = Object.assign(options || {}, <WidgetOpenerOptions>{
150
+ widgetOptions: {
151
+ mode: 'split-right'
152
+ }
153
+ });
154
+ }
155
+ if ('openExternal' in monacoOptions && monacoOptions.openExternal) {
156
+ options = Object.assign(options || {}, <HttpOpenHandlerOptions>{
157
+ openExternal: true
158
+ });
159
+ }
160
+ }
161
+ const uri = new URI(monacoUri.toString());
162
+ try {
163
+ await open(this.openerService, uri, options);
164
+ return true;
165
+ } catch (e) {
166
+ console.error(`Fail to open '${uri.toString()}':`, e);
167
+ return false;
168
+ }
169
+ }
170
+
171
+ protected injectKeybindingResolver(editor: MonacoEditor): void {
172
+ const keybindingService = StandaloneServices.get(IKeybindingService);
173
+ keybindingService.resolveKeybinding = keybinding => [new MonacoResolvedKeybinding(MonacoResolvedKeybinding.keySequence(keybinding.chords), this.keybindingRegistry)];
174
+ keybindingService.resolveKeyboardEvent = keyboardEvent => {
175
+ const keybinding = new KeyCodeChord(
176
+ keyboardEvent.ctrlKey,
177
+ keyboardEvent.shiftKey,
178
+ keyboardEvent.altKey,
179
+ keyboardEvent.metaKey,
180
+ keyboardEvent.keyCode
181
+ );
182
+ return new MonacoResolvedKeybinding(MonacoResolvedKeybinding.keySequence([keybinding]), this.keybindingRegistry);
183
+ };
184
+ }
185
+
186
+ protected createEditor(uri: URI, override: EditorServiceOverrides, toDispose: DisposableCollection): Promise<MonacoEditor> {
187
+ if (DiffUris.isDiffUri(uri)) {
188
+ return this.createMonacoDiffEditor(uri, override, toDispose);
189
+ }
190
+ return this.createMonacoEditor(uri, override, toDispose);
191
+ }
192
+
193
+ protected get preferencePrefixes(): string[] {
194
+ return ['editor.'];
195
+ }
196
+ async createMonacoEditor(uri: URI, override: EditorServiceOverrides, toDispose: DisposableCollection): Promise<MonacoEditor> {
197
+ const model = await this.getModel(uri, toDispose);
198
+ const options = this.createMonacoEditorOptions(model);
199
+ const factory = this.factories.getContributions().find(({ scheme }) => uri.scheme === scheme);
200
+ const editor = factory
201
+ ? factory.create(model, options, override)
202
+ : new MonacoEditor(uri, model, document.createElement('div'), this.services, options, override);
203
+ toDispose.push(this.editorPreferences.onPreferenceChanged(event => {
204
+ if (event.affects(uri.toString(), model.languageId)) {
205
+ this.updateMonacoEditorOptions(editor, event);
206
+ }
207
+ }));
208
+ toDispose.push(editor.onLanguageChanged(() => this.updateMonacoEditorOptions(editor)));
209
+ toDispose.push(editor.onDidChangeReadOnly(() => this.updateReadOnlyMessage(options, model.readOnly)));
210
+ editor.document.onWillSaveModel(event => event.waitUntil(this.formatOnSave(editor, event)));
211
+ return editor;
212
+ }
213
+
214
+ protected updateReadOnlyMessage(options: MonacoEditor.IOptions, readOnly: boolean | MarkdownString): void {
215
+ options.readOnlyMessage = MarkdownString.is(readOnly) ? readOnly : undefined;
216
+ }
217
+
218
+ protected createMonacoEditorOptions(model: MonacoEditorModel): MonacoEditor.IOptions {
219
+ const options = this.createOptions(this.preferencePrefixes, model.uri, model.languageId);
220
+ options.model = model.textEditorModel;
221
+ options.readOnly = model.readOnly;
222
+ this.updateReadOnlyMessage(options, model.readOnly);
223
+ options.lineNumbersMinChars = model.lineNumbersMinChars;
224
+ return options;
225
+ }
226
+ protected updateMonacoEditorOptions(editor: MonacoEditor, event?: EditorPreferenceChange): void {
227
+ if (event) {
228
+ const preferenceName = event.preferenceName;
229
+ const overrideIdentifier = editor.document.languageId;
230
+ const newValue = this.editorPreferences.get({ preferenceName, overrideIdentifier }, undefined, editor.uri.toString());
231
+ editor.getControl().updateOptions(this.setOption(preferenceName, newValue, this.preferencePrefixes));
232
+ } else {
233
+ const options = this.createMonacoEditorOptions(editor.document);
234
+ delete options.model;
235
+ editor.getControl().updateOptions(options);
236
+ }
237
+ }
238
+
239
+ protected shouldFormat(editor: MonacoEditor, event: WillSaveMonacoModelEvent): boolean {
240
+ if (event.reason !== TextDocumentSaveReason.Manual) {
241
+ return false;
242
+ }
243
+ if (event.options?.formatType) {
244
+ switch (event.options.formatType) {
245
+ case FormatType.ON: return true;
246
+ case FormatType.OFF: return false;
247
+ case FormatType.DIRTY: return editor.document.dirty;
248
+ }
249
+ }
250
+ return true;
251
+ }
252
+
253
+ protected async formatOnSave(editor: MonacoEditor, event: WillSaveMonacoModelEvent): Promise<monaco.editor.IIdentifiedSingleEditOperation[]> {
254
+ if (!this.shouldFormat(editor, event)) {
255
+ return [];
256
+ }
257
+ const overrideIdentifier = editor.document.languageId;
258
+ const uri = editor.uri.toString();
259
+ const formatOnSave = this.editorPreferences.get({ preferenceName: 'editor.formatOnSave', overrideIdentifier }, undefined, uri);
260
+ if (formatOnSave) {
261
+ const formatOnSaveTimeout = this.editorPreferences.get({ preferenceName: 'editor.formatOnSaveTimeout', overrideIdentifier }, undefined, uri)!;
262
+ await Promise.race([
263
+ timeoutReject(formatOnSaveTimeout, `Aborted format on save after ${formatOnSaveTimeout}ms`),
264
+ editor.runAction('editor.action.formatDocument')
265
+ ]);
266
+ }
267
+ const shouldRemoveWhiteSpace = this.filePreferences.get({ preferenceName: 'files.trimTrailingWhitespace', overrideIdentifier }, undefined, uri);
268
+ if (shouldRemoveWhiteSpace) {
269
+ await editor.runAction('editor.action.trimTrailingWhitespace');
270
+ }
271
+ return [];
272
+ }
273
+
274
+ protected get diffPreferencePrefixes(): string[] {
275
+ return [...this.preferencePrefixes, 'diffEditor.'];
276
+ }
277
+ protected async createMonacoDiffEditor(uri: URI, override: EditorServiceOverrides, toDispose: DisposableCollection): Promise<MonacoDiffEditor> {
278
+ const [original, modified] = DiffUris.decode(uri);
279
+
280
+ const [originalModel, modifiedModel] = await Promise.all([this.getModel(original, toDispose), this.getModel(modified, toDispose)]);
281
+
282
+ const options = this.createMonacoDiffEditorOptions(originalModel, modifiedModel);
283
+ const editor = new MonacoDiffEditor(
284
+ uri,
285
+ document.createElement('div'),
286
+ originalModel, modifiedModel,
287
+ this.services,
288
+ this.diffNavigatorFactory,
289
+ options,
290
+ override);
291
+ toDispose.push(this.editorPreferences.onPreferenceChanged(event => {
292
+ const originalFileUri = original.withoutQuery().withScheme('file').toString();
293
+ if (event.affects(originalFileUri, editor.document.languageId)) {
294
+ this.updateMonacoDiffEditorOptions(editor, event, originalFileUri);
295
+ }
296
+ }));
297
+ toDispose.push(editor.onLanguageChanged(() => this.updateMonacoDiffEditorOptions(editor)));
298
+ return editor;
299
+ }
300
+ protected createMonacoDiffEditorOptions(original: MonacoEditorModel, modified: MonacoEditorModel): MonacoDiffEditor.IOptions {
301
+ const options = this.createOptions(this.diffPreferencePrefixes, modified.uri, modified.languageId);
302
+ options.originalEditable = !original.readOnly;
303
+ options.readOnly = modified.readOnly;
304
+ options.readOnlyMessage = MarkdownString.is(modified.readOnly) ? modified.readOnly : undefined;
305
+ return options;
306
+ }
307
+ protected updateMonacoDiffEditorOptions(editor: MonacoDiffEditor, event?: EditorPreferenceChange, resourceUri?: string): void {
308
+ if (event) {
309
+ const preferenceName = event.preferenceName;
310
+ const overrideIdentifier = editor.document.languageId;
311
+ const newValue = this.editorPreferences.get({ preferenceName, overrideIdentifier }, undefined, resourceUri);
312
+ editor.diffEditor.updateOptions(this.setOption(preferenceName, newValue, this.diffPreferencePrefixes));
313
+ } else {
314
+ const options = this.createMonacoDiffEditorOptions(editor.originalModel, editor.modifiedModel);
315
+ editor.diffEditor.updateOptions(options);
316
+ }
317
+ }
318
+
319
+ /** @deprecated always pass a language as an overrideIdentifier */
320
+ protected createOptions(prefixes: string[], uri: string): Record<string, any>;
321
+ protected createOptions(prefixes: string[], uri: string, overrideIdentifier: string): Record<string, any>;
322
+ protected createOptions(prefixes: string[], uri: string, overrideIdentifier?: string): Record<string, any> {
323
+ const flat: Record<string, any> = {};
324
+ for (const preferenceName of Object.keys(this.editorPreferences)) {
325
+ flat[preferenceName] = (<any>this.editorPreferences).get({ preferenceName, overrideIdentifier }, undefined, uri);
326
+ }
327
+ return Object.entries(flat).reduce((tree, [preferenceName, value]) => this.setOption(preferenceName, deepClone(value), prefixes, tree), {});
328
+ }
329
+
330
+ protected setOption(preferenceName: string, value: any, prefixes: string[], options: Record<string, any> = {}): {
331
+ [name: string]: any;
332
+ } {
333
+ const optionName = this.toOptionName(preferenceName, prefixes);
334
+ this.doSetOption(options, value, optionName.split('.'));
335
+ return options;
336
+ }
337
+ protected toOptionName(preferenceName: string, prefixes: string[]): string {
338
+ for (const prefix of prefixes) {
339
+ if (preferenceName.startsWith(prefix)) {
340
+ return preferenceName.substring(prefix.length);
341
+ }
342
+ }
343
+ return preferenceName;
344
+ }
345
+ protected doSetOption(obj: Record<string, any>, value: any, names: string[]): void {
346
+ for (let i = 0; i < names.length - 1; i++) {
347
+ const name = names[i];
348
+ if (obj[name] === undefined) {
349
+ obj = obj[name] = {};
350
+ } else if (typeof obj[name] !== 'object' || obj[name] === null) { // eslint-disable-line no-null/no-null
351
+ console.warn(`Preference (diff)editor.${names.join('.')} conflicts with another preference name.`);
352
+ obj = obj[name] = {};
353
+ } else {
354
+ obj = obj[name];
355
+ }
356
+ }
357
+ obj[names[names.length - 1]] = value;
358
+ }
359
+
360
+ getDiffNavigator(editor: TextEditor): DiffNavigator {
361
+ if (editor instanceof MonacoDiffEditor) {
362
+ return editor.diffNavigator;
363
+ }
364
+ return MonacoDiffNavigatorFactory.nullNavigator;
365
+ }
366
+
367
+ async createInline(uri: URI, node: HTMLElement, options?: MonacoEditor.IOptions): Promise<MonacoEditor> {
368
+ return this.doCreateEditor(uri, async (override, toDispose) => {
369
+ const overrides = override ? Array.from(override) : [];
370
+ overrides.push([IContextMenuService, { showContextMenu: () => {/** no op! */ } }]);
371
+ const document = new MonacoEditorModel({
372
+ uri,
373
+ readContents: async () => '',
374
+ dispose: () => { }
375
+ }, this.m2p, this.p2m);
376
+ toDispose.push(document);
377
+ const model = (await document.load()).textEditorModel;
378
+ return new MonacoEditor(
379
+ uri,
380
+ document,
381
+ node,
382
+ this.services,
383
+ Object.assign({
384
+ model,
385
+ isSimpleWidget: true,
386
+ autoSizing: false,
387
+ minHeight: 1,
388
+ maxHeight: 1
389
+ }, MonacoEditorProvider.inlineOptions, options),
390
+ overrides
391
+ );
392
+ });
393
+ }
394
+
395
+ static inlineOptions: monaco.editor.IEditorConstructionOptions = {
396
+ wordWrap: 'on',
397
+ overviewRulerLanes: 0,
398
+ glyphMargin: false,
399
+ lineNumbers: 'off',
400
+ folding: false,
401
+ selectOnLineNumbers: false,
402
+ hideCursorInOverviewRuler: true,
403
+ selectionHighlight: false,
404
+ scrollbar: {
405
+ horizontal: 'hidden'
406
+ },
407
+ lineDecorationsWidth: 0,
408
+ overviewRulerBorder: false,
409
+ scrollBeyondLastLine: false,
410
+ renderLineHighlight: 'none',
411
+ fixedOverflowWidgets: true,
412
+ acceptSuggestionOnEnter: 'smart',
413
+ minimap: {
414
+ enabled: false
415
+ }
416
+ };
417
+
418
+ async createEmbeddedDiffEditor(parentEditor: MonacoEditor, node: HTMLElement, originalUri: URI, modifiedUri: URI = parentEditor.uri,
419
+ options?: MonacoDiffEditor.IOptions): Promise<MonacoDiffEditor> {
420
+ options = {
421
+ scrollBeyondLastLine: true,
422
+ overviewRulerLanes: 2,
423
+ fixedOverflowWidgets: true,
424
+ minimap: { enabled: false },
425
+ renderSideBySide: false,
426
+ readOnly: true,
427
+ renderIndicators: false,
428
+ diffAlgorithm: 'advanced',
429
+ stickyScroll: { enabled: false },
430
+ ...options,
431
+ scrollbar: {
432
+ verticalScrollbarSize: 14,
433
+ horizontal: 'auto',
434
+ useShadows: true,
435
+ verticalHasArrows: false,
436
+ horizontalHasArrows: false,
437
+ ...options?.scrollbar
438
+ }
439
+ };
440
+ const uri = DiffUris.encode(originalUri, modifiedUri);
441
+ return await this.doCreateEditor(uri, async (override, toDispose) =>
442
+ new MonacoDiffEditor(
443
+ uri,
444
+ node,
445
+ await this.getModel(originalUri, toDispose),
446
+ await this.getModel(modifiedUri, toDispose),
447
+ this.services,
448
+ this.diffNavigatorFactory,
449
+ options,
450
+ override,
451
+ parentEditor
452
+ )
453
+ ) as MonacoDiffEditor;
454
+ }
455
+ }