Skip to content

Commit

Permalink
break dependency injection cycle between LabelProvider and its contri…
Browse files Browse the repository at this point in the history
…butions

See #5884 (comment)

Signed-off-by: Anton Kosyakov <anton.kosyakov@typefox.io>
  • Loading branch information
akosyakov committed Nov 23, 2019
1 parent b9969ba commit 145f913
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
1 change: 1 addition & 0 deletions packages/core/src/browser/frontend-application-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ export const frontendApplicationModule = new ContainerModule((bind, unbind, isBo

bindContributionProvider(bind, LabelProviderContribution);
bind(LabelProvider).toSelf().inSingletonScope();
bind(FrontendApplicationContribution).toService(LabelProvider);
bind(LabelProviderContribution).to(DefaultUriLabelProviderContribution).inSingletonScope();
bind(LabelProviderContribution).to(DiffUriLabelProviderContribution).inSingletonScope();

Expand Down
17 changes: 12 additions & 5 deletions packages/core/src/browser/label-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import URI from '../common/uri';
import { ContributionProvider } from '../common/contribution-provider';
import { Prioritizeable, MaybePromise } from '../common/types';
import { Event, Emitter } from '../common';
import { FrontendApplicationContribution } from './frontend-application';

export const FOLDER_ICON = 'fa fa-folder';
export const FILE_ICON = 'fa fa-file';
Expand Down Expand Up @@ -98,14 +99,20 @@ export class DefaultUriLabelProviderContribution implements LabelProviderContrib
}

@injectable()
export class LabelProvider {
export class LabelProvider implements FrontendApplicationContribution {

protected readonly onDidChangeEmitter = new Emitter<DidChangeLabelEvent>();

constructor(
@inject(ContributionProvider) @named(LabelProviderContribution)
protected readonly contributionProvider: ContributionProvider<LabelProviderContribution>
) {
@inject(ContributionProvider) @named(LabelProviderContribution)
protected readonly contributionProvider: ContributionProvider<LabelProviderContribution>;

/**
* Start listening to contributions.
*
* Don't call this method directly!
* It's called by the frontend application during initialization.
*/
initialize(): void {
const contributions = this.contributionProvider.getContributions();
for (const contribution of contributions) {
if (contribution.onDidChange) {
Expand Down

0 comments on commit 145f913

Please sign in to comment.