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

Decide on instantiation for IAuthenticationService and ILanguageDetectionService #161366

Merged
merged 2 commits into from Sep 21, 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 @@ -16,7 +16,7 @@ import { CommandsRegistry } from 'vs/platform/commands/common/commands';
import { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey';
import { ICredentialsService } from 'vs/platform/credentials/common/credentials';
import { IDialogService } from 'vs/platform/dialogs/common/dialogs';
import { registerSingleton } from 'vs/platform/instantiation/common/extensions';
import { InstantiationType, registerSingleton } from 'vs/platform/instantiation/common/extensions';
import { Severity } from 'vs/platform/notification/common/notification';
import { IProductService } from 'vs/platform/product/common/productService';
import { IQuickInputService } from 'vs/platform/quickinput/common/quickInput';
Expand Down Expand Up @@ -163,9 +163,16 @@ const authenticationExtPoint = ExtensionsRegistry.registerExtensionPoint<Authent
}
});

let placeholderMenuItem: IDisposable | undefined = MenuRegistry.appendMenuItem(MenuId.AccountsContext, {
command: {
id: 'noAuthenticationProviders',
title: nls.localize('authentication.Placeholder', "No accounts requested yet..."),
precondition: ContextKeyExpr.false()
},
});

export class AuthenticationService extends Disposable implements IAuthenticationService {
declare readonly _serviceBrand: undefined;
private _placeholderMenuItem: IDisposable | undefined;
private _signInRequestItems = new Map<string, SessionRequestInfo>();
private _sessionAccessRequestItems = new Map<string, { [extensionId: string]: { disposables: IDisposable[]; possibleSessions: AuthenticationSession[] } }>();
private _accountBadgeDisposable = this._register(new MutableDisposable());
Expand Down Expand Up @@ -198,13 +205,6 @@ export class AuthenticationService extends Disposable implements IAuthentication
@IQuickInputService private readonly quickInputService: IQuickInputService
) {
super();
this._placeholderMenuItem = MenuRegistry.appendMenuItem(MenuId.AccountsContext, {
command: {
id: 'noAuthenticationProviders',
title: nls.localize('authentication.Placeholder', "No accounts requested yet..."),
precondition: ContextKeyExpr.false()
},
});

authenticationExtPoint.setHandler((extensions, { added, removed }) => {
added.forEach(point => {
Expand Down Expand Up @@ -255,9 +255,9 @@ export class AuthenticationService extends Disposable implements IAuthentication
this._authenticationProviders.set(id, authenticationProvider);
this._onDidRegisterAuthenticationProvider.fire({ id, label: authenticationProvider.label });

if (this._placeholderMenuItem) {
this._placeholderMenuItem.dispose();
this._placeholderMenuItem = undefined;
if (placeholderMenuItem) {
placeholderMenuItem.dispose();
placeholderMenuItem = undefined;
}
}

Expand All @@ -275,7 +275,7 @@ export class AuthenticationService extends Disposable implements IAuthentication
}

if (!this._authenticationProviders.size) {
this._placeholderMenuItem = MenuRegistry.appendMenuItem(MenuId.AccountsContext, {
placeholderMenuItem = MenuRegistry.appendMenuItem(MenuId.AccountsContext, {
command: {
id: 'noAuthenticationProviders',
title: nls.localize('loading', "Loading..."),
Expand Down Expand Up @@ -735,4 +735,4 @@ export class AuthenticationService extends Disposable implements IAuthentication
}
}

registerSingleton(IAuthenticationService, AuthenticationService, false);
registerSingleton(IAuthenticationService, AuthenticationService, InstantiationType.Delayed);
Expand Up @@ -11,7 +11,7 @@ import { IConfigurationService } from 'vs/platform/configuration/common/configur
import { ILanguageService } from 'vs/editor/common/languages/language';
import { URI } from 'vs/base/common/uri';
import { isWeb } from 'vs/base/common/platform';
import { registerSingleton } from 'vs/platform/instantiation/common/extensions';
import { InstantiationType, registerSingleton } from 'vs/platform/instantiation/common/extensions';
import { LanguageDetectionSimpleWorker } from 'vs/workbench/services/languageDetection/browser/languageDetectionSimpleWorker';
import { IModelService } from 'vs/editor/common/services/model';
import { SimpleWorkerClient } from 'vs/base/common/worker/simpleWorker';
Expand Down Expand Up @@ -149,6 +149,9 @@ export class LanguageDetectionService extends Disposable implements ILanguageDet
return this._languageDetectionWorkerClient.detectLanguage(resource, biases, preferHistory, supportedLangs);
}

// TODO: explore using the history service or something similar to provide this list of opened editors
// so this service can support delayed instantiation. This may be tricky since it seems the IHistoryService
// only gives history for a workspace... where this takes advantage of history at a global level as well.
private initEditorOpenedListeners(storageService: IStorageService) {
try {
const globalLangHistroyData = JSON.parse(storageService.get(LanguageDetectionService.globalOpenedLanguagesStorageKey, StorageScope.PROFILE, '[]'));
Expand Down Expand Up @@ -354,4 +357,5 @@ export class LanguageDetectionWorkerClient extends EditorWorkerClient {
}
}

registerSingleton(ILanguageDetectionService, LanguageDetectionService, false);
// For now we use Eager until we handle keeping track of history better.
registerSingleton(ILanguageDetectionService, LanguageDetectionService, InstantiationType.Eager);