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

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 (77) 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-editor-zone-widget.js +1 -1
  14. package/lib/browser/monaco-frontend-application-contribution.js +25 -25
  15. package/lib/browser/simple-monaco-editor.d.ts +3 -1
  16. package/lib/browser/simple-monaco-editor.d.ts.map +1 -1
  17. package/lib/browser/simple-monaco-editor.js +9 -2
  18. package/lib/browser/simple-monaco-editor.js.map +1 -1
  19. package/package.json +8 -8
  20. package/src/browser/index.ts +17 -17
  21. package/src/browser/markdown-renderer/monaco-markdown-renderer.ts +109 -109
  22. package/src/browser/monaco-bulk-edit-service.ts +64 -64
  23. package/src/browser/monaco-color-registry.ts +73 -73
  24. package/src/browser/monaco-command-registry.ts +85 -85
  25. package/src/browser/monaco-command-service.ts +90 -90
  26. package/src/browser/monaco-command.ts +303 -303
  27. package/src/browser/monaco-context-key-service.ts +144 -144
  28. package/src/browser/monaco-context-menu.ts +112 -112
  29. package/src/browser/monaco-diff-editor.ts +141 -141
  30. package/src/browser/monaco-diff-navigator-factory.ts +39 -39
  31. package/src/browser/monaco-editor-model.ts +693 -693
  32. package/src/browser/monaco-editor-peek-view-widget.ts +233 -233
  33. package/src/browser/monaco-editor-provider.ts +455 -455
  34. package/src/browser/monaco-editor-service.ts +152 -152
  35. package/src/browser/monaco-editor-zone-widget.ts +250 -250
  36. package/src/browser/monaco-editor.ts +733 -733
  37. package/src/browser/monaco-formatting-conflicts.ts +116 -116
  38. package/src/browser/monaco-frontend-application-contribution.ts +182 -182
  39. package/src/browser/monaco-frontend-module.ts +319 -319
  40. package/src/browser/monaco-gotoline-quick-access.ts +47 -47
  41. package/src/browser/monaco-gotosymbol-quick-access.ts +53 -53
  42. package/src/browser/monaco-icon-registry.ts +49 -49
  43. package/src/browser/monaco-indexed-db.ts +130 -130
  44. package/src/browser/monaco-init.ts +134 -134
  45. package/src/browser/monaco-keybinding.ts +111 -111
  46. package/src/browser/monaco-keycode-map.ts +171 -171
  47. package/src/browser/monaco-languages.ts +177 -177
  48. package/src/browser/monaco-marker-collection.ts +83 -83
  49. package/src/browser/monaco-menu.ts +147 -147
  50. package/src/browser/monaco-mime-service.ts +71 -71
  51. package/src/browser/monaco-outline-contribution.ts +404 -404
  52. package/src/browser/monaco-outline-decorator.ts +66 -66
  53. package/src/browser/monaco-quick-access-registry.ts +112 -112
  54. package/src/browser/monaco-quick-input-service.ts +701 -701
  55. package/src/browser/monaco-resolved-keybinding.ts +162 -162
  56. package/src/browser/monaco-snippet-suggest-provider.ts +306 -306
  57. package/src/browser/monaco-standalone-theme-service.ts +51 -51
  58. package/src/browser/monaco-status-bar-contribution.ts +110 -110
  59. package/src/browser/monaco-text-model-service.ts +157 -157
  60. package/src/browser/monaco-theming-service.ts +204 -204
  61. package/src/browser/monaco-to-protocol-converter.ts +82 -82
  62. package/src/browser/monaco-undo-redo-handler.ts +64 -64
  63. package/src/browser/monaco-workspace.ts +416 -416
  64. package/src/browser/protocol-to-monaco-converter.ts +158 -158
  65. package/src/browser/simple-monaco-editor.ts +228 -216
  66. package/src/browser/style/index.css +266 -266
  67. package/src/browser/textmate/index.ts +20 -20
  68. package/src/browser/textmate/monaco-textmate-frontend-bindings.ts +90 -90
  69. package/src/browser/textmate/monaco-textmate-service.ts +187 -187
  70. package/src/browser/textmate/monaco-theme-registry.ts +176 -176
  71. package/src/browser/textmate/monaco-theme-types.ts +37 -37
  72. package/src/browser/textmate/textmate-contribution.ts +29 -29
  73. package/src/browser/textmate/textmate-registry.ts +129 -129
  74. package/src/browser/textmate/textmate-snippet-completion-provider.ts +73 -73
  75. package/src/browser/textmate/textmate-tokenizer.ts +84 -84
  76. package/src/browser/workspace-symbol-command.ts +196 -196
  77. package/src/package.spec.ts +28 -28
@@ -1,51 +1,51 @@
1
- /* eslint-disable @typescript-eslint/no-explicit-any */
2
- // *****************************************************************************
3
- // Copyright (C) 2024 STMicroelectronics and others.
4
- //
5
- // This program and the accompanying materials are made available under the
6
- // terms of the Eclipse Public License v. 2.0 which is available at
7
- // http://www.eclipse.org/legal/epl-2.0.
8
- //
9
- // This Source Code may also be made available under the following Secondary
10
- // Licenses when the conditions for such availability set forth in the Eclipse
11
- // Public License v. 2.0 are satisfied: GNU General Public License, version 2
12
- // with the GNU Classpath Exception which is available at
13
- // https://www.gnu.org/software/classpath/license.html.
14
- //
15
- // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
16
- // *****************************************************************************
17
-
18
- import { IDisposable } from '@theia/monaco-editor-core/esm/vs/base/common/lifecycle';
19
- import { StandaloneThemeService } from '@theia/monaco-editor-core/esm/vs/editor/standalone/browser/standaloneThemeService';
20
-
21
- export class MonacoStandaloneThemeService extends StandaloneThemeService {
22
- protected get styleElements(): HTMLStyleElement[] {
23
- // access private style element array
24
- return (this as any)._styleElements;
25
- }
26
-
27
- protected get allCSS(): string {
28
- return (this as any)._allCSS;
29
- }
30
-
31
- override registerEditorContainer(domNode: HTMLElement): IDisposable {
32
- const style = domNode.ownerDocument.createElement('style');
33
- style.type = 'text/css';
34
- style.media = 'screen';
35
- style.className = 'monaco-colors';
36
- style.textContent = this.allCSS;
37
- domNode.ownerDocument.head.appendChild(style);
38
- this.styleElements.push(style);
39
- return {
40
- dispose: () => {
41
- for (let i = 0; i < this.styleElements.length; i++) {
42
- if (this.styleElements[i] === style) {
43
- this.styleElements.splice(i, 1);
44
- style.remove();
45
- return;
46
- }
47
- }
48
- }
49
- };
50
- }
51
- }
1
+ /* eslint-disable @typescript-eslint/no-explicit-any */
2
+ // *****************************************************************************
3
+ // Copyright (C) 2024 STMicroelectronics and others.
4
+ //
5
+ // This program and the accompanying materials are made available under the
6
+ // terms of the Eclipse Public License v. 2.0 which is available at
7
+ // http://www.eclipse.org/legal/epl-2.0.
8
+ //
9
+ // This Source Code may also be made available under the following Secondary
10
+ // Licenses when the conditions for such availability set forth in the Eclipse
11
+ // Public License v. 2.0 are satisfied: GNU General Public License, version 2
12
+ // with the GNU Classpath Exception which is available at
13
+ // https://www.gnu.org/software/classpath/license.html.
14
+ //
15
+ // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
16
+ // *****************************************************************************
17
+
18
+ import { IDisposable } from '@theia/monaco-editor-core/esm/vs/base/common/lifecycle';
19
+ import { StandaloneThemeService } from '@theia/monaco-editor-core/esm/vs/editor/standalone/browser/standaloneThemeService';
20
+
21
+ export class MonacoStandaloneThemeService extends StandaloneThemeService {
22
+ protected get styleElements(): HTMLStyleElement[] {
23
+ // access private style element array
24
+ return (this as any)._styleElements;
25
+ }
26
+
27
+ protected get allCSS(): string {
28
+ return (this as any)._allCSS;
29
+ }
30
+
31
+ override registerEditorContainer(domNode: HTMLElement): IDisposable {
32
+ const style = domNode.ownerDocument.createElement('style');
33
+ style.type = 'text/css';
34
+ style.media = 'screen';
35
+ style.className = 'monaco-colors';
36
+ style.textContent = this.allCSS;
37
+ domNode.ownerDocument.head.appendChild(style);
38
+ this.styleElements.push(style);
39
+ return {
40
+ dispose: () => {
41
+ for (let i = 0; i < this.styleElements.length; i++) {
42
+ if (this.styleElements[i] === style) {
43
+ this.styleElements.splice(i, 1);
44
+ style.remove();
45
+ return;
46
+ }
47
+ }
48
+ }
49
+ };
50
+ }
51
+ }
@@ -1,110 +1,110 @@
1
- // *****************************************************************************
2
- // Copyright (C) 2018 Ericsson
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
- import { injectable, inject } from '@theia/core/shared/inversify';
18
- import { DisposableCollection, nls } from '@theia/core';
19
- import { FrontendApplicationContribution, FrontendApplication, StatusBar, StatusBarAlignment } from '@theia/core/lib/browser';
20
- import { EditorCommands, EditorManager, EditorWidget } from '@theia/editor/lib/browser';
21
- import { MonacoEditor } from './monaco-editor';
22
- import * as monaco from '@theia/monaco-editor-core';
23
-
24
- @injectable()
25
- export class MonacoStatusBarContribution implements FrontendApplicationContribution {
26
-
27
- protected readonly toDispose = new DisposableCollection();
28
-
29
- constructor(
30
- @inject(EditorManager) protected readonly editorManager: EditorManager,
31
- @inject(StatusBar) protected readonly statusBar: StatusBar
32
- ) { }
33
-
34
- onStart(app: FrontendApplication): void {
35
- this.updateStatusBar();
36
- this.editorManager.onCurrentEditorChanged(() => this.updateStatusBar());
37
- }
38
-
39
- protected updateStatusBar(): void {
40
- const editor = this.editorManager.currentEditor;
41
- const editorModel = this.getModel(editor);
42
- if (editor && editorModel) {
43
- this.setConfigTabSizeWidget();
44
- this.setLineEndingWidget();
45
-
46
- this.toDispose.dispose();
47
- this.toDispose.push(editorModel.onDidChangeOptions(() => {
48
- this.setConfigTabSizeWidget();
49
- this.setLineEndingWidget();
50
- }));
51
- let previous = editorModel.getEOL();
52
- this.toDispose.push(editorModel.onDidChangeContent(e => {
53
- if (previous !== e.eol) {
54
- previous = e.eol;
55
- this.setLineEndingWidget();
56
- }
57
- }));
58
- } else {
59
- this.removeConfigTabSizeWidget();
60
- this.removeLineEndingWidget();
61
- }
62
- }
63
-
64
- protected setConfigTabSizeWidget(): void {
65
- const editor = this.editorManager.currentEditor;
66
- const editorModel = this.getModel(editor);
67
- if (editor && editorModel) {
68
- const modelOptions = editorModel.getOptions();
69
- const tabSize = modelOptions.tabSize;
70
- const indentSize = modelOptions.indentSize;
71
- const spaceOrTabSizeMessage = modelOptions.insertSpaces
72
- ? nls.localizeByDefault('Spaces: {0}', indentSize)
73
- : nls.localizeByDefault('Tab Size: {0}', tabSize);
74
- this.statusBar.setElement('editor-status-tabbing-config', {
75
- text: spaceOrTabSizeMessage,
76
- alignment: StatusBarAlignment.RIGHT,
77
- priority: 10,
78
- command: EditorCommands.CONFIG_INDENTATION.id,
79
- tooltip: nls.localizeByDefault('Select Indentation')
80
- });
81
- }
82
- }
83
- protected removeConfigTabSizeWidget(): void {
84
- this.statusBar.removeElement('editor-status-tabbing-config');
85
- }
86
-
87
- protected setLineEndingWidget(): void {
88
- const editor = this.editorManager.currentEditor;
89
- const editorModel = this.getModel(editor);
90
- if (editor && editorModel) {
91
- const eol = editorModel.getEOL();
92
- const text = eol === '\n' ? 'LF' : 'CRLF';
93
- this.statusBar.setElement('editor-status-eol', {
94
- text: `${text}`,
95
- alignment: StatusBarAlignment.RIGHT,
96
- priority: 11,
97
- command: EditorCommands.CONFIG_EOL.id,
98
- tooltip: nls.localizeByDefault('Select End of Line Sequence')
99
- });
100
- }
101
- }
102
- protected removeLineEndingWidget(): void {
103
- this.statusBar.removeElement('editor-status-eol');
104
- }
105
-
106
- protected getModel(editor: EditorWidget | undefined): monaco.editor.ITextModel | undefined {
107
- const monacoEditor = MonacoEditor.get(editor);
108
- return monacoEditor && monacoEditor.getControl().getModel() || undefined;
109
- }
110
- }
1
+ // *****************************************************************************
2
+ // Copyright (C) 2018 Ericsson
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
+ import { injectable, inject } from '@theia/core/shared/inversify';
18
+ import { DisposableCollection, nls } from '@theia/core';
19
+ import { FrontendApplicationContribution, FrontendApplication, StatusBar, StatusBarAlignment } from '@theia/core/lib/browser';
20
+ import { EditorCommands, EditorManager, EditorWidget } from '@theia/editor/lib/browser';
21
+ import { MonacoEditor } from './monaco-editor';
22
+ import * as monaco from '@theia/monaco-editor-core';
23
+
24
+ @injectable()
25
+ export class MonacoStatusBarContribution implements FrontendApplicationContribution {
26
+
27
+ protected readonly toDispose = new DisposableCollection();
28
+
29
+ constructor(
30
+ @inject(EditorManager) protected readonly editorManager: EditorManager,
31
+ @inject(StatusBar) protected readonly statusBar: StatusBar
32
+ ) { }
33
+
34
+ onStart(app: FrontendApplication): void {
35
+ this.updateStatusBar();
36
+ this.editorManager.onCurrentEditorChanged(() => this.updateStatusBar());
37
+ }
38
+
39
+ protected updateStatusBar(): void {
40
+ const editor = this.editorManager.currentEditor;
41
+ const editorModel = this.getModel(editor);
42
+ if (editor && editorModel) {
43
+ this.setConfigTabSizeWidget();
44
+ this.setLineEndingWidget();
45
+
46
+ this.toDispose.dispose();
47
+ this.toDispose.push(editorModel.onDidChangeOptions(() => {
48
+ this.setConfigTabSizeWidget();
49
+ this.setLineEndingWidget();
50
+ }));
51
+ let previous = editorModel.getEOL();
52
+ this.toDispose.push(editorModel.onDidChangeContent(e => {
53
+ if (previous !== e.eol) {
54
+ previous = e.eol;
55
+ this.setLineEndingWidget();
56
+ }
57
+ }));
58
+ } else {
59
+ this.removeConfigTabSizeWidget();
60
+ this.removeLineEndingWidget();
61
+ }
62
+ }
63
+
64
+ protected setConfigTabSizeWidget(): void {
65
+ const editor = this.editorManager.currentEditor;
66
+ const editorModel = this.getModel(editor);
67
+ if (editor && editorModel) {
68
+ const modelOptions = editorModel.getOptions();
69
+ const tabSize = modelOptions.tabSize;
70
+ const indentSize = modelOptions.indentSize;
71
+ const spaceOrTabSizeMessage = modelOptions.insertSpaces
72
+ ? nls.localizeByDefault('Spaces: {0}', indentSize)
73
+ : nls.localizeByDefault('Tab Size: {0}', tabSize);
74
+ this.statusBar.setElement('editor-status-tabbing-config', {
75
+ text: spaceOrTabSizeMessage,
76
+ alignment: StatusBarAlignment.RIGHT,
77
+ priority: 10,
78
+ command: EditorCommands.CONFIG_INDENTATION.id,
79
+ tooltip: nls.localizeByDefault('Select Indentation')
80
+ });
81
+ }
82
+ }
83
+ protected removeConfigTabSizeWidget(): void {
84
+ this.statusBar.removeElement('editor-status-tabbing-config');
85
+ }
86
+
87
+ protected setLineEndingWidget(): void {
88
+ const editor = this.editorManager.currentEditor;
89
+ const editorModel = this.getModel(editor);
90
+ if (editor && editorModel) {
91
+ const eol = editorModel.getEOL();
92
+ const text = eol === '\n' ? 'LF' : 'CRLF';
93
+ this.statusBar.setElement('editor-status-eol', {
94
+ text: `${text}`,
95
+ alignment: StatusBarAlignment.RIGHT,
96
+ priority: 11,
97
+ command: EditorCommands.CONFIG_EOL.id,
98
+ tooltip: nls.localizeByDefault('Select End of Line Sequence')
99
+ });
100
+ }
101
+ }
102
+ protected removeLineEndingWidget(): void {
103
+ this.statusBar.removeElement('editor-status-eol');
104
+ }
105
+
106
+ protected getModel(editor: EditorWidget | undefined): monaco.editor.ITextModel | undefined {
107
+ const monacoEditor = MonacoEditor.get(editor);
108
+ return monacoEditor && monacoEditor.getControl().getModel() || undefined;
109
+ }
110
+ }
@@ -1,157 +1,157 @@
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
- import { inject, injectable, named, postConstruct } from '@theia/core/shared/inversify';
18
- import URI from '@theia/core/lib/common/uri';
19
- import { ResourceProvider, ReferenceCollection, Event, MaybePromise, Resource, ContributionProvider, OS } from '@theia/core';
20
- import { EditorPreferences, EditorPreferenceChange } from '@theia/editor/lib/browser';
21
- import { MonacoEditorModel } from './monaco-editor-model';
22
- import { IDisposable, IReference } from '@theia/monaco-editor-core/esm/vs/base/common/lifecycle';
23
- import { MonacoToProtocolConverter } from './monaco-to-protocol-converter';
24
- import { ProtocolToMonacoConverter } from './protocol-to-monaco-converter';
25
- import { ILogger } from '@theia/core/lib/common/logger';
26
- import * as monaco from '@theia/monaco-editor-core';
27
- import { ITextModelService, ITextModelContentProvider } from '@theia/monaco-editor-core/esm/vs/editor/common/services/resolverService';
28
- import { ITextModelUpdateOptions } from '@theia/monaco-editor-core/esm/vs/editor/common/model';
29
- import { FileService } from '@theia/filesystem/lib/browser/file-service';
30
- import { StandaloneServices } from '@theia/monaco-editor-core/esm/vs/editor/standalone/browser/standaloneServices';
31
- import { ITextResourcePropertiesService } from '@theia/monaco-editor-core/esm/vs/editor/common/services/textResourceConfiguration';
32
-
33
- export const MonacoEditorModelFactory = Symbol('MonacoEditorModelFactory');
34
- export interface MonacoEditorModelFactory {
35
-
36
- readonly scheme: string;
37
-
38
- createModel(
39
- resource: Resource
40
- ): MaybePromise<MonacoEditorModel>;
41
-
42
- }
43
-
44
- @injectable()
45
- export class MonacoTextModelService implements ITextModelService {
46
- declare readonly _serviceBrand: undefined;
47
-
48
- protected readonly _models = new ReferenceCollection<string, MonacoEditorModel>(
49
- uri => this.loadModel(new URI(uri))
50
- );
51
-
52
- @inject(ResourceProvider)
53
- protected readonly resourceProvider: ResourceProvider;
54
-
55
- @inject(EditorPreferences)
56
- protected readonly editorPreferences: EditorPreferences;
57
-
58
- @inject(MonacoToProtocolConverter)
59
- protected readonly m2p: MonacoToProtocolConverter;
60
-
61
- @inject(ProtocolToMonacoConverter)
62
- protected readonly p2m: ProtocolToMonacoConverter;
63
-
64
- @inject(ContributionProvider)
65
- @named(MonacoEditorModelFactory)
66
- protected readonly factories: ContributionProvider<MonacoEditorModelFactory>;
67
-
68
- @inject(ILogger)
69
- protected readonly logger: ILogger;
70
-
71
- @inject(FileService)
72
- protected readonly fileService: FileService;
73
-
74
- @postConstruct()
75
- protected init(): void {
76
- const resourcePropertiesService = StandaloneServices.get(ITextResourcePropertiesService);
77
-
78
- if (resourcePropertiesService) {
79
- resourcePropertiesService.getEOL = () => {
80
- const eol = this.editorPreferences['files.eol'];
81
- if (eol && eol !== 'auto') {
82
- return eol;
83
- }
84
- return OS.backend.EOL;
85
- };
86
- }
87
- }
88
-
89
- get models(): MonacoEditorModel[] {
90
- return this._models.values();
91
- }
92
-
93
- get(uri: string): MonacoEditorModel | undefined {
94
- return this._models.get(uri);
95
- }
96
-
97
- get onDidCreate(): Event<MonacoEditorModel> {
98
- return this._models.onDidCreate;
99
- }
100
-
101
- createModelReference(raw: monaco.Uri | URI): Promise<IReference<MonacoEditorModel>> {
102
- return this._models.acquire(raw.toString());
103
- }
104
-
105
- /**
106
- * creates a model which is not saved by the model service.
107
- * this will therefore also not be created on backend side.
108
- */
109
- createUnmanagedModel(raw: monaco.Uri | URI): Promise<MonacoEditorModel> {
110
- return this.loadModel(new URI(raw.toString()));
111
- }
112
-
113
- async loadModel(uri: URI): Promise<MonacoEditorModel> {
114
- await this.editorPreferences.ready;
115
- const resource = await this.resourceProvider(uri);
116
- const model = await (await this.createModel(resource)).load();
117
- return model;
118
- }
119
-
120
- protected createModel(resource: Resource): MaybePromise<MonacoEditorModel> {
121
- const factory = this.factories.getContributions().find(({ scheme }) => resource.uri.scheme === scheme);
122
- return factory ? factory.createModel(resource) : new MonacoEditorModel(resource, this.m2p, this.p2m, this.logger, this.editorPreferences);
123
- }
124
-
125
- protected readonly modelOptions: { [name: string]: (keyof ITextModelUpdateOptions | undefined) } = {
126
- 'editor.tabSize': 'tabSize',
127
- 'editor.insertSpaces': 'insertSpaces',
128
- 'editor.indentSize': 'indentSize'
129
- };
130
-
131
- protected toModelOption(editorPreference: EditorPreferenceChange['preferenceName']): keyof ITextModelUpdateOptions | undefined {
132
- switch (editorPreference) {
133
- case 'editor.tabSize': return 'tabSize';
134
- // @monaco-uplift: uncomment this line once 'editor.indentSize' preference is available
135
- // case 'editor.indentSize': return 'indentSize';
136
- case 'editor.insertSpaces': return 'insertSpaces';
137
- case 'editor.bracketPairColorization.enabled':
138
- case 'editor.bracketPairColorization.independentColorPoolPerBracketType':
139
- return 'bracketColorizationOptions';
140
- case 'editor.trimAutoWhitespace': return 'trimAutoWhitespace';
141
-
142
- }
143
- return undefined;
144
- }
145
-
146
- registerTextModelContentProvider(scheme: string, provider: ITextModelContentProvider): IDisposable {
147
- return {
148
- dispose(): void {
149
- // no-op
150
- }
151
- };
152
- }
153
-
154
- canHandleResource(resource: monaco.Uri): boolean {
155
- return this.fileService.canHandleResource(URI.fromComponents(resource));
156
- }
157
- }
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
+ import { inject, injectable, named, postConstruct } from '@theia/core/shared/inversify';
18
+ import URI from '@theia/core/lib/common/uri';
19
+ import { ResourceProvider, ReferenceCollection, Event, MaybePromise, Resource, ContributionProvider, OS } from '@theia/core';
20
+ import { EditorPreferences, EditorPreferenceChange } from '@theia/editor/lib/browser';
21
+ import { MonacoEditorModel } from './monaco-editor-model';
22
+ import { IDisposable, IReference } from '@theia/monaco-editor-core/esm/vs/base/common/lifecycle';
23
+ import { MonacoToProtocolConverter } from './monaco-to-protocol-converter';
24
+ import { ProtocolToMonacoConverter } from './protocol-to-monaco-converter';
25
+ import { ILogger } from '@theia/core/lib/common/logger';
26
+ import * as monaco from '@theia/monaco-editor-core';
27
+ import { ITextModelService, ITextModelContentProvider } from '@theia/monaco-editor-core/esm/vs/editor/common/services/resolverService';
28
+ import { ITextModelUpdateOptions } from '@theia/monaco-editor-core/esm/vs/editor/common/model';
29
+ import { FileService } from '@theia/filesystem/lib/browser/file-service';
30
+ import { StandaloneServices } from '@theia/monaco-editor-core/esm/vs/editor/standalone/browser/standaloneServices';
31
+ import { ITextResourcePropertiesService } from '@theia/monaco-editor-core/esm/vs/editor/common/services/textResourceConfiguration';
32
+
33
+ export const MonacoEditorModelFactory = Symbol('MonacoEditorModelFactory');
34
+ export interface MonacoEditorModelFactory {
35
+
36
+ readonly scheme: string;
37
+
38
+ createModel(
39
+ resource: Resource
40
+ ): MaybePromise<MonacoEditorModel>;
41
+
42
+ }
43
+
44
+ @injectable()
45
+ export class MonacoTextModelService implements ITextModelService {
46
+ declare readonly _serviceBrand: undefined;
47
+
48
+ protected readonly _models = new ReferenceCollection<string, MonacoEditorModel>(
49
+ uri => this.loadModel(new URI(uri))
50
+ );
51
+
52
+ @inject(ResourceProvider)
53
+ protected readonly resourceProvider: ResourceProvider;
54
+
55
+ @inject(EditorPreferences)
56
+ protected readonly editorPreferences: EditorPreferences;
57
+
58
+ @inject(MonacoToProtocolConverter)
59
+ protected readonly m2p: MonacoToProtocolConverter;
60
+
61
+ @inject(ProtocolToMonacoConverter)
62
+ protected readonly p2m: ProtocolToMonacoConverter;
63
+
64
+ @inject(ContributionProvider)
65
+ @named(MonacoEditorModelFactory)
66
+ protected readonly factories: ContributionProvider<MonacoEditorModelFactory>;
67
+
68
+ @inject(ILogger)
69
+ protected readonly logger: ILogger;
70
+
71
+ @inject(FileService)
72
+ protected readonly fileService: FileService;
73
+
74
+ @postConstruct()
75
+ protected init(): void {
76
+ const resourcePropertiesService = StandaloneServices.get(ITextResourcePropertiesService);
77
+
78
+ if (resourcePropertiesService) {
79
+ resourcePropertiesService.getEOL = () => {
80
+ const eol = this.editorPreferences['files.eol'];
81
+ if (eol && eol !== 'auto') {
82
+ return eol;
83
+ }
84
+ return OS.backend.EOL;
85
+ };
86
+ }
87
+ }
88
+
89
+ get models(): MonacoEditorModel[] {
90
+ return this._models.values();
91
+ }
92
+
93
+ get(uri: string): MonacoEditorModel | undefined {
94
+ return this._models.get(uri);
95
+ }
96
+
97
+ get onDidCreate(): Event<MonacoEditorModel> {
98
+ return this._models.onDidCreate;
99
+ }
100
+
101
+ createModelReference(raw: monaco.Uri | URI): Promise<IReference<MonacoEditorModel>> {
102
+ return this._models.acquire(raw.toString());
103
+ }
104
+
105
+ /**
106
+ * creates a model which is not saved by the model service.
107
+ * this will therefore also not be created on backend side.
108
+ */
109
+ createUnmanagedModel(raw: monaco.Uri | URI): Promise<MonacoEditorModel> {
110
+ return this.loadModel(new URI(raw.toString()));
111
+ }
112
+
113
+ async loadModel(uri: URI): Promise<MonacoEditorModel> {
114
+ await this.editorPreferences.ready;
115
+ const resource = await this.resourceProvider(uri);
116
+ const model = await (await this.createModel(resource)).load();
117
+ return model;
118
+ }
119
+
120
+ protected createModel(resource: Resource): MaybePromise<MonacoEditorModel> {
121
+ const factory = this.factories.getContributions().find(({ scheme }) => resource.uri.scheme === scheme);
122
+ return factory ? factory.createModel(resource) : new MonacoEditorModel(resource, this.m2p, this.p2m, this.logger, this.editorPreferences);
123
+ }
124
+
125
+ protected readonly modelOptions: { [name: string]: (keyof ITextModelUpdateOptions | undefined) } = {
126
+ 'editor.tabSize': 'tabSize',
127
+ 'editor.insertSpaces': 'insertSpaces',
128
+ 'editor.indentSize': 'indentSize'
129
+ };
130
+
131
+ protected toModelOption(editorPreference: EditorPreferenceChange['preferenceName']): keyof ITextModelUpdateOptions | undefined {
132
+ switch (editorPreference) {
133
+ case 'editor.tabSize': return 'tabSize';
134
+ // @monaco-uplift: uncomment this line once 'editor.indentSize' preference is available
135
+ // case 'editor.indentSize': return 'indentSize';
136
+ case 'editor.insertSpaces': return 'insertSpaces';
137
+ case 'editor.bracketPairColorization.enabled':
138
+ case 'editor.bracketPairColorization.independentColorPoolPerBracketType':
139
+ return 'bracketColorizationOptions';
140
+ case 'editor.trimAutoWhitespace': return 'trimAutoWhitespace';
141
+
142
+ }
143
+ return undefined;
144
+ }
145
+
146
+ registerTextModelContentProvider(scheme: string, provider: ITextModelContentProvider): IDisposable {
147
+ return {
148
+ dispose(): void {
149
+ // no-op
150
+ }
151
+ };
152
+ }
153
+
154
+ canHandleResource(resource: monaco.Uri): boolean {
155
+ return this.fileService.canHandleResource(URI.fromComponents(resource));
156
+ }
157
+ }