@theia/monaco 1.53.0-next.4 → 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,116 +1,116 @@
1
- // *****************************************************************************
2
- // Copyright (C) 2020 Red Hat, Inc. 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 { injectable, inject } from '@theia/core/shared/inversify';
18
- import { PreferenceService, FrontendApplicationContribution, PreferenceLanguageOverrideService } from '@theia/core/lib/browser';
19
- import { EditorManager } from '@theia/editor/lib/browser';
20
- import { MonacoQuickInputService } from './monaco-quick-input-service';
21
- import * as monaco from '@theia/monaco-editor-core';
22
- import { FormattingConflicts, FormattingMode } from '@theia/monaco-editor-core/esm/vs/editor/contrib/format/browser/format';
23
- import { DocumentFormattingEditProvider, DocumentRangeFormattingEditProvider } from '@theia/monaco-editor-core/esm/vs/editor/common/languages';
24
- import { ITextModel } from '@theia/monaco-editor-core/esm/vs/editor/common/model';
25
- import { nls } from '@theia/core/lib/common/nls';
26
-
27
- type FormattingEditProvider = DocumentFormattingEditProvider | DocumentRangeFormattingEditProvider;
28
-
29
- const PREFERENCE_NAME = 'editor.defaultFormatter';
30
-
31
- @injectable()
32
- export class MonacoFormattingConflictsContribution implements FrontendApplicationContribution {
33
-
34
- @inject(MonacoQuickInputService)
35
- protected readonly monacoQuickInputService: MonacoQuickInputService;
36
-
37
- @inject(PreferenceService)
38
- protected readonly preferenceService: PreferenceService;
39
-
40
- @inject(PreferenceLanguageOverrideService)
41
- protected readonly preferenceSchema: PreferenceLanguageOverrideService;
42
-
43
- @inject(EditorManager)
44
- protected readonly editorManager: EditorManager;
45
-
46
- async initialize(): Promise<void> {
47
-
48
- FormattingConflicts.setFormatterSelector(<T extends FormattingEditProvider>(
49
- formatters: T[], document: ITextModel, mode: FormattingMode) =>
50
- this.selectFormatter(formatters, document, mode));
51
- }
52
-
53
- protected async setDefaultFormatter(language: string, formatter: string): Promise<void> {
54
- const name = this.preferenceSchema.overridePreferenceName({
55
- preferenceName: PREFERENCE_NAME,
56
- overrideIdentifier: language
57
- });
58
-
59
- await this.preferenceService.set(name, formatter);
60
- }
61
-
62
- private getDefaultFormatter(language: string, resourceURI: string): string | undefined {
63
- const name = this.preferenceSchema.overridePreferenceName({
64
- preferenceName: PREFERENCE_NAME,
65
- overrideIdentifier: language
66
- });
67
-
68
- return this.preferenceService.get<string>(name, undefined, resourceURI);
69
- }
70
-
71
- private async selectFormatter<T extends FormattingEditProvider>(
72
- formatters: T[], document: monaco.editor.ITextModel | ITextModel, mode: FormattingMode): Promise<T | undefined> {
73
-
74
- if (formatters.length === 0) {
75
- return undefined;
76
- }
77
-
78
- if (formatters.length === 1) {
79
- return formatters[0];
80
- }
81
-
82
- const currentEditor = this.editorManager.currentEditor;
83
- if (!currentEditor) {
84
- return undefined;
85
- }
86
-
87
- const languageId = currentEditor.editor.document.languageId;
88
- const defaultFormatterId = this.getDefaultFormatter(languageId, document.uri.toString());
89
-
90
- if (defaultFormatterId) {
91
- const formatter = formatters.find(f => f.extensionId && f.extensionId.value === defaultFormatterId);
92
- if (formatter) {
93
- return formatter;
94
- }
95
- }
96
-
97
- return new Promise<T | undefined>(async (resolve, reject) => {
98
- const items = formatters
99
- .filter(formatter => formatter.displayName)
100
- .map(formatter => ({
101
- label: formatter.displayName!,
102
- detail: formatter.extensionId ? formatter.extensionId.value : undefined,
103
- value: formatter,
104
- }))
105
- .sort((a, b) => a.label!.localeCompare(b.label!));
106
-
107
- const selectedFormatter = await this.monacoQuickInputService.showQuickPick(items, { placeholder: nls.localizeByDefault('Format Document With...') });
108
- if (selectedFormatter) {
109
- this.setDefaultFormatter(languageId, selectedFormatter.detail ? selectedFormatter.detail : '');
110
- resolve(selectedFormatter.value);
111
- } else {
112
- resolve(undefined);
113
- }
114
- });
115
- }
116
- }
1
+ // *****************************************************************************
2
+ // Copyright (C) 2020 Red Hat, Inc. 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 { injectable, inject } from '@theia/core/shared/inversify';
18
+ import { PreferenceService, FrontendApplicationContribution, PreferenceLanguageOverrideService } from '@theia/core/lib/browser';
19
+ import { EditorManager } from '@theia/editor/lib/browser';
20
+ import { MonacoQuickInputService } from './monaco-quick-input-service';
21
+ import * as monaco from '@theia/monaco-editor-core';
22
+ import { FormattingConflicts, FormattingMode } from '@theia/monaco-editor-core/esm/vs/editor/contrib/format/browser/format';
23
+ import { DocumentFormattingEditProvider, DocumentRangeFormattingEditProvider } from '@theia/monaco-editor-core/esm/vs/editor/common/languages';
24
+ import { ITextModel } from '@theia/monaco-editor-core/esm/vs/editor/common/model';
25
+ import { nls } from '@theia/core/lib/common/nls';
26
+
27
+ type FormattingEditProvider = DocumentFormattingEditProvider | DocumentRangeFormattingEditProvider;
28
+
29
+ const PREFERENCE_NAME = 'editor.defaultFormatter';
30
+
31
+ @injectable()
32
+ export class MonacoFormattingConflictsContribution implements FrontendApplicationContribution {
33
+
34
+ @inject(MonacoQuickInputService)
35
+ protected readonly monacoQuickInputService: MonacoQuickInputService;
36
+
37
+ @inject(PreferenceService)
38
+ protected readonly preferenceService: PreferenceService;
39
+
40
+ @inject(PreferenceLanguageOverrideService)
41
+ protected readonly preferenceSchema: PreferenceLanguageOverrideService;
42
+
43
+ @inject(EditorManager)
44
+ protected readonly editorManager: EditorManager;
45
+
46
+ async initialize(): Promise<void> {
47
+
48
+ FormattingConflicts.setFormatterSelector(<T extends FormattingEditProvider>(
49
+ formatters: T[], document: ITextModel, mode: FormattingMode) =>
50
+ this.selectFormatter(formatters, document, mode));
51
+ }
52
+
53
+ protected async setDefaultFormatter(language: string, formatter: string): Promise<void> {
54
+ const name = this.preferenceSchema.overridePreferenceName({
55
+ preferenceName: PREFERENCE_NAME,
56
+ overrideIdentifier: language
57
+ });
58
+
59
+ await this.preferenceService.set(name, formatter);
60
+ }
61
+
62
+ private getDefaultFormatter(language: string, resourceURI: string): string | undefined {
63
+ const name = this.preferenceSchema.overridePreferenceName({
64
+ preferenceName: PREFERENCE_NAME,
65
+ overrideIdentifier: language
66
+ });
67
+
68
+ return this.preferenceService.get<string>(name, undefined, resourceURI);
69
+ }
70
+
71
+ private async selectFormatter<T extends FormattingEditProvider>(
72
+ formatters: T[], document: monaco.editor.ITextModel | ITextModel, mode: FormattingMode): Promise<T | undefined> {
73
+
74
+ if (formatters.length === 0) {
75
+ return undefined;
76
+ }
77
+
78
+ if (formatters.length === 1) {
79
+ return formatters[0];
80
+ }
81
+
82
+ const currentEditor = this.editorManager.currentEditor;
83
+ if (!currentEditor) {
84
+ return undefined;
85
+ }
86
+
87
+ const languageId = currentEditor.editor.document.languageId;
88
+ const defaultFormatterId = this.getDefaultFormatter(languageId, document.uri.toString());
89
+
90
+ if (defaultFormatterId) {
91
+ const formatter = formatters.find(f => f.extensionId && f.extensionId.value === defaultFormatterId);
92
+ if (formatter) {
93
+ return formatter;
94
+ }
95
+ }
96
+
97
+ return new Promise<T | undefined>(async (resolve, reject) => {
98
+ const items = formatters
99
+ .filter(formatter => formatter.displayName)
100
+ .map(formatter => ({
101
+ label: formatter.displayName!,
102
+ detail: formatter.extensionId ? formatter.extensionId.value : undefined,
103
+ value: formatter,
104
+ }))
105
+ .sort((a, b) => a.label!.localeCompare(b.label!));
106
+
107
+ const selectedFormatter = await this.monacoQuickInputService.showQuickPick(items, { placeholder: nls.localizeByDefault('Format Document With...') });
108
+ if (selectedFormatter) {
109
+ this.setDefaultFormatter(languageId, selectedFormatter.detail ? selectedFormatter.detail : '');
110
+ resolve(selectedFormatter.value);
111
+ } else {
112
+ resolve(undefined);
113
+ }
114
+ });
115
+ }
116
+ }
@@ -1,182 +1,182 @@
1
- // *****************************************************************************
2
- // Copyright (C) 2018 Ericsson 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 { injectable, inject, postConstruct } from '@theia/core/shared/inversify';
18
- import { ColorTheme, CssStyleCollector, FrontendApplicationContribution, PreferenceSchemaProvider, QuickAccessRegistry, StylingParticipant } from '@theia/core/lib/browser';
19
- import { MonacoSnippetSuggestProvider } from './monaco-snippet-suggest-provider';
20
- import * as monaco from '@theia/monaco-editor-core';
21
- import { setSnippetSuggestSupport } from '@theia/monaco-editor-core/esm/vs/editor/contrib/suggest/browser/suggest';
22
- import { CompletionItemProvider } from '@theia/monaco-editor-core/esm/vs/editor/common/languages';
23
- import { MonacoTextModelService } from './monaco-text-model-service';
24
- import { MonacoThemingService } from './monaco-theming-service';
25
- import { isHighContrast } from '@theia/core/lib/common/theme';
26
- import { editorOptionsRegistry, IEditorOption } from '@theia/monaco-editor-core/esm/vs/editor/common/config/editorOptions';
27
- import { MAX_SAFE_INTEGER } from '@theia/core';
28
- import { editorGeneratedPreferenceProperties } from '@theia/editor/lib/browser/editor-generated-preference-schema';
29
- import { WorkspaceFileService } from '@theia/workspace/lib/common/workspace-file-service';
30
- import { SecondaryWindowHandler } from '@theia/core/lib/browser/secondary-window-handler';
31
- import { EditorWidget } from '@theia/editor/lib/browser';
32
- import { MonacoEditor } from './monaco-editor';
33
- import { StandaloneServices } from '@theia/monaco-editor-core/esm/vs/editor/standalone/browser/standaloneServices';
34
- import { StandaloneThemeService } from '@theia/monaco-editor-core/esm/vs/editor/standalone/browser/standaloneThemeService';
35
- import { IStandaloneThemeService } from '@theia/monaco-editor-core/esm/vs/editor/standalone/common/standaloneTheme';
36
-
37
- @injectable()
38
- export class MonacoFrontendApplicationContribution implements FrontendApplicationContribution, StylingParticipant {
39
-
40
- @inject(MonacoTextModelService)
41
- protected readonly textModelService: MonacoTextModelService;
42
-
43
- @inject(MonacoSnippetSuggestProvider)
44
- protected readonly snippetSuggestProvider: MonacoSnippetSuggestProvider;
45
-
46
- @inject(PreferenceSchemaProvider)
47
- protected readonly preferenceSchema: PreferenceSchemaProvider;
48
-
49
- @inject(QuickAccessRegistry)
50
- protected readonly quickAccessRegistry: QuickAccessRegistry;
51
-
52
- @inject(MonacoThemingService) protected readonly monacoThemingService: MonacoThemingService;
53
-
54
- @inject(WorkspaceFileService) protected readonly workspaceFileService: WorkspaceFileService;
55
-
56
- @inject(SecondaryWindowHandler)
57
- protected readonly secondaryWindowHandler: SecondaryWindowHandler;
58
-
59
- @postConstruct()
60
- protected init(): void {
61
- this.addAdditionalPreferenceValidations();
62
- // Monaco registers certain quick access providers (e.g. QuickCommandAccess) at import time, but we want to use our own.
63
- this.quickAccessRegistry.clear();
64
-
65
- /**
66
- * @monaco-uplift.Should be guaranteed to work.
67
- * Incomparable enums prevent TypeScript from believing that public ITextModel satisfied private ITextModel
68
- */
69
- setSnippetSuggestSupport(this.snippetSuggestProvider as unknown as CompletionItemProvider);
70
-
71
- for (const language of monaco.languages.getLanguages()) {
72
- this.preferenceSchema.registerOverrideIdentifier(language.id);
73
- }
74
- const registerLanguage = monaco.languages.register.bind(monaco.languages);
75
- monaco.languages.register = language => {
76
- // first register override identifier, because monaco will immediately update already opened documents and then initialize with bad preferences.
77
- this.preferenceSchema.registerOverrideIdentifier(language.id);
78
- registerLanguage(language);
79
- };
80
-
81
- this.monacoThemingService.initialize();
82
- }
83
-
84
- initialize(): void {
85
- const workspaceExtensions = this.workspaceFileService.getWorkspaceFileExtensions();
86
- monaco.languages.register({
87
- id: 'jsonc',
88
- 'aliases': [
89
- 'JSON with Comments'
90
- ],
91
- 'extensions': workspaceExtensions.map(ext => `.${ext}`)
92
- });
93
- }
94
- onStart(): void {
95
- this.secondaryWindowHandler.onDidAddWidget(([widget, window]) => {
96
- if (widget instanceof EditorWidget && widget.editor instanceof MonacoEditor) {
97
- const themeService = StandaloneServices.get(IStandaloneThemeService) as StandaloneThemeService;
98
- themeService.registerEditorContainer(widget.node);
99
- }
100
- });
101
- }
102
-
103
- registerThemeStyle(theme: ColorTheme, collector: CssStyleCollector): void {
104
- if (isHighContrast(theme.type)) {
105
- const focusBorder = theme.getColor('focusBorder');
106
- const contrastBorder = theme.getColor('contrastBorder');
107
- if (focusBorder) {
108
- // Quick input
109
- collector.addRule(`
110
- .quick-input-list .monaco-list-row {
111
- outline-offset: -1px;
112
- }
113
- .quick-input-list .monaco-list-row.focused {
114
- outline: 1px dotted ${focusBorder};
115
- }
116
- .quick-input-list .monaco-list-row:hover {
117
- outline: 1px dashed ${focusBorder};
118
- }
119
- `);
120
- // Input box always displays an outline, even when unfocused
121
- collector.addRule(`
122
- .monaco-editor .find-widget .monaco-inputbox {
123
- outline: var(--theia-border-width) solid;
124
- outline-offset: calc(-1 * var(--theia-border-width));
125
- outline-color: var(--theia-focusBorder);
126
- }
127
- `);
128
- }
129
- if (contrastBorder) {
130
- collector.addRule(`
131
- .quick-input-widget {
132
- outline: 1px solid ${contrastBorder};
133
- outline-offset: -1px;
134
- }
135
- `);
136
- }
137
- } else {
138
- collector.addRule(`
139
- .quick-input-widget {
140
- box-shadow: rgb(0 0 0 / 36%) 0px 0px 8px 2px;
141
- }
142
- `);
143
- }
144
- }
145
-
146
- /**
147
- * For reasons that are unclear, while most preferences that apply in editors are validated, a few are not.
148
- * There is a utility in `examples/api-samples/src/browser/monaco-editor-preferences/monaco-editor-preference-extractor.ts` to help determine which are not.
149
- * Check `src/vs/editor/common/config/editorOptions.ts` for constructor arguments and to make sure that the preference names used to extract constructors are still accurate.
150
- */
151
- protected addAdditionalPreferenceValidations(): void {
152
- let editorIntConstructor: undefined | (new (...args: unknown[]) => IEditorOption<number, number>);
153
- let editorBoolConstructor: undefined | (new (...args: unknown[]) => IEditorOption<number, boolean>);
154
- let editorStringEnumConstructor: undefined | (new (...args: unknown[]) => IEditorOption<number, string>);
155
- for (const validator of editorOptionsRegistry) {
156
- /* eslint-disable @typescript-eslint/no-explicit-any,max-len */
157
- if (editorIntConstructor && editorBoolConstructor && editorStringEnumConstructor) { break; }
158
- if (validator.name === 'acceptSuggestionOnCommitCharacter') {
159
- editorBoolConstructor = validator.constructor as any;
160
- } else if (validator.name === 'acceptSuggestionOnEnter') {
161
- editorStringEnumConstructor = validator.constructor as any;
162
- } else if (validator.name === 'accessibilityPageSize') {
163
- editorIntConstructor = validator.constructor as any;
164
- }
165
- /* eslint-enable @typescript-eslint/no-explicit-any */
166
- }
167
- if (editorIntConstructor && editorBoolConstructor && editorStringEnumConstructor) {
168
- let id = 200; // Needs to be bigger than the biggest index in the EditorOption enum.
169
- editorOptionsRegistry.push(
170
- new editorIntConstructor(id++, 'tabSize', 4, 1, MAX_SAFE_INTEGER, editorGeneratedPreferenceProperties['editor.tabSize']),
171
- new editorBoolConstructor(id++, 'insertSpaces', true, editorGeneratedPreferenceProperties['editor.insertSpaces']),
172
- new editorBoolConstructor(id++, 'detectIndentation', true, editorGeneratedPreferenceProperties['editor.detectIndentation']),
173
- new editorBoolConstructor(id++, 'trimAutoWhitespace', true, editorGeneratedPreferenceProperties['editor.trimAutoWhitespace']),
174
- new editorBoolConstructor(id++, 'largeFileOptimizations', true, editorGeneratedPreferenceProperties['editor.largeFileOptimizations']),
175
- new editorBoolConstructor(id++, 'wordBasedSuggestions', true, editorGeneratedPreferenceProperties['editor.wordBasedSuggestions']),
176
- new editorStringEnumConstructor(id++, 'wordBasedSuggestionsMode', 'matchingDocuments', editorGeneratedPreferenceProperties['editor.wordBasedSuggestionsMode'].enum, editorGeneratedPreferenceProperties['editor.wordBasedSuggestionsMode']),
177
- new editorBoolConstructor(id++, 'stablePeek', false, editorGeneratedPreferenceProperties['editor.stablePeek']),
178
- new editorIntConstructor(id++, 'maxTokenizationLineLength', 20000, 1, MAX_SAFE_INTEGER, editorGeneratedPreferenceProperties['editor.maxTokenizationLineLength']),
179
- );
180
- }
181
- }
182
- }
1
+ // *****************************************************************************
2
+ // Copyright (C) 2018 Ericsson 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 { injectable, inject, postConstruct } from '@theia/core/shared/inversify';
18
+ import { ColorTheme, CssStyleCollector, FrontendApplicationContribution, PreferenceSchemaProvider, QuickAccessRegistry, StylingParticipant } from '@theia/core/lib/browser';
19
+ import { MonacoSnippetSuggestProvider } from './monaco-snippet-suggest-provider';
20
+ import * as monaco from '@theia/monaco-editor-core';
21
+ import { setSnippetSuggestSupport } from '@theia/monaco-editor-core/esm/vs/editor/contrib/suggest/browser/suggest';
22
+ import { CompletionItemProvider } from '@theia/monaco-editor-core/esm/vs/editor/common/languages';
23
+ import { MonacoTextModelService } from './monaco-text-model-service';
24
+ import { MonacoThemingService } from './monaco-theming-service';
25
+ import { isHighContrast } from '@theia/core/lib/common/theme';
26
+ import { editorOptionsRegistry, IEditorOption } from '@theia/monaco-editor-core/esm/vs/editor/common/config/editorOptions';
27
+ import { MAX_SAFE_INTEGER } from '@theia/core';
28
+ import { editorGeneratedPreferenceProperties } from '@theia/editor/lib/browser/editor-generated-preference-schema';
29
+ import { WorkspaceFileService } from '@theia/workspace/lib/common/workspace-file-service';
30
+ import { SecondaryWindowHandler } from '@theia/core/lib/browser/secondary-window-handler';
31
+ import { EditorWidget } from '@theia/editor/lib/browser';
32
+ import { MonacoEditor } from './monaco-editor';
33
+ import { StandaloneServices } from '@theia/monaco-editor-core/esm/vs/editor/standalone/browser/standaloneServices';
34
+ import { StandaloneThemeService } from '@theia/monaco-editor-core/esm/vs/editor/standalone/browser/standaloneThemeService';
35
+ import { IStandaloneThemeService } from '@theia/monaco-editor-core/esm/vs/editor/standalone/common/standaloneTheme';
36
+
37
+ @injectable()
38
+ export class MonacoFrontendApplicationContribution implements FrontendApplicationContribution, StylingParticipant {
39
+
40
+ @inject(MonacoTextModelService)
41
+ protected readonly textModelService: MonacoTextModelService;
42
+
43
+ @inject(MonacoSnippetSuggestProvider)
44
+ protected readonly snippetSuggestProvider: MonacoSnippetSuggestProvider;
45
+
46
+ @inject(PreferenceSchemaProvider)
47
+ protected readonly preferenceSchema: PreferenceSchemaProvider;
48
+
49
+ @inject(QuickAccessRegistry)
50
+ protected readonly quickAccessRegistry: QuickAccessRegistry;
51
+
52
+ @inject(MonacoThemingService) protected readonly monacoThemingService: MonacoThemingService;
53
+
54
+ @inject(WorkspaceFileService) protected readonly workspaceFileService: WorkspaceFileService;
55
+
56
+ @inject(SecondaryWindowHandler)
57
+ protected readonly secondaryWindowHandler: SecondaryWindowHandler;
58
+
59
+ @postConstruct()
60
+ protected init(): void {
61
+ this.addAdditionalPreferenceValidations();
62
+ // Monaco registers certain quick access providers (e.g. QuickCommandAccess) at import time, but we want to use our own.
63
+ this.quickAccessRegistry.clear();
64
+
65
+ /**
66
+ * @monaco-uplift.Should be guaranteed to work.
67
+ * Incomparable enums prevent TypeScript from believing that public ITextModel satisfied private ITextModel
68
+ */
69
+ setSnippetSuggestSupport(this.snippetSuggestProvider as unknown as CompletionItemProvider);
70
+
71
+ for (const language of monaco.languages.getLanguages()) {
72
+ this.preferenceSchema.registerOverrideIdentifier(language.id);
73
+ }
74
+ const registerLanguage = monaco.languages.register.bind(monaco.languages);
75
+ monaco.languages.register = language => {
76
+ // first register override identifier, because monaco will immediately update already opened documents and then initialize with bad preferences.
77
+ this.preferenceSchema.registerOverrideIdentifier(language.id);
78
+ registerLanguage(language);
79
+ };
80
+
81
+ this.monacoThemingService.initialize();
82
+ }
83
+
84
+ initialize(): void {
85
+ const workspaceExtensions = this.workspaceFileService.getWorkspaceFileExtensions();
86
+ monaco.languages.register({
87
+ id: 'jsonc',
88
+ 'aliases': [
89
+ 'JSON with Comments'
90
+ ],
91
+ 'extensions': workspaceExtensions.map(ext => `.${ext}`)
92
+ });
93
+ }
94
+ onStart(): void {
95
+ this.secondaryWindowHandler.onDidAddWidget(([widget, window]) => {
96
+ if (widget instanceof EditorWidget && widget.editor instanceof MonacoEditor) {
97
+ const themeService = StandaloneServices.get(IStandaloneThemeService) as StandaloneThemeService;
98
+ themeService.registerEditorContainer(widget.node);
99
+ }
100
+ });
101
+ }
102
+
103
+ registerThemeStyle(theme: ColorTheme, collector: CssStyleCollector): void {
104
+ if (isHighContrast(theme.type)) {
105
+ const focusBorder = theme.getColor('focusBorder');
106
+ const contrastBorder = theme.getColor('contrastBorder');
107
+ if (focusBorder) {
108
+ // Quick input
109
+ collector.addRule(`
110
+ .quick-input-list .monaco-list-row {
111
+ outline-offset: -1px;
112
+ }
113
+ .quick-input-list .monaco-list-row.focused {
114
+ outline: 1px dotted ${focusBorder};
115
+ }
116
+ .quick-input-list .monaco-list-row:hover {
117
+ outline: 1px dashed ${focusBorder};
118
+ }
119
+ `);
120
+ // Input box always displays an outline, even when unfocused
121
+ collector.addRule(`
122
+ .monaco-editor .find-widget .monaco-inputbox {
123
+ outline: var(--theia-border-width) solid;
124
+ outline-offset: calc(-1 * var(--theia-border-width));
125
+ outline-color: var(--theia-focusBorder);
126
+ }
127
+ `);
128
+ }
129
+ if (contrastBorder) {
130
+ collector.addRule(`
131
+ .quick-input-widget {
132
+ outline: 1px solid ${contrastBorder};
133
+ outline-offset: -1px;
134
+ }
135
+ `);
136
+ }
137
+ } else {
138
+ collector.addRule(`
139
+ .quick-input-widget {
140
+ box-shadow: rgb(0 0 0 / 36%) 0px 0px 8px 2px;
141
+ }
142
+ `);
143
+ }
144
+ }
145
+
146
+ /**
147
+ * For reasons that are unclear, while most preferences that apply in editors are validated, a few are not.
148
+ * There is a utility in `examples/api-samples/src/browser/monaco-editor-preferences/monaco-editor-preference-extractor.ts` to help determine which are not.
149
+ * Check `src/vs/editor/common/config/editorOptions.ts` for constructor arguments and to make sure that the preference names used to extract constructors are still accurate.
150
+ */
151
+ protected addAdditionalPreferenceValidations(): void {
152
+ let editorIntConstructor: undefined | (new (...args: unknown[]) => IEditorOption<number, number>);
153
+ let editorBoolConstructor: undefined | (new (...args: unknown[]) => IEditorOption<number, boolean>);
154
+ let editorStringEnumConstructor: undefined | (new (...args: unknown[]) => IEditorOption<number, string>);
155
+ for (const validator of editorOptionsRegistry) {
156
+ /* eslint-disable @typescript-eslint/no-explicit-any,max-len */
157
+ if (editorIntConstructor && editorBoolConstructor && editorStringEnumConstructor) { break; }
158
+ if (validator.name === 'acceptSuggestionOnCommitCharacter') {
159
+ editorBoolConstructor = validator.constructor as any;
160
+ } else if (validator.name === 'acceptSuggestionOnEnter') {
161
+ editorStringEnumConstructor = validator.constructor as any;
162
+ } else if (validator.name === 'accessibilityPageSize') {
163
+ editorIntConstructor = validator.constructor as any;
164
+ }
165
+ /* eslint-enable @typescript-eslint/no-explicit-any */
166
+ }
167
+ if (editorIntConstructor && editorBoolConstructor && editorStringEnumConstructor) {
168
+ let id = 200; // Needs to be bigger than the biggest index in the EditorOption enum.
169
+ editorOptionsRegistry.push(
170
+ new editorIntConstructor(id++, 'tabSize', 4, 1, MAX_SAFE_INTEGER, editorGeneratedPreferenceProperties['editor.tabSize']),
171
+ new editorBoolConstructor(id++, 'insertSpaces', true, editorGeneratedPreferenceProperties['editor.insertSpaces']),
172
+ new editorBoolConstructor(id++, 'detectIndentation', true, editorGeneratedPreferenceProperties['editor.detectIndentation']),
173
+ new editorBoolConstructor(id++, 'trimAutoWhitespace', true, editorGeneratedPreferenceProperties['editor.trimAutoWhitespace']),
174
+ new editorBoolConstructor(id++, 'largeFileOptimizations', true, editorGeneratedPreferenceProperties['editor.largeFileOptimizations']),
175
+ new editorBoolConstructor(id++, 'wordBasedSuggestions', true, editorGeneratedPreferenceProperties['editor.wordBasedSuggestions']),
176
+ new editorStringEnumConstructor(id++, 'wordBasedSuggestionsMode', 'matchingDocuments', editorGeneratedPreferenceProperties['editor.wordBasedSuggestionsMode'].enum, editorGeneratedPreferenceProperties['editor.wordBasedSuggestionsMode']),
177
+ new editorBoolConstructor(id++, 'stablePeek', false, editorGeneratedPreferenceProperties['editor.stablePeek']),
178
+ new editorIntConstructor(id++, 'maxTokenizationLineLength', 20000, 1, MAX_SAFE_INTEGER, editorGeneratedPreferenceProperties['editor.maxTokenizationLineLength']),
179
+ );
180
+ }
181
+ }
182
+ }