mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 10:58:30 -05:00
Merge from master
This commit is contained in:
@@ -2,9 +2,8 @@
|
||||
* 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 URI from 'vs/base/common/uri';
|
||||
import { URI } from 'vs/base/common/uri';
|
||||
import * as paths from 'vs/base/common/paths';
|
||||
import * as resources from 'vs/base/common/resources';
|
||||
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
|
||||
@@ -16,7 +15,7 @@ import { isLinux } from 'vs/base/common/platform';
|
||||
|
||||
export const IWorkspaceContextService = createDecorator<IWorkspaceContextService>('contextService');
|
||||
|
||||
export enum WorkbenchState {
|
||||
export const enum WorkbenchState {
|
||||
EMPTY = 1,
|
||||
FOLDER,
|
||||
WORKSPACE
|
||||
@@ -64,7 +63,7 @@ export interface IWorkspaceContextService {
|
||||
* Returns the folder for the given resource from the workspace.
|
||||
* Can be null if there is no workspace or the resource is not inside the workspace.
|
||||
*/
|
||||
getWorkspaceFolder(resource: URI): IWorkspaceFolder;
|
||||
getWorkspaceFolder(resource: URI): IWorkspaceFolder | null;
|
||||
|
||||
/**
|
||||
* Return `true` if the current workspace has the given identifier otherwise `false`.
|
||||
@@ -81,7 +80,6 @@ export namespace IWorkspace {
|
||||
export function isIWorkspace(thing: any): thing is IWorkspace {
|
||||
return thing && typeof thing === 'object'
|
||||
&& typeof (thing as IWorkspace).id === 'string'
|
||||
&& typeof (thing as IWorkspace).name === 'string'
|
||||
&& Array.isArray((thing as IWorkspace).folders);
|
||||
}
|
||||
}
|
||||
@@ -93,11 +91,6 @@ export interface IWorkspace {
|
||||
*/
|
||||
readonly id: string;
|
||||
|
||||
/**
|
||||
* the name of the workspace.
|
||||
*/
|
||||
readonly name: string;
|
||||
|
||||
/**
|
||||
* Folders in the workspace.
|
||||
*/
|
||||
@@ -106,7 +99,7 @@ export interface IWorkspace {
|
||||
/**
|
||||
* the location of the workspace configuration
|
||||
*/
|
||||
readonly configuration?: URI;
|
||||
readonly configuration?: URI | null;
|
||||
}
|
||||
|
||||
export interface IWorkspaceFolderData {
|
||||
@@ -151,19 +144,15 @@ export class Workspace implements IWorkspace {
|
||||
|
||||
constructor(
|
||||
private _id: string,
|
||||
private _name: string = '',
|
||||
folders: WorkspaceFolder[] = [],
|
||||
private _configuration: URI = null,
|
||||
private _ctime?: number
|
||||
private _configuration: URI | null = null
|
||||
) {
|
||||
this.folders = folders;
|
||||
}
|
||||
|
||||
update(workspace: Workspace) {
|
||||
this._id = workspace.id;
|
||||
this._name = workspace.name;
|
||||
this._configuration = workspace.configuration;
|
||||
this._ctime = workspace.ctime;
|
||||
this.folders = workspace.folders;
|
||||
}
|
||||
|
||||
@@ -180,27 +169,15 @@ export class Workspace implements IWorkspace {
|
||||
return this._id;
|
||||
}
|
||||
|
||||
get ctime(): number {
|
||||
return this._ctime;
|
||||
}
|
||||
|
||||
get name(): string {
|
||||
return this._name;
|
||||
}
|
||||
|
||||
set name(name: string) {
|
||||
this._name = name;
|
||||
}
|
||||
|
||||
get configuration(): URI {
|
||||
get configuration(): URI | null {
|
||||
return this._configuration;
|
||||
}
|
||||
|
||||
set configuration(configuration: URI) {
|
||||
set configuration(configuration: URI | null) {
|
||||
this._configuration = configuration;
|
||||
}
|
||||
|
||||
getFolder(resource: URI): IWorkspaceFolder {
|
||||
getFolder(resource: URI): IWorkspaceFolder | null | undefined {
|
||||
if (!resource) {
|
||||
return null;
|
||||
}
|
||||
@@ -216,7 +193,7 @@ export class Workspace implements IWorkspace {
|
||||
}
|
||||
|
||||
toJSON(): IWorkspace {
|
||||
return { id: this.id, folders: this.folders, name: this.name, configuration: this.configuration };
|
||||
return { id: this.id, folders: this.folders, configuration: this.configuration };
|
||||
}
|
||||
}
|
||||
|
||||
@@ -234,7 +211,7 @@ export class WorkspaceFolder implements IWorkspaceFolder {
|
||||
}
|
||||
|
||||
toResource(relativePath: string): URI {
|
||||
return this.uri.with({ path: paths.join(this.uri.path, relativePath) });
|
||||
return resources.joinPath(this.uri, relativePath);
|
||||
}
|
||||
|
||||
toJSON(): IWorkspaceFolderData {
|
||||
@@ -248,9 +225,9 @@ export function toWorkspaceFolders(configuredFolders: IStoredWorkspaceFolder[],
|
||||
.map(({ uri, raw, name }, index) => new WorkspaceFolder({ uri, name: name || resources.basenameOrAuthority(uri), index }, raw));
|
||||
}
|
||||
|
||||
function parseWorkspaceFolders(configuredFolders: IStoredWorkspaceFolder[], relativeTo: URI): WorkspaceFolder[] {
|
||||
function parseWorkspaceFolders(configuredFolders: IStoredWorkspaceFolder[], relativeTo: URI | undefined): (WorkspaceFolder | undefined)[] {
|
||||
return configuredFolders.map((configuredFolder, index) => {
|
||||
let uri: URI;
|
||||
let uri: URI | null = null;
|
||||
if (isRawFileWorkspaceFolder(configuredFolder)) {
|
||||
uri = toUri(configuredFolder.path, relativeTo);
|
||||
} else if (isRawUriWorkspaceFolder(configuredFolder)) {
|
||||
@@ -268,17 +245,17 @@ function parseWorkspaceFolders(configuredFolders: IStoredWorkspaceFolder[], rela
|
||||
if (!uri) {
|
||||
return void 0;
|
||||
}
|
||||
return new WorkspaceFolder({ uri, name: configuredFolder.name, index }, configuredFolder);
|
||||
return new WorkspaceFolder({ uri, name: configuredFolder.name! /*is ensured in caller*/, index }, configuredFolder);
|
||||
});
|
||||
}
|
||||
|
||||
function toUri(path: string, relativeTo: URI): URI {
|
||||
function toUri(path: string, relativeTo: URI | undefined): URI | null {
|
||||
if (path) {
|
||||
if (paths.isAbsolute(path)) {
|
||||
return URI.file(path);
|
||||
}
|
||||
if (relativeTo) {
|
||||
return relativeTo.with({ path: paths.join(relativeTo.path, path) });
|
||||
return resources.joinPath(relativeTo, path);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import URI from 'vs/base/common/uri';
|
||||
import { URI } from 'vs/base/common/uri';
|
||||
import { Workspace, toWorkspaceFolders } from 'vs/platform/workspace/common/workspace';
|
||||
import { isWindows } from 'vs/base/common/platform';
|
||||
|
||||
@@ -13,7 +13,6 @@ export const TestWorkspace = testWorkspace(wsUri);
|
||||
export function testWorkspace(resource: URI): Workspace {
|
||||
return new Workspace(
|
||||
resource.toString(),
|
||||
resource.fsPath,
|
||||
toWorkspaceFolders([{ path: resource.fsPath }])
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,18 +3,16 @@
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
'use strict';
|
||||
|
||||
import * as assert from 'assert';
|
||||
import { Workspace, toWorkspaceFolders, WorkspaceFolder } from 'vs/platform/workspace/common/workspace';
|
||||
import URI from 'vs/base/common/uri';
|
||||
import { URI } from 'vs/base/common/uri';
|
||||
import { IRawFileWorkspaceFolder } from 'vs/platform/workspaces/common/workspaces';
|
||||
|
||||
suite('Workspace', () => {
|
||||
|
||||
test('getFolder returns the folder with given uri', () => {
|
||||
const expected = new WorkspaceFolder({ uri: URI.file('/src/test'), name: '', index: 2 });
|
||||
let testObject = new Workspace('', '', [new WorkspaceFolder({ uri: URI.file('/src/main'), name: '', index: 0 }), expected, new WorkspaceFolder({ uri: URI.file('/src/code'), name: '', index: 2 })]);
|
||||
let testObject = new Workspace('', [new WorkspaceFolder({ uri: URI.file('/src/main'), name: '', index: 0 }), expected, new WorkspaceFolder({ uri: URI.file('/src/code'), name: '', index: 2 })]);
|
||||
|
||||
const actual = testObject.getFolder(expected.uri);
|
||||
|
||||
@@ -23,7 +21,7 @@ suite('Workspace', () => {
|
||||
|
||||
test('getFolder returns the folder if the uri is sub', () => {
|
||||
const expected = new WorkspaceFolder({ uri: URI.file('/src/test'), name: '', index: 0 });
|
||||
let testObject = new Workspace('', '', [expected, new WorkspaceFolder({ uri: URI.file('/src/main'), name: '', index: 1 }), new WorkspaceFolder({ uri: URI.file('/src/code'), name: '', index: 2 })]);
|
||||
let testObject = new Workspace('', [expected, new WorkspaceFolder({ uri: URI.file('/src/main'), name: '', index: 1 }), new WorkspaceFolder({ uri: URI.file('/src/code'), name: '', index: 2 })]);
|
||||
|
||||
const actual = testObject.getFolder(URI.file('/src/test/a'));
|
||||
|
||||
@@ -32,7 +30,7 @@ suite('Workspace', () => {
|
||||
|
||||
test('getFolder returns the closest folder if the uri is sub', () => {
|
||||
const expected = new WorkspaceFolder({ uri: URI.file('/src/test'), name: '', index: 2 });
|
||||
let testObject = new Workspace('', '', [new WorkspaceFolder({ uri: URI.file('/src/main'), name: '', index: 0 }), new WorkspaceFolder({ uri: URI.file('/src/code'), name: '', index: 1 }), expected]);
|
||||
let testObject = new Workspace('', [new WorkspaceFolder({ uri: URI.file('/src/main'), name: '', index: 0 }), new WorkspaceFolder({ uri: URI.file('/src/code'), name: '', index: 1 }), expected]);
|
||||
|
||||
const actual = testObject.getFolder(URI.file('/src/test/a'));
|
||||
|
||||
@@ -40,7 +38,7 @@ suite('Workspace', () => {
|
||||
});
|
||||
|
||||
test('getFolder returns null if the uri is not sub', () => {
|
||||
let testObject = new Workspace('', '', [new WorkspaceFolder({ uri: URI.file('/src/test'), name: '', index: 0 }), new WorkspaceFolder({ uri: URI.file('/src/code'), name: '', index: 1 })]);
|
||||
let testObject = new Workspace('', [new WorkspaceFolder({ uri: URI.file('/src/test'), name: '', index: 0 }), new WorkspaceFolder({ uri: URI.file('/src/code'), name: '', index: 1 })]);
|
||||
|
||||
const actual = testObject.getFolder(URI.file('/src/main/a'));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user