@codingame/monaco-vscode-api 1.67.8-dev.0 → 1.67.10
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/README.md +27 -3
- package/dist/api.js +578 -1820
- package/dist/async-9ffe4d42.js +46 -0
- package/dist/messages.d.ts +7 -0
- package/dist/messages.js +4305 -0
- package/dist/missing-services-8a03a564.js +812 -0
- package/dist/modelEditor.d.ts +158 -0
- package/dist/modelEditor.js +717 -0
- package/dist/services-ac6b4b50.js +747 -0
- package/dist/services.d.ts +5360 -9322
- package/dist/services.js +17 -2
- package/package.json +34 -19
- package/dist/services-f1f30499.js +0 -300
|
@@ -0,0 +1,717 @@
|
|
|
1
|
+
import { b as __decorate, d as __param, f as IFileService, h as IUriIdentityService, e as ITextFileService, S as SIDE_GROUP, A as ACTIVE_GROUP, l as IEditorService, x as isPreferredGroup } from './services-ac6b4b50.js';
|
|
2
|
+
import { E as Emitter, w as withUndefinedAsNull, b as ILanguageDetectionService, u as unsupported } from './missing-services-8a03a564.js';
|
|
3
|
+
import { Disposable, MutableDisposable, dispose, toDisposable } from 'monaco-editor/esm/vs/base/common/lifecycle.js';
|
|
4
|
+
import { ThrottledDelayer } from 'monaco-editor/esm/vs/base/common/async.js';
|
|
5
|
+
import { PLAINTEXT_LANGUAGE_ID } from 'monaco-editor/esm/vs/editor/common/languages/modesRegistry.js';
|
|
6
|
+
import { localize } from 'monaco-editor/esm/vs/nls.js';
|
|
7
|
+
import { IModelService } from 'monaco-editor/esm/vs/editor/common/services/model.js';
|
|
8
|
+
import { ILanguageService } from 'monaco-editor/esm/vs/editor/common/languages/language.js';
|
|
9
|
+
import { IAccessibilityService } from 'monaco-editor/esm/vs/platform/accessibility/common/accessibility.js';
|
|
10
|
+
import { MultiModelEditStackElement } from 'monaco-editor/esm/vs/editor/common/model/editStack.js';
|
|
11
|
+
import { ITextModelService } from 'monaco-editor/esm/vs/editor/common/services/resolverService.js';
|
|
12
|
+
import { IUndoRedoService } from 'monaco-editor/esm/vs/platform/undoRedo/common/undoRedo.js';
|
|
13
|
+
import { once } from 'monaco-editor/esm/vs/base/common/functional.js';
|
|
14
|
+
import { Schemas } from 'monaco-editor/esm/vs/base/common/network.js';
|
|
15
|
+
import { IInstantiationService } from 'monaco-editor/esm/vs/platform/instantiation/common/instantiation.js';
|
|
16
|
+
import { URI } from 'monaco-editor/esm/vs/base/common/uri.js';
|
|
17
|
+
import { AbstractCodeEditorService } from 'monaco-editor/esm/vs/editor/browser/services/abstractCodeEditorService.js';
|
|
18
|
+
import { isCodeEditor, isDiffEditor, getCodeEditor } from 'monaco-editor/esm/vs/editor/browser/editorBrowser.js';
|
|
19
|
+
import { isEqual } from 'monaco-editor/esm/vs/base/common/resources.js';
|
|
20
|
+
import { IThemeService } from 'monaco-editor/esm/vs/platform/theme/common/themeService.js';
|
|
21
|
+
import { IConfigurationService } from 'monaco-editor/esm/vs/platform/configuration/common/configuration.js';
|
|
22
|
+
import { Dimension } from 'monaco-editor/esm/vs/base/browser/dom.js';
|
|
23
|
+
import { SyncDescriptor } from 'monaco-editor/esm/vs/platform/instantiation/common/descriptors.js';
|
|
24
|
+
import { ICodeEditorService } from 'monaco-editor/esm/vs/editor/browser/services/codeEditorService.js';
|
|
25
|
+
import { Event } from 'monaco-editor/esm/vs/base/common/event.js';
|
|
26
|
+
import { StandaloneServices } from 'monaco-editor/esm/vs/editor/standalone/browser/standaloneServices.js';
|
|
27
|
+
import 'monaco-editor/esm/vs/platform/environment/common/environment.js';
|
|
28
|
+
import 'monaco-editor/esm/vs/base/common/platform.js';
|
|
29
|
+
import 'monaco-editor/esm/vs/platform/workspace/common/workspace.js';
|
|
30
|
+
import 'monaco-editor/esm/vs/base/common/path.js';
|
|
31
|
+
import 'monaco-editor/esm/vs/base/common/linkedList.js';
|
|
32
|
+
import 'monaco-editor/esm/vs/platform/log/common/log.js';
|
|
33
|
+
import 'monaco-editor/esm/vs/editor/editor.api.js';
|
|
34
|
+
import 'monaco-editor/esm/vs/base/common/errors.js';
|
|
35
|
+
import 'monaco-editor/esm/vs/base/common/stopwatch.js';
|
|
36
|
+
import 'monaco-editor/esm/vs/base/common/cancellation.js';
|
|
37
|
+
import 'monaco-editor/esm/vs/platform/commands/common/commands.js';
|
|
38
|
+
import 'monaco-editor/esm/vs/platform/notification/common/notification.js';
|
|
39
|
+
import 'monaco-editor/esm/vs/editor/browser/services/bulkEditService.js';
|
|
40
|
+
import 'monaco-editor/esm/vs/editor/common/languages/languageConfigurationRegistry.js';
|
|
41
|
+
import 'monaco-editor/esm/vs/editor/common/services/editorWorker.js';
|
|
42
|
+
import 'monaco-editor/esm/vs/editor/common/services/languageFeatures.js';
|
|
43
|
+
import 'monaco-editor/esm/vs/platform/clipboard/common/clipboardService.js';
|
|
44
|
+
import 'monaco-editor/esm/vs/platform/dialogs/common/dialogs.js';
|
|
45
|
+
import 'monaco-editor/esm/vs/platform/markers/common/markers.js';
|
|
46
|
+
import 'monaco-editor/esm/vs/platform/opener/common/opener.js';
|
|
47
|
+
import 'monaco-editor/esm/vs/platform/quickinput/common/quickInput.js';
|
|
48
|
+
import 'monaco-editor/esm/vs/platform/telemetry/common/telemetry.js';
|
|
49
|
+
import 'monaco-editor/esm/vs/base/common/severity.js';
|
|
50
|
+
import 'monaco-editor/esm/vs/base/common/buffer.js';
|
|
51
|
+
import 'monaco-editor/esm/vs/base/browser/ui/progressbar/progressbar.js';
|
|
52
|
+
import 'monaco-editor/esm/vs/base/common/color.js';
|
|
53
|
+
import 'monaco-editor/esm/vs/base/common/objects.js';
|
|
54
|
+
import 'monaco-editor/esm/vs/base/common/types.js';
|
|
55
|
+
import 'monaco-editor/esm/vs/base/parts/quickinput/browser/quickInput.js';
|
|
56
|
+
import 'monaco-editor/esm/vs/platform/instantiation/common/extensions.js';
|
|
57
|
+
import 'monaco-editor/esm/vs/platform/label/common/label.js';
|
|
58
|
+
import 'monaco-editor/esm/vs/editor/common/languageFeatureRegistry.js';
|
|
59
|
+
import 'monaco-editor/esm/vs/base/common/strings.js';
|
|
60
|
+
import 'monaco-editor/esm/vs/base/browser/event.js';
|
|
61
|
+
class ReferenceCollection {
|
|
62
|
+
constructor() {
|
|
63
|
+
this.references = new Map();
|
|
64
|
+
}
|
|
65
|
+
acquire(key, ...args) {
|
|
66
|
+
let reference = this.references.get(key);
|
|
67
|
+
if (!reference) {
|
|
68
|
+
reference = { counter: 0, object: this.createReferencedObject(key, ...args) };
|
|
69
|
+
this.references.set(key, reference);
|
|
70
|
+
}
|
|
71
|
+
const { object } = reference;
|
|
72
|
+
const dispose = once(() => {
|
|
73
|
+
if (--reference.counter === 0) {
|
|
74
|
+
this.destroyReferencedObject(key, reference.object);
|
|
75
|
+
this.references.delete(key);
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
reference.counter++;
|
|
79
|
+
return { object, dispose };
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
class AsyncReferenceCollection {
|
|
83
|
+
constructor(referenceCollection) {
|
|
84
|
+
this.referenceCollection = referenceCollection;
|
|
85
|
+
}
|
|
86
|
+
async acquire(key, ...args) {
|
|
87
|
+
const ref = this.referenceCollection.acquire(key, ...args);
|
|
88
|
+
try {
|
|
89
|
+
const object = await ref.object;
|
|
90
|
+
return {
|
|
91
|
+
object,
|
|
92
|
+
dispose: () => ref.dispose()
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
catch (error) {
|
|
96
|
+
ref.dispose();
|
|
97
|
+
throw error;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
function isResourceEditorInput(editor) {
|
|
102
|
+
if (isEditorInput(editor)) {
|
|
103
|
+
return false;
|
|
104
|
+
}
|
|
105
|
+
const candidate = editor;
|
|
106
|
+
return URI.isUri(candidate?.resource);
|
|
107
|
+
}
|
|
108
|
+
class AbstractEditorInput extends Disposable {
|
|
109
|
+
}
|
|
110
|
+
function isEditorInput(editor) {
|
|
111
|
+
return editor instanceof AbstractEditorInput;
|
|
112
|
+
}
|
|
113
|
+
function isCompositeEditor(thing) {
|
|
114
|
+
return !!thing
|
|
115
|
+
&& typeof thing === 'object'
|
|
116
|
+
&& typeof thing.onDidChangeActiveEditor === 'function';
|
|
117
|
+
}
|
|
118
|
+
class EditorModel extends Disposable {
|
|
119
|
+
constructor() {
|
|
120
|
+
super(...arguments);
|
|
121
|
+
this._onWillDispose = this._register( new Emitter());
|
|
122
|
+
this.onWillDispose = this._onWillDispose.event;
|
|
123
|
+
this.disposed = false;
|
|
124
|
+
this.resolved = false;
|
|
125
|
+
}
|
|
126
|
+
async resolve() {
|
|
127
|
+
this.resolved = true;
|
|
128
|
+
}
|
|
129
|
+
isResolved() {
|
|
130
|
+
return this.resolved;
|
|
131
|
+
}
|
|
132
|
+
isDisposed() {
|
|
133
|
+
return this.disposed;
|
|
134
|
+
}
|
|
135
|
+
dispose() {
|
|
136
|
+
this.disposed = true;
|
|
137
|
+
this._onWillDispose.fire();
|
|
138
|
+
super.dispose();
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
let BaseTextEditorModel = class BaseTextEditorModel extends EditorModel {
|
|
142
|
+
constructor(modelService, languageService, languageDetectionService, accessibilityService, textEditorModelHandle) {
|
|
143
|
+
super();
|
|
144
|
+
this.modelService = modelService;
|
|
145
|
+
this.languageService = languageService;
|
|
146
|
+
this.languageDetectionService = languageDetectionService;
|
|
147
|
+
this.accessibilityService = accessibilityService;
|
|
148
|
+
this.textEditorModelHandle = undefined;
|
|
149
|
+
this.modelDisposeListener = this._register( new MutableDisposable());
|
|
150
|
+
this.autoDetectLanguageThrottler = this._register( new ThrottledDelayer(BaseTextEditorModel.AUTO_DETECT_LANGUAGE_THROTTLE_DELAY));
|
|
151
|
+
this._hasLanguageSetExplicitly = false;
|
|
152
|
+
if (textEditorModelHandle) {
|
|
153
|
+
this.handleExistingModel(textEditorModelHandle);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
handleExistingModel(textEditorModelHandle) {
|
|
157
|
+
const model = this.modelService.getModel(textEditorModelHandle);
|
|
158
|
+
if (!model) {
|
|
159
|
+
throw new Error(`Document with resource ${textEditorModelHandle.toString(true)} does not exist`);
|
|
160
|
+
}
|
|
161
|
+
this.textEditorModelHandle = textEditorModelHandle;
|
|
162
|
+
this.registerModelDisposeListener(model);
|
|
163
|
+
}
|
|
164
|
+
registerModelDisposeListener(model) {
|
|
165
|
+
this.modelDisposeListener.value = model.onWillDispose(() => {
|
|
166
|
+
this.textEditorModelHandle = undefined;
|
|
167
|
+
this.dispose();
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
get textEditorModel() {
|
|
171
|
+
return this.textEditorModelHandle ? this.modelService.getModel(this.textEditorModelHandle) : null;
|
|
172
|
+
}
|
|
173
|
+
isReadonly() {
|
|
174
|
+
return true;
|
|
175
|
+
}
|
|
176
|
+
get hasLanguageSetExplicitly() { return this._hasLanguageSetExplicitly; }
|
|
177
|
+
setLanguageId(languageId) {
|
|
178
|
+
this._hasLanguageSetExplicitly = true;
|
|
179
|
+
this.setLanguageIdInternal(languageId);
|
|
180
|
+
}
|
|
181
|
+
setLanguageIdInternal(languageId) {
|
|
182
|
+
if (!this.isResolved()) {
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
if (!languageId || languageId === this.textEditorModel.getLanguageId()) {
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
this.modelService.setMode(this.textEditorModel, this.languageService.createById(languageId));
|
|
189
|
+
}
|
|
190
|
+
getLanguageId() {
|
|
191
|
+
return this.textEditorModel?.getLanguageId();
|
|
192
|
+
}
|
|
193
|
+
autoDetectLanguage() {
|
|
194
|
+
return this.autoDetectLanguageThrottler.trigger(() => this.doAutoDetectLanguage());
|
|
195
|
+
}
|
|
196
|
+
async doAutoDetectLanguage() {
|
|
197
|
+
if (this.hasLanguageSetExplicitly ||
|
|
198
|
+
!this.textEditorModelHandle ||
|
|
199
|
+
!this.languageDetectionService.isEnabledForLanguage(this.getLanguageId() ?? PLAINTEXT_LANGUAGE_ID)
|
|
200
|
+
) {
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
const lang = await this.languageDetectionService.detectLanguage(this.textEditorModelHandle);
|
|
204
|
+
if (lang && !this.isDisposed()) {
|
|
205
|
+
this.setLanguageIdInternal(lang);
|
|
206
|
+
const languageName = this.languageService.getLanguageName(lang);
|
|
207
|
+
if (languageName) {
|
|
208
|
+
this.accessibilityService.alert( localize(
|
|
209
|
+
'languageAutoDetected',
|
|
210
|
+
"Language {0} was automatically detected and set as the language mode.",
|
|
211
|
+
languageName
|
|
212
|
+
));
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
createTextEditorModel(value, resource, preferredLanguageId) {
|
|
217
|
+
const firstLineText = this.getFirstLineText(value);
|
|
218
|
+
const languageSelection = this.getOrCreateLanguage(resource, this.languageService, preferredLanguageId, firstLineText);
|
|
219
|
+
return this.doCreateTextEditorModel(value, languageSelection, resource);
|
|
220
|
+
}
|
|
221
|
+
doCreateTextEditorModel(value, languageSelection, resource) {
|
|
222
|
+
let model = resource && this.modelService.getModel(resource);
|
|
223
|
+
if (!model) {
|
|
224
|
+
model = this.modelService.createModel(value, languageSelection, resource);
|
|
225
|
+
this.createdEditorModel = true;
|
|
226
|
+
this.registerModelDisposeListener(model);
|
|
227
|
+
}
|
|
228
|
+
else {
|
|
229
|
+
this.updateTextEditorModel(value, languageSelection.languageId);
|
|
230
|
+
}
|
|
231
|
+
this.textEditorModelHandle = model.uri;
|
|
232
|
+
return model;
|
|
233
|
+
}
|
|
234
|
+
getFirstLineText(value) {
|
|
235
|
+
const textBufferFactory = value;
|
|
236
|
+
if (typeof textBufferFactory.getFirstLineText === 'function') {
|
|
237
|
+
return textBufferFactory.getFirstLineText(1000 );
|
|
238
|
+
}
|
|
239
|
+
const textSnapshot = value;
|
|
240
|
+
return textSnapshot.getLineContent(1).substr(0, 1000 );
|
|
241
|
+
}
|
|
242
|
+
getOrCreateLanguage(resource, languageService, preferredLanguage, firstLineText) {
|
|
243
|
+
if (!preferredLanguage || preferredLanguage === PLAINTEXT_LANGUAGE_ID) {
|
|
244
|
+
return languageService.createByFilepathOrFirstLine(withUndefinedAsNull(resource), firstLineText);
|
|
245
|
+
}
|
|
246
|
+
return languageService.createById(preferredLanguage);
|
|
247
|
+
}
|
|
248
|
+
updateTextEditorModel(newValue, preferredLanguageId) {
|
|
249
|
+
if (!this.isResolved()) {
|
|
250
|
+
return;
|
|
251
|
+
}
|
|
252
|
+
if (newValue) {
|
|
253
|
+
this.modelService.updateModel(this.textEditorModel, newValue);
|
|
254
|
+
}
|
|
255
|
+
if (preferredLanguageId && preferredLanguageId !== PLAINTEXT_LANGUAGE_ID && this.textEditorModel.getLanguageId() !== preferredLanguageId) {
|
|
256
|
+
this.modelService.setMode(this.textEditorModel, this.languageService.createById(preferredLanguageId));
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
createSnapshot() {
|
|
260
|
+
if (!this.textEditorModel) {
|
|
261
|
+
return null;
|
|
262
|
+
}
|
|
263
|
+
return this.textEditorModel.createSnapshot(true );
|
|
264
|
+
}
|
|
265
|
+
isResolved() {
|
|
266
|
+
return !!this.textEditorModelHandle;
|
|
267
|
+
}
|
|
268
|
+
dispose() {
|
|
269
|
+
this.modelDisposeListener.dispose();
|
|
270
|
+
if (this.textEditorModelHandle && this.createdEditorModel) {
|
|
271
|
+
this.modelService.destroyModel(this.textEditorModelHandle);
|
|
272
|
+
}
|
|
273
|
+
this.textEditorModelHandle = undefined;
|
|
274
|
+
this.createdEditorModel = false;
|
|
275
|
+
super.dispose();
|
|
276
|
+
}
|
|
277
|
+
};
|
|
278
|
+
BaseTextEditorModel.AUTO_DETECT_LANGUAGE_THROTTLE_DELAY = 600;
|
|
279
|
+
BaseTextEditorModel = __decorate([
|
|
280
|
+
__param(0, IModelService),
|
|
281
|
+
__param(1, ILanguageService),
|
|
282
|
+
__param(2, ILanguageDetectionService),
|
|
283
|
+
__param(3, IAccessibilityService)
|
|
284
|
+
], BaseTextEditorModel);
|
|
285
|
+
let TextResourceEditorModel = class TextResourceEditorModel extends BaseTextEditorModel {
|
|
286
|
+
constructor(resource, languageService, modelService, languageDetectionService, accessibilityService) {
|
|
287
|
+
super(modelService, languageService, languageDetectionService, accessibilityService, resource);
|
|
288
|
+
}
|
|
289
|
+
dispose() {
|
|
290
|
+
if (this.textEditorModelHandle) {
|
|
291
|
+
this.modelService.destroyModel(this.textEditorModelHandle);
|
|
292
|
+
}
|
|
293
|
+
super.dispose();
|
|
294
|
+
}
|
|
295
|
+
};
|
|
296
|
+
TextResourceEditorModel = __decorate([
|
|
297
|
+
__param(1, ILanguageService),
|
|
298
|
+
__param(2, IModelService),
|
|
299
|
+
__param(3, ILanguageDetectionService),
|
|
300
|
+
__param(4, IAccessibilityService)
|
|
301
|
+
], TextResourceEditorModel);
|
|
302
|
+
class TextFileEditorModel {}
|
|
303
|
+
let ModelUndoRedoParticipant = class ModelUndoRedoParticipant extends Disposable {
|
|
304
|
+
constructor(_modelService, _textModelService, _undoRedoService) {
|
|
305
|
+
super();
|
|
306
|
+
this._modelService = _modelService;
|
|
307
|
+
this._textModelService = _textModelService;
|
|
308
|
+
this._undoRedoService = _undoRedoService;
|
|
309
|
+
this._register(this._modelService.onModelRemoved((model) => {
|
|
310
|
+
const elements = this._undoRedoService.getElements(model.uri);
|
|
311
|
+
if (elements.past.length === 0 && elements.future.length === 0) {
|
|
312
|
+
return;
|
|
313
|
+
}
|
|
314
|
+
for (const element of elements.past) {
|
|
315
|
+
if (element instanceof MultiModelEditStackElement) {
|
|
316
|
+
element.setDelegate(this);
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
for (const element of elements.future) {
|
|
320
|
+
if (element instanceof MultiModelEditStackElement) {
|
|
321
|
+
element.setDelegate(this);
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
}));
|
|
325
|
+
}
|
|
326
|
+
prepareUndoRedo(element) {
|
|
327
|
+
const missingModels = element.getMissingModels();
|
|
328
|
+
if (missingModels.length === 0) {
|
|
329
|
+
return Disposable.None;
|
|
330
|
+
}
|
|
331
|
+
const disposablesPromises = missingModels.map(async (uri) => {
|
|
332
|
+
try {
|
|
333
|
+
const reference = await this._textModelService.createModelReference(uri);
|
|
334
|
+
return reference;
|
|
335
|
+
}
|
|
336
|
+
catch (err) {
|
|
337
|
+
return Disposable.None;
|
|
338
|
+
}
|
|
339
|
+
});
|
|
340
|
+
return Promise.all(disposablesPromises).then(disposables => {
|
|
341
|
+
return {
|
|
342
|
+
dispose: () => dispose(disposables)
|
|
343
|
+
};
|
|
344
|
+
});
|
|
345
|
+
}
|
|
346
|
+
};
|
|
347
|
+
ModelUndoRedoParticipant = __decorate([
|
|
348
|
+
__param(0, IModelService),
|
|
349
|
+
__param(1, ITextModelService),
|
|
350
|
+
__param(2, IUndoRedoService)
|
|
351
|
+
], ModelUndoRedoParticipant);
|
|
352
|
+
let ResourceModelCollection = class ResourceModelCollection extends ReferenceCollection {
|
|
353
|
+
constructor(instantiationService, textFileService, fileService, modelService) {
|
|
354
|
+
super();
|
|
355
|
+
this.instantiationService = instantiationService;
|
|
356
|
+
this.textFileService = textFileService;
|
|
357
|
+
this.fileService = fileService;
|
|
358
|
+
this.modelService = modelService;
|
|
359
|
+
this.providers = new Map();
|
|
360
|
+
this.modelsToDispose = new Set();
|
|
361
|
+
}
|
|
362
|
+
createReferencedObject(key) {
|
|
363
|
+
return this.doCreateReferencedObject(key);
|
|
364
|
+
}
|
|
365
|
+
async doCreateReferencedObject(key, skipActivateProvider) {
|
|
366
|
+
this.modelsToDispose.delete(key);
|
|
367
|
+
const resource = URI.parse(key);
|
|
368
|
+
if (resource.scheme === Schemas.inMemory) {
|
|
369
|
+
const cachedModel = this.modelService.getModel(resource);
|
|
370
|
+
if (!cachedModel) {
|
|
371
|
+
throw new Error(`Unable to resolve inMemory resource ${key}`);
|
|
372
|
+
}
|
|
373
|
+
return this.instantiationService.createInstance(TextResourceEditorModel, resource);
|
|
374
|
+
}
|
|
375
|
+
if (resource.scheme === Schemas.untitled) {
|
|
376
|
+
return this.textFileService.untitled.resolve({ untitledResource: resource });
|
|
377
|
+
}
|
|
378
|
+
if (this.fileService.hasProvider(resource)) {
|
|
379
|
+
return this.textFileService.files.resolve(resource, { reason: 2 });
|
|
380
|
+
}
|
|
381
|
+
if (this.providers.has(resource.scheme)) {
|
|
382
|
+
await this.resolveTextModelContent(key);
|
|
383
|
+
return this.instantiationService.createInstance(TextResourceEditorModel, resource);
|
|
384
|
+
}
|
|
385
|
+
if (!skipActivateProvider) {
|
|
386
|
+
await this.fileService.activateProvider(resource.scheme);
|
|
387
|
+
return this.doCreateReferencedObject(key, true);
|
|
388
|
+
}
|
|
389
|
+
throw new Error(`Unable to resolve resource ${key}`);
|
|
390
|
+
}
|
|
391
|
+
destroyReferencedObject(key, modelPromise) {
|
|
392
|
+
const resource = URI.parse(key);
|
|
393
|
+
if (resource.scheme === Schemas.untitled || resource.scheme === Schemas.inMemory) {
|
|
394
|
+
return;
|
|
395
|
+
}
|
|
396
|
+
this.modelsToDispose.add(key);
|
|
397
|
+
(async () => {
|
|
398
|
+
try {
|
|
399
|
+
const model = await modelPromise;
|
|
400
|
+
if (!this.modelsToDispose.has(key)) {
|
|
401
|
+
return;
|
|
402
|
+
}
|
|
403
|
+
if (model instanceof TextFileEditorModel) {
|
|
404
|
+
await this.textFileService.files.canDispose(model);
|
|
405
|
+
}
|
|
406
|
+
if (!this.modelsToDispose.has(key)) {
|
|
407
|
+
return;
|
|
408
|
+
}
|
|
409
|
+
model.dispose();
|
|
410
|
+
}
|
|
411
|
+
catch (error) {
|
|
412
|
+
}
|
|
413
|
+
finally {
|
|
414
|
+
this.modelsToDispose.delete(key);
|
|
415
|
+
}
|
|
416
|
+
})();
|
|
417
|
+
}
|
|
418
|
+
registerTextModelContentProvider(scheme, provider) {
|
|
419
|
+
let providers = this.providers.get(scheme);
|
|
420
|
+
if (!providers) {
|
|
421
|
+
providers = [];
|
|
422
|
+
this.providers.set(scheme, providers);
|
|
423
|
+
}
|
|
424
|
+
providers.unshift(provider);
|
|
425
|
+
return toDisposable(() => {
|
|
426
|
+
const providersForScheme = this.providers.get(scheme);
|
|
427
|
+
if (!providersForScheme) {
|
|
428
|
+
return;
|
|
429
|
+
}
|
|
430
|
+
const index = providersForScheme.indexOf(provider);
|
|
431
|
+
if (index === -1) {
|
|
432
|
+
return;
|
|
433
|
+
}
|
|
434
|
+
providersForScheme.splice(index, 1);
|
|
435
|
+
if (providersForScheme.length === 0) {
|
|
436
|
+
this.providers.delete(scheme);
|
|
437
|
+
}
|
|
438
|
+
});
|
|
439
|
+
}
|
|
440
|
+
hasTextModelContentProvider(scheme) {
|
|
441
|
+
return this.providers.get(scheme) !== undefined;
|
|
442
|
+
}
|
|
443
|
+
async resolveTextModelContent(key) {
|
|
444
|
+
const resource = URI.parse(key);
|
|
445
|
+
const providersForScheme = this.providers.get(resource.scheme) || [];
|
|
446
|
+
for (const provider of providersForScheme) {
|
|
447
|
+
const value = await provider.provideTextContent(resource);
|
|
448
|
+
if (value) {
|
|
449
|
+
return value;
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
throw new Error(`Unable to resolve text model content for resource ${key}`);
|
|
453
|
+
}
|
|
454
|
+
};
|
|
455
|
+
ResourceModelCollection = __decorate([
|
|
456
|
+
__param(0, IInstantiationService),
|
|
457
|
+
__param(1, ITextFileService),
|
|
458
|
+
__param(2, IFileService),
|
|
459
|
+
__param(3, IModelService)
|
|
460
|
+
], ResourceModelCollection);
|
|
461
|
+
let TextModelResolverService = class TextModelResolverService extends Disposable {
|
|
462
|
+
constructor(instantiationService, fileService, undoRedoService, modelService, uriIdentityService) {
|
|
463
|
+
super();
|
|
464
|
+
this.instantiationService = instantiationService;
|
|
465
|
+
this.fileService = fileService;
|
|
466
|
+
this.undoRedoService = undoRedoService;
|
|
467
|
+
this.modelService = modelService;
|
|
468
|
+
this.uriIdentityService = uriIdentityService;
|
|
469
|
+
this.resourceModelCollection = this.instantiationService.createInstance(ResourceModelCollection);
|
|
470
|
+
this.asyncModelCollection = new AsyncReferenceCollection(this.resourceModelCollection);
|
|
471
|
+
this._register( new ModelUndoRedoParticipant(this.modelService, this, this.undoRedoService));
|
|
472
|
+
}
|
|
473
|
+
async createModelReference(resource) {
|
|
474
|
+
resource = this.uriIdentityService.asCanonicalUri(resource);
|
|
475
|
+
const result = await this.asyncModelCollection.acquire(resource.toString());
|
|
476
|
+
return result;
|
|
477
|
+
}
|
|
478
|
+
registerTextModelContentProvider(scheme, provider) {
|
|
479
|
+
return this.resourceModelCollection.registerTextModelContentProvider(scheme, provider);
|
|
480
|
+
}
|
|
481
|
+
canHandleResource(resource) {
|
|
482
|
+
if (this.fileService.hasProvider(resource) || resource.scheme === Schemas.untitled || resource.scheme === Schemas.inMemory) {
|
|
483
|
+
return true;
|
|
484
|
+
}
|
|
485
|
+
return this.resourceModelCollection.hasTextModelContentProvider(resource.scheme);
|
|
486
|
+
}
|
|
487
|
+
};
|
|
488
|
+
TextModelResolverService = __decorate([
|
|
489
|
+
__param(0, IInstantiationService),
|
|
490
|
+
__param(1, IFileService),
|
|
491
|
+
__param(2, IUndoRedoService),
|
|
492
|
+
__param(3, IModelService),
|
|
493
|
+
__param(4, IUriIdentityService)
|
|
494
|
+
], TextModelResolverService);
|
|
495
|
+
function applyTextEditorOptions(options, editor, scrollType) {
|
|
496
|
+
let applied = false;
|
|
497
|
+
const viewState = massageEditorViewState(options);
|
|
498
|
+
if (viewState) {
|
|
499
|
+
editor.restoreViewState(viewState);
|
|
500
|
+
applied = true;
|
|
501
|
+
}
|
|
502
|
+
if (options.selection) {
|
|
503
|
+
const range = {
|
|
504
|
+
startLineNumber: options.selection.startLineNumber,
|
|
505
|
+
startColumn: options.selection.startColumn,
|
|
506
|
+
endLineNumber: options.selection.endLineNumber ?? options.selection.startLineNumber,
|
|
507
|
+
endColumn: options.selection.endColumn ?? options.selection.startColumn
|
|
508
|
+
};
|
|
509
|
+
editor.setSelection(range, options.selectionSource ?? "code.navigation" );
|
|
510
|
+
if (options.selectionRevealType === 2 ) {
|
|
511
|
+
editor.revealRangeNearTop(range, scrollType);
|
|
512
|
+
}
|
|
513
|
+
else if (options.selectionRevealType === 3 ) {
|
|
514
|
+
editor.revealRangeNearTopIfOutsideViewport(range, scrollType);
|
|
515
|
+
}
|
|
516
|
+
else if (options.selectionRevealType === 1 ) {
|
|
517
|
+
editor.revealRangeInCenterIfOutsideViewport(range, scrollType);
|
|
518
|
+
}
|
|
519
|
+
else {
|
|
520
|
+
editor.revealRangeInCenter(range, scrollType);
|
|
521
|
+
}
|
|
522
|
+
applied = true;
|
|
523
|
+
}
|
|
524
|
+
return applied;
|
|
525
|
+
}
|
|
526
|
+
function massageEditorViewState(options) {
|
|
527
|
+
if (!options.selection || !options.viewState) {
|
|
528
|
+
return options.viewState;
|
|
529
|
+
}
|
|
530
|
+
const candidateDiffViewState = options.viewState;
|
|
531
|
+
if (candidateDiffViewState.modified) {
|
|
532
|
+
candidateDiffViewState.modified.cursorState = [];
|
|
533
|
+
return candidateDiffViewState;
|
|
534
|
+
}
|
|
535
|
+
const candidateEditorViewState = options.viewState;
|
|
536
|
+
if (candidateEditorViewState.cursorState) {
|
|
537
|
+
candidateEditorViewState.cursorState = [];
|
|
538
|
+
}
|
|
539
|
+
return candidateEditorViewState;
|
|
540
|
+
}
|
|
541
|
+
let CodeEditorService = class CodeEditorService extends AbstractCodeEditorService {
|
|
542
|
+
constructor(editorService, themeService, configurationService) {
|
|
543
|
+
super(themeService);
|
|
544
|
+
this.editorService = editorService;
|
|
545
|
+
this.configurationService = configurationService;
|
|
546
|
+
}
|
|
547
|
+
getActiveCodeEditor() {
|
|
548
|
+
const activeTextEditorControl = this.editorService.activeTextEditorControl;
|
|
549
|
+
if (isCodeEditor(activeTextEditorControl)) {
|
|
550
|
+
return activeTextEditorControl;
|
|
551
|
+
}
|
|
552
|
+
if (isDiffEditor(activeTextEditorControl)) {
|
|
553
|
+
return activeTextEditorControl.getModifiedEditor();
|
|
554
|
+
}
|
|
555
|
+
const activeControl = this.editorService.activeEditorPane?.getControl();
|
|
556
|
+
if (isCompositeEditor(activeControl) && isCodeEditor(activeControl.activeCodeEditor)) {
|
|
557
|
+
return activeControl.activeCodeEditor;
|
|
558
|
+
}
|
|
559
|
+
return null;
|
|
560
|
+
}
|
|
561
|
+
async openCodeEditor(input, source, sideBySide) {
|
|
562
|
+
const activeTextEditorControl = this.editorService.activeTextEditorControl;
|
|
563
|
+
if (!sideBySide &&
|
|
564
|
+
isDiffEditor(activeTextEditorControl) &&
|
|
565
|
+
input.options &&
|
|
566
|
+
input.resource &&
|
|
567
|
+
source === activeTextEditorControl.getModifiedEditor() &&
|
|
568
|
+
activeTextEditorControl.getModel() &&
|
|
569
|
+
isEqual(input.resource, activeTextEditorControl.getModel().modified.uri)
|
|
570
|
+
) {
|
|
571
|
+
const targetEditor = activeTextEditorControl.getModifiedEditor();
|
|
572
|
+
applyTextEditorOptions(input.options, targetEditor, 0 );
|
|
573
|
+
return targetEditor;
|
|
574
|
+
}
|
|
575
|
+
return this.doOpenCodeEditor(input, source, sideBySide);
|
|
576
|
+
}
|
|
577
|
+
async doOpenCodeEditor(input, source, sideBySide) {
|
|
578
|
+
const enablePreviewFromCodeNavigation = this.configurationService.getValue().workbench?.editor?.enablePreviewFromCodeNavigation;
|
|
579
|
+
if (!enablePreviewFromCodeNavigation &&
|
|
580
|
+
source &&
|
|
581
|
+
!input.options?.pinned &&
|
|
582
|
+
!sideBySide &&
|
|
583
|
+
!isEqual(source.getModel()?.uri, input.resource)
|
|
584
|
+
) {
|
|
585
|
+
for (const visiblePane of this.editorService.visibleEditorPanes) {
|
|
586
|
+
if (getCodeEditor(visiblePane.getControl()) === source) {
|
|
587
|
+
visiblePane.group.pinEditor();
|
|
588
|
+
break;
|
|
589
|
+
}
|
|
590
|
+
}
|
|
591
|
+
}
|
|
592
|
+
const control = await this.editorService.openEditor(input, sideBySide ? SIDE_GROUP : ACTIVE_GROUP);
|
|
593
|
+
if (control) {
|
|
594
|
+
const widget = control.getControl();
|
|
595
|
+
if (isCodeEditor(widget)) {
|
|
596
|
+
return widget;
|
|
597
|
+
}
|
|
598
|
+
if (isCompositeEditor(widget) && isCodeEditor(widget.activeCodeEditor)) {
|
|
599
|
+
return widget.activeCodeEditor;
|
|
600
|
+
}
|
|
601
|
+
}
|
|
602
|
+
return null;
|
|
603
|
+
}
|
|
604
|
+
};
|
|
605
|
+
CodeEditorService = __decorate([
|
|
606
|
+
__param(0, IEditorService),
|
|
607
|
+
__param(1, IThemeService),
|
|
608
|
+
__param(2, IConfigurationService)
|
|
609
|
+
], CodeEditorService);
|
|
610
|
+
const DEFAULT_EDITOR_MIN_DIMENSIONS = new Dimension(220, 70);
|
|
611
|
+
const DEFAULT_EDITOR_MAX_DIMENSIONS = new Dimension(Number.POSITIVE_INFINITY, Number.POSITIVE_INFINITY);
|
|
612
|
+
class SimpleEditorPane {
|
|
613
|
+
constructor(editor) {
|
|
614
|
+
this.editor = editor;
|
|
615
|
+
this.onDidChangeControl = Event.None;
|
|
616
|
+
this.onDidChangeSizeConstraints = Event.None;
|
|
617
|
+
this.onDidFocus = Event.None;
|
|
618
|
+
this.onDidBlur = Event.None;
|
|
619
|
+
this.input = undefined;
|
|
620
|
+
this.options = undefined;
|
|
621
|
+
this.group = undefined;
|
|
622
|
+
this.scopedContextKeyService = undefined;
|
|
623
|
+
this.getViewState = unsupported;
|
|
624
|
+
this.isVisible = unsupported;
|
|
625
|
+
this.hasFocus = unsupported;
|
|
626
|
+
this.getId = unsupported;
|
|
627
|
+
this.getTitle = unsupported;
|
|
628
|
+
this.focus = unsupported;
|
|
629
|
+
}
|
|
630
|
+
get minimumWidth() { return DEFAULT_EDITOR_MIN_DIMENSIONS.width; }
|
|
631
|
+
get maximumWidth() { return DEFAULT_EDITOR_MAX_DIMENSIONS.width; }
|
|
632
|
+
get minimumHeight() { return DEFAULT_EDITOR_MIN_DIMENSIONS.height; }
|
|
633
|
+
get maximumHeight() { return DEFAULT_EDITOR_MAX_DIMENSIONS.height; }
|
|
634
|
+
getControl() {
|
|
635
|
+
return this.editor;
|
|
636
|
+
}
|
|
637
|
+
}
|
|
638
|
+
let EditorService = class EditorService {
|
|
639
|
+
constructor(_openEditor, textModelService) {
|
|
640
|
+
this._openEditor = _openEditor;
|
|
641
|
+
this.textModelService = textModelService;
|
|
642
|
+
this.onDidActiveEditorChange = Event.None;
|
|
643
|
+
this.onDidVisibleEditorsChange = Event.None;
|
|
644
|
+
this.onDidEditorsChange = Event.None;
|
|
645
|
+
this.onDidCloseEditor = Event.None;
|
|
646
|
+
this.activeTextEditorControl = undefined;
|
|
647
|
+
this.activeTextEditorLanguageId = undefined;
|
|
648
|
+
this.visibleEditorPanes = [];
|
|
649
|
+
this.visibleEditors = [];
|
|
650
|
+
this.visibleTextEditorControls = [];
|
|
651
|
+
this.editors = [];
|
|
652
|
+
this.count = 0;
|
|
653
|
+
this.getEditors = () => [];
|
|
654
|
+
this.openEditors = unsupported;
|
|
655
|
+
this.replaceEditors = unsupported;
|
|
656
|
+
this.isOpened = () => false;
|
|
657
|
+
this.isVisible = () => false;
|
|
658
|
+
this.findEditors = () => [];
|
|
659
|
+
this.save = unsupported;
|
|
660
|
+
this.saveAll = unsupported;
|
|
661
|
+
this.revert = unsupported;
|
|
662
|
+
this.revertAll = unsupported;
|
|
663
|
+
}
|
|
664
|
+
async openEditor(editor, optionsOrPreferredGroup, preferredGroup) {
|
|
665
|
+
const options = isEditorInput(editor) ? optionsOrPreferredGroup : editor.options;
|
|
666
|
+
if (isPreferredGroup(optionsOrPreferredGroup)) {
|
|
667
|
+
preferredGroup = optionsOrPreferredGroup;
|
|
668
|
+
}
|
|
669
|
+
const resource = isResourceEditorInput(editor) || isEditorInput(editor) ? editor.resource : undefined;
|
|
670
|
+
if (resource == null) {
|
|
671
|
+
throw new Error('Diff editors not supported');
|
|
672
|
+
}
|
|
673
|
+
let modelEditor;
|
|
674
|
+
const modelService = StandaloneServices.get(IModelService);
|
|
675
|
+
let model = modelService.getModel(resource);
|
|
676
|
+
let newModelRef;
|
|
677
|
+
if (model == null) {
|
|
678
|
+
const modelRef = await this.textModelService.createModelReference(resource);
|
|
679
|
+
model = modelRef.object.textEditorModel;
|
|
680
|
+
}
|
|
681
|
+
else {
|
|
682
|
+
const codeEditors = StandaloneServices.get(ICodeEditorService).listCodeEditors();
|
|
683
|
+
modelEditor = codeEditors.find(editor => editor.getModel() === model);
|
|
684
|
+
}
|
|
685
|
+
if (modelEditor == null) {
|
|
686
|
+
modelEditor = await this._openEditor(model, options, preferredGroup === SIDE_GROUP);
|
|
687
|
+
}
|
|
688
|
+
if (modelEditor == null) {
|
|
689
|
+
newModelRef?.dispose();
|
|
690
|
+
return undefined;
|
|
691
|
+
}
|
|
692
|
+
if (options != null) {
|
|
693
|
+
applyTextEditorOptions(options, modelEditor, 1 );
|
|
694
|
+
}
|
|
695
|
+
return new SimpleEditorPane(modelEditor);
|
|
696
|
+
}
|
|
697
|
+
};
|
|
698
|
+
EditorService = __decorate([
|
|
699
|
+
__param(1, ITextModelService)
|
|
700
|
+
], EditorService);
|
|
701
|
+
class CustomTextModelResolverService extends TextModelResolverService {
|
|
702
|
+
async createModelReference(resource) {
|
|
703
|
+
const ref = await super.createModelReference(resource);
|
|
704
|
+
ref.object.textEditorModel.onWillDispose(() => {
|
|
705
|
+
ref.dispose();
|
|
706
|
+
});
|
|
707
|
+
return ref;
|
|
708
|
+
}
|
|
709
|
+
}
|
|
710
|
+
function getServiceOverride(openEditor) {
|
|
711
|
+
return {
|
|
712
|
+
[ITextModelService.toString()]: new SyncDescriptor(CustomTextModelResolverService),
|
|
713
|
+
[ICodeEditorService.toString()]: new SyncDescriptor(CodeEditorService),
|
|
714
|
+
[IEditorService.toString()]: new SyncDescriptor(EditorService, [openEditor])
|
|
715
|
+
};
|
|
716
|
+
}
|
|
717
|
+
export { getServiceOverride as default };
|