mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-31 09:35:39 -05:00
Merge from vscode f2d41726ba5a0e8abfe61b2c743022b1b6372010 (#7415)
* Merge from vscode f2d41726ba5a0e8abfe61b2c743022b1b6372010 * add missing files
This commit is contained in:
@@ -17,11 +17,67 @@ import { normalizeDriveLetter } from 'vs/base/common/labels';
|
||||
import { toSlashes } from 'vs/base/common/extpath';
|
||||
import { FormattingOptions } from 'vs/base/common/jsonFormatter';
|
||||
import { getRemoteAuthority } from 'vs/platform/remote/common/remoteHosts';
|
||||
import { ILogService } from 'vs/platform/log/common/log';
|
||||
import { Event as CommonEvent } from 'vs/base/common/event';
|
||||
|
||||
export const WORKSPACE_EXTENSION = 'code-workspace';
|
||||
export const WORKSPACE_FILTER = [{ name: localize('codeWorkspace', "Code Workspace"), extensions: [WORKSPACE_EXTENSION] }];
|
||||
export const UNTITLED_WORKSPACE_NAME = 'workspace.json';
|
||||
|
||||
export const IWorkspacesService = createDecorator<IWorkspacesService>('workspacesService');
|
||||
|
||||
export interface IWorkspacesService {
|
||||
|
||||
_serviceBrand: undefined;
|
||||
|
||||
// Management
|
||||
enterWorkspace(path: URI): Promise<IEnterWorkspaceResult | undefined>;
|
||||
createUntitledWorkspace(folders?: IWorkspaceFolderCreationData[], remoteAuthority?: string): Promise<IWorkspaceIdentifier>;
|
||||
deleteUntitledWorkspace(workspace: IWorkspaceIdentifier): Promise<void>;
|
||||
getWorkspaceIdentifier(workspacePath: URI): Promise<IWorkspaceIdentifier>;
|
||||
|
||||
// History
|
||||
readonly onRecentlyOpenedChange: CommonEvent<void>;
|
||||
addRecentlyOpened(recents: IRecent[]): Promise<void>;
|
||||
removeFromRecentlyOpened(workspaces: URI[]): Promise<void>;
|
||||
clearRecentlyOpened(): Promise<void>;
|
||||
getRecentlyOpened(): Promise<IRecentlyOpened>;
|
||||
}
|
||||
|
||||
export interface IRecentlyOpened {
|
||||
workspaces: Array<IRecentWorkspace | IRecentFolder>;
|
||||
files: IRecentFile[];
|
||||
}
|
||||
|
||||
export type IRecent = IRecentWorkspace | IRecentFolder | IRecentFile;
|
||||
|
||||
export interface IRecentWorkspace {
|
||||
workspace: IWorkspaceIdentifier;
|
||||
label?: string;
|
||||
}
|
||||
|
||||
export interface IRecentFolder {
|
||||
folderUri: ISingleFolderWorkspaceIdentifier;
|
||||
label?: string;
|
||||
}
|
||||
|
||||
export interface IRecentFile {
|
||||
fileUri: URI;
|
||||
label?: string;
|
||||
}
|
||||
|
||||
export function isRecentWorkspace(curr: IRecent): curr is IRecentWorkspace {
|
||||
return curr.hasOwnProperty('workspace');
|
||||
}
|
||||
|
||||
export function isRecentFolder(curr: IRecent): curr is IRecentFolder {
|
||||
return curr.hasOwnProperty('folderUri');
|
||||
}
|
||||
|
||||
export function isRecentFile(curr: IRecent): curr is IRecentFile {
|
||||
return curr.hasOwnProperty('fileUri');
|
||||
}
|
||||
|
||||
/**
|
||||
* A single folder workspace identifier is just the path to the folder.
|
||||
*/
|
||||
@@ -76,11 +132,6 @@ export interface IStoredWorkspace {
|
||||
remoteAuthority?: string;
|
||||
}
|
||||
|
||||
export interface IWorkspaceSavedEvent {
|
||||
workspace: IWorkspaceIdentifier;
|
||||
oldConfigPath: string;
|
||||
}
|
||||
|
||||
export interface IWorkspaceFolderCreationData {
|
||||
uri: URI;
|
||||
name?: string;
|
||||
@@ -96,21 +147,6 @@ export interface IEnterWorkspaceResult {
|
||||
backupPath?: string;
|
||||
}
|
||||
|
||||
export const IWorkspacesService = createDecorator<IWorkspacesService>('workspacesService');
|
||||
|
||||
export interface IWorkspacesService {
|
||||
|
||||
_serviceBrand: undefined;
|
||||
|
||||
enterWorkspace(path: URI): Promise<IEnterWorkspaceResult | undefined>;
|
||||
|
||||
createUntitledWorkspace(folders?: IWorkspaceFolderCreationData[], remoteAuthority?: string): Promise<IWorkspaceIdentifier>;
|
||||
|
||||
deleteUntitledWorkspace(workspace: IWorkspaceIdentifier): Promise<void>;
|
||||
|
||||
getWorkspaceIdentifier(workspacePath: URI): Promise<IWorkspaceIdentifier>;
|
||||
}
|
||||
|
||||
export function isSingleFolderWorkspaceIdentifier(obj: any): obj is ISingleFolderWorkspaceIdentifier {
|
||||
return obj instanceof URI;
|
||||
}
|
||||
@@ -267,3 +303,129 @@ export function useSlashForPath(storedFolders: IStoredWorkspaceFolder[]): boolea
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
//#region Workspace Storage
|
||||
|
||||
interface ISerializedRecentlyOpened {
|
||||
workspaces3: Array<ISerializedWorkspace | string>; // workspace or URI.toString() // added in 1.32
|
||||
workspaceLabels?: Array<string | null>; // added in 1.33
|
||||
files2: string[]; // files as URI.toString() // added in 1.32
|
||||
fileLabels?: Array<string | null>; // added in 1.33
|
||||
}
|
||||
|
||||
interface ILegacySerializedRecentlyOpened {
|
||||
workspaces2: Array<ILegacySerializedWorkspace | string>; // legacy, configPath as file path
|
||||
workspaces: Array<ILegacySerializedWorkspace | string | UriComponents>; // legacy (UriComponents was also supported for a few insider builds)
|
||||
files: string[]; // files as paths
|
||||
}
|
||||
|
||||
interface ISerializedWorkspace { id: string; configURIPath: string; }
|
||||
interface ILegacySerializedWorkspace { id: string; configPath: string; }
|
||||
|
||||
function isLegacySerializedWorkspace(curr: any): curr is ILegacySerializedWorkspace {
|
||||
return typeof curr === 'object' && typeof curr['id'] === 'string' && typeof curr['configPath'] === 'string';
|
||||
}
|
||||
|
||||
function isUriComponents(curr: any): curr is UriComponents {
|
||||
return curr && typeof curr['path'] === 'string' && typeof curr['scheme'] === 'string';
|
||||
}
|
||||
|
||||
export type RecentlyOpenedStorageData = object;
|
||||
|
||||
export function restoreRecentlyOpened(data: RecentlyOpenedStorageData | undefined, logService: ILogService): IRecentlyOpened {
|
||||
const result: IRecentlyOpened = { workspaces: [], files: [] };
|
||||
if (data) {
|
||||
const restoreGracefully = function <T>(entries: T[], func: (entry: T, index: number) => void) {
|
||||
for (let i = 0; i < entries.length; i++) {
|
||||
try {
|
||||
func(entries[i], i);
|
||||
} catch (e) {
|
||||
logService.warn(`Error restoring recent entry ${JSON.stringify(entries[i])}: ${e.toString()}. Skip entry.`);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const storedRecents = data as ISerializedRecentlyOpened & ILegacySerializedRecentlyOpened;
|
||||
if (Array.isArray(storedRecents.workspaces3)) {
|
||||
restoreGracefully(storedRecents.workspaces3, (workspace, i) => {
|
||||
const label: string | undefined = (Array.isArray(storedRecents.workspaceLabels) && storedRecents.workspaceLabels[i]) || undefined;
|
||||
if (typeof workspace === 'object' && typeof workspace.id === 'string' && typeof workspace.configURIPath === 'string') {
|
||||
result.workspaces.push({ label, workspace: { id: workspace.id, configPath: URI.parse(workspace.configURIPath) } });
|
||||
} else if (typeof workspace === 'string') {
|
||||
result.workspaces.push({ label, folderUri: URI.parse(workspace) });
|
||||
}
|
||||
});
|
||||
} else if (Array.isArray(storedRecents.workspaces2)) {
|
||||
restoreGracefully(storedRecents.workspaces2, workspace => {
|
||||
if (typeof workspace === 'object' && typeof workspace.id === 'string' && typeof workspace.configPath === 'string') {
|
||||
result.workspaces.push({ workspace: { id: workspace.id, configPath: URI.file(workspace.configPath) } });
|
||||
} else if (typeof workspace === 'string') {
|
||||
result.workspaces.push({ folderUri: URI.parse(workspace) });
|
||||
}
|
||||
});
|
||||
} else if (Array.isArray(storedRecents.workspaces)) {
|
||||
// TODO@martin legacy support can be removed at some point (6 month?)
|
||||
// format of 1.25 and before
|
||||
restoreGracefully(storedRecents.workspaces, workspace => {
|
||||
if (typeof workspace === 'string') {
|
||||
result.workspaces.push({ folderUri: URI.file(workspace) });
|
||||
} else if (isLegacySerializedWorkspace(workspace)) {
|
||||
result.workspaces.push({ workspace: { id: workspace.id, configPath: URI.file(workspace.configPath) } });
|
||||
} else if (isUriComponents(workspace)) {
|
||||
// added by 1.26-insiders
|
||||
result.workspaces.push({ folderUri: URI.revive(<UriComponents>workspace) });
|
||||
}
|
||||
});
|
||||
}
|
||||
if (Array.isArray(storedRecents.files2)) {
|
||||
restoreGracefully(storedRecents.files2, (file, i) => {
|
||||
const label: string | undefined = (Array.isArray(storedRecents.fileLabels) && storedRecents.fileLabels[i]) || undefined;
|
||||
if (typeof file === 'string') {
|
||||
result.files.push({ label, fileUri: URI.parse(file) });
|
||||
}
|
||||
});
|
||||
} else if (Array.isArray(storedRecents.files)) {
|
||||
restoreGracefully(storedRecents.files, file => {
|
||||
if (typeof file === 'string') {
|
||||
result.files.push({ fileUri: URI.file(file) });
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
export function toStoreData(recents: IRecentlyOpened): RecentlyOpenedStorageData {
|
||||
const serialized: ISerializedRecentlyOpened = { workspaces3: [], files2: [] };
|
||||
|
||||
let hasLabel = false;
|
||||
const workspaceLabels: (string | null)[] = [];
|
||||
for (const recent of recents.workspaces) {
|
||||
if (isRecentFolder(recent)) {
|
||||
serialized.workspaces3.push(recent.folderUri.toString());
|
||||
} else {
|
||||
serialized.workspaces3.push({ id: recent.workspace.id, configURIPath: recent.workspace.configPath.toString() });
|
||||
}
|
||||
workspaceLabels.push(recent.label || null);
|
||||
hasLabel = hasLabel || !!recent.label;
|
||||
}
|
||||
if (hasLabel) {
|
||||
serialized.workspaceLabels = workspaceLabels;
|
||||
}
|
||||
|
||||
hasLabel = false;
|
||||
const fileLabels: (string | null)[] = [];
|
||||
for (const recent of recents.files) {
|
||||
serialized.files2.push(recent.fileUri.toString());
|
||||
fileLabels.push(recent.label || null);
|
||||
hasLabel = hasLabel || !!recent.label;
|
||||
}
|
||||
if (hasLabel) {
|
||||
serialized.fileLabels = fileLabels;
|
||||
}
|
||||
|
||||
return serialized;
|
||||
}
|
||||
|
||||
//#endregion
|
||||
|
||||
@@ -1,41 +0,0 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { IWorkspaceIdentifier, ISingleFolderWorkspaceIdentifier } from 'vs/platform/workspaces/common/workspaces';
|
||||
import { URI } from 'vs/base/common/uri';
|
||||
|
||||
export interface IRecentlyOpened {
|
||||
workspaces: Array<IRecentWorkspace | IRecentFolder>;
|
||||
files: IRecentFile[];
|
||||
}
|
||||
|
||||
export type IRecent = IRecentWorkspace | IRecentFolder | IRecentFile;
|
||||
|
||||
export interface IRecentWorkspace {
|
||||
workspace: IWorkspaceIdentifier;
|
||||
label?: string;
|
||||
}
|
||||
|
||||
export interface IRecentFolder {
|
||||
folderUri: ISingleFolderWorkspaceIdentifier;
|
||||
label?: string;
|
||||
}
|
||||
|
||||
export interface IRecentFile {
|
||||
fileUri: URI;
|
||||
label?: string;
|
||||
}
|
||||
|
||||
export function isRecentWorkspace(curr: IRecent): curr is IRecentWorkspace {
|
||||
return curr.hasOwnProperty('workspace');
|
||||
}
|
||||
|
||||
export function isRecentFolder(curr: IRecent): curr is IRecentFolder {
|
||||
return curr.hasOwnProperty('folderUri');
|
||||
}
|
||||
|
||||
export function isRecentFile(curr: IRecent): curr is IRecentFile {
|
||||
return curr.hasOwnProperty('fileUri');
|
||||
}
|
||||
@@ -1,129 +0,0 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
import { UriComponents, URI } from 'vs/base/common/uri';
|
||||
import { IRecentlyOpened, isRecentFolder } from 'vs/platform/workspaces/common/workspacesHistory';
|
||||
import { ILogService } from 'vs/platform/log/common/log';
|
||||
|
||||
interface ISerializedRecentlyOpened {
|
||||
workspaces3: Array<ISerializedWorkspace | string>; // workspace or URI.toString() // added in 1.32
|
||||
workspaceLabels?: Array<string | null>; // added in 1.33
|
||||
files2: string[]; // files as URI.toString() // added in 1.32
|
||||
fileLabels?: Array<string | null>; // added in 1.33
|
||||
}
|
||||
|
||||
interface ILegacySerializedRecentlyOpened {
|
||||
workspaces2: Array<ILegacySerializedWorkspace | string>; // legacy, configPath as file path
|
||||
workspaces: Array<ILegacySerializedWorkspace | string | UriComponents>; // legacy (UriComponents was also supported for a few insider builds)
|
||||
files: string[]; // files as paths
|
||||
}
|
||||
|
||||
interface ISerializedWorkspace { id: string; configURIPath: string; }
|
||||
interface ILegacySerializedWorkspace { id: string; configPath: string; }
|
||||
|
||||
function isLegacySerializedWorkspace(curr: any): curr is ILegacySerializedWorkspace {
|
||||
return typeof curr === 'object' && typeof curr['id'] === 'string' && typeof curr['configPath'] === 'string';
|
||||
}
|
||||
|
||||
function isUriComponents(curr: any): curr is UriComponents {
|
||||
return curr && typeof curr['path'] === 'string' && typeof curr['scheme'] === 'string';
|
||||
}
|
||||
|
||||
export type RecentlyOpenedStorageData = object;
|
||||
|
||||
export function restoreRecentlyOpened(data: RecentlyOpenedStorageData | undefined, logService: ILogService): IRecentlyOpened {
|
||||
const result: IRecentlyOpened = { workspaces: [], files: [] };
|
||||
if (data) {
|
||||
const restoreGracefully = function <T>(entries: T[], func: (entry: T, index: number) => void) {
|
||||
for (let i = 0; i < entries.length; i++) {
|
||||
try {
|
||||
func(entries[i], i);
|
||||
} catch (e) {
|
||||
logService.warn(`Error restoring recent entry ${JSON.stringify(entries[i])}: ${e.toString()}. Skip entry.`);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const storedRecents = data as ISerializedRecentlyOpened & ILegacySerializedRecentlyOpened;
|
||||
if (Array.isArray(storedRecents.workspaces3)) {
|
||||
restoreGracefully(storedRecents.workspaces3, (workspace, i) => {
|
||||
const label: string | undefined = (Array.isArray(storedRecents.workspaceLabels) && storedRecents.workspaceLabels[i]) || undefined;
|
||||
if (typeof workspace === 'object' && typeof workspace.id === 'string' && typeof workspace.configURIPath === 'string') {
|
||||
result.workspaces.push({ label, workspace: { id: workspace.id, configPath: URI.parse(workspace.configURIPath) } });
|
||||
} else if (typeof workspace === 'string') {
|
||||
result.workspaces.push({ label, folderUri: URI.parse(workspace) });
|
||||
}
|
||||
});
|
||||
} else if (Array.isArray(storedRecents.workspaces2)) {
|
||||
restoreGracefully(storedRecents.workspaces2, workspace => {
|
||||
if (typeof workspace === 'object' && typeof workspace.id === 'string' && typeof workspace.configPath === 'string') {
|
||||
result.workspaces.push({ workspace: { id: workspace.id, configPath: URI.file(workspace.configPath) } });
|
||||
} else if (typeof workspace === 'string') {
|
||||
result.workspaces.push({ folderUri: URI.parse(workspace) });
|
||||
}
|
||||
});
|
||||
} else if (Array.isArray(storedRecents.workspaces)) {
|
||||
// TODO@martin legacy support can be removed at some point (6 month?)
|
||||
// format of 1.25 and before
|
||||
restoreGracefully(storedRecents.workspaces, workspace => {
|
||||
if (typeof workspace === 'string') {
|
||||
result.workspaces.push({ folderUri: URI.file(workspace) });
|
||||
} else if (isLegacySerializedWorkspace(workspace)) {
|
||||
result.workspaces.push({ workspace: { id: workspace.id, configPath: URI.file(workspace.configPath) } });
|
||||
} else if (isUriComponents(workspace)) {
|
||||
// added by 1.26-insiders
|
||||
result.workspaces.push({ folderUri: URI.revive(<UriComponents>workspace) });
|
||||
}
|
||||
});
|
||||
}
|
||||
if (Array.isArray(storedRecents.files2)) {
|
||||
restoreGracefully(storedRecents.files2, (file, i) => {
|
||||
const label: string | undefined = (Array.isArray(storedRecents.fileLabels) && storedRecents.fileLabels[i]) || undefined;
|
||||
if (typeof file === 'string') {
|
||||
result.files.push({ label, fileUri: URI.parse(file) });
|
||||
}
|
||||
});
|
||||
} else if (Array.isArray(storedRecents.files)) {
|
||||
restoreGracefully(storedRecents.files, file => {
|
||||
if (typeof file === 'string') {
|
||||
result.files.push({ fileUri: URI.file(file) });
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
export function toStoreData(recents: IRecentlyOpened): RecentlyOpenedStorageData {
|
||||
const serialized: ISerializedRecentlyOpened = { workspaces3: [], files2: [] };
|
||||
|
||||
let hasLabel = false;
|
||||
const workspaceLabels: (string | null)[] = [];
|
||||
for (const recent of recents.workspaces) {
|
||||
if (isRecentFolder(recent)) {
|
||||
serialized.workspaces3.push(recent.folderUri.toString());
|
||||
} else {
|
||||
serialized.workspaces3.push({ id: recent.workspace.id, configURIPath: recent.workspace.configPath.toString() });
|
||||
}
|
||||
workspaceLabels.push(recent.label || null);
|
||||
hasLabel = hasLabel || !!recent.label;
|
||||
}
|
||||
if (hasLabel) {
|
||||
serialized.workspaceLabels = workspaceLabels;
|
||||
}
|
||||
|
||||
hasLabel = false;
|
||||
const fileLabels: (string | null)[] = [];
|
||||
for (const recent of recents.files) {
|
||||
serialized.files2.push(recent.fileUri.toString());
|
||||
fileLabels.push(recent.label || null);
|
||||
hasLabel = hasLabel || !!recent.label;
|
||||
}
|
||||
if (hasLabel) {
|
||||
serialized.fileLabels = fileLabels;
|
||||
}
|
||||
|
||||
return serialized;
|
||||
}
|
||||
@@ -12,16 +12,14 @@ import { getBaseLabel, getPathLabel } from 'vs/base/common/labels';
|
||||
import { IPath } from 'vs/platform/windows/common/windows';
|
||||
import { Event as CommonEvent, Emitter } from 'vs/base/common/event';
|
||||
import { isWindows, isMacintosh } from 'vs/base/common/platform';
|
||||
import { IWorkspaceIdentifier, ISingleFolderWorkspaceIdentifier, isSingleFolderWorkspaceIdentifier } from 'vs/platform/workspaces/common/workspaces';
|
||||
import { IWorkspaceIdentifier, ISingleFolderWorkspaceIdentifier, isSingleFolderWorkspaceIdentifier, IRecentlyOpened, isRecentWorkspace, isRecentFolder, IRecent, isRecentFile, IRecentFolder, IRecentWorkspace, IRecentFile, toStoreData, restoreRecentlyOpened, RecentlyOpenedStorageData } from 'vs/platform/workspaces/common/workspaces';
|
||||
import { IWorkspacesMainService } from 'vs/platform/workspaces/electron-main/workspacesMainService';
|
||||
import { IRecentlyOpened, isRecentWorkspace, isRecentFolder, IRecent, isRecentFile, IRecentFolder, IRecentWorkspace, IRecentFile } from 'vs/platform/workspaces/common/workspacesHistory';
|
||||
import { ThrottledDelayer } from 'vs/base/common/async';
|
||||
import { isEqual as areResourcesEqual, dirname, originalFSPath, basename } from 'vs/base/common/resources';
|
||||
import { URI } from 'vs/base/common/uri';
|
||||
import { Schemas } from 'vs/base/common/network';
|
||||
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
|
||||
import { getSimpleWorkspaceLabel } from 'vs/platform/label/common/label';
|
||||
import { toStoreData, restoreRecentlyOpened, RecentlyOpenedStorageData } from 'vs/platform/workspaces/common/workspacesHistoryStorage';
|
||||
import { exists } from 'vs/base/node/pfs';
|
||||
import { ILifecycleMainService, LifecycleMainPhase } from 'vs/platform/lifecycle/electron-main/lifecycleMainService';
|
||||
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
|
||||
@@ -32,7 +30,7 @@ export interface IWorkspacesHistoryMainService {
|
||||
|
||||
_serviceBrand: undefined;
|
||||
|
||||
onRecentlyOpenedChange: CommonEvent<void>;
|
||||
readonly onRecentlyOpenedChange: CommonEvent<void>;
|
||||
|
||||
addRecentlyOpened(recents: IRecent[]): void;
|
||||
getRecentlyOpened(currentWorkspace?: IWorkspaceIdentifier, currentFolder?: ISingleFolderWorkspaceIdentifier, currentFiles?: IPath[]): IRecentlyOpened;
|
||||
|
||||
@@ -1,58 +0,0 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { IServerChannel } from 'vs/base/parts/ipc/common/ipc';
|
||||
import { IWorkspaceIdentifier, IWorkspaceFolderCreationData } from 'vs/platform/workspaces/common/workspaces';
|
||||
import { IWorkspacesMainService } from 'vs/platform/workspaces/electron-main/workspacesMainService';
|
||||
import { URI } from 'vs/base/common/uri';
|
||||
import { Event } from 'vs/base/common/event';
|
||||
import { IWindowsMainService } from 'vs/platform/windows/electron-main/windows';
|
||||
|
||||
export class WorkspacesChannel implements IServerChannel {
|
||||
|
||||
constructor(
|
||||
private workspacesMainService: IWorkspacesMainService,
|
||||
private windowsMainService: IWindowsMainService
|
||||
) { }
|
||||
|
||||
listen<T>(_: unknown, event: string): Event<T> {
|
||||
throw new Error(`Event not found: ${event}`);
|
||||
}
|
||||
|
||||
call(_: unknown, command: string, arg?: any): Promise<any> {
|
||||
switch (command) {
|
||||
case 'createUntitledWorkspace': {
|
||||
const rawFolders: IWorkspaceFolderCreationData[] = arg[0];
|
||||
const remoteAuthority: string = arg[1];
|
||||
let folders: IWorkspaceFolderCreationData[] | undefined = undefined;
|
||||
if (Array.isArray(rawFolders)) {
|
||||
folders = rawFolders.map(rawFolder => {
|
||||
return {
|
||||
uri: URI.revive(rawFolder.uri), // convert raw URI back to real URI
|
||||
name: rawFolder.name
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
return this.workspacesMainService.createUntitledWorkspace(folders, remoteAuthority);
|
||||
}
|
||||
case 'deleteUntitledWorkspace': {
|
||||
const identifier: IWorkspaceIdentifier = arg;
|
||||
return this.workspacesMainService.deleteUntitledWorkspace({ id: identifier.id, configPath: URI.revive(identifier.configPath) });
|
||||
}
|
||||
case 'getWorkspaceIdentifier': {
|
||||
return this.workspacesMainService.getWorkspaceIdentifier(URI.revive(arg));
|
||||
}
|
||||
case 'enterWorkspace': {
|
||||
const window = this.windowsMainService.getWindowById(arg[0]);
|
||||
if (window) {
|
||||
return this.windowsMainService.enterWorkspace(window, URI.revive(arg[1]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
throw new Error(`Call not found: ${command}`);
|
||||
}
|
||||
}
|
||||
@@ -20,18 +20,13 @@ import { Disposable } from 'vs/base/common/lifecycle';
|
||||
import { originalFSPath, isEqualOrParent, joinPath } from 'vs/base/common/resources';
|
||||
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
|
||||
|
||||
export interface IStoredWorkspace {
|
||||
folders: IStoredWorkspaceFolder[];
|
||||
remoteAuthority?: string;
|
||||
}
|
||||
|
||||
export const IWorkspacesMainService = createDecorator<IWorkspacesMainService>('workspacesMainService');
|
||||
|
||||
export interface IWorkspacesMainService {
|
||||
|
||||
_serviceBrand: undefined;
|
||||
|
||||
onUntitledWorkspaceDeleted: Event<IWorkspaceIdentifier>;
|
||||
readonly onUntitledWorkspaceDeleted: Event<IWorkspaceIdentifier>;
|
||||
|
||||
createUntitledWorkspaceSync(folders?: IWorkspaceFolderCreationData[]): IWorkspaceIdentifier;
|
||||
|
||||
@@ -50,6 +45,11 @@ export interface IWorkspacesMainService {
|
||||
getWorkspaceIdentifier(workspacePath: URI): Promise<IWorkspaceIdentifier>;
|
||||
}
|
||||
|
||||
export interface IStoredWorkspace {
|
||||
folders: IStoredWorkspaceFolder[];
|
||||
remoteAuthority?: string;
|
||||
}
|
||||
|
||||
export class WorkspacesMainService extends Disposable implements IWorkspacesMainService {
|
||||
|
||||
_serviceBrand: undefined;
|
||||
|
||||
@@ -0,0 +1,75 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { AddFirstParameterToFunctions } from 'vs/base/common/types';
|
||||
import { IWorkspacesService, IEnterWorkspaceResult, IWorkspaceFolderCreationData, IWorkspaceIdentifier, IRecentlyOpened, IRecent } from 'vs/platform/workspaces/common/workspaces';
|
||||
import { URI } from 'vs/base/common/uri';
|
||||
import { IWorkspacesMainService } from 'vs/platform/workspaces/electron-main/workspacesMainService';
|
||||
import { IWindowsMainService } from 'vs/platform/windows/electron-main/windows';
|
||||
import { IWorkspacesHistoryMainService } from 'vs/platform/workspaces/electron-main/workspacesHistoryMainService';
|
||||
|
||||
export class WorkspacesService implements AddFirstParameterToFunctions<IWorkspacesService, Promise<any> /* only methods, not events */, number /* window ID */> {
|
||||
|
||||
_serviceBrand: undefined;
|
||||
|
||||
constructor(
|
||||
@IWorkspacesMainService private readonly workspacesMainService: IWorkspacesMainService,
|
||||
@IWindowsMainService private readonly windowsMainService: IWindowsMainService,
|
||||
@IWorkspacesHistoryMainService private readonly workspacesHistoryMainService: IWorkspacesHistoryMainService
|
||||
) {
|
||||
}
|
||||
|
||||
//#region Workspace Management
|
||||
|
||||
async enterWorkspace(windowId: number, path: URI): Promise<IEnterWorkspaceResult | undefined> {
|
||||
const window = this.windowsMainService.getWindowById(windowId);
|
||||
if (window) {
|
||||
return this.windowsMainService.enterWorkspace(window, path);
|
||||
}
|
||||
|
||||
return undefined;
|
||||
}
|
||||
|
||||
createUntitledWorkspace(windowId: number, folders?: IWorkspaceFolderCreationData[], remoteAuthority?: string): Promise<IWorkspaceIdentifier> {
|
||||
return this.workspacesMainService.createUntitledWorkspace(folders, remoteAuthority);
|
||||
}
|
||||
|
||||
deleteUntitledWorkspace(windowId: number, workspace: IWorkspaceIdentifier): Promise<void> {
|
||||
return this.workspacesMainService.deleteUntitledWorkspace(workspace);
|
||||
}
|
||||
|
||||
getWorkspaceIdentifier(windowId: number, workspacePath: URI): Promise<IWorkspaceIdentifier> {
|
||||
return this.workspacesMainService.getWorkspaceIdentifier(workspacePath);
|
||||
}
|
||||
|
||||
//#endregion
|
||||
|
||||
//#region Workspaces History
|
||||
|
||||
readonly onRecentlyOpenedChange = this.workspacesHistoryMainService.onRecentlyOpenedChange;
|
||||
|
||||
async getRecentlyOpened(windowId: number): Promise<IRecentlyOpened> {
|
||||
const window = this.windowsMainService.getWindowById(windowId);
|
||||
if (window) {
|
||||
return this.workspacesHistoryMainService.getRecentlyOpened(window.config.workspace, window.config.folderUri, window.config.filesToOpenOrCreate);
|
||||
}
|
||||
|
||||
return this.workspacesHistoryMainService.getRecentlyOpened();
|
||||
}
|
||||
|
||||
async addRecentlyOpened(windowId: number, recents: IRecent[]): Promise<void> {
|
||||
return this.workspacesHistoryMainService.addRecentlyOpened(recents);
|
||||
}
|
||||
|
||||
async removeFromRecentlyOpened(windowId: number, paths: URI[]): Promise<void> {
|
||||
return this.workspacesHistoryMainService.removeFromRecentlyOpened(paths);
|
||||
}
|
||||
|
||||
async clearRecentlyOpened(windowId: number): Promise<void> {
|
||||
return this.workspacesHistoryMainService.clearRecentlyOpened();
|
||||
}
|
||||
|
||||
//#endregion
|
||||
}
|
||||
@@ -2,14 +2,12 @@
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import * as assert from 'assert';
|
||||
import * as os from 'os';
|
||||
import * as path from 'vs/base/common/path';
|
||||
|
||||
import { IWorkspaceIdentifier } from 'vs/platform/workspaces/common/workspaces';
|
||||
import { IWorkspaceIdentifier, IRecentlyOpened, isRecentFolder, IRecentFolder, IRecentWorkspace, toStoreData, restoreRecentlyOpened } from 'vs/platform/workspaces/common/workspaces';
|
||||
import { URI } from 'vs/base/common/uri';
|
||||
import { IRecentlyOpened, isRecentFolder, IRecentFolder, IRecentWorkspace } from 'vs/platform/workspaces/common/workspacesHistory';
|
||||
import { toStoreData, restoreRecentlyOpened } from 'vs/platform/workspaces/common/workspacesHistoryStorage';
|
||||
import { NullLogService } from 'vs/platform/log/common/log';
|
||||
|
||||
function toWorkspace(uri: URI): IWorkspaceIdentifier {
|
||||
|
||||
Reference in New Issue
Block a user