Skip to content

Commit

Permalink
Mark most DisposableStore properties readonly
Browse files Browse the repository at this point in the history
This prevents a common cause of leaks: reassigning the property without first disposing of the old value
  • Loading branch information
mjbvz committed Sep 19, 2023
1 parent fa45b00 commit 6586408
Show file tree
Hide file tree
Showing 26 changed files with 39 additions and 43 deletions.
2 changes: 1 addition & 1 deletion src/vs/base/browser/ui/grid/gridview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -778,7 +778,7 @@ class LeafNode implements ISplitView<ILayoutContext>, IDisposable {
private _onDidViewChange: Event<number | undefined>;
readonly onDidChange: Event<number | undefined>;

private disposables = new DisposableStore();
private readonly disposables = new DisposableStore();

constructor(
readonly view: IView,
Expand Down
4 changes: 2 additions & 2 deletions src/vs/base/browser/ui/sash/sash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ interface IPointerEventFactory {

class MouseEventFactory implements IPointerEventFactory {

private disposables = new DisposableStore();
private readonly disposables = new DisposableStore();

@memoize
get onPointerMove(): Event<PointerEvent> {
Expand All @@ -192,7 +192,7 @@ class MouseEventFactory implements IPointerEventFactory {

class GestureEventFactory implements IPointerEventFactory {

private disposables = new DisposableStore();
private readonly disposables = new DisposableStore();

@memoize
get onPointerMove(): Event<PointerEvent> {
Expand Down
5 changes: 2 additions & 3 deletions src/vs/base/browser/ui/tree/abstractTree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1027,7 +1027,7 @@ class FindController<T, TFilterData> implements IDisposable {
private readonly _onDidChangeOpenState = new Emitter<boolean>();
readonly onDidChangeOpenState = this._onDidChangeOpenState.event;

private enabledDisposables = new DisposableStore();
private readonly enabledDisposables = new DisposableStore();
private readonly disposables = new DisposableStore();

constructor(
Expand Down Expand Up @@ -1085,8 +1085,7 @@ class FindController<T, TFilterData> implements IDisposable {
this._history = this.widget.getHistory();
this.widget = undefined;

this.enabledDisposables.dispose();
this.enabledDisposables = new DisposableStore();
this.enabledDisposables.clear();

this.previousPattern = this.pattern;
this.onDidChangeValue('');
Expand Down
2 changes: 1 addition & 1 deletion src/vs/base/parts/ipc/common/ipc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -798,7 +798,7 @@ export class IPCServer<TContext = string> implements IChannelServer<TContext>, I
private readonly _onDidRemoveConnection = new Emitter<Connection<TContext>>();
readonly onDidRemoveConnection: Event<Connection<TContext>> = this._onDidRemoveConnection.event;

private disposables = new DisposableStore();
private readonly disposables = new DisposableStore();

get connections(): Connection<TContext>[] {
const result: Connection<TContext>[] = [];
Expand Down
2 changes: 1 addition & 1 deletion src/vs/base/parts/ipc/test/common/ipc.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ interface ITestService {

class TestService implements ITestService {

private disposables = new DisposableStore();
private readonly disposables = new DisposableStore();

private readonly _onPong = new Emitter<string>();
readonly onPong = this._onPong.event;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export class CodeLensContribution implements IEditorContribution {
private readonly _resolveCodeLensesScheduler: RunOnceScheduler;

private _getCodeLensModelPromise: CancelablePromise<CodeLensModel> | undefined;
private _oldCodeLensModels = new DisposableStore();
private readonly _oldCodeLensModels = new DisposableStore();
private _currentCodeLensModel: CodeLensModel | undefined;
private _resolveCodeLensesPromise: CancelablePromise<any> | undefined;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export class SnippetController2 implements IEditorContribution {
private readonly _hasPrevTabstop: IContextKey<boolean>;

private _session?: SnippetSession;
private _snippetListener = new DisposableStore();
private readonly _snippetListener = new DisposableStore();
private _modelVersionId: number = -1;
private _currentChoice?: Choice;

Expand Down
2 changes: 1 addition & 1 deletion src/vs/platform/list/browser/listService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export class ListService implements IListService {

declare readonly _serviceBrand: undefined;

private disposables = new DisposableStore();
private readonly disposables = new DisposableStore();
private lists: IRegisteredList[] = [];
private _lastFocusedWidget: WorkbenchListWidget | undefined = undefined;
private _hasCreatedStyleController: boolean = false;
Expand Down
2 changes: 1 addition & 1 deletion src/vs/workbench/api/common/extHostCodeInsets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { ExtHostEditorInsetsShape, MainThreadEditorInsetsShape } from './extHost
export class ExtHostEditorInsets implements ExtHostEditorInsetsShape {

private _handlePool = 0;
private _disposables = new DisposableStore();
private readonly _disposables = new DisposableStore();
private _insets = new Map<number, { editor: vscode.TextEditor; inset: vscode.WebviewEditorInset; onDidReceiveMessage: Emitter<any> }>();

constructor(
Expand Down
2 changes: 1 addition & 1 deletion src/vs/workbench/api/node/extHostSearch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export class NativeExtHostSearch extends ExtHostSearch implements IDisposable {

private _registeredEHSearchProvider = false;

private _disposables = new DisposableStore();
private readonly _disposables = new DisposableStore();

constructor(
@IExtHostRpcService extHostRpc: IExtHostRpcService,
Expand Down
2 changes: 1 addition & 1 deletion src/vs/workbench/browser/parts/views/viewPane.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ class ViewWelcomeController {
return visibleItems.map(v => v.descriptor);
}

private disposables = new DisposableStore();
private readonly disposables = new DisposableStore();

constructor(
private id: string,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ class DocumentSymbolsOutline implements IOutline<DocumentSymbolItem> {
readonly onDidChange: Event<OutlineChangeEvent> = this._onDidChange.event;

private _outlineModel?: OutlineModel;
private _outlineDisposables = new DisposableStore();
private readonly _outlineDisposables = new DisposableStore();

private readonly _breadcrumbsDataSource: DocumentSymbolBreadcrumbsSource;

Expand Down
2 changes: 1 addition & 1 deletion src/vs/workbench/contrib/debug/browser/debugService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export class DebugService implements IDebugService {
private taskRunner: DebugTaskRunner;
private configurationManager: ConfigurationManager;
private adapterManager: AdapterManager;
private disposables = new DisposableStore();
private readonly disposables = new DisposableStore();
private debugType!: IContextKey<string>;
private debugState!: IContextKey<string>;
private inDebugMode!: IContextKey<boolean>;
Expand Down
2 changes: 1 addition & 1 deletion src/vs/workbench/contrib/debug/browser/debugSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export class DebugSession implements IDebugSession, IDisposable {
private threads = new Map<number, Thread>();
private threadIds: number[] = [];
private cancellationMap = new Map<number, CancellationTokenSource[]>();
private rawListeners = new DisposableStore();
private readonly rawListeners = new DisposableStore();
private fetchThreadsScheduler: RunOnceScheduler | undefined;
private passFocusScheduler: RunOnceScheduler;
private lastContinuedThreadId: number | undefined;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export class InlayHintsAccessibility implements IEditorContribution {
private readonly _ariaElement: HTMLSpanElement;
private readonly _ctxIsReading: IContextKey<boolean>;

private _sessionDispoosables = new DisposableStore();
private readonly _sessionDispoosables = new DisposableStore();

constructor(
private readonly _editor: ICodeEditor,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class LanguageDetectionStatusContribution implements IWorkbenchContribution {
private readonly _disposables = new DisposableStore();
private _combinedEntry?: IStatusbarEntryAccessor;
private _delayer = new ThrottledDelayer(1000);
private _renderDisposables = new DisposableStore();
private readonly _renderDisposables = new DisposableStore();

constructor(
@ILanguageDetectionService private readonly _languageDetectionService: ILanguageDetectionService,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class EditorStatusContribution implements IWorkbenchContribution {
private _model?: LanguageStatusViewModel;
private _combinedEntry?: IStatusbarEntryAccessor;
private _dedicatedEntries = new Map<string, IStatusbarEntryAccessor>();
private _renderDisposables = new DisposableStore();
private readonly _renderDisposables = new DisposableStore();

constructor(
@ILanguageStatusService private readonly _languageStatusService: ILanguageStatusService,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ export class NotebookCellOutline implements IOutline<OutlineEntry> {
}

private _outlineProvider: NotebookCellOutlineProvider | undefined;
private _localDisposables = new DisposableStore();
private readonly _localDisposables = new DisposableStore();

constructor(
private readonly _editor: INotebookEditorPane,
Expand Down
8 changes: 4 additions & 4 deletions src/vs/workbench/contrib/scm/browser/activity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export class SCMStatusController implements IWorkbenchContribution {
private focusDisposable: IDisposable = Disposable.None;
private focusedRepository: ISCMRepository | undefined = undefined;
private readonly badgeDisposable = new MutableDisposable<IDisposable>();
private disposables = new DisposableStore();
private readonly disposables = new DisposableStore();
private repositoryDisposables = new Set<IDisposable>();

constructor(
Expand Down Expand Up @@ -207,7 +207,7 @@ export class SCMStatusController implements IWorkbenchContribution {
this.focusDisposable.dispose();
this.statusBarDisposable.dispose();
this.badgeDisposable.dispose();
this.disposables = dispose(this.disposables);
this.disposables.dispose();
dispose(this.repositoryDisposables.values());
this.repositoryDisposables.clear();
}
Expand All @@ -217,7 +217,7 @@ export class SCMActiveResourceContextKeyController implements IWorkbenchContribu

private activeResourceHasChangesContextKey: IContextKey<boolean>;
private activeResourceRepositoryContextKey: IContextKey<string | undefined>;
private disposables = new DisposableStore();
private readonly disposables = new DisposableStore();
private repositoryDisposables = new Set<IDisposable>();

constructor(
Expand Down Expand Up @@ -281,7 +281,7 @@ export class SCMActiveResourceContextKeyController implements IWorkbenchContribu
}

dispose(): void {
this.disposables = dispose(this.disposables);
this.disposables.dispose();
dispose(this.repositoryDisposables.values());
this.repositoryDisposables.clear();
}
Expand Down
5 changes: 2 additions & 3 deletions src/vs/workbench/contrib/scm/browser/dirtydiffDecorator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -714,7 +714,7 @@ export class DirtyDiffController extends Disposable implements DirtyDiffContribu
private session: IDisposable = Disposable.None;
private mouseDownInfo: { lineNumber: number } | null = null;
private enabled = false;
private gutterActionDisposables = new DisposableStore();
private readonly gutterActionDisposables = new DisposableStore();
private stylesheet: HTMLStyleElement;

constructor(
Expand All @@ -741,8 +741,7 @@ export class DirtyDiffController extends Disposable implements DirtyDiffContribu
private onDidChangeGutterAction(): void {
const gutterAction = this.configurationService.getValue<'diff' | 'none'>('scm.diffDecorationsGutterAction');

this.gutterActionDisposables.dispose();
this.gutterActionDisposables = new DisposableStore();
this.gutterActionDisposables.clear();

if (gutterAction === 'diff') {
this.gutterActionDisposables.add(this.editor.onMouseDown(e => this.onEditorMouseDown(e)));
Expand Down
2 changes: 1 addition & 1 deletion src/vs/workbench/contrib/scm/browser/menus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export class SCMTitleMenu implements IDisposable {
readonly onDidChangeTitle = this._onDidChangeTitle.event;

readonly menu: IMenu;
private disposables = new DisposableStore();
private readonly disposables = new DisposableStore();

constructor(
@IMenuService menuService: IMenuService,
Expand Down
2 changes: 1 addition & 1 deletion src/vs/workbench/contrib/scm/browser/scmSyncViewPane.ts
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ class SCMSyncPaneViewModel {
private repositories = new Map<ISCMRepository, IDisposable>();
private alwaysShowRepositories = false;

private disposables = new DisposableStore();
private readonly disposables = new DisposableStore();

constructor(
private readonly tree: WorkbenchAsyncDataTree<TreeElement, TreeElement>,
Expand Down
18 changes: 8 additions & 10 deletions src/vs/workbench/contrib/scm/browser/scmViewPane.ts
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ class ResourceRenderer implements ICompressibleTreeRenderer<ISCMResource | IReso
static readonly TEMPLATE_ID = 'resource';
get templateId(): string { return ResourceRenderer.TEMPLATE_ID; }

private disposables = new DisposableStore();
private readonly disposables = new DisposableStore();
private renderedResources = new Map<ResourceTemplate, RenderedResourceData>();

constructor(
Expand Down Expand Up @@ -1036,7 +1036,7 @@ class RepositoryVisibilityActionController {
private items = new Map<ISCMRepository, RepositoryVisibilityItem>();
private repositoryCountContextKey: IContextKey<number>;
private repositoryVisibilityCountContextKey: IContextKey<number>;
private disposables = new DisposableStore();
private readonly disposables = new DisposableStore();

constructor(
@ISCMViewService private scmViewService: ISCMViewService,
Expand Down Expand Up @@ -1178,12 +1178,12 @@ class ViewModel {
}

private items = new Map<ISCMRepository, IRepositoryItem>();
private visibilityDisposables = new DisposableStore();
private readonly visibilityDisposables = new DisposableStore();
private scrollTop: number | undefined;
private alwaysShowRepositories = false;
private showActionButton = false;
private firstVisible = true;
private disposables = new DisposableStore();
private readonly disposables = new DisposableStore();

private modeContextKey: IContextKey<ViewModelMode>;
private sortKeyContextKey: IContextKey<ViewModelSortKey>;
Expand Down Expand Up @@ -1352,7 +1352,6 @@ class ViewModel {

setVisible(visible: boolean): void {
if (visible) {
this.visibilityDisposables = new DisposableStore();
this.scmViewService.onDidChangeVisibleRepositories(this._onDidChangeVisibleRepositories, this, this.visibilityDisposables);
this._onDidChangeVisibleRepositories({ added: this.scmViewService.visibleRepositories, removed: Iterable.empty() });

Expand All @@ -1366,7 +1365,7 @@ class ViewModel {
} else {
this.updateViewState();

this.visibilityDisposables.dispose();
this.visibilityDisposables.clear();
this._onDidChangeVisibleRepositories({ added: Iterable.empty(), removed: [...this.items.keys()] });
this.scrollTop = this.tree.scrollTop;
}
Expand Down Expand Up @@ -1807,11 +1806,11 @@ class SCMInputWidget {
private editorContainer: HTMLElement;
private placeholderTextContainer: HTMLElement;
private inputEditor: CodeEditorWidget;
private disposables = new DisposableStore();
private readonly disposables = new DisposableStore();

private model: { readonly input: ISCMInput; textModelRef?: IReference<IResolvedTextEditorModel> } | undefined;
private repositoryIdContextKey: IContextKey<string | undefined>;
private repositoryDisposables = new DisposableStore();
private readonly repositoryDisposables = new DisposableStore();

private validation: IInputValidation | undefined;
private validationDisposable: IDisposable = Disposable.None;
Expand All @@ -1837,8 +1836,7 @@ class SCMInputWidget {
this.clearValidation();
this.editorContainer.classList.remove('synthetic-focus');

this.repositoryDisposables.dispose();
this.repositoryDisposables = new DisposableStore();
this.repositoryDisposables.clear();
this.repositoryIdContextKey.set(input?.repository.id);

if (!input) {
Expand Down
2 changes: 1 addition & 1 deletion src/vs/workbench/contrib/scm/browser/scmViewService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export class SCMViewService implements ISCMViewService {
private didFinishLoading: boolean = false;
private didSelectRepository: boolean = false;
private previousState: ISCMViewServiceState | undefined;
private disposables = new DisposableStore();
private readonly disposables = new DisposableStore();

private _repositories: ISCMRepositoryView[] = [];

Expand Down
2 changes: 1 addition & 1 deletion src/vs/workbench/contrib/scm/common/scmService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ class WillSaveHistoryEvent {

class SCMInputHistory {

private disposables = new DisposableStore();
private readonly disposables = new DisposableStore();
private readonly histories = new Map<string, ResourceMap<HistoryNavigator2<string>>>();

private readonly _onWillSaveHistory = this.disposables.add(new Emitter<WillSaveHistoryEvent>());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export class ReleaseNotesManager {

private _currentReleaseNotes: WebviewInput | undefined = undefined;
private _lastText: string | undefined;
private disposables = new DisposableStore();
private readonly disposables = new DisposableStore();

public constructor(
@IEnvironmentService private readonly _environmentService: IEnvironmentService,
Expand Down

0 comments on commit 6586408

Please sign in to comment.