Skip to content

Commit

Permalink
Merge branch 'master' into bugfix/plugin-tree-ids
Browse files Browse the repository at this point in the history
  • Loading branch information
colin-grant-work authored Mar 23, 2023
2 parents 61f78ce + 656cd9b commit 7385453
Show file tree
Hide file tree
Showing 9 changed files with 144 additions and 70 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
- Interface ScmInlineAction removes 'commands: CommandRegistry'
- Interface ScmInlineActions removes 'commands: CommandRegistry'
- Interface ScmTreeWidget.Props removes 'commands: CommandRegistry'
- [terminal] removed `openTerminalFromProfile` method from `TerminalFrontendContribution` [#12322](https://github.com/eclipse-theia/theia/pull/12322)

## v1.35.0 - 02/23/2023

Expand Down
2 changes: 1 addition & 1 deletion dev-packages/application-manager/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
"string-replace-loader": "^3.1.0",
"style-loader": "^2.0.0",
"umd-compat-loader": "^2.1.2",
"webpack": "^5.48.0",
"webpack": "^5.76.0",
"webpack-cli": "4.7.0",
"worker-loader": "^3.0.8",
"yargs": "^15.3.1"
Expand Down
101 changes: 66 additions & 35 deletions examples/api-tests/src/launch-preferences.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -285,8 +285,8 @@ describe('Launch Preferences', function () {
},
expectation: {
'version': '0.2.0',
'configurations': [validConfiguration, bogusConfiguration],
'compounds': [bogusCompound, bogusCompound2]
'configurations': [validConfiguration2, validConfiguration, bogusConfiguration],
'compounds': [validCompound, bogusCompound, bogusCompound2]
}
});

Expand All @@ -306,15 +306,15 @@ describe('Launch Preferences', function () {
expectation: {
'version': '0.2.0',
'configurations': [validConfiguration2],
'compounds': [bogusCompound, bogusCompound2]
'compounds': [validCompound, bogusCompound, bogusCompound2]
},
inspectExpectation: {
preferenceName: 'launch',
defaultValue: defaultLaunch,
workspaceValue: {
'version': '0.2.0',
'configurations': [validConfiguration2],
'compounds': [bogusCompound, bogusCompound2]
'compounds': [validCompound, bogusCompound, bogusCompound2]
}
}
});
Expand Down Expand Up @@ -461,6 +461,53 @@ describe('Launch Preferences', function () {
]);
}


function mergeLaunchConfigurations(config1, config2) {
if (config1 === undefined && config2 === undefined) {
return undefined;
}
if (config2 === undefined) {
return config1;
}

let result;
// skip invalid configs
if (typeof config1 === 'object' && !Array.isArray(config1)) {
result = { ...config1 };
}
if (typeof config2 === 'object' && !Array.isArray(config2)) {
result = { ...(result ?? {}), ...config2 }
}
// merge configurations and compounds arrays
const mergedConfigurations = mergeArrays(config1?.configurations, config2?.configurations);
if (mergedConfigurations) {
result.configurations = mergedConfigurations
}
const mergedCompounds = mergeArrays(config1?.compounds, config2?.compounds);
if (mergedCompounds) {
result.compounds = mergedCompounds;
}
return result;
}

function mergeArrays(array1, array2) {
if (array1 === undefined && array2 === undefined) {
return undefined;
}
if (!Array.isArray(array1) && !Array.isArray(array2)) {
return undefined;
}
let result = [];
if (Array.isArray(array1)) {
result = [...array1];
}
if (Array.isArray(array2)) {
result = [...result, ...array2];
}
return result;
}


const originalShouldOverwrite = fileResourceResolver['shouldOverwrite'];

before(async () => {
Expand Down Expand Up @@ -560,8 +607,8 @@ describe('Launch Preferences', function () {
preferenceName: 'launch',
defaultValue: defaultLaunch
};
const workspaceValue = launch || settingsLaunch;
if (workspaceValue !== undefined) {
const workspaceValue = mergeLaunchConfigurations(settingsLaunch, launch);
if (workspaceValue !== undefined && JSON.stringify(workspaceValue) !== '{}') {
Object.assign(expected, { workspaceValue });
}
}
Expand All @@ -582,8 +629,8 @@ describe('Launch Preferences', function () {
workspaceFolderValue: inspectExpectation.workspaceValue
});
} else {
const value = launch || settingsLaunch;
if (value !== undefined) {
const value = mergeLaunchConfigurations(settingsLaunch, launch);
if (value !== undefined && JSON.stringify(value) !== '{}') {
Object.assign(expected, {
workspaceValue: value,
workspaceFolderValue: value
Expand All @@ -599,7 +646,7 @@ describe('Launch Preferences', function () {

const inspect = preferences.inspect('launch');
const actual = inspect && inspect.workspaceValue;
const expected = settingsLaunch && !Array.isArray(settingsLaunch) ? { ...settingsLaunch, ...validLaunch } : validLaunch;
const expected = mergeLaunchConfigurations(settingsLaunch, validLaunch);
assert.deepStrictEqual(actual, expected);
});

Expand All @@ -608,7 +655,7 @@ describe('Launch Preferences', function () {

const inspect = preferences.inspect('launch');
const actual = inspect && inspect.workspaceValue;
const expected = settingsLaunch && !Array.isArray(settingsLaunch) ? { ...settingsLaunch, ...validLaunch } : validLaunch;
const expected = mergeLaunchConfigurations(settingsLaunch, validLaunch);
assert.deepStrictEqual(actual, expected);
});

Expand All @@ -626,7 +673,7 @@ describe('Launch Preferences', function () {

const inspect = preferences.inspect('launch');
const actual = inspect && inspect.workspaceValue;
const expected = settingsLaunch && !Array.isArray(settingsLaunch) ? { ...settingsLaunch, ...validLaunch } : validLaunch;
const expected = mergeLaunchConfigurations(settingsLaunch, validLaunch);
assert.deepStrictEqual(actual, expected);
});

Expand All @@ -636,7 +683,11 @@ describe('Launch Preferences', function () {

const inspect = preferences.inspect('launch');
const actual = inspect && inspect.workspaceValue && inspect.workspaceValue.configurations;
assert.deepStrictEqual(actual, [validConfiguration, validConfiguration2]);
let expect = [validConfiguration, validConfiguration2];
if (Array.isArray(settingsLaunch?.configurations)) {
expect = [...(settingsLaunch.configurations), ...expect]
}
assert.deepStrictEqual(actual, expect);
});
}

Expand All @@ -650,11 +701,8 @@ describe('Launch Preferences', function () {
if (Array.isArray(expected)) {
expected = { ...expected };
}
if (expected && !expected.configurations && settingsLaunch && settingsLaunch.configurations !== undefined) {
expected.configurations = settingsLaunch.configurations;
}
}
expected = expected || settingsLaunch;
expected = mergeLaunchConfigurations(settingsLaunch, expected);
assert.deepStrictEqual(actual && actual.workspaceValue, expected);
});

Expand All @@ -665,31 +713,14 @@ describe('Launch Preferences', function () {
const actual = preferences.inspect('launch');
const actualWorkspaceValue = actual && actual.workspaceValue;

let expected = undefined;
let expected = { ...launch };
if (launch) {
expected = { ...launch };
delete expected['configurations'];
}
if (settings) {
let _settingsLaunch = undefined;
if (typeof settingsLaunch === 'object' && !Array.isArray(settings['launch']) && settings['launch'] !== null) {
_settingsLaunch = settingsLaunch;
} else {
_settingsLaunch = expectation;
}
if (expected) {
if (_settingsLaunch.configurations !== undefined) {
expected.configurations = _settingsLaunch.configurations;
}
} else {
expected = _settingsLaunch;
}
}

expected = mergeLaunchConfigurations(settingsLaunch, expected);
assert.deepStrictEqual(actualWorkspaceValue, expected);
});
}

});

}
Expand Down
36 changes: 36 additions & 0 deletions packages/core/src/browser/preferences/preference-provider.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// *****************************************************************************
// Copyright (C) 2023 EclipseSource and others.
//
// This program and the accompanying materials are made available under the
// terms of the Eclipse Public License v. 2.0 which is available at
// http://www.eclipse.org/legal/epl-2.0.
//
// This Source Code may also be made available under the following Secondary
// Licenses when the conditions for such availability set forth in the Eclipse
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
// with the GNU Classpath Exception which is available at
// https://www.gnu.org/software/classpath/license.html.
//
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
// *****************************************************************************

import { PreferenceProvider } from './preference-provider';
const { expect } = require('chai');

describe('PreferenceProvider', () => {
it('should preserve extra source fields on merge', () => {
const result = PreferenceProvider.merge({ 'configurations': [], 'compounds': [] }, { 'configurations': [] });
expect(result).deep.equals({ 'configurations': [], 'compounds': [] });
});
it('should preserve extra target fields on merge', () => {
const result = PreferenceProvider.merge({ 'configurations': [] }, { 'configurations': [], 'compounds': [] });
expect(result).deep.equals({ 'configurations': [], 'compounds': [] });
});
it('should merge array values', () => {
const result = PreferenceProvider.merge(
{ 'configurations': [{ 'name': 'test1', 'request': 'launch' }], 'compounds': [] },
{ 'configurations': [{ 'name': 'test2' }] }
);
expect(result).deep.equals({ 'configurations': [{ 'name': 'test1', 'request': 'launch' }, { 'name': 'test2' }], 'compounds': [] });
});
});
7 changes: 7 additions & 0 deletions packages/core/src/browser/preferences/preference-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,9 @@ export abstract class PreferenceProvider implements Disposable {
if (JSONExt.isObject(source[key]) && JSONExt.isObject(value)) {
this.merge(source[key], value);
continue;
} else if (JSONExt.isArray(source[key]) && JSONExt.isArray(value)) {
source[key] = [...JSONExt.deepCopy(source[key] as any), ...JSONExt.deepCopy(value)];
continue;
}
}
source[key] = JSONExt.deepCopy(value);
Expand Down Expand Up @@ -267,4 +270,8 @@ export abstract class PreferenceProvider implements Disposable {
}
return preferences;
}

canHandleScope(scope: PreferenceScope): boolean {
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,7 @@ export class PreferenceServiceImpl implements PreferenceService {
for (const scope of PreferenceScope.getScopes()) {
if (this.schema.isValidInScope(preferenceName, scope)) {
const provider = this.getProvider(scope);
if (provider) {
if (provider?.canHandleScope(scope)) {
const { configUri, value } = provider.resolve<T>(preferenceName, resourceUri);
if (value !== undefined) {
result.configUri = configUri;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

import { inject, injectable, postConstruct } from '@theia/core/shared/inversify';
import URI from '@theia/core/lib/common/uri';
import { PreferenceProvider, PreferenceResolveResult } from '@theia/core/lib/browser/preferences/preference-provider';
import { PreferenceProvider, PreferenceResolveResult, PreferenceScope } from '@theia/core/lib/browser/preferences';
import { WorkspaceService } from '@theia/workspace/lib/browser/workspace-service';
import { PreferenceConfigurations } from '@theia/core/lib/browser/preferences/preference-configurations';
import { FolderPreferenceProvider, FolderPreferenceProviderFactory } from './folder-preference-provider';
Expand Down Expand Up @@ -189,6 +189,10 @@ export class FoldersPreferencesProvider extends PreferenceProvider {
return false;
}

override canHandleScope(scope: PreferenceScope): boolean {
return this.workspaceService.isMultiRootWorkspaceOpened && scope === PreferenceScope.Folder || scope === PreferenceScope.Workspace;
}

protected groupProvidersByConfigName(resourceUri?: string): Map<string, FolderPreferenceProvider[]> {
const groups = new Map<string, FolderPreferenceProvider[]>();
const providers = this.getFolderProviders(resourceUri);
Expand Down
51 changes: 23 additions & 28 deletions packages/terminal/src/browser/terminal-frontend-contribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,13 @@ export class TerminalFrontendContribution implements FrontendApplicationContribu
});

commands.registerCommand(TerminalCommands.PROFILE_NEW, {
execute: () => this.openTerminalFromProfile()
execute: async () => {
const profile = await this.selectTerminalProfile(nls.localize('theia/terminal/selectProfile', 'Select a profile for the new terminal'));
if (!profile) {
return;
}
this.openTerminal(undefined, profile[1]);
}
});

commands.registerCommand(TerminalCommands.PROFILE_DEFAULT, {
Expand Down Expand Up @@ -933,40 +939,29 @@ export class TerminalFrontendContribution implements FrontendApplicationContribu
return ref instanceof TerminalWidget ? ref : undefined;
}

protected async openTerminal(options?: ApplicationShell.WidgetOptions): Promise<void> {
let profile = this.profileService.defaultProfile;

if (!profile) {
throw new Error('There are not profiles registered');
protected async openTerminal(options?: ApplicationShell.WidgetOptions, terminalProfile?: TerminalProfile): Promise<void> {
let profile = terminalProfile;
if (!terminalProfile) {
profile = this.profileService.defaultProfile;
if (!profile) {
throw new Error('There are not profiles registered');
}
}

if (profile instanceof ShellTerminalProfile) {
const cwd = await this.selectTerminalCwd();
if (!cwd) {
return;
if (this.workspaceService.workspace) {
const cwd = await this.selectTerminalCwd();
if (!cwd) {
return;
}
profile = profile.modify({ cwd });
}
profile = profile.modify({ cwd });
}

const termWidget = await profile?.start();

this.open(termWidget, { widgetOptions: options });
}

protected async openTerminalFromProfile(options?: ApplicationShell.WidgetOptions): Promise<void> {
const result = await this.selectTerminalProfile(nls.localize('theia/terminal/selectProfile', 'Select a profile for the new terminal'));
if (!result) {
return;
if (!!termWidget) {
this.open(termWidget, { widgetOptions: options });
}
let profile = result[1];
if (profile instanceof ShellTerminalProfile) {
const cwd = await this.selectTerminalCwd();
if (!cwd) {
return;
}
profile = profile.modify({ cwd });
}
const termWidget = await profile.start();
this.open(termWidget, { widgetOptions: options });
}

protected async chooseDefaultProfile(): Promise<void> {
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -11455,10 +11455,10 @@ webpack-sources@^3.2.3:
resolved "https://registry.yarnpkg.com/webpack-sources/-/webpack-sources-3.2.3.tgz#2d4daab8451fd4b240cc27055ff6a0c2ccea0cde"
integrity sha512-/DyMEOrDgLKKIG0fmvtz+4dUX/3Ghozwgm6iPp8KRhvn+eQf9+Q7GWxVNMk3+uCPWfdXYC4ExGBckIXdFEfH1w==

webpack@^5.48.0:
version "5.75.0"
resolved "https://registry.yarnpkg.com/webpack/-/webpack-5.75.0.tgz#1e440468647b2505860e94c9ff3e44d5b582c152"
integrity sha512-piaIaoVJlqMsPtX/+3KTTO6jfvrSYgauFVdt8cr9LTHKmcq/AMd4mhzsiP7ZF/PGRNPGA8336jldh9l2Kt2ogQ==
webpack@^5.76.0:
version "5.76.2"
resolved "https://registry.yarnpkg.com/webpack/-/webpack-5.76.2.tgz#6f80d1c1d1e3bf704db571b2504a0461fac80230"
integrity sha512-Th05ggRm23rVzEOlX8y67NkYCHa9nTNcwHPBhdg+lKG+mtiW7XgggjAeeLnADAe7mLjJ6LUNfgHAuRRh+Z6J7w==
dependencies:
"@types/eslint-scope" "^3.7.3"
"@types/estree" "^0.0.51"
Expand Down

0 comments on commit 7385453

Please sign in to comment.