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

Initialize AIActivationService from preferences #15044

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions packages/ai-core/src/browser/ai-activation-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// *****************************************************************************
import { inject, injectable } from '@theia/core/shared/inversify';
import { FrontendApplicationContribution, PreferenceService } from '@theia/core/lib/browser';
import { Emitter, MaybePromise, Event, } from '@theia/core';
import { Emitter, Event } from '@theia/core';
import { ContextKeyService, ContextKey } from '@theia/core/lib/browser/context-key-service';
import { PREFERENCE_NAME_ENABLE_AI } from './ai-core-preferences';

Expand Down Expand Up @@ -44,7 +44,8 @@ export class AIActivationService implements FrontendApplicationContribution {
return this.isAiEnabledKey.get() ?? false;
}

initialize(): MaybePromise<void> {
async initialize(): Promise<void> {
await this.preferenceService.ready;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sdirix Is this alright from a performance perspective, or should we rather use preferenceService.ready.then(() => ...)?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, we should never await something which does not need to be awaited in the initialize startup calls. Therefore I would prefer the ready.then variant. I also don't see a harm for this case. Good catch!

const value = this.preferenceService.get<boolean>(ENABLE_AI_CONTEXT_KEY);
this.isAiEnabledKey = this.contextKeyService.createKey(ENABLE_AI_CONTEXT_KEY, value);
this.preferenceService.onPreferenceChanged(e => {
Expand Down
Loading