Skip to content

Commit

Permalink
Merge pull request #160364 from microsoft/dev/joyceerhl/polish-auth
Browse files Browse the repository at this point in the history
Provide UX affordances for turning on Edit Sessions
  • Loading branch information
joyceerhl committed Sep 8, 2022
2 parents bcf14fe + ea9a778 commit e41b3a8
Show file tree
Hide file tree
Showing 3 changed files with 154 additions and 38 deletions.
Expand Up @@ -29,7 +29,7 @@ import { IProductService } from 'vs/platform/product/common/productService';
import { IOpenerService } from 'vs/platform/opener/common/opener';
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
import { workbenchConfigurationNodeBase } from 'vs/workbench/common/configuration';
import { Extensions, IConfigurationRegistry } from 'vs/platform/configuration/common/configurationRegistry';
import { Extensions as ConfigurationExtensions, IConfigurationRegistry } from 'vs/platform/configuration/common/configurationRegistry';
import { IQuickInputService, IQuickPickItem } from 'vs/platform/quickinput/common/quickInput';
import { ExtensionsRegistry } from 'vs/workbench/services/extensions/common/extensionsRegistry';
import { ContextKeyExpr, ContextKeyExpression, IContextKey, IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
Expand Down Expand Up @@ -57,10 +57,9 @@ import * as Constants from 'vs/workbench/contrib/logs/common/logConstants';
registerSingleton(IEditSessionsLogService, EditSessionsLogService, false);
registerSingleton(IEditSessionsStorageService, EditSessionsWorkbenchService, false);

const continueEditSessionCommand: IAction2Options = {
const continueWorkingOnCommand: IAction2Options = {
id: '_workbench.experimental.editSessions.actions.continueEditSession',
title: { value: localize('continue edit session', "Continue Edit Session..."), original: 'Continue Edit Session...' },
category: EDIT_SESSION_SYNC_CATEGORY,
title: { value: localize('continue working on', "Continue Working On..."), original: 'Continue Working On...' },
precondition: WorkspaceFolderCountContext.notEqualsTo('0'),
f1: true
};
Expand All @@ -83,6 +82,7 @@ const resumingProgressOptions = {
const queryParamName = 'editSessionId';
const experimentalSettingName = 'workbench.experimental.editSessions.enabled';

const useEditSessionsWithContinueOn = 'workbench.experimental.editSessions.continueOn';
export class EditSessionsContribution extends Disposable implements IWorkbenchContribution {

private registered = false;
Expand Down Expand Up @@ -242,7 +242,7 @@ export class EditSessionsContribution extends Disposable implements IWorkbenchCo
const that = this;
this._register(registerAction2(class ContinueEditSessionAction extends Action2 {
constructor() {
super(continueEditSessionCommand);
super(continueWorkingOnCommand);
}

async run(accessor: ServicesAccessor, workspaceUri: URI | undefined): Promise<void> {
Expand All @@ -252,11 +252,16 @@ export class EditSessionsContribution extends Disposable implements IWorkbenchCo
};
that.telemetryService.publicLog2<ContinueEditSessionEvent, ContinueEditSessionClassification>('editSessions.continue.store');

const shouldStoreEditSession = await that.shouldContinueOnWithEditSession();

let uri = workspaceUri ?? await that.pickContinueEditSessionDestination();
if (uri === undefined) { return; }

// Run the store action to get back a ref
const ref = await that.storeEditSession(false);
let ref: string | undefined;
if (shouldStoreEditSession) {
ref = await that.storeEditSession(false);
}

// Append the ref to the URI
if (ref !== undefined && uri !== 'noDestinationUri') {
Expand All @@ -268,8 +273,12 @@ export class EditSessionsContribution extends Disposable implements IWorkbenchCo
// Open the URI
that.logService.info(`Opening ${uri.toString()}`);
await that.openerService.open(uri, { openExternal: true });
} else if (ref === undefined) {
that.logService.warn(`Failed to store edit session when invoking ${continueEditSessionCommand.id}.`);
} else if (!shouldStoreEditSession && uri !== 'noDestinationUri') {
// Open the URI without an edit session ref
that.logService.info(`Opening ${uri.toString()}`);
await that.openerService.open(uri, { openExternal: true });
} else if (ref === undefined && shouldStoreEditSession) {
that.logService.warn(`Failed to store edit session when invoking ${continueWorkingOnCommand.id}.`);
}
}
}));
Expand All @@ -287,15 +296,15 @@ export class EditSessionsContribution extends Disposable implements IWorkbenchCo
});
}

async run(accessor: ServicesAccessor, editSessionId?: string): Promise<void> {
async run(accessor: ServicesAccessor, editSessionId?: string, silent?: boolean): Promise<void> {
await that.progressService.withProgress(resumingProgressOptions, async () => {
type ResumeEvent = {};
type ResumeClassification = {
owner: 'joyceerhl'; comment: 'Reporting when the resume edit session action is invoked.';
};
that.telemetryService.publicLog2<ResumeEvent, ResumeClassification>('editSessions.resume');

await that.resumeEditSession(editSessionId);
await that.resumeEditSession(editSessionId, silent);
});
}
}));
Expand Down Expand Up @@ -529,6 +538,34 @@ export class EditSessionsContribution extends Disposable implements IWorkbenchCo
return [...trackedUris];
}

private hasEditSession() {
for (const repository of this.scmService.repositories) {
if (this.getChangedResources(repository).length > 0) {
return true;
}
}
return false;
}

private async shouldContinueOnWithEditSession(): Promise<boolean> {
// If the user is already signed in, we should store edit session
if (this.editSessionsStorageService.isSignedIn) {
return true;
}

// If the user has been asked before and said no, don't use edit sessions
if (this.configurationService.getValue(useEditSessionsWithContinueOn) === 'off') {
return false;
}

// Prompt the user to use edit sessions if they currently could benefit from using it
if (this.hasEditSession()) {
return this.editSessionsStorageService.initialize(true);
}

return false;
}

//#region Continue Edit Session extension contribution point

private registerContributedEditSessionOptions() {
Expand Down Expand Up @@ -690,7 +727,7 @@ const continueEditSessionExtPoint = ExtensionsRegistry.registerExtensionPoint<IC
const workbenchRegistry = Registry.as<IWorkbenchContributionsRegistry>(WorkbenchExtensions.Workbench);
workbenchRegistry.registerWorkbenchContribution(EditSessionsContribution, 'EditSessionsContribution', LifecyclePhase.Restored);

Registry.as<IConfigurationRegistry>(Extensions.Configuration).registerConfiguration({
Registry.as<IConfigurationRegistry>(ConfigurationExtensions.Configuration).registerConfiguration({
...workbenchConfigurationNodeBase,
'properties': {
'workbench.experimental.editSessions.autoStore': {
Expand Down Expand Up @@ -721,5 +758,16 @@ Registry.as<IConfigurationRegistry>(Extensions.Configuration).registerConfigurat
'default': 'onReload',
'markdownDescription': localize('autoResume', "Controls whether to automatically resume an available edit session for the current workspace."),
},
'workbench.experimental.editSessions.continueOn': {
enum: ['prompt', 'off'],
enumDescriptions: [
localize('continueOn.promptForAuth', 'Prompt the user to sign in to store edit sessions with Continue Working On.'),
localize('continueOn.off', 'Do not use edit sessions with Continue Working On unless the user has already turned on edit sessions.')
],
type: 'string',
tags: ['experimental', 'usesOnlineServices'],
default: 'prompt',
markdownDescription: localize('continueOn', 'Controls whether to prompt the user to store edit sessions when using Continue Working On.')
}
}
});

0 comments on commit e41b3a8

Please sign in to comment.