Skip to content

Commit

Permalink
Add docs and register some child insta services for disposal
Browse files Browse the repository at this point in the history
  • Loading branch information
jrieken committed May 16, 2024
1 parent c72bcda commit d1fdc09
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ export class CodeEditorWidget extends Disposable implements editorBrowser.ICodeE
this._register(new EditorContextKeysManager(this, this._contextKeyService));
this._register(new EditorModeContext(this, this._contextKeyService, languageFeaturesService));

this._instantiationService = instantiationService.createChild(new ServiceCollection([IContextKeyService, this._contextKeyService]));
this._instantiationService = this._register(instantiationService.createChild(new ServiceCollection([IContextKeyService, this._contextKeyService])));

this._modelData = null;

Expand Down
4 changes: 2 additions & 2 deletions src/vs/editor/browser/widget/diffEditor/diffEditorWidget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ export class DiffEditorWidget extends DelegatingEditor implements IDiffEditor {
public get onDidContentSizeChange() { return this._editors.onDidContentSizeChange; }

private readonly _contextKeyService = this._register(this._parentContextKeyService.createScoped(this._domElement));
private readonly _instantiationService = this._parentInstantiationService.createChild(
private readonly _instantiationService = this._register(this._parentInstantiationService.createChild(
new ServiceCollection([IContextKeyService, this._contextKeyService])
);
));
private readonly _rootSizeObserver: ObservableElementSizeObserver;


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,9 @@ export class MultiDiffEditorWidgetImpl extends Disposable {
});

private readonly _contextKeyService = this._register(this._parentContextKeyService.createScoped(this._element));
private readonly _instantiationService = this._parentInstantiationService.createChild(
private readonly _instantiationService = this._register(this._parentInstantiationService.createChild(
new ServiceCollection([IContextKeyService, this._contextKeyService])
);
));

constructor(
private readonly _element: HTMLElement,
Expand Down
6 changes: 5 additions & 1 deletion src/vs/platform/instantiation/common/instantiation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { DisposableStore } from 'vs/base/common/lifecycle';
import * as descriptors from './descriptors';
import { ServiceCollection } from './serviceCollection';

Expand Down Expand Up @@ -61,8 +62,11 @@ export interface IInstantiationService {
/**
* Creates a child of this service which inherits all current services
* and adds/overwrites the given services.
*
* NOTE that the returned child is `disposable` and should be disposed when not used
* anymore. This will also dispose all the services that this service has created.
*/
createChild(services: ServiceCollection): IInstantiationService;
createChild(services: ServiceCollection, store?: DisposableStore): IInstantiationService;

/**
* Disposes this instantiation service.
Expand Down
6 changes: 4 additions & 2 deletions src/vs/platform/instantiation/common/instantiationService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import { GlobalIdleValue } from 'vs/base/common/async';
import { Event } from 'vs/base/common/event';
import { illegalState } from 'vs/base/common/errors';
import { dispose, IDisposable, isDisposable, toDisposable } from 'vs/base/common/lifecycle';
import { DisposableStore, dispose, IDisposable, isDisposable, toDisposable } from 'vs/base/common/lifecycle';
import { SyncDescriptor, SyncDescriptor0 } from 'vs/platform/instantiation/common/descriptors';
import { Graph } from 'vs/platform/instantiation/common/graph';
import { GetLeadingNonServiceArgs, IInstantiationService, ServiceIdentifier, ServicesAccessor, _util } from 'vs/platform/instantiation/common/instantiation';
Expand Down Expand Up @@ -70,7 +70,7 @@ export class InstantiationService implements IInstantiationService {
}
}

createChild(services: ServiceCollection): IInstantiationService {
createChild(services: ServiceCollection, store?: DisposableStore): IInstantiationService {
this._throwIfDisposed();

const result = new class extends InstantiationService {
Expand All @@ -80,6 +80,8 @@ export class InstantiationService implements IInstantiationService {
}
}(services, this._strict, this, this._enableTracing);
this._children.add(result);

store?.add(result);
return result;
}

Expand Down
1 change: 1 addition & 0 deletions src/vs/workbench/browser/parts/compositePart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ export abstract class CompositePart<T extends Composite> extends Part {

// Register to title area update events from the composite
disposable.add(composite.onTitleAreaUpdate(() => this.onTitleAreaUpdate(composite.getId()), this));
disposable.add(compositeInstantiationService);

return composite;
}
Expand Down
2 changes: 1 addition & 1 deletion src/vs/workbench/contrib/chat/browser/chatWidget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ export class ChatWidget extends Disposable implements IChatWidget {
}

private createList(listContainer: HTMLElement, options: IChatListItemRendererOptions): void {
const scopedInstantiationService = this.instantiationService.createChild(new ServiceCollection([IContextKeyService, this.contextKeyService]));
const scopedInstantiationService = this._register(this.instantiationService.createChild(new ServiceCollection([IContextKeyService, this.contextKeyService])));
const delegate = scopedInstantiationService.createInstance(ChatListDelegate, this.viewOptions.defaultElementHeight ?? 200);
const rendererDelegate: IChatRendererDelegate = {
getListLength: () => this.tree.getNode(null).visibleChildrenCount,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ export class InlineChatContentWidget implements IContentWidget {
new ServiceCollection([
IContextKeyService,
this._store.add(contextKeyService.createScoped(this._domNode))
])
]),
this._store
);

this._widget = scopedInstaService.createInstance(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,8 @@ export class InlineChatWidget {
new ServiceCollection([
IContextKeyService,
this.scopedContextKeyService
])
]),
this._store
);

this._chatWidget = scopedInstaService.createInstance(
Expand Down

0 comments on commit d1fdc09

Please sign in to comment.