mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-05 09:35:39 -05:00
SQL Operations Studio Public Preview 1 (0.23) release source code
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
'use strict';
|
||||
|
||||
import { TPromise } from 'vs/base/common/winjs.base';
|
||||
import URI from 'vs/base/common/uri';
|
||||
import { createDecorator, ServiceIdentifier } from 'vs/platform/instantiation/common/instantiation';
|
||||
import { IWorkspaceIdentifier } from 'vs/platform/workspaces/common/workspaces';
|
||||
|
||||
export const IWorkspaceEditingService = createDecorator<IWorkspaceEditingService>('workspaceEditingService');
|
||||
|
||||
export interface IWorkspaceEditingService {
|
||||
|
||||
_serviceBrand: ServiceIdentifier<any>;
|
||||
|
||||
/**
|
||||
* add roots to the existing workspace
|
||||
*/
|
||||
addRoots(roots: URI[]): TPromise<void>;
|
||||
|
||||
/**
|
||||
* remove roots from the existing workspace
|
||||
*/
|
||||
removeRoots(roots: URI[]): TPromise<void>;
|
||||
}
|
||||
|
||||
export const IWorkspaceMigrationService = createDecorator<IWorkspaceMigrationService>('workspaceMigrationService');
|
||||
|
||||
export interface IWorkspaceMigrationService {
|
||||
|
||||
/**
|
||||
* Migrate current workspace to given workspace
|
||||
*/
|
||||
migrate(toWokspaceId: IWorkspaceIdentifier): TPromise<void>;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
'use strict';
|
||||
|
||||
import { IWorkspaceEditingService } from 'vs/workbench/services/workspace/common/workspaceEditing';
|
||||
import URI from 'vs/base/common/uri';
|
||||
import { equals, distinct } from 'vs/base/common/arrays';
|
||||
import { TPromise } from 'vs/base/common/winjs.base';
|
||||
import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace';
|
||||
import { IWindowsService } from 'vs/platform/windows/common/windows';
|
||||
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
|
||||
import { IJSONEditingService } from 'vs/workbench/services/configuration/common/jsonEditing';
|
||||
import { IWorkspacesService, IStoredWorkspaceFolder } from 'vs/platform/workspaces/common/workspaces';
|
||||
import { isLinux } from 'vs/base/common/platform';
|
||||
import { dirname, relative } from 'path';
|
||||
import { isEqualOrParent } from 'vs/base/common/paths';
|
||||
|
||||
export class WorkspaceEditingService implements IWorkspaceEditingService {
|
||||
|
||||
public _serviceBrand: any;
|
||||
|
||||
constructor(
|
||||
@IJSONEditingService private jsonEditingService: IJSONEditingService,
|
||||
@IWorkspaceContextService private contextService: IWorkspaceContextService,
|
||||
@IEnvironmentService private environmentService: IEnvironmentService,
|
||||
@IWindowsService private windowsService: IWindowsService,
|
||||
@IWorkspacesService private workspacesService: IWorkspacesService
|
||||
) {
|
||||
}
|
||||
|
||||
public addRoots(rootsToAdd: URI[]): TPromise<void> {
|
||||
if (!this.isSupported()) {
|
||||
return TPromise.as(void 0); // we need a workspace to begin with
|
||||
}
|
||||
|
||||
const roots = this.contextService.getWorkspace().roots;
|
||||
|
||||
return this.doSetRoots([...roots, ...rootsToAdd]);
|
||||
}
|
||||
|
||||
public removeRoots(rootsToRemove: URI[]): TPromise<void> {
|
||||
if (!this.isSupported()) {
|
||||
return TPromise.as(void 0); // we need a workspace to begin with
|
||||
}
|
||||
|
||||
const roots = this.contextService.getWorkspace().roots;
|
||||
const rootsToRemoveRaw = rootsToRemove.map(root => root.toString());
|
||||
|
||||
return this.doSetRoots(roots.filter(root => rootsToRemoveRaw.indexOf(root.toString()) === -1));
|
||||
}
|
||||
|
||||
private isSupported(): boolean {
|
||||
// TODO@Ben multi root
|
||||
return (
|
||||
this.environmentService.appQuality !== 'stable' // not yet enabled in stable
|
||||
&& this.contextService.hasMultiFolderWorkspace() // we need a multi folder workspace to begin with
|
||||
);
|
||||
}
|
||||
|
||||
private doSetRoots(newRoots: URI[]): TPromise<void> {
|
||||
const workspace = this.contextService.getWorkspace();
|
||||
const currentWorkspaceRoots = this.contextService.getWorkspace().roots.map(root => root.fsPath);
|
||||
const newWorkspaceRoots = this.validateRoots(newRoots);
|
||||
|
||||
// See if there are any changes
|
||||
if (equals(currentWorkspaceRoots, newWorkspaceRoots)) {
|
||||
return TPromise.as(void 0);
|
||||
}
|
||||
|
||||
// Apply to config
|
||||
if (newWorkspaceRoots.length) {
|
||||
const workspaceConfigFolder = dirname(workspace.configuration.fsPath);
|
||||
const value: IStoredWorkspaceFolder[] = newWorkspaceRoots.map(newWorkspaceRoot => {
|
||||
if (isEqualOrParent(newWorkspaceRoot, workspaceConfigFolder, !isLinux)) {
|
||||
newWorkspaceRoot = relative(workspaceConfigFolder, newWorkspaceRoot) || '.'; // absolute paths get converted to relative ones to workspace location if possible
|
||||
}
|
||||
|
||||
return { path: newWorkspaceRoot };
|
||||
});
|
||||
|
||||
return this.jsonEditingService.write(workspace.configuration, { key: 'folders', value }, true);
|
||||
} else {
|
||||
// TODO: Sandeep - Removing all roots?
|
||||
}
|
||||
|
||||
return TPromise.as(null);
|
||||
}
|
||||
|
||||
private validateRoots(roots: URI[]): string[] {
|
||||
if (!roots) {
|
||||
return [];
|
||||
}
|
||||
|
||||
// Prevent duplicates
|
||||
return distinct(roots.map(root => root.fsPath), root => isLinux ? root : root.toLowerCase());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
'use strict';
|
||||
|
||||
import { TPromise } from 'vs/base/common/winjs.base';
|
||||
import URI from 'vs/base/common/uri';
|
||||
import { once } from 'vs/base/common/event';
|
||||
import { IDisposable } from 'vs/base/common/lifecycle';
|
||||
import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace';
|
||||
import { Registry } from 'vs/platform/registry/common/platform';
|
||||
import { IConfigurationRegistry, Extensions as ConfigurationExtensions, ConfigurationScope } from 'vs/platform/configuration/common/configurationRegistry';
|
||||
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
|
||||
import { IWorkspaceIdentifier } from 'vs/platform/workspaces/common/workspaces';
|
||||
import { ILifecycleService } from 'vs/platform/lifecycle/common/lifecycle';
|
||||
import { StorageService } from 'vs/platform/storage/common/storageService';
|
||||
import { migrateStorageToMultiRootWorkspace } from 'vs/platform/storage/common/migration';
|
||||
import { IStorageService } from 'vs/platform/storage/common/storage';
|
||||
import { IJSONEditingService } from 'vs/workbench/services/configuration/common/jsonEditing';
|
||||
import { IWorkspaceMigrationService } from 'vs/workbench/services/workspace/common/workspaceEditing';
|
||||
|
||||
export class WorkspaceMigrationService implements IWorkspaceMigrationService {
|
||||
|
||||
public _serviceBrand: any;
|
||||
|
||||
private shutdownListener: IDisposable;
|
||||
|
||||
constructor(
|
||||
@IStorageService private storageService: IStorageService,
|
||||
@IJSONEditingService private jsonEditingService: IJSONEditingService,
|
||||
@IWorkspaceContextService private contextService: IWorkspaceContextService,
|
||||
@IConfigurationService private configurationService: IConfigurationService,
|
||||
@ILifecycleService private lifecycleService: ILifecycleService
|
||||
) {
|
||||
}
|
||||
|
||||
migrate(toWorkspaceId: IWorkspaceIdentifier): TPromise<void> {
|
||||
this.migrateStorage(toWorkspaceId);
|
||||
|
||||
return this.migrateConfiguration(toWorkspaceId);
|
||||
}
|
||||
|
||||
migrateStorage(toWorkspaceId: IWorkspaceIdentifier): void {
|
||||
|
||||
// The shutdown sequence could have been stopped due to a veto. Make sure to
|
||||
// always dispose the shutdown listener if we are called again in the same session.
|
||||
if (this.shutdownListener) {
|
||||
this.shutdownListener.dispose();
|
||||
this.shutdownListener = void 0;
|
||||
}
|
||||
|
||||
// Since many components write to storage only on shutdown, we register a shutdown listener
|
||||
// very late to be called as the last one.
|
||||
this.shutdownListener = once(this.lifecycleService.onShutdown)(() => {
|
||||
|
||||
// TODO@Ben revisit this when we move away from local storage to a file based approach
|
||||
const storageImpl = this.storageService as StorageService;
|
||||
migrateStorageToMultiRootWorkspace(storageImpl.storageId, toWorkspaceId, storageImpl.workspaceStorage);
|
||||
});
|
||||
}
|
||||
|
||||
private migrateConfiguration(toWorkspaceId: IWorkspaceIdentifier): TPromise<void> {
|
||||
if (!this.contextService.hasFolderWorkspace()) {
|
||||
return TPromise.as(void 0); // return early if not a folder workspace is opened
|
||||
}
|
||||
|
||||
const configurationProperties = Registry.as<IConfigurationRegistry>(ConfigurationExtensions.Configuration).getConfigurationProperties();
|
||||
const targetWorkspaceConfiguration = {};
|
||||
for (const key of this.configurationService.keys().workspace) {
|
||||
if (configurationProperties[key] && configurationProperties[key].scope === ConfigurationScope.WINDOW) {
|
||||
targetWorkspaceConfiguration[key] = this.configurationService.lookup(key).workspace;
|
||||
}
|
||||
}
|
||||
|
||||
return this.jsonEditingService.write(URI.file(toWorkspaceId.configPath), { key: 'settings', value: targetWorkspaceConfiguration }, true);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user