@theia/preferences 1.45.1 → 1.46.0-next.72
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 +81 -81
- package/lib/browser/abstract-resource-preference-provider.d.ts +47 -47
- package/lib/browser/abstract-resource-preference-provider.js +240 -240
- package/lib/browser/abstract-resource-preference-provider.spec.d.ts +1 -1
- package/lib/browser/abstract-resource-preference-provider.spec.js +83 -83
- package/lib/browser/folder-preference-provider.d.ts +20 -20
- package/lib/browser/folder-preference-provider.js +59 -59
- package/lib/browser/folders-preferences-provider.d.ts +27 -27
- package/lib/browser/folders-preferences-provider.js +245 -245
- package/lib/browser/index.d.ts +7 -7
- package/lib/browser/index.js +34 -34
- package/lib/browser/monaco-jsonc-editor.d.ts +9 -9
- package/lib/browser/monaco-jsonc-editor.js +80 -80
- package/lib/browser/package.spec.js +25 -25
- package/lib/browser/preference-bindings.d.ts +4 -4
- package/lib/browser/preference-bindings.js +63 -63
- package/lib/browser/preference-frontend-module.d.ts +6 -6
- package/lib/browser/preference-frontend-module.js +52 -52
- package/lib/browser/preference-open-handler.d.ts +9 -9
- package/lib/browser/preference-open-handler.js +64 -64
- package/lib/browser/preference-transaction-manager.d.ts +100 -100
- package/lib/browser/preference-transaction-manager.js +293 -293
- package/lib/browser/preference-tree-model.d.ts +60 -60
- package/lib/browser/preference-tree-model.js +243 -243
- package/lib/browser/preferences-contribution.d.ts +37 -37
- package/lib/browser/preferences-contribution.js +280 -280
- package/lib/browser/preferences-json-schema-contribution.d.ts +17 -17
- package/lib/browser/preferences-json-schema-contribution.js +91 -91
- package/lib/browser/preferences-monaco-contribution.d.ts +1 -1
- package/lib/browser/preferences-monaco-contribution.js +27 -27
- package/lib/browser/section-preference-provider.d.ts +21 -21
- package/lib/browser/section-preference-provider.js +96 -96
- package/lib/browser/user-configs-preference-provider.d.ts +22 -22
- package/lib/browser/user-configs-preference-provider.js +137 -137
- package/lib/browser/user-preference-provider.d.ts +13 -13
- package/lib/browser/user-preference-provider.js +41 -41
- package/lib/browser/util/preference-scope-command-manager.d.ts +17 -17
- package/lib/browser/util/preference-scope-command-manager.js +87 -87
- package/lib/browser/util/preference-tree-generator.d.ts +31 -31
- package/lib/browser/util/preference-tree-generator.js +237 -237
- package/lib/browser/util/preference-tree-label-provider.d.ts +11 -11
- package/lib/browser/util/preference-tree-label-provider.js +77 -77
- package/lib/browser/util/preference-tree-label-provider.spec.d.ts +1 -1
- package/lib/browser/util/preference-tree-label-provider.spec.js +87 -87
- package/lib/browser/util/preference-types.d.ts +62 -62
- package/lib/browser/util/preference-types.js +128 -128
- package/lib/browser/views/components/preference-array-input.d.ts +28 -28
- package/lib/browser/views/components/preference-array-input.js +180 -180
- package/lib/browser/views/components/preference-boolean-input.d.ts +17 -17
- package/lib/browser/views/components/preference-boolean-input.js +79 -79
- package/lib/browser/views/components/preference-file-input.d.ts +29 -29
- package/lib/browser/views/components/preference-file-input.js +110 -110
- package/lib/browser/views/components/preference-json-input.d.ts +19 -19
- package/lib/browser/views/components/preference-json-input.js +93 -93
- package/lib/browser/views/components/preference-markdown-renderer.d.ts +12 -12
- package/lib/browser/views/components/preference-markdown-renderer.js +81 -81
- package/lib/browser/views/components/preference-node-renderer-creator.d.ts +48 -48
- package/lib/browser/views/components/preference-node-renderer-creator.js +132 -132
- package/lib/browser/views/components/preference-node-renderer.d.ts +112 -112
- package/lib/browser/views/components/preference-node-renderer.js +441 -441
- package/lib/browser/views/components/preference-number-input.d.ts +34 -34
- package/lib/browser/views/components/preference-number-input.js +142 -142
- package/lib/browser/views/components/preference-select-input.d.ts +28 -28
- package/lib/browser/views/components/preference-select-input.js +138 -138
- package/lib/browser/views/components/preference-string-input.d.ts +17 -17
- package/lib/browser/views/components/preference-string-input.js +89 -89
- package/lib/browser/views/preference-editor-widget.d.ts +67 -67
- package/lib/browser/views/preference-editor-widget.js +363 -363
- package/lib/browser/views/preference-scope-tabbar-widget.d.ts +54 -54
- package/lib/browser/views/preference-scope-tabbar-widget.js +343 -343
- package/lib/browser/views/preference-searchbar-widget.d.ts +53 -53
- package/lib/browser/views/preference-searchbar-widget.js +173 -173
- package/lib/browser/views/preference-tree-widget.d.ts +17 -17
- package/lib/browser/views/preference-tree-widget.js +104 -104
- package/lib/browser/views/preference-widget-bindings.d.ts +3 -3
- package/lib/browser/views/preference-widget-bindings.js +87 -87
- package/lib/browser/views/preference-widget.d.ts +36 -36
- package/lib/browser/views/preference-widget.js +126 -126
- package/lib/browser/workspace-file-preference-provider.d.ts +23 -23
- package/lib/browser/workspace-file-preference-provider.js +110 -110
- package/lib/browser/workspace-preference-provider.d.ts +28 -28
- package/lib/browser/workspace-preference-provider.js +142 -142
- package/package.json +10 -10
- package/src/browser/abstract-resource-preference-provider.spec.ts +95 -95
- package/src/browser/abstract-resource-preference-provider.ts +232 -232
- package/src/browser/folder-preference-provider.ts +58 -58
- package/src/browser/folders-preferences-provider.ts +244 -244
- package/src/browser/index.ts +23 -23
- package/src/browser/monaco-jsonc-editor.ts +67 -67
- package/src/browser/package.spec.ts +28 -28
- package/src/browser/preference-bindings.ts +65 -65
- package/src/browser/preference-frontend-module.ts +57 -57
- package/src/browser/preference-open-handler.ts +53 -53
- package/src/browser/preference-transaction-manager.ts +287 -287
- package/src/browser/preference-tree-model.ts +250 -250
- package/src/browser/preferences-contribution.ts +263 -263
- package/src/browser/preferences-json-schema-contribution.ts +86 -86
- package/src/browser/preferences-monaco-contribution.ts +27 -27
- package/src/browser/section-preference-provider.ts +83 -83
- package/src/browser/style/index.css +506 -506
- package/src/browser/style/preference-array.css +94 -94
- package/src/browser/style/preference-context-menu.css +74 -74
- package/src/browser/style/preference-file.css +31 -31
- package/src/browser/style/preference-object.css +49 -49
- package/src/browser/style/search-input.css +66 -66
- package/src/browser/user-configs-preference-provider.ts +127 -127
- package/src/browser/user-preference-provider.ts +35 -35
- package/src/browser/util/preference-scope-command-manager.ts +75 -75
- package/src/browser/util/preference-tree-generator.ts +226 -226
- package/src/browser/util/preference-tree-label-provider.spec.ts +108 -108
- package/src/browser/util/preference-tree-label-provider.ts +64 -64
- package/src/browser/util/preference-types.ts +169 -169
- package/src/browser/views/components/preference-array-input.ts +174 -174
- package/src/browser/views/components/preference-boolean-input.ts +69 -69
- package/src/browser/views/components/preference-file-input.ts +104 -104
- package/src/browser/views/components/preference-json-input.ts +78 -78
- package/src/browser/views/components/preference-markdown-renderer.ts +68 -68
- package/src/browser/views/components/preference-node-renderer-creator.ts +141 -141
- package/src/browser/views/components/preference-node-renderer.ts +477 -477
- package/src/browser/views/components/preference-number-input.ts +147 -147
- package/src/browser/views/components/preference-select-input.ts +131 -131
- package/src/browser/views/components/preference-string-input.ts +76 -76
- package/src/browser/views/preference-editor-widget.ts +349 -349
- package/src/browser/views/preference-scope-tabbar-widget.tsx +344 -344
- package/src/browser/views/preference-searchbar-widget.tsx +183 -183
- package/src/browser/views/preference-tree-widget.tsx +93 -93
- package/src/browser/views/preference-widget-bindings.ts +102 -102
- package/src/browser/views/preference-widget.tsx +117 -117
- package/src/browser/workspace-file-preference-provider.ts +100 -100
- package/src/browser/workspace-preference-provider.ts +134 -134
|
@@ -1,294 +1,294 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// *****************************************************************************
|
|
3
|
-
// Copyright (C) 2021 Ericsson and others.
|
|
4
|
-
//
|
|
5
|
-
// This program and the accompanying materials are made available under the
|
|
6
|
-
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
7
|
-
// http://www.eclipse.org/legal/epl-2.0.
|
|
8
|
-
//
|
|
9
|
-
// This Source Code may also be made available under the following Secondary
|
|
10
|
-
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
11
|
-
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
12
|
-
// with the GNU Classpath Exception which is available at
|
|
13
|
-
// https://www.gnu.org/software/classpath/license.html.
|
|
14
|
-
//
|
|
15
|
-
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
16
|
-
// *****************************************************************************
|
|
17
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
18
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
19
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
20
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
21
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
22
|
-
};
|
|
23
|
-
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
24
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
25
|
-
};
|
|
26
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
27
|
-
exports.preferenceTransactionFactoryCreator = exports.PreferenceTransactionFactory = exports.PreferenceTransaction = exports.PreferenceTransactionPreludeProvider = exports.PreferenceContext = exports.Transaction = void 0;
|
|
28
|
-
const core_1 = require("@theia/core");
|
|
29
|
-
const promise_util_1 = require("@theia/core/lib/common/promise-util");
|
|
30
|
-
const inversify_1 = require("@theia/core/shared/inversify");
|
|
31
|
-
const preference_scope_1 = require("@theia/core/lib/common/preferences/preference-scope");
|
|
32
|
-
const uri_1 = require("@theia/core/lib/common/uri");
|
|
33
|
-
const async_mutex_1 = require("async-mutex");
|
|
34
|
-
const monaco_text_model_service_1 = require("@theia/monaco/lib/browser/monaco-text-model-service");
|
|
35
|
-
const monaco_jsonc_editor_1 = require("./monaco-jsonc-editor");
|
|
36
|
-
const editor_manager_1 = require("@theia/editor/lib/browser/editor-manager");
|
|
37
|
-
let Transaction =
|
|
38
|
-
/**
|
|
39
|
-
* Represents a batch of interactions with an underlying resource.
|
|
40
|
-
*/
|
|
41
|
-
class Transaction {
|
|
42
|
-
constructor() {
|
|
43
|
-
this._open = true;
|
|
44
|
-
this._result = new promise_util_1.Deferred();
|
|
45
|
-
/**
|
|
46
|
-
* The transaction will self-dispose when the queue is empty, once at least one action has been processed.
|
|
47
|
-
*/
|
|
48
|
-
this.queue = new async_mutex_1.Mutex(new core_1.CancellationError());
|
|
49
|
-
this.onWillConcludeEmitter = new core_1.Emitter();
|
|
50
|
-
this.status = new promise_util_1.Deferred();
|
|
51
|
-
/**
|
|
52
|
-
* Whether any actions have been added to the transaction.
|
|
53
|
-
* The Transaction will not self-dispose until at least one action has been performed.
|
|
54
|
-
*/
|
|
55
|
-
this.inUse = false;
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* Whether the transaction is still accepting new interactions.
|
|
59
|
-
* Enqueueing an action when the Transaction is no longer open will throw an error.
|
|
60
|
-
*/
|
|
61
|
-
get open() {
|
|
62
|
-
return this._open;
|
|
63
|
-
}
|
|
64
|
-
/**
|
|
65
|
-
* The status of the transaction when complete.
|
|
66
|
-
*/
|
|
67
|
-
get result() {
|
|
68
|
-
return this._result.promise;
|
|
69
|
-
}
|
|
70
|
-
/**
|
|
71
|
-
* An event fired when the transaction is wrapping up.
|
|
72
|
-
* Consumers can call `waitUntil` on the event to delay the resolution of the `result` Promise.
|
|
73
|
-
*/
|
|
74
|
-
get onWillConclude() {
|
|
75
|
-
return this.onWillConcludeEmitter.event;
|
|
76
|
-
}
|
|
77
|
-
init() {
|
|
78
|
-
this.doInit();
|
|
79
|
-
}
|
|
80
|
-
async doInit() {
|
|
81
|
-
const release = await this.queue.acquire();
|
|
82
|
-
try {
|
|
83
|
-
const status = await this.setUp();
|
|
84
|
-
this.status.resolve(status);
|
|
85
|
-
}
|
|
86
|
-
catch {
|
|
87
|
-
this.dispose();
|
|
88
|
-
}
|
|
89
|
-
finally {
|
|
90
|
-
release();
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
async waitFor(delay, disposeIfRejected) {
|
|
94
|
-
try {
|
|
95
|
-
await this.queue.runExclusive(() => delay);
|
|
96
|
-
}
|
|
97
|
-
catch {
|
|
98
|
-
if (disposeIfRejected) {
|
|
99
|
-
this.dispose();
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
/**
|
|
104
|
-
* @returns a promise reflecting the result of performing an action. Typically the promise will not resolve until the whole transaction is complete.
|
|
105
|
-
*/
|
|
106
|
-
async enqueueAction(...args) {
|
|
107
|
-
if (this._open) {
|
|
108
|
-
let release;
|
|
109
|
-
try {
|
|
110
|
-
release = await this.queue.acquire();
|
|
111
|
-
if (!this.inUse) {
|
|
112
|
-
this.inUse = true;
|
|
113
|
-
this.disposeWhenDone();
|
|
114
|
-
}
|
|
115
|
-
return this.act(...args);
|
|
116
|
-
}
|
|
117
|
-
catch (e) {
|
|
118
|
-
if (e instanceof core_1.CancellationError) {
|
|
119
|
-
throw e;
|
|
120
|
-
}
|
|
121
|
-
return false;
|
|
122
|
-
}
|
|
123
|
-
finally {
|
|
124
|
-
release === null || release === void 0 ? void 0 : release();
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
else {
|
|
128
|
-
throw new Error('Transaction used after disposal.');
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
disposeWhenDone() {
|
|
132
|
-
// Due to properties of the micro task system, it's possible for something to have been enqueued between
|
|
133
|
-
// the resolution of the waitForUnlock() promise and the the time this code runs, so we have to check.
|
|
134
|
-
this.queue.waitForUnlock().then(() => {
|
|
135
|
-
if (!this.queue.isLocked()) {
|
|
136
|
-
this.dispose();
|
|
137
|
-
}
|
|
138
|
-
else {
|
|
139
|
-
this.disposeWhenDone();
|
|
140
|
-
}
|
|
141
|
-
});
|
|
142
|
-
}
|
|
143
|
-
async conclude() {
|
|
144
|
-
if (this._open) {
|
|
145
|
-
try {
|
|
146
|
-
this._open = false;
|
|
147
|
-
this.queue.cancel();
|
|
148
|
-
const result = await this.tearDown();
|
|
149
|
-
const status = this.status.state === 'unresolved' || this.status.state === 'rejected' ? false : await this.status.promise;
|
|
150
|
-
await core_1.WaitUntilEvent.fire(this.onWillConcludeEmitter, { status });
|
|
151
|
-
this.onWillConcludeEmitter.dispose();
|
|
152
|
-
this._result.resolve(result);
|
|
153
|
-
}
|
|
154
|
-
catch {
|
|
155
|
-
this._result.resolve(false);
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
dispose() {
|
|
160
|
-
this.conclude();
|
|
161
|
-
}
|
|
162
|
-
};
|
|
163
|
-
__decorate([
|
|
164
|
-
(0, inversify_1.postConstruct)(),
|
|
165
|
-
__metadata("design:type", Function),
|
|
166
|
-
__metadata("design:paramtypes", []),
|
|
167
|
-
__metadata("design:returntype", void 0)
|
|
168
|
-
], Transaction.prototype, "init", null);
|
|
169
|
-
Transaction = __decorate([
|
|
170
|
-
(0, inversify_1.injectable)()
|
|
171
|
-
/**
|
|
172
|
-
* Represents a batch of interactions with an underlying resource.
|
|
173
|
-
*/
|
|
174
|
-
], Transaction);
|
|
175
|
-
exports.Transaction = Transaction;
|
|
176
|
-
exports.PreferenceContext = Symbol('PreferenceContext');
|
|
177
|
-
exports.PreferenceTransactionPreludeProvider = Symbol('PreferenceTransactionPreludeProvider');
|
|
178
|
-
let PreferenceTransaction = class PreferenceTransaction extends Transaction {
|
|
179
|
-
async doInit() {
|
|
180
|
-
var _a;
|
|
181
|
-
this.waitFor((_a = this.prelude) === null || _a === void 0 ? void 0 : _a.call(this));
|
|
182
|
-
await super.doInit();
|
|
183
|
-
}
|
|
184
|
-
async setUp() {
|
|
185
|
-
const reference = await this.textModelService.createModelReference(this.context.getConfigUri());
|
|
186
|
-
if (this._open) {
|
|
187
|
-
this.reference = reference;
|
|
188
|
-
}
|
|
189
|
-
else {
|
|
190
|
-
reference.dispose();
|
|
191
|
-
return false;
|
|
192
|
-
}
|
|
193
|
-
if (reference.object.dirty) {
|
|
194
|
-
const shouldContinue = await this.handleDirtyEditor();
|
|
195
|
-
if (!shouldContinue) {
|
|
196
|
-
this.dispose();
|
|
197
|
-
return false;
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
return true;
|
|
201
|
-
}
|
|
202
|
-
/**
|
|
203
|
-
* @returns whether the setting operation in progress, and any others started in the meantime, should continue.
|
|
204
|
-
*/
|
|
205
|
-
async handleDirtyEditor() {
|
|
206
|
-
var _a;
|
|
207
|
-
const saveAndRetry = core_1.nls.localizeByDefault('Save and Retry');
|
|
208
|
-
const open = core_1.nls.localizeByDefault('Open File');
|
|
209
|
-
const msg = await this.messageService.error(
|
|
210
|
-
// eslint-disable-next-line @theia/localization-check
|
|
211
|
-
core_1.nls.localizeByDefault('Unable to write into {0} settings because the file has unsaved changes. Please save the {0} settings file first and then try again.', core_1.nls.localizeByDefault(preference_scope_1.PreferenceScope[this.context.getScope()].toLocaleLowerCase())), saveAndRetry, open);
|
|
212
|
-
if ((_a = this.reference) === null || _a === void 0 ? void 0 : _a.object) {
|
|
213
|
-
if (msg === open) {
|
|
214
|
-
this.editorManager.open(new uri_1.default(this.reference.object.uri));
|
|
215
|
-
}
|
|
216
|
-
else if (msg === saveAndRetry) {
|
|
217
|
-
await this.reference.object.save();
|
|
218
|
-
return true;
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
return false;
|
|
222
|
-
}
|
|
223
|
-
async act(key, path, value) {
|
|
224
|
-
var _a;
|
|
225
|
-
const model = (_a = this.reference) === null || _a === void 0 ? void 0 : _a.object;
|
|
226
|
-
try {
|
|
227
|
-
if (model) {
|
|
228
|
-
await this.jsoncEditor.setValue(model, path, value);
|
|
229
|
-
return this.result;
|
|
230
|
-
}
|
|
231
|
-
return false;
|
|
232
|
-
}
|
|
233
|
-
catch (e) {
|
|
234
|
-
const message = `Failed to update the value of '${key}' in '${this.context.getConfigUri()}'.`;
|
|
235
|
-
this.messageService.error(`${message} Please check if it is corrupted.`);
|
|
236
|
-
console.error(`${message}`, e);
|
|
237
|
-
return false;
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
async tearDown() {
|
|
241
|
-
var _a, _b;
|
|
242
|
-
try {
|
|
243
|
-
const model = (_a = this.reference) === null || _a === void 0 ? void 0 : _a.object;
|
|
244
|
-
if (model) {
|
|
245
|
-
if (this.status.state === 'resolved' && await this.status.promise) {
|
|
246
|
-
await model.save();
|
|
247
|
-
return true;
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
return false;
|
|
251
|
-
}
|
|
252
|
-
finally {
|
|
253
|
-
(_b = this.reference) === null || _b === void 0 ? void 0 : _b.dispose();
|
|
254
|
-
this.reference = undefined;
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
};
|
|
258
|
-
__decorate([
|
|
259
|
-
(0, inversify_1.inject)(exports.PreferenceContext),
|
|
260
|
-
__metadata("design:type", Object)
|
|
261
|
-
], PreferenceTransaction.prototype, "context", void 0);
|
|
262
|
-
__decorate([
|
|
263
|
-
(0, inversify_1.inject)(exports.PreferenceTransactionPreludeProvider),
|
|
264
|
-
__metadata("design:type", Function)
|
|
265
|
-
], PreferenceTransaction.prototype, "prelude", void 0);
|
|
266
|
-
__decorate([
|
|
267
|
-
(0, inversify_1.inject)(monaco_text_model_service_1.MonacoTextModelService),
|
|
268
|
-
__metadata("design:type", monaco_text_model_service_1.MonacoTextModelService)
|
|
269
|
-
], PreferenceTransaction.prototype, "textModelService", void 0);
|
|
270
|
-
__decorate([
|
|
271
|
-
(0, inversify_1.inject)(monaco_jsonc_editor_1.MonacoJSONCEditor),
|
|
272
|
-
__metadata("design:type", monaco_jsonc_editor_1.MonacoJSONCEditor)
|
|
273
|
-
], PreferenceTransaction.prototype, "jsoncEditor", void 0);
|
|
274
|
-
__decorate([
|
|
275
|
-
(0, inversify_1.inject)(core_1.MessageService),
|
|
276
|
-
__metadata("design:type", core_1.MessageService)
|
|
277
|
-
], PreferenceTransaction.prototype, "messageService", void 0);
|
|
278
|
-
__decorate([
|
|
279
|
-
(0, inversify_1.inject)(editor_manager_1.EditorManager),
|
|
280
|
-
__metadata("design:type", editor_manager_1.EditorManager)
|
|
281
|
-
], PreferenceTransaction.prototype, "editorManager", void 0);
|
|
282
|
-
PreferenceTransaction = __decorate([
|
|
283
|
-
(0, inversify_1.injectable)()
|
|
284
|
-
], PreferenceTransaction);
|
|
285
|
-
exports.PreferenceTransaction = PreferenceTransaction;
|
|
286
|
-
exports.PreferenceTransactionFactory = Symbol('PreferenceTransactionFactory');
|
|
287
|
-
const preferenceTransactionFactoryCreator = ({ container }) => (context, waitFor) => {
|
|
288
|
-
const child = container.createChild();
|
|
289
|
-
child.bind(exports.PreferenceContext).toConstantValue(context);
|
|
290
|
-
child.bind(exports.PreferenceTransactionPreludeProvider).toConstantValue(() => waitFor);
|
|
291
|
-
return child.get(PreferenceTransaction);
|
|
292
|
-
};
|
|
293
|
-
exports.preferenceTransactionFactoryCreator = preferenceTransactionFactoryCreator;
|
|
1
|
+
"use strict";
|
|
2
|
+
// *****************************************************************************
|
|
3
|
+
// Copyright (C) 2021 Ericsson and others.
|
|
4
|
+
//
|
|
5
|
+
// This program and the accompanying materials are made available under the
|
|
6
|
+
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
7
|
+
// http://www.eclipse.org/legal/epl-2.0.
|
|
8
|
+
//
|
|
9
|
+
// This Source Code may also be made available under the following Secondary
|
|
10
|
+
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
11
|
+
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
12
|
+
// with the GNU Classpath Exception which is available at
|
|
13
|
+
// https://www.gnu.org/software/classpath/license.html.
|
|
14
|
+
//
|
|
15
|
+
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
16
|
+
// *****************************************************************************
|
|
17
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
18
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
19
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
20
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
21
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
22
|
+
};
|
|
23
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
24
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
25
|
+
};
|
|
26
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
27
|
+
exports.preferenceTransactionFactoryCreator = exports.PreferenceTransactionFactory = exports.PreferenceTransaction = exports.PreferenceTransactionPreludeProvider = exports.PreferenceContext = exports.Transaction = void 0;
|
|
28
|
+
const core_1 = require("@theia/core");
|
|
29
|
+
const promise_util_1 = require("@theia/core/lib/common/promise-util");
|
|
30
|
+
const inversify_1 = require("@theia/core/shared/inversify");
|
|
31
|
+
const preference_scope_1 = require("@theia/core/lib/common/preferences/preference-scope");
|
|
32
|
+
const uri_1 = require("@theia/core/lib/common/uri");
|
|
33
|
+
const async_mutex_1 = require("async-mutex");
|
|
34
|
+
const monaco_text_model_service_1 = require("@theia/monaco/lib/browser/monaco-text-model-service");
|
|
35
|
+
const monaco_jsonc_editor_1 = require("./monaco-jsonc-editor");
|
|
36
|
+
const editor_manager_1 = require("@theia/editor/lib/browser/editor-manager");
|
|
37
|
+
let Transaction =
|
|
38
|
+
/**
|
|
39
|
+
* Represents a batch of interactions with an underlying resource.
|
|
40
|
+
*/
|
|
41
|
+
class Transaction {
|
|
42
|
+
constructor() {
|
|
43
|
+
this._open = true;
|
|
44
|
+
this._result = new promise_util_1.Deferred();
|
|
45
|
+
/**
|
|
46
|
+
* The transaction will self-dispose when the queue is empty, once at least one action has been processed.
|
|
47
|
+
*/
|
|
48
|
+
this.queue = new async_mutex_1.Mutex(new core_1.CancellationError());
|
|
49
|
+
this.onWillConcludeEmitter = new core_1.Emitter();
|
|
50
|
+
this.status = new promise_util_1.Deferred();
|
|
51
|
+
/**
|
|
52
|
+
* Whether any actions have been added to the transaction.
|
|
53
|
+
* The Transaction will not self-dispose until at least one action has been performed.
|
|
54
|
+
*/
|
|
55
|
+
this.inUse = false;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Whether the transaction is still accepting new interactions.
|
|
59
|
+
* Enqueueing an action when the Transaction is no longer open will throw an error.
|
|
60
|
+
*/
|
|
61
|
+
get open() {
|
|
62
|
+
return this._open;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* The status of the transaction when complete.
|
|
66
|
+
*/
|
|
67
|
+
get result() {
|
|
68
|
+
return this._result.promise;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* An event fired when the transaction is wrapping up.
|
|
72
|
+
* Consumers can call `waitUntil` on the event to delay the resolution of the `result` Promise.
|
|
73
|
+
*/
|
|
74
|
+
get onWillConclude() {
|
|
75
|
+
return this.onWillConcludeEmitter.event;
|
|
76
|
+
}
|
|
77
|
+
init() {
|
|
78
|
+
this.doInit();
|
|
79
|
+
}
|
|
80
|
+
async doInit() {
|
|
81
|
+
const release = await this.queue.acquire();
|
|
82
|
+
try {
|
|
83
|
+
const status = await this.setUp();
|
|
84
|
+
this.status.resolve(status);
|
|
85
|
+
}
|
|
86
|
+
catch {
|
|
87
|
+
this.dispose();
|
|
88
|
+
}
|
|
89
|
+
finally {
|
|
90
|
+
release();
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
async waitFor(delay, disposeIfRejected) {
|
|
94
|
+
try {
|
|
95
|
+
await this.queue.runExclusive(() => delay);
|
|
96
|
+
}
|
|
97
|
+
catch {
|
|
98
|
+
if (disposeIfRejected) {
|
|
99
|
+
this.dispose();
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* @returns a promise reflecting the result of performing an action. Typically the promise will not resolve until the whole transaction is complete.
|
|
105
|
+
*/
|
|
106
|
+
async enqueueAction(...args) {
|
|
107
|
+
if (this._open) {
|
|
108
|
+
let release;
|
|
109
|
+
try {
|
|
110
|
+
release = await this.queue.acquire();
|
|
111
|
+
if (!this.inUse) {
|
|
112
|
+
this.inUse = true;
|
|
113
|
+
this.disposeWhenDone();
|
|
114
|
+
}
|
|
115
|
+
return this.act(...args);
|
|
116
|
+
}
|
|
117
|
+
catch (e) {
|
|
118
|
+
if (e instanceof core_1.CancellationError) {
|
|
119
|
+
throw e;
|
|
120
|
+
}
|
|
121
|
+
return false;
|
|
122
|
+
}
|
|
123
|
+
finally {
|
|
124
|
+
release === null || release === void 0 ? void 0 : release();
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
else {
|
|
128
|
+
throw new Error('Transaction used after disposal.');
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
disposeWhenDone() {
|
|
132
|
+
// Due to properties of the micro task system, it's possible for something to have been enqueued between
|
|
133
|
+
// the resolution of the waitForUnlock() promise and the the time this code runs, so we have to check.
|
|
134
|
+
this.queue.waitForUnlock().then(() => {
|
|
135
|
+
if (!this.queue.isLocked()) {
|
|
136
|
+
this.dispose();
|
|
137
|
+
}
|
|
138
|
+
else {
|
|
139
|
+
this.disposeWhenDone();
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
async conclude() {
|
|
144
|
+
if (this._open) {
|
|
145
|
+
try {
|
|
146
|
+
this._open = false;
|
|
147
|
+
this.queue.cancel();
|
|
148
|
+
const result = await this.tearDown();
|
|
149
|
+
const status = this.status.state === 'unresolved' || this.status.state === 'rejected' ? false : await this.status.promise;
|
|
150
|
+
await core_1.WaitUntilEvent.fire(this.onWillConcludeEmitter, { status });
|
|
151
|
+
this.onWillConcludeEmitter.dispose();
|
|
152
|
+
this._result.resolve(result);
|
|
153
|
+
}
|
|
154
|
+
catch {
|
|
155
|
+
this._result.resolve(false);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
dispose() {
|
|
160
|
+
this.conclude();
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
__decorate([
|
|
164
|
+
(0, inversify_1.postConstruct)(),
|
|
165
|
+
__metadata("design:type", Function),
|
|
166
|
+
__metadata("design:paramtypes", []),
|
|
167
|
+
__metadata("design:returntype", void 0)
|
|
168
|
+
], Transaction.prototype, "init", null);
|
|
169
|
+
Transaction = __decorate([
|
|
170
|
+
(0, inversify_1.injectable)()
|
|
171
|
+
/**
|
|
172
|
+
* Represents a batch of interactions with an underlying resource.
|
|
173
|
+
*/
|
|
174
|
+
], Transaction);
|
|
175
|
+
exports.Transaction = Transaction;
|
|
176
|
+
exports.PreferenceContext = Symbol('PreferenceContext');
|
|
177
|
+
exports.PreferenceTransactionPreludeProvider = Symbol('PreferenceTransactionPreludeProvider');
|
|
178
|
+
let PreferenceTransaction = class PreferenceTransaction extends Transaction {
|
|
179
|
+
async doInit() {
|
|
180
|
+
var _a;
|
|
181
|
+
this.waitFor((_a = this.prelude) === null || _a === void 0 ? void 0 : _a.call(this));
|
|
182
|
+
await super.doInit();
|
|
183
|
+
}
|
|
184
|
+
async setUp() {
|
|
185
|
+
const reference = await this.textModelService.createModelReference(this.context.getConfigUri());
|
|
186
|
+
if (this._open) {
|
|
187
|
+
this.reference = reference;
|
|
188
|
+
}
|
|
189
|
+
else {
|
|
190
|
+
reference.dispose();
|
|
191
|
+
return false;
|
|
192
|
+
}
|
|
193
|
+
if (reference.object.dirty) {
|
|
194
|
+
const shouldContinue = await this.handleDirtyEditor();
|
|
195
|
+
if (!shouldContinue) {
|
|
196
|
+
this.dispose();
|
|
197
|
+
return false;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
return true;
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* @returns whether the setting operation in progress, and any others started in the meantime, should continue.
|
|
204
|
+
*/
|
|
205
|
+
async handleDirtyEditor() {
|
|
206
|
+
var _a;
|
|
207
|
+
const saveAndRetry = core_1.nls.localizeByDefault('Save and Retry');
|
|
208
|
+
const open = core_1.nls.localizeByDefault('Open File');
|
|
209
|
+
const msg = await this.messageService.error(
|
|
210
|
+
// eslint-disable-next-line @theia/localization-check
|
|
211
|
+
core_1.nls.localizeByDefault('Unable to write into {0} settings because the file has unsaved changes. Please save the {0} settings file first and then try again.', core_1.nls.localizeByDefault(preference_scope_1.PreferenceScope[this.context.getScope()].toLocaleLowerCase())), saveAndRetry, open);
|
|
212
|
+
if ((_a = this.reference) === null || _a === void 0 ? void 0 : _a.object) {
|
|
213
|
+
if (msg === open) {
|
|
214
|
+
this.editorManager.open(new uri_1.default(this.reference.object.uri));
|
|
215
|
+
}
|
|
216
|
+
else if (msg === saveAndRetry) {
|
|
217
|
+
await this.reference.object.save();
|
|
218
|
+
return true;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
return false;
|
|
222
|
+
}
|
|
223
|
+
async act(key, path, value) {
|
|
224
|
+
var _a;
|
|
225
|
+
const model = (_a = this.reference) === null || _a === void 0 ? void 0 : _a.object;
|
|
226
|
+
try {
|
|
227
|
+
if (model) {
|
|
228
|
+
await this.jsoncEditor.setValue(model, path, value);
|
|
229
|
+
return this.result;
|
|
230
|
+
}
|
|
231
|
+
return false;
|
|
232
|
+
}
|
|
233
|
+
catch (e) {
|
|
234
|
+
const message = `Failed to update the value of '${key}' in '${this.context.getConfigUri()}'.`;
|
|
235
|
+
this.messageService.error(`${message} Please check if it is corrupted.`);
|
|
236
|
+
console.error(`${message}`, e);
|
|
237
|
+
return false;
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
async tearDown() {
|
|
241
|
+
var _a, _b;
|
|
242
|
+
try {
|
|
243
|
+
const model = (_a = this.reference) === null || _a === void 0 ? void 0 : _a.object;
|
|
244
|
+
if (model) {
|
|
245
|
+
if (this.status.state === 'resolved' && await this.status.promise) {
|
|
246
|
+
await model.save();
|
|
247
|
+
return true;
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
return false;
|
|
251
|
+
}
|
|
252
|
+
finally {
|
|
253
|
+
(_b = this.reference) === null || _b === void 0 ? void 0 : _b.dispose();
|
|
254
|
+
this.reference = undefined;
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
};
|
|
258
|
+
__decorate([
|
|
259
|
+
(0, inversify_1.inject)(exports.PreferenceContext),
|
|
260
|
+
__metadata("design:type", Object)
|
|
261
|
+
], PreferenceTransaction.prototype, "context", void 0);
|
|
262
|
+
__decorate([
|
|
263
|
+
(0, inversify_1.inject)(exports.PreferenceTransactionPreludeProvider),
|
|
264
|
+
__metadata("design:type", Function)
|
|
265
|
+
], PreferenceTransaction.prototype, "prelude", void 0);
|
|
266
|
+
__decorate([
|
|
267
|
+
(0, inversify_1.inject)(monaco_text_model_service_1.MonacoTextModelService),
|
|
268
|
+
__metadata("design:type", monaco_text_model_service_1.MonacoTextModelService)
|
|
269
|
+
], PreferenceTransaction.prototype, "textModelService", void 0);
|
|
270
|
+
__decorate([
|
|
271
|
+
(0, inversify_1.inject)(monaco_jsonc_editor_1.MonacoJSONCEditor),
|
|
272
|
+
__metadata("design:type", monaco_jsonc_editor_1.MonacoJSONCEditor)
|
|
273
|
+
], PreferenceTransaction.prototype, "jsoncEditor", void 0);
|
|
274
|
+
__decorate([
|
|
275
|
+
(0, inversify_1.inject)(core_1.MessageService),
|
|
276
|
+
__metadata("design:type", core_1.MessageService)
|
|
277
|
+
], PreferenceTransaction.prototype, "messageService", void 0);
|
|
278
|
+
__decorate([
|
|
279
|
+
(0, inversify_1.inject)(editor_manager_1.EditorManager),
|
|
280
|
+
__metadata("design:type", editor_manager_1.EditorManager)
|
|
281
|
+
], PreferenceTransaction.prototype, "editorManager", void 0);
|
|
282
|
+
PreferenceTransaction = __decorate([
|
|
283
|
+
(0, inversify_1.injectable)()
|
|
284
|
+
], PreferenceTransaction);
|
|
285
|
+
exports.PreferenceTransaction = PreferenceTransaction;
|
|
286
|
+
exports.PreferenceTransactionFactory = Symbol('PreferenceTransactionFactory');
|
|
287
|
+
const preferenceTransactionFactoryCreator = ({ container }) => (context, waitFor) => {
|
|
288
|
+
const child = container.createChild();
|
|
289
|
+
child.bind(exports.PreferenceContext).toConstantValue(context);
|
|
290
|
+
child.bind(exports.PreferenceTransactionPreludeProvider).toConstantValue(() => waitFor);
|
|
291
|
+
return child.get(PreferenceTransaction);
|
|
292
|
+
};
|
|
293
|
+
exports.preferenceTransactionFactoryCreator = preferenceTransactionFactoryCreator;
|
|
294
294
|
//# sourceMappingURL=preference-transaction-manager.js.map
|