Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some code cleanup in main process #169208

Merged
merged 3 commits into from Dec 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -19,21 +19,21 @@ export const IEnvironmentMainService = refineServiceDecorator<IEnvironmentServic
export interface IEnvironmentMainService extends INativeEnvironmentService {

// --- NLS cache path
cachedLanguagesPath: string;
readonly cachedLanguagesPath: string;

// --- backup paths
backupHome: string;
readonly backupHome: string;

// --- V8 code caching
codeCachePath: string | undefined;
useCodeCache: boolean;
readonly codeCachePath: string | undefined;
readonly useCodeCache: boolean;

// --- IPC
mainIPCHandle: string;
mainLockfile: string;
readonly mainIPCHandle: string;
readonly mainLockfile: string;

// --- config
disableUpdates: boolean;
readonly disableUpdates: boolean;
}

export class EnvironmentMainService extends NativeEnvironmentService implements IEnvironmentMainService {
Expand Down
Expand Up @@ -26,17 +26,17 @@ interface WindowLoadEvent {
/**
* The window that is loaded to a new workspace.
*/
window: ICodeWindow;
readonly window: ICodeWindow;

/**
* The workspace the window is loaded into.
*/
workspace: IWorkspaceIdentifier | ISingleFolderWorkspaceIdentifier | undefined;
readonly workspace: IWorkspaceIdentifier | ISingleFolderWorkspaceIdentifier | undefined;

/**
* More details why the window loads to a new workspace.
*/
reason: LoadReason;
readonly reason: LoadReason;
}

export const enum ShutdownReason {
Expand Down
6 changes: 3 additions & 3 deletions src/vs/platform/storage/common/storageIpc.ts
Expand Up @@ -9,7 +9,7 @@ import { UriDto } from 'vs/base/common/uri';
import { IChannel } from 'vs/base/parts/ipc/common/ipc';
import { IStorageDatabase, IStorageItemsChangeEvent, IUpdateRequest } from 'vs/base/parts/storage/common/storage';
import { IUserDataProfile } from 'vs/platform/userDataProfile/common/userDataProfile';
import { ISerializedSingleFolderWorkspaceIdentifier, ISerializedWorkspaceIdentifier, IEmptyWorkspaceIdentifier, ISingleFolderWorkspaceIdentifier, IWorkspaceIdentifier } from 'vs/platform/workspace/common/workspace';
import { ISerializedSingleFolderWorkspaceIdentifier, ISerializedWorkspaceIdentifier, IEmptyWorkspaceIdentifier, IAnyWorkspaceIdentifier } from 'vs/platform/workspace/common/workspace';

export type Key = string;
export type Value = string;
Expand Down Expand Up @@ -53,7 +53,7 @@ abstract class BaseStorageDatabaseClient extends Disposable implements IStorageD
constructor(
protected channel: IChannel,
protected profile: UriDto<IUserDataProfile> | undefined,
protected workspace: IWorkspaceIdentifier | ISingleFolderWorkspaceIdentifier | IEmptyWorkspaceIdentifier | undefined
protected workspace: IAnyWorkspaceIdentifier | undefined
) {
super();
}
Expand Down Expand Up @@ -144,7 +144,7 @@ export class WorkspaceStorageDatabaseClient extends BaseStorageDatabaseClient im

readonly onDidChangeItemsExternal = Event.None; // unsupported for workspace storage because we only ever write from one window

constructor(channel: IChannel, workspace: IWorkspaceIdentifier | ISingleFolderWorkspaceIdentifier | IEmptyWorkspaceIdentifier) {
constructor(channel: IChannel, workspace: IAnyWorkspaceIdentifier) {
super(channel, undefined, workspace);
}

Expand Down
4 changes: 2 additions & 2 deletions src/vs/platform/storage/electron-main/storageIpc.ts
Expand Up @@ -12,7 +12,7 @@ import { IBaseSerializableStorageRequest, ISerializableItemsChangeEvent, ISerial
import { IStorageChangeEvent, IStorageMain } from 'vs/platform/storage/electron-main/storageMain';
import { IStorageMainService } from 'vs/platform/storage/electron-main/storageMainService';
import { IUserDataProfile } from 'vs/platform/userDataProfile/common/userDataProfile';
import { reviveIdentifier, IEmptyWorkspaceIdentifier, ISingleFolderWorkspaceIdentifier, IWorkspaceIdentifier } from 'vs/platform/workspace/common/workspace';
import { reviveIdentifier, IAnyWorkspaceIdentifier } from 'vs/platform/workspace/common/workspace';

export class StorageDatabaseChannel extends Disposable implements IServerChannel {

Expand Down Expand Up @@ -137,7 +137,7 @@ export class StorageDatabaseChannel extends Disposable implements IServerChannel
}
}

private async withStorageInitialized(profile: IUserDataProfile | undefined, workspace: IWorkspaceIdentifier | ISingleFolderWorkspaceIdentifier | IEmptyWorkspaceIdentifier | undefined): Promise<IStorageMain> {
private async withStorageInitialized(profile: IUserDataProfile | undefined, workspace: IAnyWorkspaceIdentifier | undefined): Promise<IStorageMain> {
let storage: IStorageMain;
if (workspace) {
storage = this.storageMainService.workspaceStorage(workspace);
Expand Down
8 changes: 4 additions & 4 deletions src/vs/platform/storage/electron-main/storageMain.ts
Expand Up @@ -19,15 +19,15 @@ import { ILogService, LogLevel } from 'vs/platform/log/common/log';
import { IS_NEW_KEY } from 'vs/platform/storage/common/storage';
import { IUserDataProfile, IUserDataProfilesService } from 'vs/platform/userDataProfile/common/userDataProfile';
import { currentSessionDateStorageKey, firstSessionDateStorageKey, lastSessionDateStorageKey } from 'vs/platform/telemetry/common/telemetry';
import { IEmptyWorkspaceIdentifier, ISingleFolderWorkspaceIdentifier, IWorkspaceIdentifier, isSingleFolderWorkspaceIdentifier, isWorkspaceIdentifier } from 'vs/platform/workspace/common/workspace';
import { isSingleFolderWorkspaceIdentifier, isWorkspaceIdentifier, IAnyWorkspaceIdentifier } from 'vs/platform/workspace/common/workspace';

export interface IStorageMainOptions {

/**
* If enabled, storage will not persist to disk
* but into memory.
*/
useInMemoryStorage?: boolean;
readonly useInMemoryStorage?: boolean;
}

/**
Expand Down Expand Up @@ -103,7 +103,7 @@ export interface IStorageMain extends IDisposable {
}

export interface IStorageChangeEvent {
key: string;
readonly key: string;
}

abstract class BaseStorageMain extends Disposable implements IStorageMain {
Expand Down Expand Up @@ -359,7 +359,7 @@ export class WorkspaceStorageMain extends BaseStorageMain {
}

constructor(
private workspace: IWorkspaceIdentifier | ISingleFolderWorkspaceIdentifier | IEmptyWorkspaceIdentifier,
private workspace: IAnyWorkspaceIdentifier,
private readonly options: IStorageMainOptions,
logService: ILogService,
private readonly environmentService: IEnvironmentService,
Expand Down
8 changes: 4 additions & 4 deletions src/vs/platform/storage/electron-main/storageMainService.ts
Expand Up @@ -17,7 +17,7 @@ import { AbstractStorageService, isProfileUsingDefaultStorage, IStorageService,
import { ApplicationStorageMain, ProfileStorageMain, InMemoryStorageMain, IStorageMain, IStorageMainOptions, WorkspaceStorageMain, IStorageChangeEvent } from 'vs/platform/storage/electron-main/storageMain';
import { IUserDataProfile, IUserDataProfilesService } from 'vs/platform/userDataProfile/common/userDataProfile';
import { IUserDataProfilesMainService } from 'vs/platform/userDataProfile/electron-main/userDataProfile';
import { IEmptyWorkspaceIdentifier, ISingleFolderWorkspaceIdentifier, IWorkspaceIdentifier } from 'vs/platform/workspace/common/workspace';
import { IAnyWorkspaceIdentifier } from 'vs/platform/workspace/common/workspace';
import { IUriIdentityService } from 'vs/platform/uriIdentity/common/uriIdentity';

//#region Storage Main Service (intent: make application, profile and workspace storage accessible to windows from main process)
Expand Down Expand Up @@ -62,7 +62,7 @@ export interface IStorageMainService {
* Note: DO NOT use this for reading/writing from the main process!
* This is currently not supported.
*/
workspaceStorage(workspace: IWorkspaceIdentifier | ISingleFolderWorkspaceIdentifier | IEmptyWorkspaceIdentifier): IStorageMain;
workspaceStorage(workspace: IAnyWorkspaceIdentifier): IStorageMain;

/**
* Checks if the provided path is currently in use for a storage database.
Expand Down Expand Up @@ -232,7 +232,7 @@ export class StorageMainService extends Disposable implements IStorageMainServic

private readonly mapWorkspaceToStorage = new Map<string /* workspace ID */, IStorageMain>();

workspaceStorage(workspace: IWorkspaceIdentifier | ISingleFolderWorkspaceIdentifier | IEmptyWorkspaceIdentifier): IStorageMain {
workspaceStorage(workspace: IAnyWorkspaceIdentifier): IStorageMain {
let workspaceStorage = this.mapWorkspaceToStorage.get(workspace.id);
if (!workspaceStorage) {
this.logService.trace(`StorageMainService: creating workspace storage (${workspace.id})`);
Expand All @@ -250,7 +250,7 @@ export class StorageMainService extends Disposable implements IStorageMainServic
return workspaceStorage;
}

private createWorkspaceStorage(workspace: IWorkspaceIdentifier | ISingleFolderWorkspaceIdentifier | IEmptyWorkspaceIdentifier): IStorageMain {
private createWorkspaceStorage(workspace: IAnyWorkspaceIdentifier): IStorageMain {
if (this.shutdownReason === ShutdownReason.KILL) {

// Workaround for native crashes that we see when
Expand Down
10 changes: 5 additions & 5 deletions src/vs/platform/storage/electron-sandbox/storageService.ts
Expand Up @@ -12,7 +12,7 @@ import { IMainProcessService } from 'vs/platform/ipc/electron-sandbox/services';
import { AbstractStorageService, isProfileUsingDefaultStorage, StorageScope, WillSaveStateReason } from 'vs/platform/storage/common/storage';
import { ApplicationStorageDatabaseClient, ProfileStorageDatabaseClient, WorkspaceStorageDatabaseClient } from 'vs/platform/storage/common/storageIpc';
import { isUserDataProfile, IUserDataProfile } from 'vs/platform/userDataProfile/common/userDataProfile';
import { IAnyWorkspaceIdentifier, IEmptyWorkspaceIdentifier, ISingleFolderWorkspaceIdentifier, IWorkspaceIdentifier } from 'vs/platform/workspace/common/workspace';
import { IAnyWorkspaceIdentifier } from 'vs/platform/workspace/common/workspace';

export class NativeStorageService extends AbstractStorageService {

Expand All @@ -28,7 +28,7 @@ export class NativeStorageService extends AbstractStorageService {
private workspaceStorage = this.createWorkspaceStorage(this.initialWorkspace);

constructor(
private readonly initialWorkspace: IWorkspaceIdentifier | ISingleFolderWorkspaceIdentifier | IEmptyWorkspaceIdentifier | undefined,
private readonly initialWorkspace: IAnyWorkspaceIdentifier | undefined,
private readonly initialProfiles: { defaultProfile: IUserDataProfile; currentProfile: IUserDataProfile },
private readonly mainProcessService: IMainProcessService,
private readonly environmentService: IEnvironmentService
Expand Down Expand Up @@ -72,9 +72,9 @@ export class NativeStorageService extends AbstractStorageService {
return profileStorage;
}

private createWorkspaceStorage(workspace: IWorkspaceIdentifier | ISingleFolderWorkspaceIdentifier | IEmptyWorkspaceIdentifier): IStorage;
private createWorkspaceStorage(workspace: IWorkspaceIdentifier | ISingleFolderWorkspaceIdentifier | IEmptyWorkspaceIdentifier | undefined): IStorage | undefined;
private createWorkspaceStorage(workspace: IWorkspaceIdentifier | ISingleFolderWorkspaceIdentifier | IEmptyWorkspaceIdentifier | undefined): IStorage | undefined {
private createWorkspaceStorage(workspace: IAnyWorkspaceIdentifier): IStorage;
private createWorkspaceStorage(workspace: IAnyWorkspaceIdentifier | undefined): IStorage | undefined;
private createWorkspaceStorage(workspace: IAnyWorkspaceIdentifier | undefined): IStorage | undefined {

// First clear any previously associated disposables
this.workspaceStorageDisposables.clear();
Expand Down
6 changes: 3 additions & 3 deletions src/vs/platform/window/electron-main/window.ts
Expand Up @@ -124,7 +124,7 @@ export interface IWindowState {
x?: number;
y?: number;
mode?: WindowMode;
display?: number;
readonly display?: number;
}

export const defaultWindowState = function (mode = WindowMode.Normal): IWindowState {
Expand All @@ -143,8 +143,8 @@ export const enum WindowMode {
}

export interface ILoadEvent {
workspace: IWorkspaceIdentifier | ISingleFolderWorkspaceIdentifier | undefined;
reason: LoadReason;
readonly workspace: IWorkspaceIdentifier | ISingleFolderWorkspaceIdentifier | undefined;
readonly reason: LoadReason;
}

export const enum WindowError {
Expand Down
14 changes: 8 additions & 6 deletions src/vs/platform/windows/electron-main/windowImpl.ts
Expand Up @@ -52,18 +52,18 @@ import { hostname, release } from 'os';
import { resolveMachineId } from 'vs/platform/telemetry/electron-main/telemetryUtils';

export interface IWindowCreationOptions {
state: IWindowState;
extensionDevelopmentPath?: string[];
isExtensionTestHost?: boolean;
readonly state: IWindowState;
readonly extensionDevelopmentPath?: string[];
readonly isExtensionTestHost?: boolean;
}

interface ITouchBarSegment extends SegmentedControlSegment {
id: string;
readonly id: string;
}

interface ILoadOptions {
isReload?: boolean;
disableExtensions?: boolean;
readonly isReload?: boolean;
readonly disableExtensions?: boolean;
}

const enum ReadyState {
Expand Down Expand Up @@ -133,10 +133,12 @@ export class CodeWindow extends Disposable implements ICodeWindow {
if (!this.config) {
return undefined;
}

const profile = this.userDataProfilesService.profiles.find(profile => profile.id === this.config?.profiles.profile.id);
if (this.isExtensionDevelopmentHost && profile) {
return profile;
}

return this.userDataProfilesService.getOrSetProfileForWorkspace(this.config.workspace ?? 'empty-window', profile ?? this.userDataProfilesService.defaultProfile);
}

Expand Down
Expand Up @@ -18,7 +18,7 @@ import { defaultWindowState, ICodeWindow, IWindowState as IWindowUIState, Window
import { isSingleFolderWorkspaceIdentifier, isWorkspaceIdentifier, IWorkspaceIdentifier } from 'vs/platform/workspace/common/workspace';

export interface IWindowState {
windowId?: number;
readonly windowId?: number;
workspace?: IWorkspaceIdentifier;
folderUri?: URI;
backupPath?: string;
Expand Down
4 changes: 2 additions & 2 deletions src/vs/platform/workspace/common/workspace.ts
Expand Up @@ -204,8 +204,8 @@ export function reviveIdentifier(identifier: undefined): undefined;
export function reviveIdentifier(identifier: ISerializedWorkspaceIdentifier): IWorkspaceIdentifier;
export function reviveIdentifier(identifier: ISerializedSingleFolderWorkspaceIdentifier): ISingleFolderWorkspaceIdentifier;
export function reviveIdentifier(identifier: IEmptyWorkspaceIdentifier): IEmptyWorkspaceIdentifier;
export function reviveIdentifier(identifier: ISerializedWorkspaceIdentifier | ISerializedSingleFolderWorkspaceIdentifier | IEmptyWorkspaceIdentifier | undefined): IWorkspaceIdentifier | ISingleFolderWorkspaceIdentifier | IEmptyWorkspaceIdentifier | undefined;
export function reviveIdentifier(identifier: ISerializedWorkspaceIdentifier | ISerializedSingleFolderWorkspaceIdentifier | IEmptyWorkspaceIdentifier | undefined): IWorkspaceIdentifier | ISingleFolderWorkspaceIdentifier | IEmptyWorkspaceIdentifier | undefined {
export function reviveIdentifier(identifier: ISerializedWorkspaceIdentifier | ISerializedSingleFolderWorkspaceIdentifier | IEmptyWorkspaceIdentifier | undefined): IAnyWorkspaceIdentifier | undefined;
export function reviveIdentifier(identifier: ISerializedWorkspaceIdentifier | ISerializedSingleFolderWorkspaceIdentifier | IEmptyWorkspaceIdentifier | undefined): IAnyWorkspaceIdentifier | undefined {

// Single Folder
const singleFolderIdentifierCandidate = identifier as ISerializedSingleFolderWorkspaceIdentifier | undefined;
Expand Down
Expand Up @@ -31,8 +31,8 @@ import { getWorkspaceIdentifier } from 'vs/platform/workspaces/node/workspaces';
export const IWorkspacesManagementMainService = createDecorator<IWorkspacesManagementMainService>('workspacesManagementMainService');

export interface IWorkspaceEnteredEvent {
window: ICodeWindow;
workspace: IWorkspaceIdentifier;
readonly window: ICodeWindow;
readonly workspace: IWorkspaceIdentifier;
}

export interface IWorkspacesManagementMainService {
Expand Down
Expand Up @@ -7,13 +7,13 @@ import { IEnvironmentService } from 'vs/platform/environment/common/environment'
import { IMainProcessService } from 'vs/platform/ipc/electron-sandbox/services';
import { NativeStorageService } from 'vs/platform/storage/electron-sandbox/storageService';
import { IUserDataProfilesService } from 'vs/platform/userDataProfile/common/userDataProfile';
import { IEmptyWorkspaceIdentifier, ISingleFolderWorkspaceIdentifier, IWorkspaceIdentifier } from 'vs/platform/workspace/common/workspace';
import { IAnyWorkspaceIdentifier } from 'vs/platform/workspace/common/workspace';
import { IUserDataProfileService } from 'vs/workbench/services/userDataProfile/common/userDataProfile';

export class NativeWorkbenchStorageService extends NativeStorageService {

constructor(
workspace: IWorkspaceIdentifier | ISingleFolderWorkspaceIdentifier | IEmptyWorkspaceIdentifier | undefined,
workspace: IAnyWorkspaceIdentifier | undefined,
private readonly userDataProfileService: IUserDataProfileService,
userDataProfilesService: IUserDataProfilesService,
mainProcessService: IMainProcessService,
Expand Down