@theia/monaco 1.46.1 → 1.47.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.
Files changed (158) hide show
  1. package/lib/browser/index.js +2 -11
  2. package/lib/browser/index.js.map +1 -1
  3. package/lib/browser/markdown-renderer/monaco-markdown-renderer.d.ts +0 -4
  4. package/lib/browser/markdown-renderer/monaco-markdown-renderer.d.ts.map +1 -1
  5. package/lib/browser/markdown-renderer/monaco-markdown-renderer.js +18 -41
  6. package/lib/browser/markdown-renderer/monaco-markdown-renderer.js.map +1 -1
  7. package/lib/browser/monaco-bulk-edit-service.d.ts +1 -3
  8. package/lib/browser/monaco-bulk-edit-service.d.ts.map +1 -1
  9. package/lib/browser/monaco-bulk-edit-service.js +5 -13
  10. package/lib/browser/monaco-bulk-edit-service.js.map +1 -1
  11. package/lib/browser/monaco-color-registry.js +2 -7
  12. package/lib/browser/monaco-color-registry.js.map +1 -1
  13. package/lib/browser/monaco-command-registry.d.ts +1 -1
  14. package/lib/browser/monaco-command-registry.d.ts.map +1 -1
  15. package/lib/browser/monaco-command-registry.js +11 -16
  16. package/lib/browser/monaco-command-registry.js.map +1 -1
  17. package/lib/browser/monaco-command-service.d.ts +1 -6
  18. package/lib/browser/monaco-command-service.d.ts.map +1 -1
  19. package/lib/browser/monaco-command-service.js +20 -30
  20. package/lib/browser/monaco-command-service.js.map +1 -1
  21. package/lib/browser/monaco-command.d.ts +0 -6
  22. package/lib/browser/monaco-command.d.ts.map +1 -1
  23. package/lib/browser/monaco-command.js +19 -40
  24. package/lib/browser/monaco-command.js.map +1 -1
  25. package/lib/browser/monaco-context-key-service.d.ts +2 -2
  26. package/lib/browser/monaco-context-key-service.d.ts.map +1 -1
  27. package/lib/browser/monaco-context-key-service.js +11 -20
  28. package/lib/browser/monaco-context-key-service.js.map +1 -1
  29. package/lib/browser/monaco-context-menu.d.ts +4 -3
  30. package/lib/browser/monaco-context-menu.d.ts.map +1 -1
  31. package/lib/browser/monaco-context-menu.js +21 -19
  32. package/lib/browser/monaco-context-menu.js.map +1 -1
  33. package/lib/browser/monaco-diff-editor.d.ts +3 -3
  34. package/lib/browser/monaco-diff-editor.d.ts.map +1 -1
  35. package/lib/browser/monaco-diff-editor.js +2 -2
  36. package/lib/browser/monaco-diff-editor.js.map +1 -1
  37. package/lib/browser/monaco-diff-navigator-factory.d.ts +2 -3
  38. package/lib/browser/monaco-diff-navigator-factory.d.ts.map +1 -1
  39. package/lib/browser/monaco-diff-navigator-factory.js +7 -33
  40. package/lib/browser/monaco-diff-navigator-factory.js.map +1 -1
  41. package/lib/browser/monaco-editor-model.d.ts +4 -2
  42. package/lib/browser/monaco-editor-model.d.ts.map +1 -1
  43. package/lib/browser/monaco-editor-model.js +4 -1
  44. package/lib/browser/monaco-editor-model.js.map +1 -1
  45. package/lib/browser/monaco-editor-provider.d.ts +3 -20
  46. package/lib/browser/monaco-editor-provider.d.ts.map +1 -1
  47. package/lib/browser/monaco-editor-provider.js +37 -95
  48. package/lib/browser/monaco-editor-provider.js.map +1 -1
  49. package/lib/browser/monaco-editor-service.d.ts +7 -2
  50. package/lib/browser/monaco-editor-service.d.ts.map +1 -1
  51. package/lib/browser/monaco-editor-service.js +23 -31
  52. package/lib/browser/monaco-editor-service.js.map +1 -1
  53. package/lib/browser/monaco-editor.d.ts +4 -1
  54. package/lib/browser/monaco-editor.d.ts.map +1 -1
  55. package/lib/browser/monaco-editor.js +33 -26
  56. package/lib/browser/monaco-editor.js.map +1 -1
  57. package/lib/browser/monaco-formatting-conflicts.js +10 -18
  58. package/lib/browser/monaco-formatting-conflicts.js.map +1 -1
  59. package/lib/browser/monaco-frontend-application-contribution.d.ts +0 -6
  60. package/lib/browser/monaco-frontend-application-contribution.d.ts.map +1 -1
  61. package/lib/browser/monaco-frontend-application-contribution.js +18 -63
  62. package/lib/browser/monaco-frontend-application-contribution.js.map +1 -1
  63. package/lib/browser/monaco-frontend-module.d.ts.map +1 -1
  64. package/lib/browser/monaco-frontend-module.js +17 -8
  65. package/lib/browser/monaco-frontend-module.js.map +1 -1
  66. package/lib/browser/monaco-gotoline-quick-access.js +5 -16
  67. package/lib/browser/monaco-gotoline-quick-access.js.map +1 -1
  68. package/lib/browser/monaco-gotosymbol-quick-access.js +7 -18
  69. package/lib/browser/monaco-gotosymbol-quick-access.js.map +1 -1
  70. package/lib/browser/monaco-icon-registry.d.ts +1 -2
  71. package/lib/browser/monaco-icon-registry.d.ts.map +1 -1
  72. package/lib/browser/monaco-icon-registry.js +4 -7
  73. package/lib/browser/monaco-icon-registry.js.map +1 -1
  74. package/lib/browser/monaco-indexed-db.js +2 -7
  75. package/lib/browser/monaco-indexed-db.js.map +1 -1
  76. package/lib/browser/monaco-init.d.ts +5 -0
  77. package/lib/browser/monaco-init.d.ts.map +1 -0
  78. package/lib/browser/monaco-init.js +114 -0
  79. package/lib/browser/monaco-init.js.map +1 -0
  80. package/lib/browser/monaco-keybinding.js +17 -25
  81. package/lib/browser/monaco-keybinding.js.map +1 -1
  82. package/lib/browser/monaco-keycode-map.js +37 -37
  83. package/lib/browser/monaco-keycode-map.js.map +1 -1
  84. package/lib/browser/monaco-languages.js +10 -18
  85. package/lib/browser/monaco-languages.js.map +1 -1
  86. package/lib/browser/monaco-menu.js +4 -15
  87. package/lib/browser/monaco-menu.js.map +1 -1
  88. package/lib/browser/monaco-mime-service.js +3 -11
  89. package/lib/browser/monaco-mime-service.js.map +1 -1
  90. package/lib/browser/monaco-outline-contribution.js +6 -14
  91. package/lib/browser/monaco-outline-contribution.js.map +1 -1
  92. package/lib/browser/monaco-outline-decorator.js +2 -7
  93. package/lib/browser/monaco-outline-decorator.js.map +1 -1
  94. package/lib/browser/monaco-quick-access-registry.js +4 -12
  95. package/lib/browser/monaco-quick-access-registry.js.map +1 -1
  96. package/lib/browser/monaco-quick-input-service.d.ts +7 -9
  97. package/lib/browser/monaco-quick-input-service.d.ts.map +1 -1
  98. package/lib/browser/monaco-quick-input-service.js +76 -123
  99. package/lib/browser/monaco-quick-input-service.js.map +1 -1
  100. package/lib/browser/monaco-resolved-keybinding.d.ts +10 -10
  101. package/lib/browser/monaco-resolved-keybinding.d.ts.map +1 -1
  102. package/lib/browser/monaco-resolved-keybinding.js +16 -16
  103. package/lib/browser/monaco-resolved-keybinding.js.map +1 -1
  104. package/lib/browser/monaco-snippet-suggest-provider.js +4 -12
  105. package/lib/browser/monaco-snippet-suggest-provider.js.map +1 -1
  106. package/lib/browser/monaco-status-bar-contribution.js +5 -16
  107. package/lib/browser/monaco-status-bar-contribution.js.map +1 -1
  108. package/lib/browser/monaco-text-model-service.js +21 -29
  109. package/lib/browser/monaco-text-model-service.js.map +1 -1
  110. package/lib/browser/monaco-theming-service.js +8 -16
  111. package/lib/browser/monaco-theming-service.js.map +1 -1
  112. package/lib/browser/monaco-to-protocol-converter.js +2 -7
  113. package/lib/browser/monaco-to-protocol-converter.js.map +1 -1
  114. package/lib/browser/monaco-workspace.d.ts +1 -3
  115. package/lib/browser/monaco-workspace.d.ts.map +1 -1
  116. package/lib/browser/monaco-workspace.js +27 -35
  117. package/lib/browser/monaco-workspace.js.map +1 -1
  118. package/lib/browser/protocol-to-monaco-converter.js +2 -7
  119. package/lib/browser/protocol-to-monaco-converter.js.map +1 -1
  120. package/lib/browser/simple-monaco-editor.d.ts +1 -0
  121. package/lib/browser/simple-monaco-editor.d.ts.map +1 -1
  122. package/lib/browser/simple-monaco-editor.js +10 -2
  123. package/lib/browser/simple-monaco-editor.js.map +1 -1
  124. package/lib/browser/textmate/index.js +5 -14
  125. package/lib/browser/textmate/index.js.map +1 -1
  126. package/lib/browser/textmate/monaco-textmate-service.js +19 -27
  127. package/lib/browser/textmate/monaco-textmate-service.js.map +1 -1
  128. package/lib/browser/textmate/monaco-theme-registry.js +4 -12
  129. package/lib/browser/textmate/monaco-theme-registry.js.map +1 -1
  130. package/lib/browser/textmate/textmate-registry.js +2 -7
  131. package/lib/browser/textmate/textmate-registry.js.map +1 -1
  132. package/lib/browser/workspace-symbol-command.js +14 -22
  133. package/lib/browser/workspace-symbol-command.js.map +1 -1
  134. package/package.json +11 -10
  135. package/src/browser/markdown-renderer/monaco-markdown-renderer.ts +10 -18
  136. package/src/browser/monaco-bulk-edit-service.ts +2 -2
  137. package/src/browser/monaco-command-registry.ts +4 -1
  138. package/src/browser/monaco-command-service.ts +16 -25
  139. package/src/browser/monaco-command.ts +5 -15
  140. package/src/browser/monaco-context-key-service.ts +7 -6
  141. package/src/browser/monaco-context-menu.ts +13 -3
  142. package/src/browser/monaco-diff-editor.ts +8 -9
  143. package/src/browser/monaco-diff-navigator-factory.ts +6 -28
  144. package/src/browser/monaco-editor-model.ts +6 -3
  145. package/src/browser/monaco-editor-provider.ts +25 -59
  146. package/src/browser/monaco-editor-service.ts +10 -5
  147. package/src/browser/monaco-editor.ts +28 -9
  148. package/src/browser/monaco-frontend-application-contribution.ts +0 -35
  149. package/src/browser/monaco-frontend-module.ts +25 -17
  150. package/src/browser/monaco-icon-registry.ts +6 -4
  151. package/src/browser/monaco-init.ts +114 -0
  152. package/src/browser/monaco-keybinding.ts +3 -3
  153. package/src/browser/monaco-quick-input-service.ts +79 -108
  154. package/src/browser/monaco-resolved-keybinding.ts +23 -23
  155. package/src/browser/monaco-text-model-service.ts +1 -1
  156. package/src/browser/monaco-workspace.ts +10 -10
  157. package/src/browser/simple-monaco-editor.ts +9 -2
  158. package/src/browser/textmate/monaco-textmate-service.ts +1 -1
@@ -21,17 +21,11 @@ import { DiffUris } from '@theia/core/lib/browser/diff-uris';
21
21
  import { inject, injectable, named } from '@theia/core/shared/inversify';
22
22
  import { DisposableCollection, deepClone, Disposable } from '@theia/core/lib/common';
23
23
  import { TextDocumentSaveReason } from '@theia/core/shared/vscode-languageserver-protocol';
24
- import { MonacoCommandServiceFactory } from './monaco-command-service';
25
- import { MonacoContextMenuService } from './monaco-context-menu';
26
24
  import { MonacoDiffEditor } from './monaco-diff-editor';
27
25
  import { MonacoDiffNavigatorFactory } from './monaco-diff-navigator-factory';
28
26
  import { EditorServiceOverrides, MonacoEditor, MonacoEditorServices } from './monaco-editor';
29
27
  import { MonacoEditorModel, WillSaveMonacoModelEvent } from './monaco-editor-model';
30
- import { MonacoEditorService } from './monaco-editor-service';
31
- import { MonacoTextModelService } from './monaco-text-model-service';
32
28
  import { MonacoWorkspace } from './monaco-workspace';
33
- import { MonacoBulkEditService } from './monaco-bulk-edit-service';
34
- import { ApplicationServer } from '@theia/core/lib/common/application-protocol';
35
29
  import { ContributionProvider } from '@theia/core';
36
30
  import { KeybindingRegistry, OpenerService, open, WidgetOpenerOptions, FormatType } from '@theia/core/lib/browser';
37
31
  import { MonacoResolvedKeybinding } from './monaco-resolved-keybinding';
@@ -39,23 +33,17 @@ import { HttpOpenHandlerOptions } from '@theia/core/lib/browser/http-open-handle
39
33
  import { MonacoToProtocolConverter } from './monaco-to-protocol-converter';
40
34
  import { ProtocolToMonacoConverter } from './protocol-to-monaco-converter';
41
35
  import { FileSystemPreferences } from '@theia/filesystem/lib/browser';
42
- import { MonacoQuickInputImplementation } from './monaco-quick-input-service';
43
- import { ContextKeyService } from '@theia/monaco-editor-core/esm/vs/platform/contextkey/browser/contextKeyService';
44
36
  import * as monaco from '@theia/monaco-editor-core';
45
- import { OpenerService as MonacoOpenerService } from '@theia/monaco-editor-core/esm/vs/editor/browser/services/openerService';
46
- import { StandaloneCommandService, StandaloneServices } from '@theia/monaco-editor-core/esm/vs/editor/standalone/browser/standaloneServices';
37
+ import { StandaloneServices } from '@theia/monaco-editor-core/esm/vs/editor/standalone/browser/standaloneServices';
47
38
  import { IOpenerService, OpenExternalOptions, OpenInternalOptions } from '@theia/monaco-editor-core/esm/vs/platform/opener/common/opener';
48
- import { SimpleKeybinding } from '@theia/monaco-editor-core/esm/vs/base/common/keybindings';
49
- import { ICodeEditorService } from '@theia/monaco-editor-core/esm/vs/editor/browser/services/codeEditorService';
50
- import { IInstantiationService } from '@theia/monaco-editor-core/esm/vs/platform/instantiation/common/instantiation';
51
39
  import { IKeybindingService } from '@theia/monaco-editor-core/esm/vs/platform/keybinding/common/keybinding';
52
40
  import { timeoutReject } from '@theia/core/lib/common/promise-util';
53
- import { ITextModelService } from '@theia/monaco-editor-core/esm/vs/editor/common/services/resolverService';
54
41
  import { IContextMenuService } from '@theia/monaco-editor-core/esm/vs/platform/contextview/browser/contextView';
55
- import { IBulkEditService } from '@theia/monaco-editor-core/esm/vs/editor/browser/services/bulkEditService';
42
+ import { KeyCodeChord } from '@theia/monaco-editor-core/esm/vs/base/common/keybindings';
56
43
  import { IContextKeyService } from '@theia/monaco-editor-core/esm/vs/platform/contextkey/common/contextkey';
57
- import { IQuickInputService } from '@theia/monaco-editor-core/esm/vs/platform/quickinput/common/quickInput';
58
- import { ICommandService } from '@theia/monaco-editor-core/esm/vs/platform/commands/common/commands';
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';
59
47
 
60
48
  export const MonacoEditorFactory = Symbol('MonacoEditorFactory');
61
49
  export interface MonacoEditorFactory {
@@ -70,9 +58,6 @@ export class MonacoEditorProvider {
70
58
  @named(MonacoEditorFactory)
71
59
  protected readonly factories: ContributionProvider<MonacoEditorFactory>;
72
60
 
73
- @inject(MonacoBulkEditService)
74
- protected readonly bulkEditService: MonacoBulkEditService;
75
-
76
61
  @inject(MonacoEditorServices)
77
62
  protected readonly services: MonacoEditorServices;
78
63
 
@@ -85,9 +70,6 @@ export class MonacoEditorProvider {
85
70
  @inject(FileSystemPreferences)
86
71
  protected readonly filePreferences: FileSystemPreferences;
87
72
 
88
- @inject(MonacoQuickInputImplementation)
89
- protected readonly quickInputService: MonacoQuickInputImplementation;
90
-
91
73
  protected _current: MonacoEditor | undefined;
92
74
  /**
93
75
  * Returns the last focused MonacoEditor.
@@ -99,26 +81,16 @@ export class MonacoEditorProvider {
99
81
  }
100
82
 
101
83
  constructor(
102
- @inject(MonacoEditorService) protected readonly codeEditorService: MonacoEditorService,
103
- @inject(MonacoTextModelService) protected readonly textModelService: MonacoTextModelService,
104
- @inject(MonacoContextMenuService) protected readonly contextMenuService: MonacoContextMenuService,
105
84
  @inject(MonacoToProtocolConverter) protected readonly m2p: MonacoToProtocolConverter,
106
85
  @inject(ProtocolToMonacoConverter) protected readonly p2m: ProtocolToMonacoConverter,
107
86
  @inject(MonacoWorkspace) protected readonly workspace: MonacoWorkspace,
108
- @inject(MonacoCommandServiceFactory) protected readonly commandServiceFactory: MonacoCommandServiceFactory,
109
87
  @inject(EditorPreferences) protected readonly editorPreferences: EditorPreferences,
110
88
  @inject(MonacoDiffNavigatorFactory) protected readonly diffNavigatorFactory: MonacoDiffNavigatorFactory,
111
- /** @deprecated since 1.6.0 */
112
- @inject(ApplicationServer) protected readonly applicationServer: ApplicationServer,
113
- @inject(ContextKeyService) protected readonly contextKeyService: ContextKeyService
114
89
  ) {
115
- StandaloneServices.initialize({
116
- [ICodeEditorService.toString()]: codeEditorService,
117
- });
118
90
  }
119
91
 
120
92
  protected async getModel(uri: URI, toDispose: DisposableCollection): Promise<MonacoEditorModel> {
121
- const reference = await this.textModelService.createModelReference(uri);
93
+ const reference = await StandaloneServices.get(ITextModelService).createModelReference(monaco.Uri.from(uri.toComponents())) as IReference<MonacoEditorModel>;
122
94
  // if document is invalid makes sure that all events from underlying resource are processed before throwing invalid model
123
95
  if (!reference.object.valid) {
124
96
  await reference.object.sync();
@@ -139,34 +111,20 @@ export class MonacoEditorProvider {
139
111
  protected async doCreateEditor(uri: URI, factory: (
140
112
  override: EditorServiceOverrides, toDispose: DisposableCollection) => Promise<MonacoEditor>
141
113
  ): Promise<MonacoEditor> {
142
- const commandService = this.commandServiceFactory();
143
114
  const domNode = document.createElement('div');
144
- const contextKeyService = this.contextKeyService.createScoped(domNode);
145
- const { codeEditorService, textModelService, contextMenuService } = this;
146
- const workspaceEditService = this.bulkEditService;
147
- const toDispose = new DisposableCollection(commandService);
148
- const openerService = new MonacoOpenerService(codeEditorService, commandService);
149
- openerService.registerOpener({
115
+ const contextKeyService = StandaloneServices.get(IContextKeyService).createScoped(domNode);
116
+ StandaloneServices.get(IOpenerService).registerOpener({
150
117
  open: (u, options) => this.interceptOpen(u, options)
151
118
  });
152
119
  const overrides: EditorServiceOverrides = [
153
- [ICodeEditorService, codeEditorService],
154
- [ITextModelService, textModelService],
155
- [IContextMenuService, contextMenuService],
156
- [IBulkEditService, workspaceEditService],
157
120
  [IContextKeyService, contextKeyService],
158
- [IOpenerService, openerService],
159
- [IQuickInputService, this.quickInputService],
160
- [ICommandService, commandService]
161
121
  ];
122
+ const toDispose = new DisposableCollection();
162
123
  const editor = await factory(overrides, toDispose);
163
124
  editor.onDispose(() => toDispose.dispose());
164
125
 
165
126
  this.injectKeybindingResolver(editor);
166
127
 
167
- const standaloneCommandService = new StandaloneCommandService(StandaloneServices.get(IInstantiationService));
168
- commandService.setDelegate(standaloneCommandService);
169
-
170
128
  toDispose.push(editor.onFocusChanged(focused => {
171
129
  if (focused) {
172
130
  this._current = editor;
@@ -212,16 +170,16 @@ export class MonacoEditorProvider {
212
170
 
213
171
  protected injectKeybindingResolver(editor: MonacoEditor): void {
214
172
  const keybindingService = StandaloneServices.get(IKeybindingService);
215
- keybindingService.resolveKeybinding = keybinding => [new MonacoResolvedKeybinding(MonacoResolvedKeybinding.keySequence(keybinding), this.keybindingRegistry)];
173
+ keybindingService.resolveKeybinding = keybinding => [new MonacoResolvedKeybinding(MonacoResolvedKeybinding.keySequence(keybinding.chords), this.keybindingRegistry)];
216
174
  keybindingService.resolveKeyboardEvent = keyboardEvent => {
217
- const keybinding = new SimpleKeybinding(
175
+ const keybinding = new KeyCodeChord(
218
176
  keyboardEvent.ctrlKey,
219
177
  keyboardEvent.shiftKey,
220
178
  keyboardEvent.altKey,
221
179
  keyboardEvent.metaKey,
222
180
  keyboardEvent.keyCode
223
- ).toChord();
224
- return new MonacoResolvedKeybinding(MonacoResolvedKeybinding.keySequence(keybinding), this.keybindingRegistry);
181
+ );
182
+ return new MonacoResolvedKeybinding(MonacoResolvedKeybinding.keySequence([keybinding]), this.keybindingRegistry);
225
183
  };
226
184
  }
227
185
 
@@ -248,13 +206,20 @@ export class MonacoEditorProvider {
248
206
  }
249
207
  }));
250
208
  toDispose.push(editor.onLanguageChanged(() => this.updateMonacoEditorOptions(editor)));
209
+ toDispose.push(editor.onDidChangeReadOnly(() => this.updateReadOnlyMessage(options, model.readOnly)));
251
210
  editor.document.onWillSaveModel(event => event.waitUntil(this.formatOnSave(editor, event)));
252
211
  return editor;
253
212
  }
213
+
214
+ protected updateReadOnlyMessage(options: MonacoEditor.IOptions, readOnly: boolean | MarkdownString ): void {
215
+ options.readOnlyMessage = MarkdownString.is(readOnly) ? readOnly : undefined;
216
+ }
217
+
254
218
  protected createMonacoEditorOptions(model: MonacoEditorModel): MonacoEditor.IOptions {
255
219
  const options = this.createOptions(this.preferencePrefixes, model.uri, model.languageId);
256
220
  options.model = model.textEditorModel;
257
221
  options.readOnly = model.readOnly;
222
+ this.updateReadOnlyMessage(options, model.readOnly);
258
223
  options.lineNumbersMinChars = model.lineNumbersMinChars;
259
224
  return options;
260
225
  }
@@ -336,6 +301,7 @@ export class MonacoEditorProvider {
336
301
  const options = this.createOptions(this.diffPreferencePrefixes, modified.uri, modified.languageId);
337
302
  options.originalEditable = !original.readOnly;
338
303
  options.readOnly = modified.readOnly;
304
+ options.readOnlyMessage = MarkdownString.is(modified.readOnly) ? modified.readOnly : undefined;
339
305
  return options;
340
306
  }
341
307
  protected updateMonacoDiffEditorOptions(editor: MonacoDiffEditor, event?: EditorPreferenceChange, resourceUri?: string): void {
@@ -403,10 +369,10 @@ export class MonacoEditorProvider {
403
369
  const overrides = override ? Array.from(override) : [];
404
370
  overrides.push([IContextMenuService, { showContextMenu: () => {/** no op! */ } }]);
405
371
  const document = new MonacoEditorModel({
406
- uri,
407
- readContents: async () => '',
408
- dispose: () => { }
409
- }, this.m2p, this.p2m);
372
+ uri,
373
+ readContents: async () => '',
374
+ dispose: () => { }
375
+ }, this.m2p, this.p2m);
410
376
  toDispose.push(document);
411
377
  const model = (await document.load()).textEditorModel;
412
378
  return new MonacoEditor(
@@ -22,15 +22,20 @@ import { MonacoEditor } from './monaco-editor';
22
22
  import { MonacoToProtocolConverter } from './monaco-to-protocol-converter';
23
23
  import { MonacoEditorModel } from './monaco-editor-model';
24
24
  import { IResourceEditorInput, ITextResourceEditorInput } from '@theia/monaco-editor-core/esm/vs/platform/editor/common/editor';
25
- import { StandaloneServices } from '@theia/monaco-editor-core/esm/vs/editor/standalone/browser/standaloneServices';
26
- import { IStandaloneThemeService } from '@theia/monaco-editor-core/esm/vs/editor/standalone/common/standaloneTheme';
27
25
  import { StandaloneCodeEditorService } from '@theia/monaco-editor-core/esm/vs/editor/standalone/browser/standaloneCodeEditorService';
28
26
  import { StandaloneCodeEditor } from '@theia/monaco-editor-core/esm/vs/editor/standalone/browser/standaloneCodeEditor';
29
27
  import { ICodeEditor } from '@theia/monaco-editor-core/esm/vs/editor/browser/editorBrowser';
30
- import { ContextKeyService as VSCodeContextKeyService } from '@theia/monaco-editor-core/esm/vs/platform/contextkey/browser/contextKeyService';
28
+ import { IContextKeyService } from '@theia/monaco-editor-core/esm/vs/platform/contextkey/common/contextkey';
29
+ import { IThemeService } from '@theia/monaco-editor-core/esm/vs/platform/theme/common/themeService';
31
30
 
32
31
  decorate(injectable(), StandaloneCodeEditorService);
33
32
 
33
+ export const VSCodeContextKeyService = Symbol('VSCodeContextKeyService');
34
+ export const VSCodeThemeService = Symbol('VSCodeThemeService');
35
+
36
+ export const MonacoEditorServiceFactory = Symbol('MonacoEditorServiceFactory');
37
+ export type MonacoEditorServiceFactoryType = (contextKeyService: IContextKeyService, themeService: IThemeService) => MonacoEditorService;
38
+
34
39
  @injectable()
35
40
  export class MonacoEditorService extends StandaloneCodeEditorService {
36
41
 
@@ -51,8 +56,8 @@ export class MonacoEditorService extends StandaloneCodeEditorService {
51
56
  @inject(PreferenceService)
52
57
  protected readonly preferencesService: PreferenceService;
53
58
 
54
- constructor(@inject(VSCodeContextKeyService) contextKeyService: VSCodeContextKeyService) {
55
- super(contextKeyService, StandaloneServices.get(IStandaloneThemeService));
59
+ constructor(@inject(VSCodeContextKeyService) contextKeyService: IContextKeyService, @inject(VSCodeThemeService) themeService: IThemeService) {
60
+ super(contextKeyService, themeService);
56
61
  }
57
62
 
58
63
  /**
@@ -35,7 +35,8 @@ import {
35
35
  EditorDecoration,
36
36
  EditorMouseEvent,
37
37
  EncodingMode,
38
- EditorDecorationOptions
38
+ EditorDecorationOptions,
39
+ MouseTargetType
39
40
  } from '@theia/editor/lib/browser';
40
41
  import { MonacoEditorModel } from './monaco-editor-model';
41
42
  import { MonacoToProtocolConverter } from './monaco-to-protocol-converter';
@@ -46,9 +47,10 @@ import * as monaco from '@theia/monaco-editor-core';
46
47
  import { StandaloneServices } from '@theia/monaco-editor-core/esm/vs/editor/standalone/browser/standaloneServices';
47
48
  import { ILanguageService } from '@theia/monaco-editor-core/esm/vs/editor/common/languages/language';
48
49
  import { IInstantiationService, ServiceIdentifier } from '@theia/monaco-editor-core/esm/vs/platform/instantiation/common/instantiation';
49
- import { ICodeEditor } from '@theia/monaco-editor-core/esm/vs/editor/browser/editorBrowser';
50
- import { ServiceCollection } from '@theia/monaco-editor-core/esm/vs/platform/instantiation/common/serviceCollection';
50
+ import { ICodeEditor, IMouseTargetMargin } from '@theia/monaco-editor-core/esm/vs/editor/browser/editorBrowser';
51
51
  import { IStandaloneEditorConstructionOptions, StandaloneEditor } from '@theia/monaco-editor-core/esm/vs/editor/standalone/browser/standaloneCodeEditor';
52
+ import { ServiceCollection } from '@theia/monaco-editor-core/esm/vs/platform/instantiation/common/serviceCollection';
53
+ import { MarkdownString } from '@theia/core/lib/common/markdown-rendering';
52
54
 
53
55
  export type ServicePair<T> = [ServiceIdentifier<T>, T];
54
56
 
@@ -85,6 +87,7 @@ export class MonacoEditor extends MonacoEditorServices implements TextEditor {
85
87
  protected readonly onFocusChangedEmitter = new Emitter<boolean>();
86
88
  protected readonly onDocumentContentChangedEmitter = new Emitter<TextDocumentChangeEvent>();
87
89
  protected readonly onMouseDownEmitter = new Emitter<EditorMouseEvent>();
90
+ readonly onDidChangeReadOnly = this.document.onDidChangeReadOnly;
88
91
  protected readonly onLanguageChangedEmitter = new Emitter<string>();
89
92
  readonly onLanguageChanged = this.onLanguageChangedEmitter.event;
90
93
  protected readonly onScrollChangedEmitter = new Emitter<void>();
@@ -116,7 +119,10 @@ export class MonacoEditor extends MonacoEditorServices implements TextEditor {
116
119
  this.autoSizing = options && options.autoSizing !== undefined ? options.autoSizing : false;
117
120
  this.minHeight = options && options.minHeight !== undefined ? options.minHeight : -1;
118
121
  this.maxHeight = options && options.maxHeight !== undefined ? options.maxHeight : -1;
119
- this.toDispose.push(this.create(options, override));
122
+ this.toDispose.push(this.create({
123
+ ...MonacoEditor.createReadOnlyOptions(document.readOnly),
124
+ ...options
125
+ }, override));
120
126
  this.addHandlers(this.editor);
121
127
  }
122
128
 
@@ -151,7 +157,7 @@ export class MonacoEditor extends MonacoEditorServices implements TextEditor {
151
157
  }
152
158
 
153
159
  protected getInstantiatorWithOverrides(override?: EditorServiceOverrides): IInstantiationService {
154
- const instantiator = StandaloneServices.initialize({});
160
+ const instantiator = StandaloneServices.get(IInstantiationService);
155
161
  if (override) {
156
162
  const overrideServices = new ServiceCollection(...override);
157
163
  return instantiator.createChild(overrideServices);
@@ -185,12 +191,12 @@ export class MonacoEditor extends MonacoEditorServices implements TextEditor {
185
191
  const { element, position, range } = e.target;
186
192
  this.onMouseDownEmitter.fire({
187
193
  target: {
188
- ...e.target,
194
+ type: e.target.type as unknown as MouseTargetType,
189
195
  element: element || undefined,
190
196
  mouseColumn: this.m2p.asPosition(undefined, e.target.mouseColumn).character,
191
197
  range: range && this.m2p.asRange(range) || undefined,
192
198
  position: position && this.m2p.asPosition(position.lineNumber, position.column) || undefined,
193
- detail: (e.target as monaco.editor.IMouseTargetMargin).detail || {},
199
+ detail: (e.target as unknown as IMouseTargetMargin).detail || {},
194
200
  },
195
201
  event: e.event.browserEvent
196
202
  });
@@ -198,6 +204,9 @@ export class MonacoEditor extends MonacoEditorServices implements TextEditor {
198
204
  this.toDispose.push(codeEditor.onDidScrollChange(e => {
199
205
  this.onScrollChangedEmitter.fire(undefined);
200
206
  }));
207
+ this.toDispose.push(this.onDidChangeReadOnly(readOnly => {
208
+ codeEditor.updateOptions(MonacoEditor.createReadOnlyOptions(readOnly));
209
+ }));
201
210
  }
202
211
 
203
212
  getVisibleRanges(): Range[] {
@@ -220,8 +229,8 @@ export class MonacoEditor extends MonacoEditorServices implements TextEditor {
220
229
  return this.onDocumentContentChangedEmitter.event;
221
230
  }
222
231
 
223
- get isReadonly(): boolean {
224
- return this.document.isReadonly();
232
+ get isReadonly(): boolean | MarkdownString {
233
+ return this.document.readOnly;
225
234
  }
226
235
 
227
236
  get cursor(): Position {
@@ -641,4 +650,14 @@ export namespace MonacoEditor {
641
650
  return candidate && candidate.getControl() === control;
642
651
  });
643
652
  }
653
+
654
+ export function createReadOnlyOptions(readOnly?: boolean | MarkdownString): monaco.editor.IEditorOptions {
655
+ if (typeof readOnly === 'boolean') {
656
+ return { readOnly, readOnlyMessage: undefined };
657
+ }
658
+ if (readOnly) {
659
+ return { readOnly: true, readOnlyMessage: readOnly };
660
+ }
661
+ return {};
662
+ }
644
663
  }
@@ -20,15 +20,7 @@ import { MonacoSnippetSuggestProvider } from './monaco-snippet-suggest-provider'
20
20
  import * as monaco from '@theia/monaco-editor-core';
21
21
  import { setSnippetSuggestSupport } from '@theia/monaco-editor-core/esm/vs/editor/contrib/suggest/browser/suggest';
22
22
  import { CompletionItemProvider } from '@theia/monaco-editor-core/esm/vs/editor/common/languages';
23
- import { MonacoEditorService } from './monaco-editor-service';
24
23
  import { MonacoTextModelService } from './monaco-text-model-service';
25
- import { ContextKeyService as VSCodeContextKeyService } from '@theia/monaco-editor-core/esm/vs/platform/contextkey/browser/contextKeyService';
26
- import { StandaloneServices } from '@theia/monaco-editor-core/esm/vs/editor/standalone/browser/standaloneServices';
27
- import { ICodeEditorService } from '@theia/monaco-editor-core/esm/vs/editor/browser/services/codeEditorService';
28
- import { ITextModelService } from '@theia/monaco-editor-core/esm/vs/editor/common/services/resolverService';
29
- import { IContextKeyService } from '@theia/monaco-editor-core/esm/vs/platform/contextkey/common/contextkey';
30
- import { IContextMenuService } from '@theia/monaco-editor-core/esm/vs/platform/contextview/browser/contextView';
31
- import { MonacoContextMenuService } from './monaco-context-menu';
32
24
  import { MonacoThemingService } from './monaco-theming-service';
33
25
  import { isHighContrast } from '@theia/core/lib/common/theme';
34
26
  import { editorOptionsRegistry, IEditorOption } from '@theia/monaco-editor-core/esm/vs/editor/common/config/editorOptions';
@@ -36,28 +28,12 @@ import { MAX_SAFE_INTEGER } from '@theia/core';
36
28
  import { editorGeneratedPreferenceProperties } from '@theia/editor/lib/browser/editor-generated-preference-schema';
37
29
  import { WorkspaceFileService } from '@theia/workspace/lib/common/workspace-file-service';
38
30
 
39
- let theiaDidInitialize = false;
40
- const originalInitialize = StandaloneServices.initialize;
41
- StandaloneServices.initialize = overrides => {
42
- if (!theiaDidInitialize) {
43
- console.warn('Monaco was initialized before overrides were installed by Theia\'s initialization.'
44
- + ' Please check the lifecycle of services that use Monaco and ensure that Monaco entities are not instantiated before Theia is initialized.', new Error());
45
- }
46
- return originalInitialize(overrides);
47
- };
48
-
49
31
  @injectable()
50
32
  export class MonacoFrontendApplicationContribution implements FrontendApplicationContribution, StylingParticipant {
51
33
 
52
- @inject(MonacoEditorService)
53
- protected readonly codeEditorService: MonacoEditorService;
54
-
55
34
  @inject(MonacoTextModelService)
56
35
  protected readonly textModelService: MonacoTextModelService;
57
36
 
58
- @inject(VSCodeContextKeyService)
59
- protected readonly contextKeyService: VSCodeContextKeyService;
60
-
61
37
  @inject(MonacoSnippetSuggestProvider)
62
38
  protected readonly snippetSuggestProvider: MonacoSnippetSuggestProvider;
63
39
 
@@ -67,9 +43,6 @@ export class MonacoFrontendApplicationContribution implements FrontendApplicatio
67
43
  @inject(QuickAccessRegistry)
68
44
  protected readonly quickAccessRegistry: QuickAccessRegistry;
69
45
 
70
- @inject(MonacoContextMenuService)
71
- protected readonly contextMenuService: MonacoContextMenuService;
72
-
73
46
  @inject(MonacoThemingService) protected readonly monacoThemingService: MonacoThemingService;
74
47
 
75
48
  @inject(WorkspaceFileService) protected readonly workspaceFileService: WorkspaceFileService;
@@ -77,14 +50,6 @@ export class MonacoFrontendApplicationContribution implements FrontendApplicatio
77
50
  @postConstruct()
78
51
  protected init(): void {
79
52
  this.addAdditionalPreferenceValidations();
80
- const { codeEditorService, textModelService, contextKeyService, contextMenuService } = this;
81
- theiaDidInitialize = true;
82
- StandaloneServices.initialize({
83
- [ICodeEditorService.toString()]: codeEditorService,
84
- [ITextModelService.toString()]: textModelService,
85
- [IContextKeyService.toString()]: contextKeyService,
86
- [IContextMenuService.toString()]: contextMenuService,
87
- });
88
53
  // Monaco registers certain quick access providers (e.g. QuickCommandAccess) at import time, but we want to use our own.
89
54
  this.quickAccessRegistry.clear();
90
55
 
@@ -31,7 +31,7 @@ Object.assign(MonacoNls, {
31
31
  });
32
32
 
33
33
  import '../../src/browser/style/index.css';
34
- import { ContainerModule, decorate, injectable, interfaces } from '@theia/core/shared/inversify';
34
+ import { ContainerModule, interfaces } from '@theia/core/shared/inversify';
35
35
  import { MenuContribution, CommandContribution, quickInputServicePath } from '@theia/core/lib/common';
36
36
  import {
37
37
  FrontendApplicationContribution, KeybindingContribution,
@@ -45,12 +45,12 @@ import { MonacoEditorCommandHandlers } from './monaco-command';
45
45
  import { MonacoKeybindingContribution } from './monaco-keybinding';
46
46
  import { MonacoLanguages } from './monaco-languages';
47
47
  import { MonacoWorkspace } from './monaco-workspace';
48
- import { MonacoEditorService } from './monaco-editor-service';
48
+ import { MonacoEditorService, MonacoEditorServiceFactory, VSCodeContextKeyService, VSCodeThemeService } from './monaco-editor-service';
49
49
  import { MonacoTextModelService, MonacoEditorModelFactory } from './monaco-text-model-service';
50
50
  import { MonacoContextMenuService } from './monaco-context-menu';
51
51
  import { MonacoOutlineContribution } from './monaco-outline-contribution';
52
52
  import { MonacoStatusBarContribution } from './monaco-status-bar-contribution';
53
- import { MonacoCommandService, MonacoCommandServiceFactory } from './monaco-command-service';
53
+ import { MonacoCommandService } from './monaco-command-service';
54
54
  import { MonacoCommandRegistry } from './monaco-command-registry';
55
55
  import { MonacoDiffNavigatorFactory } from './monaco-diff-navigator-factory';
56
56
  import { MonacoFrontendApplicationContribution } from './monaco-frontend-application-contribution';
@@ -80,16 +80,15 @@ import { GotoLineQuickAccessContribution } from './monaco-gotoline-quick-access'
80
80
  import { GotoSymbolQuickAccessContribution } from './monaco-gotosymbol-quick-access';
81
81
  import { QuickAccessContribution, QuickAccessRegistry } from '@theia/core/lib/browser/quick-input/quick-access';
82
82
  import { MonacoQuickAccessRegistry } from './monaco-quick-access-registry';
83
- import { ContextKeyService as VSCodeContextKeyService } from '@theia/monaco-editor-core/esm/vs/platform/contextkey/browser/contextKeyService';
84
83
  import { ConfigurationTarget, IConfigurationChangeEvent, IConfigurationService } from '@theia/monaco-editor-core/esm/vs/platform/configuration/common/configuration';
85
- import { StandaloneConfigurationService, StandaloneServices } from '@theia/monaco-editor-core/esm/vs/editor/standalone/browser/standaloneServices';
84
+ import { StandaloneConfigurationService } from '@theia/monaco-editor-core/esm/vs/editor/standalone/browser/standaloneServices';
86
85
  import { Configuration } from '@theia/monaco-editor-core/esm/vs/platform/configuration/common/configurationModels';
87
86
  import { MarkdownRenderer } from '@theia/core/lib/browser/markdown-rendering/markdown-renderer';
88
87
  import { MonacoMarkdownRenderer } from './markdown-renderer/monaco-markdown-renderer';
89
88
  import { ThemeService } from '@theia/core/lib/browser/theming';
90
89
  import { ThemeServiceWithDB } from './monaco-indexed-db';
91
-
92
- decorate(injectable(), VSCodeContextKeyService);
90
+ import { IContextKeyService } from '@theia/monaco-editor-core/esm/vs/platform/contextkey/common/contextkey';
91
+ import { IThemeService } from '@theia/monaco-editor-core/esm/vs/platform/theme/common/themeService';
93
92
 
94
93
  export default new ContainerModule((bind, unbind, isBound, rebind) => {
95
94
  bind(MonacoThemingService).toSelf().inSingletonScope();
@@ -114,15 +113,16 @@ export default new ContainerModule((bind, unbind, isBound, rebind) => {
114
113
 
115
114
  bind(MonacoWorkspace).toSelf().inSingletonScope();
116
115
 
117
- bind(MonacoConfigurationService).toDynamicValue(({ container }) =>
118
- createMonacoConfigurationService(container)
119
- ).inSingletonScope();
120
- bind(VSCodeContextKeyService).toDynamicValue(({ container }) =>
121
- new VSCodeContextKeyService(container.get(MonacoConfigurationService))
122
- ).inSingletonScope();
116
+ bind(MonacoConfigurationService).toDynamicValue(({ container }) => createMonacoConfigurationService(container)).inSingletonScope();
123
117
 
124
118
  bind(MonacoBulkEditService).toSelf().inSingletonScope();
125
- bind(MonacoEditorService).toSelf().inSingletonScope();
119
+ bind(MonacoEditorServiceFactory).toFactory((context: interfaces.Context) => (contextKeyService: IContextKeyService, themeService: IThemeService) => {
120
+ const child = context.container.createChild();
121
+ child.bind(VSCodeContextKeyService).toConstantValue(contextKeyService);
122
+ child.bind(VSCodeThemeService).toConstantValue(themeService);
123
+ child.bind(MonacoEditorService).toSelf().inSingletonScope();
124
+ return child.get(MonacoEditorService);
125
+ });
126
126
  bind(MonacoTextModelService).toSelf().inSingletonScope();
127
127
  bind(MonacoContextMenuService).toSelf().inSingletonScope();
128
128
  bind(MonacoEditorServices).toSelf().inSingletonScope();
@@ -130,7 +130,6 @@ export default new ContainerModule((bind, unbind, isBound, rebind) => {
130
130
  bindContributionProvider(bind, MonacoEditorFactory);
131
131
  bindContributionProvider(bind, MonacoEditorModelFactory);
132
132
  bind(MonacoCommandService).toSelf().inTransientScope();
133
- bind(MonacoCommandServiceFactory).toAutoFactory(MonacoCommandService);
134
133
 
135
134
  bind(TextEditorProvider).toProvider(context =>
136
135
  uri => context.container.get(MonacoEditorProvider).get(uri)
@@ -198,7 +197,7 @@ export const MonacoConfigurationService = Symbol('MonacoConfigurationService');
198
197
  export function createMonacoConfigurationService(container: interfaces.Container): IConfigurationService {
199
198
  const preferences = container.get<PreferenceService>(PreferenceService);
200
199
  const preferenceSchemaProvider = container.get<PreferenceSchemaProvider>(PreferenceSchemaProvider);
201
- const service = StandaloneServices.get(IConfigurationService) as StandaloneConfigurationService;
200
+ const service = new StandaloneConfigurationService();
202
201
  const _configuration: Configuration = service['_configuration'];
203
202
 
204
203
  _configuration.getValue = (section, overrides) => {
@@ -216,6 +215,14 @@ export function createMonacoConfigurationService(container: interfaces.Container
216
215
  return proxy;
217
216
  };
218
217
 
218
+ /*
219
+ * Since we never read values from the underlying service, writing to it doesn't make sense. The standalone editor writes to the configuration when being created,
220
+ * which makes sense in the standalone case where there is no preference infrastructure in place. Those writes degrade the performance, however, so we patch the
221
+ * service to an empty implementation.
222
+ */
223
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
224
+ service.updateValues = (values: [string, any][]) => Promise.resolve();
225
+
219
226
  const toTarget = (scope: PreferenceScope): ConfigurationTarget => {
220
227
  switch (scope) {
221
228
  case PreferenceScope.Default: return ConfigurationTarget.DEFAULT;
@@ -246,11 +253,12 @@ export function createMonacoConfigurationService(container: interfaces.Container
246
253
  overrides.push([override, [...values]]);
247
254
  }
248
255
  service['_onDidChangeConfiguration'].fire(<IConfigurationChangeEvent>{
256
+ sourceConfig: {},
249
257
  change: {
250
258
  keys: [...context.keys],
251
259
  overrides
252
260
  },
253
- affectedKeys: [...context.affectedKeys],
261
+ affectedKeys: context.affectedKeys,
254
262
  source,
255
263
  affectsConfiguration: (prefix, options) => {
256
264
  if (!context.affectedKeys.has(prefix)) {
@@ -15,9 +15,9 @@
15
15
  // *****************************************************************************
16
16
 
17
17
  import { injectable } from '@theia/core/shared/inversify';
18
- import { ThemeIcon } from '@theia/monaco-editor-core/esm/vs/platform/theme/common/themeService';
19
18
  import { IconRegistry } from '@theia/core/lib/browser/icon-registry';
20
- import { IconDefinition, IconFontDefinition, getIconRegistry } from '@theia/monaco-editor-core/esm/vs/platform/theme/common/iconRegistry';
19
+ import { getIconRegistry } from '@theia/monaco-editor-core/esm/vs/platform/theme/common/iconRegistry';
20
+ import { IconDefinition, IconFontDefinition, ThemeIcon } from '@theia/core/lib/common/theme';
21
21
 
22
22
  @injectable()
23
23
  export class MonacoIconRegistry implements IconRegistry {
@@ -33,7 +33,8 @@ export class MonacoIconRegistry implements IconRegistry {
33
33
  }
34
34
 
35
35
  registerIconFont(id: string, definition: IconFontDefinition): IconFontDefinition {
36
- return this.iconRegistry.registerIconFont(id, definition);
36
+ // need to cast because of vscode issue https://github.com/microsoft/vscode/issues/190584
37
+ return this.iconRegistry.registerIconFont(id, definition) as IconFontDefinition;
37
38
  }
38
39
 
39
40
  deregisterIconFont(id: string): void {
@@ -41,7 +42,8 @@ export class MonacoIconRegistry implements IconRegistry {
41
42
  }
42
43
 
43
44
  getIconFont(id: string): IconFontDefinition | undefined {
44
- return this.iconRegistry.getIconFont(id);
45
+ // need to cast because of vscode issue https://github.com/microsoft/vscode/issues/190584
46
+ return this.iconRegistry.getIconFont(id) as IconFontDefinition;
45
47
  }
46
48
  }
47
49