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