Skip to content

Commit

Permalink
use workspaceIdentifier while getting profile (microsoft#152177)
Browse files Browse the repository at this point in the history
  • Loading branch information
sandy081 authored Jun 15, 2022
1 parent f64b324 commit 8332665
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/vs/platform/userDataProfile/common/userDataProfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export interface IUserDataProfilesService {
newProfile(name: string, options?: ProfileOptions): IUserDataProfile;
createProfile(profile: IUserDataProfile, options: ProfileOptions, workspaceIdentifier?: ISingleFolderWorkspaceIdentifier | IWorkspaceIdentifier): Promise<IUserDataProfile>;
setProfileForWorkspace(profile: IUserDataProfile, workspaceIdentifier: ISingleFolderWorkspaceIdentifier | IWorkspaceIdentifier): Promise<IUserDataProfile>;
getProfile(workspace: URI): IUserDataProfile;
getProfile(workspaceIdentifier: ISingleFolderWorkspaceIdentifier | IWorkspaceIdentifier): IUserDataProfile;
getAllProfiles(): Promise<IUserDataProfile[]>;
removeProfile(profile: IUserDataProfile): Promise<void>;
}
Expand Down Expand Up @@ -123,6 +123,6 @@ export class UserDataProfilesService extends Disposable implements IUserDataProf
getAllProfiles(): Promise<IUserDataProfile[]> { throw new Error('Not implemented'); }
createProfile(profile: IUserDataProfile, options: ProfileOptions, workspaceIdentifier?: ISingleFolderWorkspaceIdentifier | IWorkspaceIdentifier): Promise<IUserDataProfile> { throw new Error('Not implemented'); }
setProfileForWorkspace(profile: IUserDataProfile, workspaceIdentifier: ISingleFolderWorkspaceIdentifier | IWorkspaceIdentifier): Promise<IUserDataProfile> { throw new Error('Not implemented'); }
getProfile(workspace: URI): IUserDataProfile { throw new Error('Not implemented'); }
getProfile(workspaceIdentifier: ISingleFolderWorkspaceIdentifier | IWorkspaceIdentifier): IUserDataProfile { throw new Error('Not implemented'); }
removeProfile(profile: IUserDataProfile): Promise<void> { throw new Error('Not implemented'); }
}
10 changes: 7 additions & 3 deletions src/vs/platform/userDataProfile/electron-main/userDataProfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ export class UserDataProfilesMainService extends UserDataProfilesService impleme
return this.profiles.profiles;
}

override getProfile(workspace: URI): IUserDataProfile {
return this.profiles.workspaces.get(workspace) ?? this.defaultProfile;
override getProfile(workspaceIdentifier: ISingleFolderWorkspaceIdentifier | IWorkspaceIdentifier): IUserDataProfile {
return this.profiles.workspaces.get(this.getWorkspace(workspaceIdentifier)) ?? this.defaultProfile;
}

override async createProfile(profile: IUserDataProfile, options: ProfileOptions, workspaceIdentifier?: ISingleFolderWorkspaceIdentifier | IWorkspaceIdentifier): Promise<IUserDataProfile> {
Expand All @@ -93,7 +93,7 @@ export class UserDataProfilesMainService extends UserDataProfilesService impleme

override async setProfileForWorkspace(profile: IUserDataProfile, workspaceIdentifier: ISingleFolderWorkspaceIdentifier | IWorkspaceIdentifier): Promise<IUserDataProfile> {
profile = reviveProfile(profile, this.profilesHome.scheme);
const workspace = isSingleFolderWorkspaceIdentifier(workspaceIdentifier) ? workspaceIdentifier.uri : workspaceIdentifier.configPath;
const workspace = this.getWorkspace(workspaceIdentifier);
const storedWorkspaceInfos = this.storedWorskpaceInfos.filter(info => !this.uriIdentityService.extUri.isEqual(info.workspace, workspace));
if (!profile.isDefault) {
storedWorkspaceInfos.push({ workspace, profile: profile.location });
Expand All @@ -102,6 +102,10 @@ export class UserDataProfilesMainService extends UserDataProfilesService impleme
return this.profiles.profiles.find(p => this.uriIdentityService.extUri.isEqual(p.location, profile.location))!;
}

private getWorkspace(workspaceIdentifier: ISingleFolderWorkspaceIdentifier | IWorkspaceIdentifier) {
return isSingleFolderWorkspaceIdentifier(workspaceIdentifier) ? workspaceIdentifier.uri : workspaceIdentifier.configPath;
}

override async removeProfile(profile: IUserDataProfile): Promise<void> {
if (profile.isDefault) {
throw new Error('Cannot remove default profile');
Expand Down
2 changes: 1 addition & 1 deletion src/vs/platform/windows/electron-main/window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -885,7 +885,7 @@ export class CodeWindow extends Disposable implements ICodeWindow {
configuration.policiesData = this.policyService.serialize(); // set policies data again
configuration.profiles = {
default: this.userDataProfilesService.defaultProfile,
current: configuration.workspace ? this.userDataProfilesService.getProfile(isWorkspaceIdentifier(configuration.workspace) ? configuration.workspace.configPath : configuration.workspace.uri) : this.userDataProfilesService.defaultProfile,
current: configuration.workspace ? this.userDataProfilesService.getProfile(configuration.workspace) : this.userDataProfilesService.defaultProfile,
};

// Load config
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1302,7 +1302,7 @@ export class WindowsMainService extends Disposable implements IWindowsMainServic

profiles: {
default: this.userDataProfilesService.defaultProfile,
current: options.workspace ? this.userDataProfilesService.getProfile(isWorkspaceIdentifier(options.workspace) ? options.workspace.configPath : options.workspace.uri) : this.userDataProfilesService.defaultProfile,
current: options.workspace ? this.userDataProfilesService.getProfile(options.workspace) : this.userDataProfilesService.defaultProfile,
},

homeDir: this.environmentMainService.userHome.fsPath,
Expand Down

0 comments on commit 8332665

Please sign in to comment.