mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-05 09:35:39 -05:00
Fix stringify error from resource deployment extension (#14059)
* Fix stringify error from resource deployment extension * add comment
This commit is contained in:
@@ -71,3 +71,22 @@ export async function tryExecuteAction<T>(action: () => T | PromiseLike<T>): Pro
|
||||
}
|
||||
return { result, error };
|
||||
}
|
||||
|
||||
export function deepClone<T>(obj: T): T {
|
||||
if (!obj || typeof obj !== 'object') {
|
||||
return obj;
|
||||
}
|
||||
if (obj instanceof RegExp) {
|
||||
// See https://github.com/Microsoft/TypeScript/issues/10990
|
||||
return obj as any;
|
||||
}
|
||||
const result: any = Array.isArray(obj) ? [] : {};
|
||||
Object.keys(<any>obj).forEach((key: string) => {
|
||||
if ((<any>obj)[key] && typeof (<any>obj)[key] === 'object') {
|
||||
result[key] = deepClone((<any>obj)[key]);
|
||||
} else {
|
||||
result[key] = (<any>obj)[key];
|
||||
}
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ import { IPlatformService } from './platformService';
|
||||
import { IToolsService } from './toolsService';
|
||||
import * as loc from './../localizedConstants';
|
||||
import { ResourceTypeWizard } from '../ui/resourceTypeWizard';
|
||||
import { deepClone } from '../common/utils';
|
||||
|
||||
const localize = nls.loadMessageBundle();
|
||||
|
||||
@@ -40,7 +41,11 @@ export class ResourceTypeService implements IResourceTypeService {
|
||||
vscode.extensions.all.forEach((extension) => {
|
||||
const extensionResourceTypes = extension.packageJSON.contributes && extension.packageJSON.contributes.resourceDeploymentTypes as ResourceType[];
|
||||
if (extensionResourceTypes) {
|
||||
extensionResourceTypes.forEach((resourceType: ResourceType) => {
|
||||
extensionResourceTypes.forEach((extensionResourceType: ResourceType) => {
|
||||
// Clone the object - we modify it by adding complex types and so if we modify the original contribution then
|
||||
// we can break VS Code functionality since it will sometimes pass this object over the RPC layer which requires
|
||||
// stringifying it - which can break with some of the complex types we add.
|
||||
const resourceType = deepClone(extensionResourceType);
|
||||
this.updatePathProperties(resourceType, extension.extensionPath);
|
||||
resourceType.getProvider = (selectedOptions) => { return this.getProvider(resourceType, selectedOptions); };
|
||||
resourceType.getOkButtonText = (selectedOptions) => { return this.getOkButtonText(resourceType, selectedOptions); };
|
||||
|
||||
Reference in New Issue
Block a user