@theia/preferences 1.76.0-next.7 → 1.76.0
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/lib/browser/preference-frontend-contribution.d.ts +18 -0
- package/lib/browser/preference-frontend-contribution.d.ts.map +1 -1
- package/lib/browser/preference-frontend-contribution.js +48 -12
- package/lib/browser/preference-frontend-contribution.js.map +1 -1
- package/lib/browser/preference-frontend-contribution.spec.d.ts +2 -0
- package/lib/browser/preference-frontend-contribution.spec.d.ts.map +1 -0
- package/lib/browser/preference-frontend-contribution.spec.js +76 -0
- package/lib/browser/preference-frontend-contribution.spec.js.map +1 -0
- package/lib/browser/preference-frontend-module.d.ts.map +1 -1
- package/lib/browser/preference-frontend-module.js +4 -0
- package/lib/browser/preference-frontend-module.js.map +1 -1
- package/lib/browser/session-preference-remote-cli-contribution.d.ts +17 -0
- package/lib/browser/session-preference-remote-cli-contribution.d.ts.map +1 -0
- package/lib/browser/session-preference-remote-cli-contribution.js +54 -0
- package/lib/browser/session-preference-remote-cli-contribution.js.map +1 -0
- package/lib/browser/session-preference-remote-cli-contribution.spec.d.ts +2 -0
- package/lib/browser/session-preference-remote-cli-contribution.spec.d.ts.map +1 -0
- package/lib/browser/session-preference-remote-cli-contribution.spec.js +50 -0
- package/lib/browser/session-preference-remote-cli-contribution.spec.js.map +1 -0
- package/lib/common/cli-preferences.d.ts +28 -0
- package/lib/common/cli-preferences.d.ts.map +1 -1
- package/lib/common/cli-preferences.js +66 -1
- package/lib/common/cli-preferences.js.map +1 -1
- package/lib/common/cli-preferences.spec.d.ts +2 -0
- package/lib/common/cli-preferences.spec.d.ts.map +1 -0
- package/lib/common/cli-preferences.spec.js +64 -0
- package/lib/common/cli-preferences.spec.js.map +1 -0
- package/lib/node/preference-cli-contribution.d.ts.map +1 -1
- package/lib/node/preference-cli-contribution.js +3 -22
- package/lib/node/preference-cli-contribution.js.map +1 -1
- package/package.json +9 -9
- package/src/browser/preference-frontend-contribution.spec.ts +92 -0
- package/src/browser/preference-frontend-contribution.ts +50 -13
- package/src/browser/preference-frontend-module.ts +4 -0
- package/src/browser/session-preference-remote-cli-contribution.spec.ts +59 -0
- package/src/browser/session-preference-remote-cli-contribution.ts +49 -0
- package/src/common/cli-preferences.spec.ts +73 -0
- package/src/common/cli-preferences.ts +75 -0
- package/src/node/preference-cli-contribution.ts +3 -22
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli-preferences.spec.js","sourceRoot":"","sources":["../../src/common/cli-preferences.spec.ts"],"names":[],"mappings":";AAAA,gFAAgF;AAChF,oDAAoD;AACpD,EAAE;AACF,2EAA2E;AAC3E,mEAAmE;AACnE,wCAAwC;AACxC,EAAE;AACF,4EAA4E;AAC5E,8EAA8E;AAC9E,6EAA6E;AAC7E,yDAAyD;AACzD,uDAAuD;AACvD,EAAE;AACF,gFAAgF;AAChF,gFAAgF;;AAEhF,+BAA8B;AAC9B,uDAAuD;AAEvD,QAAQ,CAAC,0BAA0B,EAAE,GAAG,EAAE;IAEtC,EAAE,CAAC,mCAAmC,EAAE,GAAG,EAAE;QACzC,IAAA,aAAM,EAAC,oCAAkB,CAAC,KAAK,CAAC,oBAAoB,CAAC,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,iBAAiB,EAAE,EAAE,CAAC,CAAC,CAAC;IAClG,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,uCAAuC,EAAE,GAAG,EAAE;QAC7C,IAAA,aAAM,EAAC,oCAAkB,CAAC,KAAK,CAAC,kBAAkB,CAAC,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,aAAa,EAAE,IAAI,CAAC,CAAC,CAAC;QAC1F,IAAA,aAAM,EAAC,oCAAkB,CAAC,KAAK,CAAC,mBAAmB,CAAC,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC,CAAC;I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AAE,qBAAqB,EAAE,MAAM,qDAAqD,CAAC;AAC9G,OAAO,EAAE,cAAc,
|
|
1
|
+
{"version":3,"file":"preference-cli-contribution.d.ts","sourceRoot":"","sources":["../../src/node/preference-cli-contribution.ts"],"names":[],"mappings":"AAiBA,OAAO,EAAE,IAAI,EAAE,MAAM,0BAA0B,CAAC;AAChD,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAC3D,OAAO,EAAE,gBAAgB,EAAE,qBAAqB,EAAE,MAAM,qDAAqD,CAAC;AAC9G,OAAO,EAAE,cAAc,EAAsB,MAAM,2BAA2B,CAAC;AAC/E,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAEtC,qBACa,yBAA0B,YAAW,eAAe,EAAE,cAAc,EAAE,qBAAqB;IAGpG,SAAS,CAAC,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;IAEnC,SAAS,CAAC,WAAW,EAAE,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAM;IAChD,SAAS,CAAC,kBAAkB,EAAE,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAM;IAEvD,SAAS,CAAC,IAAI,EAAE,IAAI,CAAC,EAAE,CAAC,GAAG,IAAI;IAW/B,YAAY,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI;IASjD,SAAS,CAAC,SAAS,CAAC,GAAG,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,GAAG,IAAI;IAK9D,cAAc,IAAI,OAAO,CAAC,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAC;IAI9C,qBAAqB,IAAI,OAAO,CAAC,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAC;IAI3D;;;;OAIG;IACH,WAAW,CAAC,QAAQ,EAAE,gBAAgB,GAAG,MAAM,EAAE;CAIpD"}
|
|
@@ -18,6 +18,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
18
18
|
exports.PreferenceCliContribution = void 0;
|
|
19
19
|
const tslib_1 = require("tslib");
|
|
20
20
|
const inversify_1 = require("@theia/core/shared/inversify");
|
|
21
|
+
const cli_preferences_1 = require("../common/cli-preferences");
|
|
21
22
|
const core_1 = require("@theia/core");
|
|
22
23
|
let PreferenceCliContribution = class PreferenceCliContribution {
|
|
23
24
|
constructor() {
|
|
@@ -44,24 +45,7 @@ let PreferenceCliContribution = class PreferenceCliContribution {
|
|
|
44
45
|
}
|
|
45
46
|
parseInto(raw, target) {
|
|
46
47
|
const entries = raw instanceof Array ? raw : [raw];
|
|
47
|
-
|
|
48
|
-
const firstEqualIndex = entry.indexOf('=');
|
|
49
|
-
if (firstEqualIndex <= 0) {
|
|
50
|
-
this.logger.warn(`Ignoring preference CLI argument "${entry}": expected KEY=JSONVALUE.`);
|
|
51
|
-
continue;
|
|
52
|
-
}
|
|
53
|
-
let rawValue = entry.substring(firstEqualIndex + 1);
|
|
54
|
-
if (rawValue.startsWith('base64:')) {
|
|
55
|
-
rawValue = Buffer.from(rawValue.substring('base64:'.length), 'base64').toString('utf-8');
|
|
56
|
-
}
|
|
57
|
-
try {
|
|
58
|
-
target.push([entry.substring(0, firstEqualIndex), JSON.parse(rawValue)]);
|
|
59
|
-
}
|
|
60
|
-
catch (e) {
|
|
61
|
-
const reason = e instanceof Error ? e.message : String(e);
|
|
62
|
-
this.logger.warn(`Ignoring preference CLI argument "${entry}": value is not valid JSON (${reason}).`);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
48
|
+
target.push(...cli_preferences_1.CliPreferenceEntry.parseAll(entries, message => this.logger.warn(message)));
|
|
65
49
|
}
|
|
66
50
|
async getPreferences() {
|
|
67
51
|
return this.preferences;
|
|
@@ -75,10 +59,7 @@ let PreferenceCliContribution = class PreferenceCliContribution {
|
|
|
75
59
|
* shell argument parsing intact.
|
|
76
60
|
*/
|
|
77
61
|
enhanceArgs(_context) {
|
|
78
|
-
return this.sessionPreferences.map((
|
|
79
|
-
const encoded = Buffer.from(JSON.stringify(value), 'utf-8').toString('base64');
|
|
80
|
-
return `--session-preference=${key}=base64:${encoded}`;
|
|
81
|
-
});
|
|
62
|
+
return this.sessionPreferences.map(entry => cli_preferences_1.CliPreferenceEntry.toArg('session-preference', entry));
|
|
82
63
|
}
|
|
83
64
|
};
|
|
84
65
|
exports.PreferenceCliContribution = PreferenceCliContribution;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"preference-cli-contribution.js","sourceRoot":"","sources":["../../src/node/preference-cli-contribution.ts"],"names":[],"mappings":";AAAA,gFAAgF;AAChF,yCAAyC;AACzC,EAAE;AACF,2EAA2E;AAC3E,mEAAmE;AACnE,wCAAwC;AACxC,EAAE;AACF,4EAA4E;AAC5E,8EAA8E;AAC9E,6EAA6E;AAC7E,yDAAyD;AACzD,uDAAuD;AACvD,EAAE;AACF,gFAAgF;AAChF,gFAAgF;;;;AAEhF,4DAAyE;
|
|
1
|
+
{"version":3,"file":"preference-cli-contribution.js","sourceRoot":"","sources":["../../src/node/preference-cli-contribution.ts"],"names":[],"mappings":";AAAA,gFAAgF;AAChF,yCAAyC;AACzC,EAAE;AACF,2EAA2E;AAC3E,mEAAmE;AACnE,wCAAwC;AACxC,EAAE;AACF,4EAA4E;AAC5E,8EAA8E;AAC9E,6EAA6E;AAC7E,yDAAyD;AACzD,uDAAuD;AACvD,EAAE;AACF,gFAAgF;AAChF,gFAAgF;;;;AAEhF,4DAAyE;AAIzE,+DAA+E;AAC/E,sCAAsC;AAG/B,IAAM,yBAAyB,GAA/B,MAAM,yBAAyB;IAA/B;QAKO,gBAAW,GAAwB,EAAE,CAAC;QACtC,uBAAkB,GAAwB,EAAE,CAAC;IA4C3D,CAAC;IA1CG,SAAS,CAAC,IAAc;QACpB,IAAI,CAAC,MAAM,CAAC,gBAAgB,EAAE;YAC1B,KAAK,EAAE,CAAC;YACR,IAAI,EAAE,4DAA4D;SACrE,CAAC,CAAC;QACH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AyB;IADrC,IAAA,sBAAU,GAAE;GACA,yBAAyB,CAkDrC"}
|
package/package.json
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@theia/preferences",
|
|
3
|
-
"version": "1.76.0
|
|
3
|
+
"version": "1.76.0",
|
|
4
4
|
"description": "Theia - Preferences Extension",
|
|
5
5
|
"dependencies": {
|
|
6
|
-
"@theia/core": "1.76.0
|
|
7
|
-
"@theia/editor": "1.76.0
|
|
8
|
-
"@theia/filesystem": "1.76.0
|
|
9
|
-
"@theia/monaco": "1.76.0
|
|
6
|
+
"@theia/core": "1.76.0",
|
|
7
|
+
"@theia/editor": "1.76.0",
|
|
8
|
+
"@theia/filesystem": "1.76.0",
|
|
9
|
+
"@theia/monaco": "1.76.0",
|
|
10
10
|
"@theia/monaco-editor-core": "1.108.201",
|
|
11
|
-
"@theia/userstorage": "1.76.0
|
|
12
|
-
"@theia/workspace": "1.76.0
|
|
11
|
+
"@theia/userstorage": "1.76.0",
|
|
12
|
+
"@theia/workspace": "1.76.0",
|
|
13
13
|
"async-mutex": "^0.3.2",
|
|
14
14
|
"fast-deep-equal": "^3.1.3",
|
|
15
15
|
"jsonc-parser": "^3.3.1",
|
|
@@ -50,10 +50,10 @@
|
|
|
50
50
|
"watch": "theiaext watch"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
|
-
"@theia/ext-scripts": "1.
|
|
53
|
+
"@theia/ext-scripts": "1.76.0"
|
|
54
54
|
},
|
|
55
55
|
"nyc": {
|
|
56
56
|
"extends": "../../configs/nyc.json"
|
|
57
57
|
},
|
|
58
|
-
"gitHead": "
|
|
58
|
+
"gitHead": "b9b54c500b46515512e2b44371bc0c7122947bed"
|
|
59
59
|
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
// *****************************************************************************
|
|
2
|
+
// Copyright (C) 2026 EclipseSource GmbH and others.
|
|
3
|
+
//
|
|
4
|
+
// This program and the accompanying materials are made available under the
|
|
5
|
+
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
+
// http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
+
//
|
|
8
|
+
// This Source Code may also be made available under the following Secondary
|
|
9
|
+
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
+
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
+
// with the GNU Classpath Exception which is available at
|
|
12
|
+
// https://www.gnu.org/software/classpath/license.html.
|
|
13
|
+
//
|
|
14
|
+
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
15
|
+
// *****************************************************************************
|
|
16
|
+
|
|
17
|
+
import { expect } from 'chai';
|
|
18
|
+
import { LaunchArguments } from '@theia/core/lib/common/launch-arguments';
|
|
19
|
+
|
|
20
|
+
const launchArgs = (values: Record<string, string[]>): LaunchArguments => ({ values, negated: [] });
|
|
21
|
+
import { PreferenceFrontendContribution } from './preference-frontend-contribution';
|
|
22
|
+
|
|
23
|
+
class TestPreferenceFrontendContribution extends PreferenceFrontendContribution {
|
|
24
|
+
|
|
25
|
+
forwardedArgs: LaunchArguments | undefined;
|
|
26
|
+
sessionBackendCalls = 0;
|
|
27
|
+
persistentBackendCalls = 0;
|
|
28
|
+
|
|
29
|
+
resolve(): Promise<{ session: [string, unknown][], persistent: [string, unknown][] }> {
|
|
30
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
31
|
+
(this as any).launchArgs = { getLaunchArgs: () => this.forwardedArgs };
|
|
32
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
33
|
+
(this as any).CliPreferences = {
|
|
34
|
+
getSessionPreferences: async () => {
|
|
35
|
+
this.sessionBackendCalls++;
|
|
36
|
+
return [['backend.session', 1]] as [string, unknown][];
|
|
37
|
+
},
|
|
38
|
+
getPreferences: async () => {
|
|
39
|
+
this.persistentBackendCalls++;
|
|
40
|
+
return [['backend.persistent', 2]] as [string, unknown][];
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
return this.resolveCliPreferences();
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
describe('PreferenceFrontendContribution#resolveCliPreferences', () => {
|
|
48
|
+
|
|
49
|
+
let contribution: TestPreferenceFrontendContribution;
|
|
50
|
+
|
|
51
|
+
beforeEach(() => {
|
|
52
|
+
contribution = new TestPreferenceFrontendContribution();
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it('reads preferences from the backend on a cold-start window (no forwarded options)', async () => {
|
|
56
|
+
contribution.forwardedArgs = undefined;
|
|
57
|
+
|
|
58
|
+
const result = await contribution.resolve();
|
|
59
|
+
|
|
60
|
+
expect(result.session).to.deep.equal([['backend.session', 1]]);
|
|
61
|
+
expect(result.persistent).to.deep.equal([['backend.persistent', 2]]);
|
|
62
|
+
expect(contribution.sessionBackendCalls).to.equal(1);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it('layers --session-preference from the forwarded options on top of the backend values', async () => {
|
|
66
|
+
contribution.forwardedArgs = launchArgs({ 'session-preference': ['editor.fontSize=20'], 'attach-container': ['B'] });
|
|
67
|
+
|
|
68
|
+
const result = await contribution.resolve();
|
|
69
|
+
|
|
70
|
+
// Process-wide backend values are kept (base) and the forwarded value is added on top.
|
|
71
|
+
expect(result.session).to.deep.equal([['backend.session', 1], ['editor.fontSize', 20]]);
|
|
72
|
+
expect(result.persistent).to.deep.equal([['backend.persistent', 2]]);
|
|
73
|
+
expect(contribution.sessionBackendCalls).to.equal(1);
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it('layers --set-preference from the forwarded options on top of the backend values', async () => {
|
|
77
|
+
contribution.forwardedArgs = launchArgs({ 'set-preference': ['editor.tabSize=2'] });
|
|
78
|
+
|
|
79
|
+
const result = await contribution.resolve();
|
|
80
|
+
|
|
81
|
+
expect(result.persistent).to.deep.equal([['backend.persistent', 2], ['editor.tabSize', 2]]);
|
|
82
|
+
expect(result.session).to.deep.equal([['backend.session', 1]]);
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
it('lets a forwarded value override a same-key backend value', async () => {
|
|
86
|
+
contribution.forwardedArgs = launchArgs({ 'session-preference': ['backend.session=99'] });
|
|
87
|
+
|
|
88
|
+
const result = await contribution.resolve();
|
|
89
|
+
|
|
90
|
+
expect(result.session).to.deep.equal([['backend.session', 99]]);
|
|
91
|
+
});
|
|
92
|
+
});
|
|
@@ -16,7 +16,9 @@
|
|
|
16
16
|
|
|
17
17
|
import { inject, injectable, named } from '@theia/core/shared/inversify';
|
|
18
18
|
import { FrontendApplicationContribution } from '@theia/core/lib/browser';
|
|
19
|
-
import {
|
|
19
|
+
import { LaunchArguments } from '@theia/core/lib/common/launch-arguments';
|
|
20
|
+
import { WindowLaunchArgs } from '@theia/core/lib/browser/window/window-launch-args';
|
|
21
|
+
import { CliPreferences, CliPreferenceEntry } from '../common/cli-preferences';
|
|
20
22
|
import { PreferenceService, PreferenceScope } from '@theia/core/lib/common/preferences';
|
|
21
23
|
import { ILogger } from '@theia/core';
|
|
22
24
|
|
|
@@ -31,23 +33,15 @@ export class PreferenceFrontendContribution implements FrontendApplicationContri
|
|
|
31
33
|
@inject(ILogger) @named('preferences:PreferenceFrontendContribution')
|
|
32
34
|
protected readonly logger: ILogger;
|
|
33
35
|
|
|
36
|
+
@inject(WindowLaunchArgs)
|
|
37
|
+
protected readonly launchArgs: WindowLaunchArgs;
|
|
38
|
+
|
|
34
39
|
onStart(): void {
|
|
35
40
|
this.applyCliPreferences();
|
|
36
41
|
}
|
|
37
42
|
|
|
38
43
|
protected async applyCliPreferences(): Promise<void> {
|
|
39
|
-
|
|
40
|
-
// can overlap with the preference service initialising its providers.
|
|
41
|
-
const [session, persistent] = await Promise.all([
|
|
42
|
-
this.CliPreferences.getSessionPreferences().catch(e => {
|
|
43
|
-
this.logger.warn('Failed to fetch --session-preference values:', e);
|
|
44
|
-
return [] as [string, unknown][];
|
|
45
|
-
}),
|
|
46
|
-
this.CliPreferences.getPreferences().catch(e => {
|
|
47
|
-
this.logger.warn('Failed to fetch --set-preference values:', e);
|
|
48
|
-
return [] as [string, unknown][];
|
|
49
|
-
})
|
|
50
|
-
]);
|
|
44
|
+
const { session, persistent } = await this.resolveCliPreferences();
|
|
51
45
|
|
|
52
46
|
// `preferenceService.set()` needs the target provider registered in the providers
|
|
53
47
|
// map, which only happens once `initializeProviders()` has walked every scope and
|
|
@@ -70,6 +64,49 @@ export class PreferenceFrontendContribution implements FrontendApplicationContri
|
|
|
70
64
|
await this.applyAll(persistent, PreferenceScope.User);
|
|
71
65
|
}
|
|
72
66
|
|
|
67
|
+
/**
|
|
68
|
+
* Resolves the CLI-provided preferences to apply to this window.
|
|
69
|
+
*
|
|
70
|
+
* The shared backend reflects the original cold-start launch (it cannot distinguish between
|
|
71
|
+
* windows), so it supplies the process-wide CLI preferences. A forwarded (second-instance)
|
|
72
|
+
* window additionally carries its own options, provided by the trusted main process, and layers
|
|
73
|
+
* them on top, overriding by key. Merging (rather than replacing) means a plain
|
|
74
|
+
* second-instance window keeps the process-wide values instead of dropping them, while an attach
|
|
75
|
+
* window still gets its own overrides.
|
|
76
|
+
*/
|
|
77
|
+
protected async resolveCliPreferences(): Promise<{ session: [string, unknown][], persistent: [string, unknown][] }> {
|
|
78
|
+
// Fetch both buckets in parallel; both are RPC hops to the same backend and
|
|
79
|
+
// can overlap with the preference service initialising its providers.
|
|
80
|
+
const [session, persistent] = await Promise.all([
|
|
81
|
+
this.CliPreferences.getSessionPreferences().catch(e => {
|
|
82
|
+
this.logger.warn('Failed to fetch --session-preference values:', e);
|
|
83
|
+
return [] as [string, unknown][];
|
|
84
|
+
}),
|
|
85
|
+
this.CliPreferences.getPreferences().catch(e => {
|
|
86
|
+
this.logger.warn('Failed to fetch --set-preference values:', e);
|
|
87
|
+
return [] as [string, unknown][];
|
|
88
|
+
})
|
|
89
|
+
]);
|
|
90
|
+
const forwarded = this.launchArgs.getLaunchArgs();
|
|
91
|
+
if (forwarded === undefined) {
|
|
92
|
+
return { session, persistent };
|
|
93
|
+
}
|
|
94
|
+
const warn = (message: string) => this.logger.warn(message);
|
|
95
|
+
return {
|
|
96
|
+
session: this.mergeEntries(session, CliPreferenceEntry.parseAll(LaunchArguments.values(forwarded, 'session-preference'), warn)),
|
|
97
|
+
persistent: this.mergeEntries(persistent, CliPreferenceEntry.parseAll(LaunchArguments.values(forwarded, 'set-preference'), warn))
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** Overlays `overrides` onto `base`, later entries winning per key while preserving order (base first). */
|
|
102
|
+
protected mergeEntries(base: ReadonlyArray<[string, unknown]>, overrides: ReadonlyArray<[string, unknown]>): [string, unknown][] {
|
|
103
|
+
const merged = new Map<string, unknown>();
|
|
104
|
+
for (const [key, value] of [...base, ...overrides]) {
|
|
105
|
+
merged.set(key, value);
|
|
106
|
+
}
|
|
107
|
+
return [...merged];
|
|
108
|
+
}
|
|
109
|
+
|
|
73
110
|
/**
|
|
74
111
|
* Applies a batch of CLI-provided preferences sequentially. A rejection from an
|
|
75
112
|
* individual write (bad key, invalid scope, etc.) is logged and does not abort the
|
|
@@ -32,6 +32,8 @@ import { PreferenceOpenHandler } from './preference-open-handler';
|
|
|
32
32
|
import { CliPreferences, CliPreferencesPath } from '../common/cli-preferences';
|
|
33
33
|
import { ServiceConnectionProvider } from '@theia/core/lib/browser/messaging/service-connection-provider';
|
|
34
34
|
import { PreferenceFrontendContribution } from './preference-frontend-contribution';
|
|
35
|
+
import { RemoteCliArgsContribution } from '@theia/core/lib/common/remote-cli-args-contribution';
|
|
36
|
+
import { SessionPreferenceRemoteCliContribution } from './session-preference-remote-cli-contribution';
|
|
35
37
|
import { SessionPreferenceStatusBarContribution } from './session-preference-status-bar-contribution';
|
|
36
38
|
import { PreferenceLayoutProvider } from './util/preference-layout';
|
|
37
39
|
import { PreferencesWidget } from './views/preference-widget';
|
|
@@ -71,6 +73,8 @@ export function bindPreferences(bind: interfaces.Bind, unbind: interfaces.Unbind
|
|
|
71
73
|
bind(CliPreferences).toDynamicValue(ctx => ServiceConnectionProvider.createProxy<CliPreferences>(ctx.container, CliPreferencesPath)).inSingletonScope();
|
|
72
74
|
bind(PreferenceFrontendContribution).toSelf().inSingletonScope();
|
|
73
75
|
bind(FrontendApplicationContribution).toService(PreferenceFrontendContribution);
|
|
76
|
+
bind(SessionPreferenceRemoteCliContribution).toSelf().inSingletonScope();
|
|
77
|
+
bind(RemoteCliArgsContribution).toService(SessionPreferenceRemoteCliContribution);
|
|
74
78
|
bind(SessionPreferenceStatusBarContribution).toSelf().inSingletonScope();
|
|
75
79
|
bind(FrontendApplicationContribution).toService(SessionPreferenceStatusBarContribution);
|
|
76
80
|
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
// *****************************************************************************
|
|
2
|
+
// Copyright (C) 2026 EclipseSource GmbH and others.
|
|
3
|
+
//
|
|
4
|
+
// This program and the accompanying materials are made available under the
|
|
5
|
+
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
+
// http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
+
//
|
|
8
|
+
// This Source Code may also be made available under the following Secondary
|
|
9
|
+
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
+
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
+
// with the GNU Classpath Exception which is available at
|
|
12
|
+
// https://www.gnu.org/software/classpath/license.html.
|
|
13
|
+
//
|
|
14
|
+
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
15
|
+
// *****************************************************************************
|
|
16
|
+
|
|
17
|
+
import { expect } from 'chai';
|
|
18
|
+
import { LaunchArguments } from '@theia/core/lib/common/launch-arguments';
|
|
19
|
+
|
|
20
|
+
const launchArgs = (values: Record<string, string[]>): LaunchArguments => ({ values, negated: [] });
|
|
21
|
+
import { CliPreferenceEntry } from '../common/cli-preferences';
|
|
22
|
+
import { SessionPreferenceRemoteCliContribution } from './session-preference-remote-cli-contribution';
|
|
23
|
+
|
|
24
|
+
class TestContribution extends SessionPreferenceRemoteCliContribution {
|
|
25
|
+
set forwardedArgs(args: LaunchArguments | undefined) {
|
|
26
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
27
|
+
(this as any).launchArgs = { getLaunchArgs: () => args };
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
describe('SessionPreferenceRemoteCliContribution#getRemoteCliArgs', () => {
|
|
32
|
+
|
|
33
|
+
let contribution: TestContribution;
|
|
34
|
+
|
|
35
|
+
beforeEach(() => {
|
|
36
|
+
contribution = new TestContribution();
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it('returns no args for a cold-start window (no forwarded options)', async () => {
|
|
40
|
+
contribution.forwardedArgs = undefined;
|
|
41
|
+
expect(await contribution.getRemoteCliArgs()).to.deep.equal([]);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it('returns no args for a forwarded window without --session-preference', async () => {
|
|
45
|
+
contribution.forwardedArgs = launchArgs({ 'attach-container': ['B'] });
|
|
46
|
+
expect(await contribution.getRemoteCliArgs()).to.deep.equal([]);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it('formats forwarded --session-preference values for the remote backend', async () => {
|
|
50
|
+
contribution.forwardedArgs = launchArgs({ 'attach-container': ['B'], 'session-preference': ['editor.fontSize=20'] });
|
|
51
|
+
|
|
52
|
+
const args = await contribution.getRemoteCliArgs();
|
|
53
|
+
|
|
54
|
+
expect(args).to.have.lengthOf(1);
|
|
55
|
+
// The produced arg must parse back to the original entry on the remote.
|
|
56
|
+
const value = args[0].substring('--session-preference='.length);
|
|
57
|
+
expect(CliPreferenceEntry.parse(value)).to.deep.equal(['editor.fontSize', 20]);
|
|
58
|
+
});
|
|
59
|
+
});
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
// *****************************************************************************
|
|
2
|
+
// Copyright (C) 2026 EclipseSource GmbH and others.
|
|
3
|
+
//
|
|
4
|
+
// This program and the accompanying materials are made available under the
|
|
5
|
+
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
+
// http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
+
//
|
|
8
|
+
// This Source Code may also be made available under the following Secondary
|
|
9
|
+
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
+
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
+
// with the GNU Classpath Exception which is available at
|
|
12
|
+
// https://www.gnu.org/software/classpath/license.html.
|
|
13
|
+
//
|
|
14
|
+
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
15
|
+
// *****************************************************************************
|
|
16
|
+
|
|
17
|
+
import { inject, injectable } from '@theia/core/shared/inversify';
|
|
18
|
+
import { RemoteCliArgsContribution } from '@theia/core/lib/common/remote-cli-args-contribution';
|
|
19
|
+
import { LaunchArguments } from '@theia/core/lib/common/launch-arguments';
|
|
20
|
+
import { WindowLaunchArgs } from '@theia/core/lib/browser/window/window-launch-args';
|
|
21
|
+
import { CliPreferenceEntry } from '../common/cli-preferences';
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Re-applies `--session-preference` values on a remote backend that is started for a *forwarded*
|
|
25
|
+
* (second-instance) window.
|
|
26
|
+
*
|
|
27
|
+
* The shared local backend only knows the preferences of the original cold-start launch, so its
|
|
28
|
+
* `RemoteCliContribution#enhanceArgs` cannot supply the right values for a window opened by a
|
|
29
|
+
* later launch. This frontend contribution reads the session preferences forwarded to the current
|
|
30
|
+
* window (provided by the trusted main process) and formats them as CLI arguments for the remote
|
|
31
|
+
* backend.
|
|
32
|
+
*/
|
|
33
|
+
@injectable()
|
|
34
|
+
export class SessionPreferenceRemoteCliContribution implements RemoteCliArgsContribution {
|
|
35
|
+
|
|
36
|
+
@inject(WindowLaunchArgs)
|
|
37
|
+
protected readonly launchArgs: WindowLaunchArgs;
|
|
38
|
+
|
|
39
|
+
async getRemoteCliArgs(): Promise<string[]> {
|
|
40
|
+
const forwarded = this.launchArgs.getLaunchArgs();
|
|
41
|
+
if (forwarded === undefined) {
|
|
42
|
+
// Cold-start window: the shared backend already forwards its session preferences.
|
|
43
|
+
return [];
|
|
44
|
+
}
|
|
45
|
+
return CliPreferenceEntry
|
|
46
|
+
.parseAll(LaunchArguments.values(forwarded, 'session-preference'))
|
|
47
|
+
.map(entry => CliPreferenceEntry.toArg('session-preference', entry));
|
|
48
|
+
}
|
|
49
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
// *****************************************************************************
|
|
2
|
+
// Copyright (C) 2026 EclipseSource GmbH and others.
|
|
3
|
+
//
|
|
4
|
+
// This program and the accompanying materials are made available under the
|
|
5
|
+
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
+
// http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
+
//
|
|
8
|
+
// This Source Code may also be made available under the following Secondary
|
|
9
|
+
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
+
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
+
// with the GNU Classpath Exception which is available at
|
|
12
|
+
// https://www.gnu.org/software/classpath/license.html.
|
|
13
|
+
//
|
|
14
|
+
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
15
|
+
// *****************************************************************************
|
|
16
|
+
|
|
17
|
+
import { expect } from 'chai';
|
|
18
|
+
import { CliPreferenceEntry } from './cli-preferences';
|
|
19
|
+
|
|
20
|
+
describe('CliPreferenceEntry.parse', () => {
|
|
21
|
+
|
|
22
|
+
it('parses a KEY=JSONVALUE assignment', () => {
|
|
23
|
+
expect(CliPreferenceEntry.parse('editor.fontSize=14')).to.deep.equal(['editor.fontSize', 14]);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it('parses boolean and string JSON values', () => {
|
|
27
|
+
expect(CliPreferenceEntry.parse('foo.enabled=true')).to.deep.equal(['foo.enabled', true]);
|
|
28
|
+
expect(CliPreferenceEntry.parse('foo.label="hello"')).to.deep.equal(['foo.label', 'hello']);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it('keeps "=" characters that are part of the value', () => {
|
|
32
|
+
expect(CliPreferenceEntry.parse('foo.expr="a=b"')).to.deep.equal(['foo.expr', 'a=b']);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it('decodes a base64-encoded value', () => {
|
|
36
|
+
// base64 of the JSON value `42`
|
|
37
|
+
expect(CliPreferenceEntry.parse('foo.num=base64:NDI=')).to.deep.equal(['foo.num', 42]);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it('returns undefined when there is no key', () => {
|
|
41
|
+
expect(CliPreferenceEntry.parse('=1')).to.be.undefined;
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it('returns undefined when there is no "="', () => {
|
|
45
|
+
expect(CliPreferenceEntry.parse('noequals')).to.be.undefined;
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it('returns undefined for an invalid JSON value', () => {
|
|
49
|
+
expect(CliPreferenceEntry.parse('foo.bar=not json')).to.be.undefined;
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
describe('parseAll', () => {
|
|
53
|
+
it('parses and filters a list, dropping invalid entries', () => {
|
|
54
|
+
const result = CliPreferenceEntry.parseAll(['a=1', 'bad', 'b="x"']);
|
|
55
|
+
expect(result).to.deep.equal([['a', 1], ['b', 'x']]);
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
describe('toArg', () => {
|
|
60
|
+
it('formats an entry as a base64-encoded CLI argument', () => {
|
|
61
|
+
// base64 of the JSON value `42`
|
|
62
|
+
expect(CliPreferenceEntry.toArg('session-preference', ['foo.num', 42])).to.equal('--session-preference=foo.num=base64:NDI=');
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it('round-trips a value with shell-special characters through toArg + parse', () => {
|
|
66
|
+
const entry: [string, unknown] = ['foo.expr', '$HOME && "quoted"'];
|
|
67
|
+
const arg = CliPreferenceEntry.toArg('session-preference', entry);
|
|
68
|
+
// The value part of `--session-preference=<value>` must parse back to the original entry.
|
|
69
|
+
const value = arg.substring('--session-preference='.length);
|
|
70
|
+
expect(CliPreferenceEntry.parse(value)).to.deep.equal(entry);
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
});
|
|
@@ -21,3 +21,78 @@ export interface CliPreferences {
|
|
|
21
21
|
getPreferences(): Promise<[string, unknown][]>;
|
|
22
22
|
getSessionPreferences(): Promise<[string, unknown][]>;
|
|
23
23
|
}
|
|
24
|
+
|
|
25
|
+
export namespace CliPreferenceEntry {
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Sink for warnings about malformed entries. Callers running in an Inversify context should
|
|
29
|
+
* pass their named `ILogger`, since these helpers live in `common` and cannot inject one
|
|
30
|
+
* themselves. Defaults to `console.warn`.
|
|
31
|
+
*/
|
|
32
|
+
export type WarningSink = (message: string) => void;
|
|
33
|
+
|
|
34
|
+
const defaultWarn: WarningSink = message => console.warn(message);
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Parses a single `KEY=JSONVALUE` preference assignment as accepted by `--set-preference`
|
|
38
|
+
* and `--session-preference`. The value may be `base64:`-prefixed (used when forwarding
|
|
39
|
+
* values that must survive shell/URL transport intact). Returns `undefined` (after logging a
|
|
40
|
+
* warning to {@link warn}) when the entry has no key or the value is not valid JSON.
|
|
41
|
+
*/
|
|
42
|
+
export function parse(entry: string, warn: WarningSink = defaultWarn): [string, unknown] | undefined {
|
|
43
|
+
const firstEqualIndex = entry.indexOf('=');
|
|
44
|
+
if (firstEqualIndex <= 0) {
|
|
45
|
+
warn(`Ignoring preference CLI argument "${entry}": expected KEY=JSONVALUE.`);
|
|
46
|
+
return undefined;
|
|
47
|
+
}
|
|
48
|
+
const rawValue = entry.substring(firstEqualIndex + 1);
|
|
49
|
+
try {
|
|
50
|
+
// Decoding happens inside the `try` so that a malformed `base64:` payload is reported
|
|
51
|
+
// like any other invalid value instead of throwing out of `parse`.
|
|
52
|
+
const value = rawValue.startsWith('base64:') ? decodeBase64(rawValue.substring('base64:'.length)) : rawValue;
|
|
53
|
+
return [entry.substring(0, firstEqualIndex), JSON.parse(value)];
|
|
54
|
+
} catch (e) {
|
|
55
|
+
const reason = e instanceof Error ? e.message : String(e);
|
|
56
|
+
warn(`Ignoring preference CLI argument "${entry}": value is not valid JSON (${reason}).`);
|
|
57
|
+
return undefined;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Formats a preference entry as a CLI argument of the form
|
|
63
|
+
* `--<optionName>=<key>=base64:<base64(JSON(value))>`, the inverse of {@link parse}.
|
|
64
|
+
*
|
|
65
|
+
* The value is base64-encoded so it survives shell/URL transport intact (e.g. when the
|
|
66
|
+
* argument is passed to a remote backend over an SSH command line).
|
|
67
|
+
*/
|
|
68
|
+
export function toArg(optionName: string, [key, value]: [string, unknown]): string {
|
|
69
|
+
return `--${optionName}=${key}=base64:${encodeBase64(JSON.stringify(value))}`;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Parses a list of `KEY=JSONVALUE` assignments, dropping any invalid entries and reporting
|
|
74
|
+
* them to {@link warn}.
|
|
75
|
+
*/
|
|
76
|
+
export function parseAll(entries: readonly string[], warn: WarningSink = defaultWarn): [string, unknown][] {
|
|
77
|
+
const result: [string, unknown][] = [];
|
|
78
|
+
for (const entry of entries) {
|
|
79
|
+
const parsed = parse(entry, warn);
|
|
80
|
+
if (parsed) {
|
|
81
|
+
result.push(parsed);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return result;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// `Buffer` is available on the backend and is polyfilled into the frontend bundle by the
|
|
88
|
+
// esbuild generator, so a single implementation covers both. It also handles UTF-8 directly,
|
|
89
|
+
// unlike `atob`/`btoa`, which only deal in binary strings.
|
|
90
|
+
|
|
91
|
+
function decodeBase64(value: string): string {
|
|
92
|
+
return Buffer.from(value, 'base64').toString('utf-8');
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function encodeBase64(value: string): string {
|
|
96
|
+
return Buffer.from(value, 'utf-8').toString('base64');
|
|
97
|
+
}
|
|
98
|
+
}
|
|
@@ -18,7 +18,7 @@ import { injectable, inject, named } from '@theia/core/shared/inversify';
|
|
|
18
18
|
import { Argv } from '@theia/core/shared/yargs';
|
|
19
19
|
import { CliContribution } from '@theia/core/lib/node/cli';
|
|
20
20
|
import { RemoteCliContext, RemoteCliContribution } from '@theia/core/lib/node/remote/remote-cli-contribution';
|
|
21
|
-
import { CliPreferences } from '../common/cli-preferences';
|
|
21
|
+
import { CliPreferences, CliPreferenceEntry } from '../common/cli-preferences';
|
|
22
22
|
import { ILogger } from '@theia/core';
|
|
23
23
|
|
|
24
24
|
@injectable()
|
|
@@ -52,23 +52,7 @@ export class PreferenceCliContribution implements CliContribution, CliPreference
|
|
|
52
52
|
|
|
53
53
|
protected parseInto(raw: unknown, target: [string, unknown][]): void {
|
|
54
54
|
const entries: string[] = raw instanceof Array ? raw : [raw as string];
|
|
55
|
-
|
|
56
|
-
const firstEqualIndex = entry.indexOf('=');
|
|
57
|
-
if (firstEqualIndex <= 0) {
|
|
58
|
-
this.logger.warn(`Ignoring preference CLI argument "${entry}": expected KEY=JSONVALUE.`);
|
|
59
|
-
continue;
|
|
60
|
-
}
|
|
61
|
-
let rawValue = entry.substring(firstEqualIndex + 1);
|
|
62
|
-
if (rawValue.startsWith('base64:')) {
|
|
63
|
-
rawValue = Buffer.from(rawValue.substring('base64:'.length), 'base64').toString('utf-8');
|
|
64
|
-
}
|
|
65
|
-
try {
|
|
66
|
-
target.push([entry.substring(0, firstEqualIndex), JSON.parse(rawValue)]);
|
|
67
|
-
} catch (e) {
|
|
68
|
-
const reason = e instanceof Error ? e.message : String(e);
|
|
69
|
-
this.logger.warn(`Ignoring preference CLI argument "${entry}": value is not valid JSON (${reason}).`);
|
|
70
|
-
}
|
|
71
|
-
}
|
|
55
|
+
target.push(...CliPreferenceEntry.parseAll(entries, message => this.logger.warn(message)));
|
|
72
56
|
}
|
|
73
57
|
|
|
74
58
|
async getPreferences(): Promise<[string, unknown][]> {
|
|
@@ -85,10 +69,7 @@ export class PreferenceCliContribution implements CliContribution, CliPreference
|
|
|
85
69
|
* shell argument parsing intact.
|
|
86
70
|
*/
|
|
87
71
|
enhanceArgs(_context: RemoteCliContext): string[] {
|
|
88
|
-
return this.sessionPreferences.map((
|
|
89
|
-
const encoded = Buffer.from(JSON.stringify(value), 'utf-8').toString('base64');
|
|
90
|
-
return `--session-preference=${key}=base64:${encoded}`;
|
|
91
|
-
});
|
|
72
|
+
return this.sessionPreferences.map(entry => CliPreferenceEntry.toArg('session-preference', entry));
|
|
92
73
|
}
|
|
93
74
|
|
|
94
75
|
}
|