Skip to content

Commit

Permalink
fixup! [plug-in] implement inspect configuration method
Browse files Browse the repository at this point in the history
  • Loading branch information
akurinnoy committed Jan 24, 2019
1 parent b8d8490 commit 0cd49c0
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 40 deletions.
45 changes: 24 additions & 21 deletions packages/plugin-ext/src/plugin/preference-registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,32 +210,35 @@ export class PreferenceRegistryExtImpl implements PreferenceRegistryExt {
}

private parse(data: PreferenceData): Configuration {
const defaultConfigurationModel = new ConfigurationModelImpl(this.parseConfigurationData(data[PreferenceScope.Default]), Object.keys(data[PreferenceScope.Default]));
const userConfiguration = new ConfigurationModelImpl(this.parseConfigurationData(data[PreferenceScope.User]), Object.keys(data[PreferenceScope.User]));
const workspaceConfiguration = new ConfigurationModelImpl(this.parseConfigurationData(data[PreferenceScope.Workspace]), Object.keys(data[PreferenceScope.Workspace]));
const defaultConfigurationModel = this.getConfigurationModel(data[PreferenceScope.Default]);
const userConfiguration = this.getConfigurationModel(data[PreferenceScope.User]);
const workspaceConfiguration = this.getConfigurationModel(data[PreferenceScope.Workspace]);
return new Configuration(defaultConfigurationModel, userConfiguration, workspaceConfiguration);
}

private getConfigurationModel(data: { [key: string]: any }): ConfigurationModelImpl {
if (!data) {
return new ConfigurationModelImpl();
}
return new ConfigurationModelImpl(this.parseConfigurationData(data), Object.keys(data));
}

private parseConfigurationData(data: { [key: string]: any }): { [key: string]: any } {
let res;
try {
res = Object.keys(data).reduce((result: any, key: string) => {
const parts = key.split('.');
let branch = result;
for (let i = 0; i < parts.length; i++) {
if (i === parts.length - 1) {
branch[parts[i]] = data[key];
continue;
}
if (!branch[parts[i]]) {
branch[parts[i]] = {};
}
branch = branch[parts[i]];
return Object.keys(data).reduce((result: any, key: string) => {
const parts = key.split('.');
let branch = result;
for (let i = 0; i < parts.length; i++) {
if (i === parts.length - 1) {
branch[parts[i]] = data[key];
continue;
}
return result;
}, {});
} catch (e) { }
return res;
if (!branch[parts[i]]) {
branch[parts[i]] = {};
}
branch = branch[parts[i]];
}
return result;
}, {});
}

private toConfigurationChangeEvent(eventData: PreferenceChange): theia.ConfigurationChangeEvent {
Expand Down
9 changes: 8 additions & 1 deletion packages/plugin-ext/src/plugin/preferences/configuration.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/********************************************************************************
* Copyright (C) 2018 Red Hat, Inc. and others.
* Copyright (C) 2019 Red Hat, Inc. 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
Expand All @@ -13,6 +13,13 @@
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/
// copied from https://github.com/Microsoft/vscode/blob/6959ac313dbbe4a6b360de785c8ef4b548ebf8d7/src/vs/platform/configuration/common/configuration.ts,
// https://github.com/Microsoft/vscode/blob/6959ac313dbbe4a6b360de785c8ef4b548ebf8d7/src/vs/platform/configuration/common/configurationModels.ts,
// https://github.com/Microsoft/vscode/blob/6959ac313dbbe4a6b360de785c8ef4b548ebf8d7/src/vs/base/common/arrays.ts
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import URI from 'vscode-uri';
import { WorkspaceExtImpl } from '../workspace';
Expand Down
18 changes: 0 additions & 18 deletions packages/plugin/src/theia.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3934,23 +3934,6 @@ declare module '@theia/plugin' {
export function findFiles(include: GlobPattern, exclude?: GlobPattern | undefined, maxResults?: number, token?: CancellationToken): PromiseLike<Uri[]>;

/**
<<<<<<< HEAD
* Make changes to one or many resources or create, delete, and rename resources as defined by the given
* [workspace edit](#WorkspaceEdit).
*
* All changes of a workspace edit are applied in the same order in which they have been added. If
* multiple textual inserts are made at the same position, these strings appear in the resulting text
* in the order the 'inserts' were made. Invalid sequences like 'delete file a' -> 'insert text in file a'
* cause failure of the operation.
*
* When applying a workspace edit that consists only of text edits an 'all-or-nothing'-strategy is used.
* A workspace edit with resource creations or deletions aborts the operation, e.g. consective edits will
* not be attempted, when a single edit fails.
*
* @param edit A workspace edit.
* @return A thenable that resolves when the edit could be applied.
*/
=======
* Make changes to one or many resources or create, delete, and rename resources as defined by the given
* [workspace edit](#WorkspaceEdit).
*
Expand All @@ -3966,7 +3949,6 @@ declare module '@theia/plugin' {
* @param edit A workspace edit.
* @return A thenable that resolves when the edit could be applied.
*/
>>>>>>> [plug-in] implement inspect configuration method
export function applyEdit(edit: WorkspaceEdit): PromiseLike<boolean>;


Expand Down

0 comments on commit 0cd49c0

Please sign in to comment.