From 241bfb83d088de9b9f1b739c098a7e7048fd54bc Mon Sep 17 00:00:00 2001 From: Matt Bierner Date: Tue, 2 Aug 2022 15:18:24 -0700 Subject: [PATCH] Use optional chaining for more method calls This rewrites code such as: ```ts if (thing) { thing.method(); } ``` To the more concise: ```ts thing?.method(); ``` This was done using a simple find replace. I tried to keep the change pretty conservative so it only touches simple cases like above --- src/vs/base/browser/dom.ts | 4 +- src/vs/base/browser/indexedDB.ts | 4 +- src/vs/base/browser/mouseEvent.ts | 8 +--- .../browser/ui/actionbar/actionViewItems.ts | 8 +--- .../browser/ui/centered/centeredViewLayout.ts | 4 +- src/vs/base/browser/ui/dropdown/dropdown.ts | 4 +- .../ui/dropdown/dropdownActionViewItem.ts | 4 +- .../base/browser/ui/findinput/replaceInput.ts | 12 ++--- src/vs/base/browser/ui/inputbox/inputBox.ts | 4 +- src/vs/base/browser/ui/list/listPaging.ts | 4 +- src/vs/base/browser/ui/list/listWidget.ts | 4 +- src/vs/base/browser/ui/menu/menu.ts | 4 +- src/vs/base/browser/ui/menu/menubar.ts | 4 +- src/vs/base/common/cancellation.ts | 4 +- src/vs/base/node/zip.ts | 4 +- .../parts/ipc/electron-main/ipc.electron.ts | 4 +- src/vs/base/parts/ipc/node/ipc.cp.ts | 4 +- .../parts/quickinput/browser/quickInput.ts | 4 +- src/vs/base/test/browser/indexedDB.test.ts | 4 +- .../issue/issueReporterMain.ts | 8 +--- .../editor/browser/widget/diffEditorWidget.ts | 4 +- src/vs/editor/browser/widget/diffReview.ts | 8 +--- .../editor/common/viewModel/viewModelImpl.ts | 8 +--- .../editor/contrib/folding/browser/folding.ts | 12 ++--- .../browser/peek/referencesController.ts | 4 +- .../contrib/hover/browser/contentHover.ts | 4 +- .../inPlaceReplace/browser/inPlaceReplace.ts | 8 +--- .../browser/ghostTextController.ts | 4 +- .../suggestWidgetInlineCompletionProvider.ts | 8 +--- .../snippet/browser/snippetController2.ts | 8 +--- .../browser/wordHighlighter.ts | 8 +--- .../contrib/zoneWidget/browser/zoneWidget.ts | 8 +--- .../accessibilityHelp/accessibilityHelp.ts | 4 +- .../browser/inspectTokens/inspectTokens.ts | 4 +- .../contextview/browser/contextMenuHandler.ts | 8 +--- .../browser/contextScopedHistoryWidget.ts | 8 +--- .../issue/electron-main/issueMainService.ts | 8 +--- src/vs/platform/log/common/bufferLog.ts | 8 +--- .../electron-main/nativeHostMainService.ts | 12 ++--- .../remote/common/remoteAgentConnection.ts | 4 +- .../sharedProcessWorkerMain.ts | 4 +- .../terminal/common/terminalDataBuffering.ts | 4 +- src/vs/platform/tunnel/node/tunnelService.ts | 4 +- .../common/userDataAutoSyncService.ts | 4 +- .../common/userDataSyncService.ts | 4 +- .../platform/windows/electron-main/window.ts | 4 +- .../mainThreadDocumentContentProviders.ts | 4 +- .../api/browser/mainThreadOutputService.ts | 4 +- .../workbench/api/common/extHostComments.ts | 4 +- .../api/common/extHostLanguageFeatures.ts | 8 +--- .../workbench/api/common/extHostNotebook.ts | 4 +- .../workbench/api/common/extHostProgress.ts | 4 +- .../workbench/api/common/extHostQuickOpen.ts | 8 +--- src/vs/workbench/browser/layout.ts | 12 ++--- .../parts/activitybar/activitybarPart.ts | 12 ++--- .../parts/auxiliarybar/auxiliaryBarActions.ts | 4 +- .../workbench/browser/parts/compositeBar.ts | 8 +--- .../parts/editor/breadcrumbsControl.ts | 4 +- .../browser/parts/editor/editorActions.ts | 4 +- .../browser/parts/editor/editorCommands.ts | 4 +- .../notifications/notificationsCommands.ts | 12 ++--- .../notifications/notificationsStatus.ts | 4 +- .../browser/parts/panel/panelActions.ts | 4 +- .../browser/parts/panel/panelPart.ts | 4 +- .../browser/parts/sidebar/sidebarActions.ts | 4 +- .../browser/parts/titlebar/menubarControl.ts | 12 ++--- .../common/editor/diffEditorInput.ts | 4 +- src/vs/workbench/common/notifications.ts | 4 +- .../browser/preview/bulkEdit.contribution.ts | 24 +++------- .../browser/accessibility/accessibility.ts | 4 +- .../inspectEditorTokens.ts | 4 +- .../contrib/comments/browser/commentNode.ts | 16 ++----- .../contrib/comments/browser/commentReply.ts | 4 +- .../browser/commentsEditorContribution.ts | 12 ++--- .../browser/breakpointEditorContribution.ts | 12 ++--- .../contrib/debug/browser/breakpointsView.ts | 4 +- .../contrib/debug/browser/debugService.ts | 4 +- .../contrib/debug/browser/debugStatus.ts | 4 +- .../contrib/debug/browser/debugToolBar.ts | 4 +- .../contrib/debug/browser/rawDebugSession.ts | 4 +- .../workbench/contrib/debug/browser/repl.ts | 12 ++--- .../contrib/debug/browser/replFilter.ts | 8 +--- .../debug/common/debugContentProvider.ts | 4 +- .../experimentService.test.ts | 4 +- .../extensions/browser/extensionEditor.ts | 4 +- .../extensions/browser/extensionsViewlet.ts | 4 +- .../extensions/browser/extensionsWidgets.ts | 4 +- .../extensionRecommendationsService.test.ts | 4 +- .../editors/textFileSaveErrorHandler.ts | 4 +- .../contrib/files/browser/explorerService.ts | 4 +- .../files/browser/views/explorerView.ts | 4 +- .../browser/inlayHintsAccessibilty.ts | 8 +--- .../interactive/browser/interactiveEditor.ts | 12 ++--- .../contrib/markers/browser/markersView.ts | 4 +- .../markers/browser/markersViewActions.ts | 8 +--- .../browser/diff/notebookTextDiffEditor.ts | 8 +--- .../notebook/browser/notebookEditor.ts | 4 +- .../notebook/browser/notebookEditorWidget.ts | 4 +- .../browser/viewModel/baseCellViewModel.ts | 4 +- .../contrib/output/browser/outputView.ts | 4 +- .../output/common/outputChannelModel.ts | 4 +- .../browser/preferences.contribution.ts | 8 +--- .../preferences/browser/settingsEditor2.ts | 4 +- .../preferences/browser/settingsTree.ts | 4 +- .../preferences/browser/settingsWidgets.ts | 4 +- .../browser/relauncher.contribution.ts | 4 +- .../contrib/remote/browser/remote.ts | 8 +--- .../contrib/remote/browser/remoteExplorer.ts | 20 +++------ .../search/browser/patternInputWidget.ts | 4 +- .../contrib/search/browser/replaceService.ts | 4 +- .../search/browser/search.contribution.ts | 8 +--- .../contrib/search/browser/searchActions.ts | 44 +++++-------------- .../tasks/browser/abstractTaskService.ts | 8 +--- .../terminal/browser/terminalEditor.ts | 4 +- .../terminal/browser/terminalFindWidget.ts | 4 +- .../contrib/terminal/browser/terminalView.ts | 4 +- .../welcomeOverlay/browser/welcomeOverlay.ts | 4 +- .../common/viewsWelcomeContribution.ts | 4 +- .../test/browser/decorationsService.test.ts | 4 +- .../common/abstractExtensionService.ts | 4 +- .../electronExtensionService.ts | 4 +- .../progress/browser/progressService.ts | 4 +- .../search/common/fileSearchManager.ts | 4 +- .../services/search/node/fileSearch.ts | 4 +- .../search/node/ripgrepTextSearchEngine.ts | 8 +--- .../common/textFileEditorModelManager.ts | 4 +- .../workspaces/common/workspaceTrust.ts | 8 +--- 127 files changed, 198 insertions(+), 594 deletions(-) diff --git a/src/vs/base/browser/dom.ts b/src/vs/base/browser/dom.ts index 06d13c90d9369..d378b5f654270 100644 --- a/src/vs/base/browser/dom.ts +++ b/src/vs/base/browser/dom.ts @@ -1149,9 +1149,7 @@ export function removeTabIndexAndUpdateFocus(node: HTMLElement): void { // in the hierarchy of the parent DOM nodes. if (document.activeElement === node) { const parentFocusable = findParentWithAttribute(node.parentElement, 'tabIndex'); - if (parentFocusable) { - parentFocusable.focus(); - } + parentFocusable?.focus(); } node.removeAttribute('tabindex'); diff --git a/src/vs/base/browser/indexedDB.ts b/src/vs/base/browser/indexedDB.ts index 256519321240a..29100e142fe2f 100644 --- a/src/vs/base/browser/indexedDB.ts +++ b/src/vs/base/browser/indexedDB.ts @@ -106,9 +106,7 @@ export class IndexedDB { if (this.pendingTransactions.length) { this.pendingTransactions.splice(0, this.pendingTransactions.length).forEach(transaction => transaction.abort()); } - if (this.database) { - this.database.close(); - } + this.database?.close(); this.database = null; } diff --git a/src/vs/base/browser/mouseEvent.ts b/src/vs/base/browser/mouseEvent.ts index a4f106a6c19d7..7a0ebca76cf37 100644 --- a/src/vs/base/browser/mouseEvent.ts +++ b/src/vs/base/browser/mouseEvent.ts @@ -211,14 +211,10 @@ export class StandardWheelEvent { } public preventDefault(): void { - if (this.browserEvent) { - this.browserEvent.preventDefault(); - } + this.browserEvent?.preventDefault(); } public stopPropagation(): void { - if (this.browserEvent) { - this.browserEvent.stopPropagation(); - } + this.browserEvent?.stopPropagation(); } } diff --git a/src/vs/base/browser/ui/actionbar/actionViewItems.ts b/src/vs/base/browser/ui/actionbar/actionViewItems.ts index 7d0833e27bee5..6883fb117647f 100644 --- a/src/vs/base/browser/ui/actionbar/actionViewItems.ts +++ b/src/vs/base/browser/ui/actionbar/actionViewItems.ts @@ -439,15 +439,11 @@ export class SelectActionViewItem extends BaseActionViewItem { } override focus(): void { - if (this.selectBox) { - this.selectBox.focus(); - } + this.selectBox?.focus(); } override blur(): void { - if (this.selectBox) { - this.selectBox.blur(); - } + this.selectBox?.blur(); } override render(container: HTMLElement): void { diff --git a/src/vs/base/browser/ui/centered/centeredViewLayout.ts b/src/vs/base/browser/ui/centered/centeredViewLayout.ts index b16ac4334ca67..b746382e57a35 100644 --- a/src/vs/base/browser/ui/centered/centeredViewLayout.ts +++ b/src/vs/base/browser/ui/centered/centeredViewLayout.ts @@ -159,9 +159,7 @@ export class CenteredViewLayout implements IDisposable { this.container.removeChild(this.splitView.el); } this.splitViewDisposables.clear(); - if (this.splitView) { - this.splitView.dispose(); - } + this.splitView?.dispose(); this.splitView = undefined; this.emptyViews = undefined; this.container.appendChild(this.view.element); diff --git a/src/vs/base/browser/ui/dropdown/dropdown.ts b/src/vs/base/browser/ui/dropdown/dropdown.ts index d389e0f0e7891..b0f07682dd609 100644 --- a/src/vs/base/browser/ui/dropdown/dropdown.ts +++ b/src/vs/base/browser/ui/dropdown/dropdown.ts @@ -192,9 +192,7 @@ export class Dropdown extends BaseDropdown { override hide(): void { super.hide(); - if (this.contextViewProvider) { - this.contextViewProvider.hideContextView(); - } + this.contextViewProvider?.hideContextView(); } protected renderContents(container: HTMLElement): IDisposable | null { diff --git a/src/vs/base/browser/ui/dropdown/dropdownActionViewItem.ts b/src/vs/base/browser/ui/dropdown/dropdownActionViewItem.ts index 00b21774ea098..00da36a947b13 100644 --- a/src/vs/base/browser/ui/dropdown/dropdownActionViewItem.ts +++ b/src/vs/base/browser/ui/dropdown/dropdownActionViewItem.ts @@ -155,9 +155,7 @@ export class DropdownMenuActionViewItem extends BaseActionViewItem { } show(): void { - if (this.dropdownMenu) { - this.dropdownMenu.show(); - } + this.dropdownMenu?.show(); } protected override updateEnabled(): void { diff --git a/src/vs/base/browser/ui/findinput/replaceInput.ts b/src/vs/base/browser/ui/findinput/replaceInput.ts index a80c5a1faaf91..2861edde0b888 100644 --- a/src/vs/base/browser/ui/findinput/replaceInput.ts +++ b/src/vs/base/browser/ui/findinput/replaceInput.ts @@ -353,9 +353,7 @@ export class ReplaceInput extends Widget { } public validate(): void { - if (this.inputBox) { - this.inputBox.validate(); - } + this.inputBox?.validate(); } public showMessage(message: InputBoxMessage): void { @@ -363,15 +361,11 @@ export class ReplaceInput extends Widget { } public clearMessage(): void { - if (this.inputBox) { - this.inputBox.hideMessage(); - } + this.inputBox?.hideMessage(); } private clearValidation(): void { - if (this.inputBox) { - this.inputBox.hideMessage(); - } + this.inputBox?.hideMessage(); } public set width(newWidth: number) { diff --git a/src/vs/base/browser/ui/inputbox/inputBox.ts b/src/vs/base/browser/ui/inputbox/inputBox.ts index a3087e1c9c1c2..ae89cb33f38de 100644 --- a/src/vs/base/browser/ui/inputbox/inputBox.ts +++ b/src/vs/base/browser/ui/inputbox/inputBox.ts @@ -621,9 +621,7 @@ export class InputBox extends Widget { this.message = null; - if (this.actionbar) { - this.actionbar.dispose(); - } + this.actionbar?.dispose(); super.dispose(); } diff --git a/src/vs/base/browser/ui/list/listPaging.ts b/src/vs/base/browser/ui/list/listPaging.ts index ba2b55040f524..a5f3a920e3825 100644 --- a/src/vs/base/browser/ui/list/listPaging.ts +++ b/src/vs/base/browser/ui/list/listPaging.ts @@ -38,9 +38,7 @@ class PagedRenderer implements IListRenderer, height: number | undefined): void { - if (data.disposable) { - data.disposable.dispose(); - } + data.disposable?.dispose(); if (!data.data) { return; diff --git a/src/vs/base/browser/ui/list/listWidget.ts b/src/vs/base/browser/ui/list/listWidget.ts index f89a2f5d23719..0cea984085d4e 100644 --- a/src/vs/base/browser/ui/list/listWidget.ts +++ b/src/vs/base/browser/ui/list/listWidget.ts @@ -1528,9 +1528,7 @@ export class List implements ISpliceable, IThemable, IDisposable { } triggerTypeNavigation(): void { - if (this.typeNavigationController) { - this.typeNavigationController.trigger(); - } + this.typeNavigationController?.trigger(); } setSelection(indexes: number[], browserEvent?: UIEvent): void { diff --git a/src/vs/base/browser/ui/menu/menu.ts b/src/vs/base/browser/ui/menu/menu.ts index 7a22cb3503899..5e4410b5005f2 100644 --- a/src/vs/base/browser/ui/menu/menu.ts +++ b/src/vs/base/browser/ui/menu/menu.ts @@ -552,9 +552,7 @@ class BaseMenuActionViewItem extends BaseActionViewItem { override focus(): void { super.focus(); - if (this.item) { - this.item.focus(); - } + this.item?.focus(); this.applyStyle(); } diff --git a/src/vs/base/browser/ui/menu/menubar.ts b/src/vs/base/browser/ui/menu/menubar.ts index 572b33983ccba..fa843ff260ab4 100644 --- a/src/vs/base/browser/ui/menu/menubar.ts +++ b/src/vs/base/browser/ui/menu/menubar.ts @@ -985,9 +985,7 @@ export class MenuBar extends Disposable { this.focusedMenu.holder.remove(); } - if (this.focusedMenu.widget) { - this.focusedMenu.widget.dispose(); - } + this.focusedMenu.widget?.dispose(); this.focusedMenu = { index: this.focusedMenu.index }; } diff --git a/src/vs/base/common/cancellation.ts b/src/vs/base/common/cancellation.ts index 9cc02257cab22..78e01b75ec14c 100644 --- a/src/vs/base/common/cancellation.ts +++ b/src/vs/base/common/cancellation.ts @@ -129,9 +129,7 @@ export class CancellationTokenSource { if (cancel) { this.cancel(); } - if (this._parentListener) { - this._parentListener.dispose(); - } + this._parentListener?.dispose(); if (!this._token) { // ensure to initialize with an empty token if we had none this._token = CancellationToken.None; diff --git a/src/vs/base/node/zip.ts b/src/vs/base/node/zip.ts index c815e61861aee..2033f7cd98e4f 100644 --- a/src/vs/base/node/zip.ts +++ b/src/vs/base/node/zip.ts @@ -81,9 +81,7 @@ function extractEntry(stream: Readable, fileName: string, mode: number, targetPa let istream: WriteStream; token.onCancellationRequested(() => { - if (istream) { - istream.destroy(); - } + istream?.destroy(); }); return Promise.resolve(Promises.mkdir(targetDirName, { recursive: true })).then(() => new Promise((c, e) => { diff --git a/src/vs/base/parts/ipc/electron-main/ipc.electron.ts b/src/vs/base/parts/ipc/electron-main/ipc.electron.ts index f0d395c4bfabc..b40d381cffb43 100644 --- a/src/vs/base/parts/ipc/electron-main/ipc.electron.ts +++ b/src/vs/base/parts/ipc/electron-main/ipc.electron.ts @@ -37,9 +37,7 @@ export class Server extends IPCServer { const id = webContents.id; const client = Server.Clients.get(id); - if (client) { - client.dispose(); - } + client?.dispose(); const onDidClientReconnect = new Emitter(); Server.Clients.set(id, toDisposable(() => onDidClientReconnect.fire())); diff --git a/src/vs/base/parts/ipc/node/ipc.cp.ts b/src/vs/base/parts/ipc/node/ipc.cp.ts index fa6d8073ab7d7..9059597634953 100644 --- a/src/vs/base/parts/ipc/node/ipc.cp.ts +++ b/src/vs/base/parts/ipc/node/ipc.cp.ts @@ -241,9 +241,7 @@ export class Client implements IChannelClient, IDisposable { console.warn('IPC "' + this.options.serverName + '" crashed with exit code ' + code + ' and signal ' + signal); } - if (this.disposeDelayer) { - this.disposeDelayer.cancel(); - } + this.disposeDelayer?.cancel(); this.disposeClient(); this._onDidProcessExit.fire({ code, signal }); }); diff --git a/src/vs/base/parts/quickinput/browser/quickInput.ts b/src/vs/base/parts/quickinput/browser/quickInput.ts index 58a09cc29e50d..2b906e565f40b 100644 --- a/src/vs/base/parts/quickinput/browser/quickInput.ts +++ b/src/vs/base/parts/quickinput/browser/quickInput.ts @@ -1610,9 +1610,7 @@ export class QuickInputController extends Disposable { this.onShowEmitter.fire(); const oldController = this.controller; this.controller = controller; - if (oldController) { - oldController.didHide(); - } + oldController?.didHide(); this.setEnabled(true); ui.leftActionBar.clear(); diff --git a/src/vs/base/test/browser/indexedDB.test.ts b/src/vs/base/test/browser/indexedDB.test.ts index 581b67191484f..ba9dcd0f51c51 100644 --- a/src/vs/base/test/browser/indexedDB.test.ts +++ b/src/vs/base/test/browser/indexedDB.test.ts @@ -16,9 +16,7 @@ flakySuite('IndexedDB', () => { }); teardown(() => { - if (indexedDB) { - indexedDB.close(); - } + indexedDB?.close(); }); test('runInTransaction', async () => { diff --git a/src/vs/code/electron-sandbox/issue/issueReporterMain.ts b/src/vs/code/electron-sandbox/issue/issueReporterMain.ts index 6a0e7994b0441..dc4a1692710b2 100644 --- a/src/vs/code/electron-sandbox/issue/issueReporterMain.ts +++ b/src/vs/code/electron-sandbox/issue/issueReporterMain.ts @@ -151,14 +151,10 @@ export class IssueReporter extends Disposable { const { fileOnExtension } = this.issueReporterModel.getData(); if (fileOnExtension) { const issueTitle = document.getElementById('issue-title'); - if (issueTitle) { - issueTitle.focus(); - } + issueTitle?.focus(); } else { const issueType = document.getElementById('issue-type'); - if (issueType) { - issueType.focus(); - } + issueType?.focus(); } } diff --git a/src/vs/editor/browser/widget/diffEditorWidget.ts b/src/vs/editor/browser/widget/diffEditorWidget.ts index ef1aa278e53c2..6dc7769a008e2 100644 --- a/src/vs/editor/browser/widget/diffEditorWidget.ts +++ b/src/vs/editor/browser/widget/diffEditorWidget.ts @@ -1324,9 +1324,7 @@ export class DiffEditorWidget extends Disposable implements editorBrowser.IDiffE } private _setStrategy(newStrategy: DiffEditorWidgetStyle): void { - if (this._strategy) { - this._strategy.dispose(); - } + this._strategy?.dispose(); this._strategy = newStrategy; newStrategy.applyColors(this._themeService.getColorTheme()); diff --git a/src/vs/editor/browser/widget/diffReview.ts b/src/vs/editor/browser/widget/diffReview.ts index 38ae5e81a3298..449e9c46436d4 100644 --- a/src/vs/editor/browser/widget/diffReview.ts +++ b/src/vs/editor/browser/widget/diffReview.ts @@ -846,9 +846,7 @@ class DiffReviewNext extends EditorAction { public run(accessor: ServicesAccessor, editor: ICodeEditor): void { const diffEditor = findFocusedDiffEditor(accessor); - if (diffEditor) { - diffEditor.diffReviewNext(); - } + diffEditor?.diffReviewNext(); } } @@ -869,9 +867,7 @@ class DiffReviewPrev extends EditorAction { public run(accessor: ServicesAccessor, editor: ICodeEditor): void { const diffEditor = findFocusedDiffEditor(accessor); - if (diffEditor) { - diffEditor.diffReviewPrev(); - } + diffEditor?.diffReviewPrev(); } } diff --git a/src/vs/editor/common/viewModel/viewModelImpl.ts b/src/vs/editor/common/viewModel/viewModelImpl.ts index a241643468ea7..819e9d02e0c81 100644 --- a/src/vs/editor/common/viewModel/viewModelImpl.ts +++ b/src/vs/editor/common/viewModel/viewModelImpl.ts @@ -761,13 +761,9 @@ export class ViewModel extends Disposable implements IViewModel { const decorations = this.model.getOverviewRulerDecorations(); for (const decoration of decorations) { const opts1 = decoration.options.overviewRuler; - if (opts1) { - opts1.invalidateCachedColor(); - } + opts1?.invalidateCachedColor(); const opts2 = decoration.options.minimap; - if (opts2) { - opts2.invalidateCachedColor(); - } + opts2?.invalidateCachedColor(); } } diff --git a/src/vs/editor/contrib/folding/browser/folding.ts b/src/vs/editor/contrib/folding/browser/folding.ts index c35cdb69a6598..b556d7d5d013e 100644 --- a/src/vs/editor/contrib/folding/browser/folding.ts +++ b/src/vs/editor/contrib/folding/browser/folding.ts @@ -245,17 +245,13 @@ export class FoldingController extends Disposable implements IEditorContribution this.foldingRegionPromise.cancel(); this.foldingRegionPromise = null; } - if (this.updateScheduler) { - this.updateScheduler.cancel(); - } + this.updateScheduler?.cancel(); this.updateScheduler = null; this.foldingModel = null; this.foldingModelPromise = null; this.hiddenRangeModel = null; this.cursorChangedScheduler = null; - if (this.rangeProvider) { - this.rangeProvider.dispose(); - } + this.rangeProvider?.dispose(); this.rangeProvider = null; } }); @@ -263,9 +259,7 @@ export class FoldingController extends Disposable implements IEditorContribution } private onFoldingStrategyChanged() { - if (this.rangeProvider) { - this.rangeProvider.dispose(); - } + this.rangeProvider?.dispose(); this.rangeProvider = null; this.triggerFoldingModelChanged(); } diff --git a/src/vs/editor/contrib/gotoSymbol/browser/peek/referencesController.ts b/src/vs/editor/contrib/gotoSymbol/browser/peek/referencesController.ts index d675e5b885272..b35ba50247dde 100644 --- a/src/vs/editor/contrib/gotoSymbol/browser/peek/referencesController.ts +++ b/src/vs/editor/contrib/gotoSymbol/browser/peek/referencesController.ts @@ -238,9 +238,7 @@ export abstract class ReferencesController implements IEditorContribution { } private _gotoReference(ref: Location): Promise { - if (this._widget) { - this._widget.hide(); - } + this._widget?.hide(); this._ignoreModelChangeEvent = true; const range = Range.lift(ref.range).collapseToStart(); diff --git a/src/vs/editor/contrib/hover/browser/contentHover.ts b/src/vs/editor/contrib/hover/browser/contentHover.ts index 93941e6172c01..666337b5614d2 100644 --- a/src/vs/editor/contrib/hover/browser/contentHover.ts +++ b/src/vs/editor/contrib/hover/browser/contentHover.ts @@ -428,9 +428,7 @@ export class ContentHoverWidget extends Disposable implements IContentWidget { if (visibleData.stoleFocus) { this._hover.containerDomNode.focus(); } - if (visibleData.colorPicker) { - visibleData.colorPicker.layout(); - } + visibleData.colorPicker?.layout(); } public hide(): void { diff --git a/src/vs/editor/contrib/inPlaceReplace/browser/inPlaceReplace.ts b/src/vs/editor/contrib/inPlaceReplace/browser/inPlaceReplace.ts index a2c7a5acbe7e5..19e0e39412088 100644 --- a/src/vs/editor/contrib/inPlaceReplace/browser/inPlaceReplace.ts +++ b/src/vs/editor/contrib/inPlaceReplace/browser/inPlaceReplace.ts @@ -56,9 +56,7 @@ class InPlaceReplaceController implements IEditorContribution { public run(source: string, up: boolean): Promise | undefined { // cancel any pending request - if (this.currentRequest) { - this.currentRequest.cancel(); - } + this.currentRequest?.cancel(); const editorSelection = this.editor.getSelection(); const model = this.editor.getModel(); @@ -121,9 +119,7 @@ class InPlaceReplaceController implements IEditorContribution { }]); // remove decoration after delay - if (this.decorationRemover) { - this.decorationRemover.cancel(); - } + this.decorationRemover?.cancel(); this.decorationRemover = timeout(350); this.decorationRemover.then(() => this.decorations.clear()).catch(onUnexpectedError); diff --git a/src/vs/editor/contrib/inlineCompletions/browser/ghostTextController.ts b/src/vs/editor/contrib/inlineCompletions/browser/ghostTextController.ts index b9896b5a061ef..92dd4007425d1 100644 --- a/src/vs/editor/contrib/inlineCompletions/browser/ghostTextController.ts +++ b/src/vs/editor/contrib/inlineCompletions/browser/ghostTextController.ts @@ -247,8 +247,6 @@ export class TriggerInlineSuggestionAction extends EditorAction { public async run(accessor: ServicesAccessor | undefined, editor: ICodeEditor): Promise { const controller = GhostTextController.get(editor); - if (controller) { - controller.trigger(); - } + controller?.trigger(); } } diff --git a/src/vs/editor/contrib/inlineCompletions/browser/suggestWidgetInlineCompletionProvider.ts b/src/vs/editor/contrib/inlineCompletions/browser/suggestWidgetInlineCompletionProvider.ts index 2871642c47242..b2d9acaf0ba1c 100644 --- a/src/vs/editor/contrib/inlineCompletions/browser/suggestWidgetInlineCompletionProvider.ts +++ b/src/vs/editor/contrib/inlineCompletions/browser/suggestWidgetInlineCompletionProvider.ts @@ -182,16 +182,12 @@ export class SuggestWidgetInlineCompletionProvider extends Disposable { public stopForceRenderingAbove(): void { const suggestController = SuggestController.get(this.editor); - if (suggestController) { - suggestController.stopForceRenderingAbove(); - } + suggestController?.stopForceRenderingAbove(); } public forceRenderingAbove(): void { const suggestController = SuggestController.get(this.editor); - if (suggestController) { - suggestController.forceRenderingAbove(); - } + suggestController?.forceRenderingAbove(); } } diff --git a/src/vs/editor/contrib/snippet/browser/snippetController2.ts b/src/vs/editor/contrib/snippet/browser/snippetController2.ts index 862f3a204934f..c3f773e8e9fb5 100644 --- a/src/vs/editor/contrib/snippet/browser/snippetController2.ts +++ b/src/vs/editor/contrib/snippet/browser/snippetController2.ts @@ -280,16 +280,12 @@ export class SnippetController2 implements IEditorContribution { } prev(): void { - if (this._session) { - this._session.prev(); - } + this._session?.prev(); this._updateState(); } next(): void { - if (this._session) { - this._session.next(); - } + this._session?.next(); this._updateState(); } diff --git a/src/vs/editor/contrib/wordHighlighter/browser/wordHighlighter.ts b/src/vs/editor/contrib/wordHighlighter/browser/wordHighlighter.ts index bf7d87de82b0c..1b8a60d8093b4 100644 --- a/src/vs/editor/contrib/wordHighlighter/browser/wordHighlighter.ts +++ b/src/vs/editor/contrib/wordHighlighter/browser/wordHighlighter.ts @@ -550,15 +550,11 @@ class WordHighlighterContribution extends Disposable implements IEditorContribut } public moveNext() { - if (this.wordHighlighter) { - this.wordHighlighter.moveNext(); - } + this.wordHighlighter?.moveNext(); } public moveBack() { - if (this.wordHighlighter) { - this.wordHighlighter.moveBack(); - } + this.wordHighlighter?.moveBack(); } public restoreViewState(state: boolean | undefined): void { diff --git a/src/vs/editor/contrib/zoneWidget/browser/zoneWidget.ts b/src/vs/editor/contrib/zoneWidget/browser/zoneWidget.ts index 8850f9d95074c..6f863ad803d23 100644 --- a/src/vs/editor/contrib/zoneWidget/browser/zoneWidget.ts +++ b/src/vs/editor/contrib/zoneWidget/browser/zoneWidget.ts @@ -287,9 +287,7 @@ export abstract class ZoneWidget implements IHorizontalSashLayoutProvider { this._doLayout(containerHeight, this._getWidth(layoutInfo)); } - if (this._resizeSash) { - this._resizeSash.layout(); - } + this._resizeSash?.layout(); } get position(): Position | undefined { @@ -323,9 +321,7 @@ export abstract class ZoneWidget implements IHorizontalSashLayoutProvider { this.editor.removeOverlayWidget(this._overlayWidget); this._overlayWidget = null; } - if (this._arrow) { - this._arrow.hide(); - } + this._arrow?.hide(); } private _decoratingElementsHeight(): number { diff --git a/src/vs/editor/standalone/browser/accessibilityHelp/accessibilityHelp.ts b/src/vs/editor/standalone/browser/accessibilityHelp/accessibilityHelp.ts index 4e3eb751577d7..8601905af40cc 100644 --- a/src/vs/editor/standalone/browser/accessibilityHelp/accessibilityHelp.ts +++ b/src/vs/editor/standalone/browser/accessibilityHelp/accessibilityHelp.ts @@ -340,9 +340,7 @@ class ShowAccessibilityHelpAction extends EditorAction { public run(accessor: ServicesAccessor, editor: ICodeEditor): void { const controller = AccessibilityHelpController.get(editor); - if (controller) { - controller.show(); - } + controller?.show(); } } diff --git a/src/vs/editor/standalone/browser/inspectTokens/inspectTokens.ts b/src/vs/editor/standalone/browser/inspectTokens/inspectTokens.ts index 6ac269a0f8ce7..cc3d4cef52e7d 100644 --- a/src/vs/editor/standalone/browser/inspectTokens/inspectTokens.ts +++ b/src/vs/editor/standalone/browser/inspectTokens/inspectTokens.ts @@ -89,9 +89,7 @@ class InspectTokens extends EditorAction { public run(accessor: ServicesAccessor, editor: ICodeEditor): void { const controller = InspectTokensController.get(editor); - if (controller) { - controller.launch(); - } + controller?.launch(); } } diff --git a/src/vs/platform/contextview/browser/contextMenuHandler.ts b/src/vs/platform/contextview/browser/contextMenuHandler.ts index aa6612d89ff1b..e71f33b589196 100644 --- a/src/vs/platform/contextview/browser/contextMenuHandler.ts +++ b/src/vs/platform/contextview/browser/contextMenuHandler.ts @@ -134,9 +134,7 @@ export class ContextMenuHandler { this.block = null; } - if (this.focusToReturn) { - this.focusToReturn.focus(); - } + this.focusToReturn?.focus(); } }, shadowRootElement, !!shadowRootElement); } @@ -147,9 +145,7 @@ export class ContextMenuHandler { this.contextViewService.hideContextView(false); // Restore focus here - if (this.focusToReturn) { - this.focusToReturn.focus(); - } + this.focusToReturn?.focus(); } private onDidActionRun(e: IRunEvent): void { diff --git a/src/vs/platform/history/browser/contextScopedHistoryWidget.ts b/src/vs/platform/history/browser/contextScopedHistoryWidget.ts index 7791293a4494f..af357a69ffa86 100644 --- a/src/vs/platform/history/browser/contextScopedHistoryWidget.ts +++ b/src/vs/platform/history/browser/contextScopedHistoryWidget.ts @@ -118,9 +118,7 @@ KeybindingsRegistry.registerCommandAndKeybindingRule({ primary: KeyCode.UpArrow, secondary: [KeyMod.Alt | KeyCode.UpArrow], handler: (accessor) => { - if (lastFocusedWidget) { - lastFocusedWidget.showPreviousValue(); - } + lastFocusedWidget?.showPreviousValue(); } }); @@ -135,8 +133,6 @@ KeybindingsRegistry.registerCommandAndKeybindingRule({ primary: KeyCode.DownArrow, secondary: [KeyMod.Alt | KeyCode.DownArrow], handler: (accessor) => { - if (lastFocusedWidget) { - lastFocusedWidget.showNextValue(); - } + lastFocusedWidget?.showNextValue(); } }); diff --git a/src/vs/platform/issue/electron-main/issueMainService.ts b/src/vs/platform/issue/electron-main/issueMainService.ts index e283eb85e95cb..a3edd3cc7dd63 100644 --- a/src/vs/platform/issue/electron-main/issueMainService.ts +++ b/src/vs/platform/issue/electron-main/issueMainService.ts @@ -176,15 +176,11 @@ export class IssueMainService implements ICommonIssueService { }); validatedIpcMain.on('vscode:closeIssueReporter', event => { - if (this.issueReporterWindow) { - this.issueReporterWindow.close(); - } + this.issueReporterWindow?.close(); }); validatedIpcMain.on('vscode:closeProcessExplorer', event => { - if (this.processExplorerWindow) { - this.processExplorerWindow.close(); - } + this.processExplorerWindow?.close(); }); validatedIpcMain.on('vscode:windowsInfoRequest', async event => { diff --git a/src/vs/platform/log/common/bufferLog.ts b/src/vs/platform/log/common/bufferLog.ts index 58b9e41e60cc6..76b3bfdc6c17b 100644 --- a/src/vs/platform/log/common/bufferLog.ts +++ b/src/vs/platform/log/common/bufferLog.ts @@ -81,14 +81,10 @@ export class BufferLogService extends AbstractLogger implements ILogService { } override dispose(): void { - if (this._logger) { - this._logger.dispose(); - } + this._logger?.dispose(); } flush(): void { - if (this._logger) { - this._logger.flush(); - } + this._logger?.flush(); } } diff --git a/src/vs/platform/native/electron-main/nativeHostMainService.ts b/src/vs/platform/native/electron-main/nativeHostMainService.ts index a4b9b303b8711..a8fa55f59bf1c 100644 --- a/src/vs/platform/native/electron-main/nativeHostMainService.ts +++ b/src/vs/platform/native/electron-main/nativeHostMainService.ts @@ -173,16 +173,12 @@ export class NativeHostMainService extends Disposable implements INativeHostMain async toggleFullScreen(windowId: number | undefined): Promise { const window = this.windowById(windowId); - if (window) { - window.toggleFullScreen(); - } + window?.toggleFullScreen(); } async handleTitleDoubleClick(windowId: number | undefined): Promise { const window = this.windowById(windowId); - if (window) { - window.handleTitleDoubleClick(); - } + window?.handleTitleDoubleClick(); } async isMaximized(windowId: number | undefined): Promise { @@ -665,9 +661,7 @@ export class NativeHostMainService extends Disposable implements INativeHostMain async notifyReady(windowId: number | undefined): Promise { const window = this.windowById(windowId); - if (window) { - window.setReady(); - } + window?.setReady(); } async relaunch(windowId: number | undefined, options?: { addArgs?: string[]; removeArgs?: string[] }): Promise { diff --git a/src/vs/platform/remote/common/remoteAgentConnection.ts b/src/vs/platform/remote/common/remoteAgentConnection.ts index fde30c2d8a626..d6883c9f3d9ba 100644 --- a/src/vs/platform/remote/common/remoteAgentConnection.ts +++ b/src/vs/platform/remote/common/remoteAgentConnection.ts @@ -333,9 +333,7 @@ async function connectToRemoteExtensionHostAgentAndReadOneMessage(options: IS } result.reject(error); } else { - if (options.reconnectionProtocol) { - options.reconnectionProtocol.endAcceptReconnection(); - } + options.reconnectionProtocol?.endAcceptReconnection(); options.logService.trace(`${logPrefix} 6/6. handshake finished, connection is up and running after ${logElapsed(startTime)}!`); result.resolve({ protocol, firstMessage: msg }); } diff --git a/src/vs/platform/sharedProcess/electron-browser/sharedProcessWorkerMain.ts b/src/vs/platform/sharedProcess/electron-browser/sharedProcessWorkerMain.ts index 165268c5e1263..f05f360ce5e07 100644 --- a/src/vs/platform/sharedProcess/electron-browser/sharedProcessWorkerMain.ts +++ b/src/vs/platform/sharedProcess/electron-browser/sharedProcessWorkerMain.ts @@ -102,9 +102,7 @@ class SharedProcessWorkerMain { private terminate(configuration: ISharedProcessWorkerConfiguration): void { const processDisposable = this.processes.get(hash(configuration)); - if (processDisposable) { - processDisposable.dispose(); - } + processDisposable?.dispose(); } } diff --git a/src/vs/platform/terminal/common/terminalDataBuffering.ts b/src/vs/platform/terminal/common/terminalDataBuffering.ts index 21432ca631ec7..276b01c54672d 100644 --- a/src/vs/platform/terminal/common/terminalDataBuffering.ts +++ b/src/vs/platform/terminal/common/terminalDataBuffering.ts @@ -51,9 +51,7 @@ export class TerminalDataBufferer implements IDisposable { stopBuffering(id: number) { const buffer = this._terminalBufferMap.get(id); - if (buffer) { - buffer.dispose(); - } + buffer?.dispose(); } flushBuffer(id: number): void { diff --git a/src/vs/platform/tunnel/node/tunnelService.ts b/src/vs/platform/tunnel/node/tunnelService.ts index 178247f60c59c..7cdd91afd5381 100644 --- a/src/vs/platform/tunnel/node/tunnelService.ts +++ b/src/vs/platform/tunnel/node/tunnelService.ts @@ -20,9 +20,7 @@ import { ISignService } from 'vs/platform/sign/common/sign'; async function createRemoteTunnel(options: IConnectionOptions, defaultTunnelHost: string, tunnelRemoteHost: string, tunnelRemotePort: number, tunnelLocalPort?: number): Promise { let readyTunnel: NodeRemoteTunnel | undefined; for (let attempts = 3; attempts; attempts--) { - if (readyTunnel) { - readyTunnel.dispose(); - } + readyTunnel?.dispose(); const tunnel = new NodeRemoteTunnel(options, defaultTunnelHost, tunnelRemoteHost, tunnelRemotePort, tunnelLocalPort); readyTunnel = await tunnel.waitForReady(); if ((tunnelLocalPort && BROWSER_RESTRICTED_PORTS[tunnelLocalPort]) || !BROWSER_RESTRICTED_PORTS[readyTunnel.tunnelLocalPort]) { diff --git a/src/vs/platform/userDataSync/common/userDataAutoSyncService.ts b/src/vs/platform/userDataSync/common/userDataAutoSyncService.ts index bf59598603bba..e77ce86c96307 100644 --- a/src/vs/platform/userDataSync/common/userDataAutoSyncService.ts +++ b/src/vs/platform/userDataSync/common/userDataAutoSyncService.ts @@ -408,9 +408,7 @@ class AutoSync extends Disposable { this.logService.info('Auto sync: Cancelled sync that is in progress'); this.syncPromise = undefined; } - if (this.syncTask) { - this.syncTask.stop(); - } + this.syncTask?.stop(); this.logService.info('Auto Sync: Stopped'); })); this.logService.info('Auto Sync: Started'); diff --git a/src/vs/platform/userDataSync/common/userDataSyncService.ts b/src/vs/platform/userDataSync/common/userDataSyncService.ts index d5e5b74cb7f78..cb02de94e91fb 100644 --- a/src/vs/platform/userDataSync/common/userDataSyncService.ts +++ b/src/vs/platform/userDataSync/common/userDataSyncService.ts @@ -118,9 +118,7 @@ export class UserDataSyncService extends Disposable implements IUserDataSyncServ return cancellablePromise.finally(() => cancellablePromise = undefined); }, async stop(): Promise { - if (cancellablePromise) { - cancellablePromise.cancel(); - } + cancellablePromise?.cancel(); if (that.status !== SyncStatus.Idle) { return that.stop(synchronizers); } diff --git a/src/vs/platform/windows/electron-main/window.ts b/src/vs/platform/windows/electron-main/window.ts index c1e6bb0b70b8a..e11613b3ca9a7 100644 --- a/src/vs/platform/windows/electron-main/window.ts +++ b/src/vs/platform/windows/electron-main/window.ts @@ -1408,9 +1408,7 @@ export class CodeWindow extends Disposable implements ICodeWindow { } close(): void { - if (this._win) { - this._win.close(); - } + this._win?.close(); } sendWhenReady(channel: string, token: CancellationToken, ...args: any[]): void { diff --git a/src/vs/workbench/api/browser/mainThreadDocumentContentProviders.ts b/src/vs/workbench/api/browser/mainThreadDocumentContentProviders.ts index 4ecd40a83e941..47e1f32ed47eb 100644 --- a/src/vs/workbench/api/browser/mainThreadDocumentContentProviders.ts +++ b/src/vs/workbench/api/browser/mainThreadDocumentContentProviders.ts @@ -71,9 +71,7 @@ export class MainThreadDocumentContentProviders implements MainThreadDocumentCon // cancel and dispose an existing update const pending = this._pendingUpdate.get(model.id); - if (pending) { - pending.cancel(); - } + pending?.cancel(); // create and keep update token const myToken = new CancellationTokenSource(); diff --git a/src/vs/workbench/api/browser/mainThreadOutputService.ts b/src/vs/workbench/api/browser/mainThreadOutputService.ts index 85f8495e80dac..39e110e3f22cf 100644 --- a/src/vs/workbench/api/browser/mainThreadOutputService.ts +++ b/src/vs/workbench/api/browser/mainThreadOutputService.ts @@ -80,9 +80,7 @@ export class MainThreadOutputService extends Disposable implements MainThreadOut public async $dispose(channelId: string): Promise { const channel = this._getChannel(channelId); - if (channel) { - channel.dispose(); - } + channel?.dispose(); } private _getChannel(channelId: string): IOutputChannel | undefined { diff --git a/src/vs/workbench/api/common/extHostComments.ts b/src/vs/workbench/api/common/extHostComments.ts index 2259201d139b7..226c3d0dc12a8 100644 --- a/src/vs/workbench/api/common/extHostComments.ts +++ b/src/vs/workbench/api/common/extHostComments.ts @@ -620,9 +620,7 @@ export function createExtHostComments(mainContext: IMainContext, commands: ExtHo $deleteCommentThread(threadHandle: number): void { const thread = this._threads.get(threadHandle); - if (thread) { - thread.dispose(); - } + thread?.dispose(); this._threads.delete(threadHandle); } diff --git a/src/vs/workbench/api/common/extHostLanguageFeatures.ts b/src/vs/workbench/api/common/extHostLanguageFeatures.ts index d9244952ab06b..68df773b0b866 100644 --- a/src/vs/workbench/api/common/extHostLanguageFeatures.ts +++ b/src/vs/workbench/api/common/extHostLanguageFeatures.ts @@ -1130,9 +1130,7 @@ class InlineCompletionAdapter extends InlineCompletionAdapterBase { let disposableStore: DisposableStore | undefined = undefined; const pid = this._references.createReferenceId({ dispose() { - if (disposableStore) { - disposableStore.dispose(); - } + disposableStore?.dispose(); }, items: normalizedResult }); @@ -1236,9 +1234,7 @@ class InlineCompletionAdapterNew extends InlineCompletionAdapterBase { let disposableStore: DisposableStore | undefined = undefined; const pid = this._references.createReferenceId({ dispose() { - if (disposableStore) { - disposableStore.dispose(); - } + disposableStore?.dispose(); }, items: normalizedResult }); diff --git a/src/vs/workbench/api/common/extHostNotebook.ts b/src/vs/workbench/api/common/extHostNotebook.ts index 7c9cc4c0eb0d7..6a1df44dc0e24 100644 --- a/src/vs/workbench/api/common/extHostNotebook.ts +++ b/src/vs/workbench/api/common/extHostNotebook.ts @@ -215,9 +215,7 @@ export class ExtHostNotebookController implements ExtHostNotebookShape { return new extHostTypes.Disposable(() => { this._notebookStatusBarItemProviders.delete(handle); this._notebookProxy.$unregisterNotebookCellStatusBarItemProvider(handle, eventHandle); - if (subscription) { - subscription.dispose(); - } + subscription?.dispose(); }); } diff --git a/src/vs/workbench/api/common/extHostProgress.ts b/src/vs/workbench/api/common/extHostProgress.ts index 83b833b35b217..12cffddda115f 100644 --- a/src/vs/workbench/api/common/extHostProgress.ts +++ b/src/vs/workbench/api/common/extHostProgress.ts @@ -42,9 +42,7 @@ export class ExtHostProgress implements ExtHostProgressShape { const progressEnd = (handle: number): void => { this._proxy.$progressEnd(handle); this._mapHandleToCancellationSource.delete(handle); - if (source) { - source.dispose(); - } + source?.dispose(); }; let p: Thenable; diff --git a/src/vs/workbench/api/common/extHostQuickOpen.ts b/src/vs/workbench/api/common/extHostQuickOpen.ts index 1bc50dd99e2a3..6d7ab756c8c8d 100644 --- a/src/vs/workbench/api/common/extHostQuickOpen.ts +++ b/src/vs/workbench/api/common/extHostQuickOpen.ts @@ -223,9 +223,7 @@ export function createExtHostQuickOpen(mainContext: IMainContext, workspace: IEx $onDidAccept(sessionId: number): void { const session = this._sessions.get(sessionId); - if (session) { - session._fireDidAccept(); - } + session?._fireDidAccept(); } $onDidChangeActive(sessionId: number, handles: number[]): void { @@ -256,9 +254,7 @@ export function createExtHostQuickOpen(mainContext: IMainContext, workspace: IEx $onDidHide(sessionId: number): void { const session = this._sessions.get(sessionId); - if (session) { - session._fireDidHide(); - } + session?._fireDidHide(); } } diff --git a/src/vs/workbench/browser/layout.ts b/src/vs/workbench/browser/layout.ts index d5f339775a32a..ef74671541d97 100644 --- a/src/vs/workbench/browser/layout.ts +++ b/src/vs/workbench/browser/layout.ts @@ -902,16 +902,12 @@ export abstract class Layout extends Disposable implements IWorkbenchLayoutServi break; case Parts.PANEL_PART: { const activePanel = this.paneCompositeService.getActivePaneComposite(ViewContainerLocation.Panel); - if (activePanel) { - activePanel.focus(); - } + activePanel?.focus(); break; } case Parts.SIDEBAR_PART: { const activeViewlet = this.paneCompositeService.getActivePaneComposite(ViewContainerLocation.Sidebar); - if (activeViewlet) { - activeViewlet.focus(); - } + activeViewlet?.focus(); break; } case Parts.ACTIVITYBAR_PART: @@ -922,9 +918,7 @@ export abstract class Layout extends Disposable implements IWorkbenchLayoutServi default: { // Title Bar & Banner simply pass focus to container const container = this.getContainer(part); - if (container) { - container.focus(); - } + container?.focus(); } } } diff --git a/src/vs/workbench/browser/parts/activitybar/activitybarPart.ts b/src/vs/workbench/browser/parts/activitybar/activitybarPart.ts index 5ee5d6e78acfa..fedd79ca5e7bb 100644 --- a/src/vs/workbench/browser/parts/activitybar/activitybarPart.ts +++ b/src/vs/workbench/browser/parts/activitybar/activitybarPart.ts @@ -483,9 +483,7 @@ export class ActivitybarPart extends Part implements IPaneCompositeSelectorPart this.keyboardNavigationDisposables.add(addDisposableListener(this.menuBarContainer, EventType.KEY_DOWN, e => { const kbEvent = new StandardKeyboardEvent(e); if (kbEvent.equals(KeyCode.DownArrow) || kbEvent.equals(KeyCode.RightArrow)) { - if (this.compositeBar) { - this.compositeBar.focus(); - } + this.compositeBar?.focus(); } })); } @@ -497,9 +495,7 @@ export class ActivitybarPart extends Part implements IPaneCompositeSelectorPart if (kbEvent.equals(KeyCode.DownArrow) || kbEvent.equals(KeyCode.RightArrow)) { this.globalActivityActionBar?.focus(true); } else if (kbEvent.equals(KeyCode.UpArrow) || kbEvent.equals(KeyCode.LeftArrow)) { - if (this.menuBar) { - this.menuBar.toggleFocus(); - } + this.menuBar?.toggleFocus(); } })); } @@ -628,9 +624,7 @@ export class ActivitybarPart extends Part implements IPaneCompositeSelectorPart private onDidDeregisterViewContainer(viewContainer: ViewContainer): void { const disposable = this.viewContainerDisposables.get(viewContainer.id); - if (disposable) { - disposable.dispose(); - } + disposable?.dispose(); this.viewContainerDisposables.delete(viewContainer.id); this.removeComposite(viewContainer.id); diff --git a/src/vs/workbench/browser/parts/auxiliarybar/auxiliaryBarActions.ts b/src/vs/workbench/browser/parts/auxiliarybar/auxiliaryBarActions.ts index cf521c32e16ab..4603210c4714c 100644 --- a/src/vs/workbench/browser/parts/auxiliarybar/auxiliaryBarActions.ts +++ b/src/vs/workbench/browser/parts/auxiliarybar/auxiliaryBarActions.ts @@ -63,9 +63,7 @@ class FocusAuxiliaryBarAction extends Action { // Focus into active composite const composite = this.paneCompositeService.getActivePaneComposite(ViewContainerLocation.AuxiliaryBar); - if (composite) { - composite.focus(); - } + composite?.focus(); } } diff --git a/src/vs/workbench/browser/parts/compositeBar.ts b/src/vs/workbench/browser/parts/compositeBar.ts index d15c1f36d9652..0de8126355523 100644 --- a/src/vs/workbench/browser/parts/compositeBar.ts +++ b/src/vs/workbench/browser/parts/compositeBar.ts @@ -557,9 +557,7 @@ export class CompositeBar extends Widget implements ICompositeBar { this.compositeOverflowAction.dispose(); this.compositeOverflowAction = undefined; - if (this.compositeOverflowActionViewItem) { - this.compositeOverflowActionViewItem.dispose(); - } + this.compositeOverflowActionViewItem?.dispose(); this.compositeOverflowActionViewItem = undefined; } @@ -596,9 +594,7 @@ export class CompositeBar extends Widget implements ICompositeBar { // Add overflow action as needed if (totalComposites > compositesToShow.length && !this.compositeOverflowAction) { this.compositeOverflowAction = this.instantiationService.createInstance(CompositeOverflowActivityAction, () => { - if (this.compositeOverflowActionViewItem) { - this.compositeOverflowActionViewItem.showMenu(); - } + this.compositeOverflowActionViewItem?.showMenu(); }); this.compositeOverflowActionViewItem = this.instantiationService.createInstance( CompositeOverflowActivityActionViewItem, diff --git a/src/vs/workbench/browser/parts/editor/breadcrumbsControl.ts b/src/vs/workbench/browser/parts/editor/breadcrumbsControl.ts index 0ef796ae3fa45..120b7c0343a60 100644 --- a/src/vs/workbench/browser/parts/editor/breadcrumbsControl.ts +++ b/src/vs/workbench/browser/parts/editor/breadcrumbsControl.ts @@ -711,9 +711,7 @@ KeybindingsRegistry.registerCommandAndKeybindingRule({ } widget.setFocused(undefined); widget.setSelection(undefined); - if (groups.activeGroup.activeEditorPane) { - groups.activeGroup.activeEditorPane.focus(); - } + groups.activeGroup.activeEditorPane?.focus(); } }); KeybindingsRegistry.registerCommandAndKeybindingRule({ diff --git a/src/vs/workbench/browser/parts/editor/editorActions.ts b/src/vs/workbench/browser/parts/editor/editorActions.ts index c93f52e60c6ab..78a4f548c3461 100644 --- a/src/vs/workbench/browser/parts/editor/editorActions.ts +++ b/src/vs/workbench/browser/parts/editor/editorActions.ts @@ -278,9 +278,7 @@ abstract class AbstractFocusGroupAction extends Action { override async run(): Promise { const group = this.editorGroupService.findGroup(this.scope, this.editorGroupService.activeGroup, true); - if (group) { - group.focus(); - } + group?.focus(); } } diff --git a/src/vs/workbench/browser/parts/editor/editorCommands.ts b/src/vs/workbench/browser/parts/editor/editorCommands.ts index ab5ebcce987fe..264ba8fba9b83 100644 --- a/src/vs/workbench/browser/parts/editor/editorCommands.ts +++ b/src/vs/workbench/browser/parts/editor/editorCommands.ts @@ -1035,9 +1035,7 @@ function registerFocusEditorGroupWihoutWrapCommands(): void { const editorGroupService = accessor.get(IEditorGroupsService); const group = editorGroupService.findGroup({ direction: command.direction }, editorGroupService.activeGroup, false); - if (group) { - group.focus(); - } + group?.focus(); }); } } diff --git a/src/vs/workbench/browser/parts/notifications/notificationsCommands.ts b/src/vs/workbench/browser/parts/notifications/notificationsCommands.ts index 7649aba7b08f4..e474515f5bdc8 100644 --- a/src/vs/workbench/browser/parts/notifications/notificationsCommands.ts +++ b/src/vs/workbench/browser/parts/notifications/notificationsCommands.ts @@ -133,9 +133,7 @@ export function registerNotificationCommands(center: INotificationsCenterControl primary: KeyCode.RightArrow, handler: (accessor, args?) => { const notification = getNotificationFromContext(accessor.get(IListService), args); - if (notification) { - notification.expand(); - } + notification?.expand(); } }); @@ -147,9 +145,7 @@ export function registerNotificationCommands(center: INotificationsCenterControl primary: KeyCode.LeftArrow, handler: (accessor, args?) => { const notification = getNotificationFromContext(accessor.get(IListService), args); - if (notification) { - notification.collapse(); - } + notification?.collapse(); } }); @@ -162,9 +158,7 @@ export function registerNotificationCommands(center: INotificationsCenterControl secondary: [KeyCode.Enter], handler: accessor => { const notification = getNotificationFromContext(accessor.get(IListService)); - if (notification) { - notification.toggle(); - } + notification?.toggle(); } }); diff --git a/src/vs/workbench/browser/parts/notifications/notificationsStatus.ts b/src/vs/workbench/browser/parts/notifications/notificationsStatus.ts index 670e5f35cae8a..ae61fa84403d1 100644 --- a/src/vs/workbench/browser/parts/notifications/notificationsStatus.ts +++ b/src/vs/workbench/browser/parts/notifications/notificationsStatus.ts @@ -217,9 +217,7 @@ export class NotificationsStatus extends Disposable { clearTimeout(hideHandle); } - if (statusMessageEntry) { - statusMessageEntry.dispose(); - } + statusMessageEntry?.dispose(); } }; diff --git a/src/vs/workbench/browser/parts/panel/panelActions.ts b/src/vs/workbench/browser/parts/panel/panelActions.ts index b23e8bd6fa3cd..074fafd9d6165 100644 --- a/src/vs/workbench/browser/parts/panel/panelActions.ts +++ b/src/vs/workbench/browser/parts/panel/panelActions.ts @@ -70,9 +70,7 @@ class FocusPanelAction extends Action { // Focus into active panel const panel = this.paneCompositeService.getActivePaneComposite(ViewContainerLocation.Panel); - if (panel) { - panel.focus(); - } + panel?.focus(); } } diff --git a/src/vs/workbench/browser/parts/panel/panelPart.ts b/src/vs/workbench/browser/parts/panel/panelPart.ts index 2263ec0769ed9..5d299207fe515 100644 --- a/src/vs/workbench/browser/parts/panel/panelPart.ts +++ b/src/vs/workbench/browser/parts/panel/panelPart.ts @@ -292,9 +292,7 @@ export abstract class BasePanelPart extends CompositePart impleme private async onDidDeregisterPanel(panelId: string): Promise { const disposable = this.panelDisposables.get(panelId); - if (disposable) { - disposable.dispose(); - } + disposable?.dispose(); this.panelDisposables.delete(panelId); const activeContainers = this.viewDescriptorService.getViewContainersByLocation(this.viewContainerLocation) diff --git a/src/vs/workbench/browser/parts/sidebar/sidebarActions.ts b/src/vs/workbench/browser/parts/sidebar/sidebarActions.ts index f1ab76ec17b65..9ebb1e99eb74f 100644 --- a/src/vs/workbench/browser/parts/sidebar/sidebarActions.ts +++ b/src/vs/workbench/browser/parts/sidebar/sidebarActions.ts @@ -42,9 +42,7 @@ export class FocusSideBarAction extends Action2 { // Focus into active viewlet const viewlet = paneCompositeService.getActivePaneComposite(ViewContainerLocation.Sidebar); - if (viewlet) { - viewlet.focus(); - } + viewlet?.focus(); } } diff --git a/src/vs/workbench/browser/parts/titlebar/menubarControl.ts b/src/vs/workbench/browser/parts/titlebar/menubarControl.ts index b431d4df48ebe..cff3e83c064b7 100644 --- a/src/vs/workbench/browser/parts/titlebar/menubarControl.ts +++ b/src/vs/workbench/browser/parts/titlebar/menubarControl.ts @@ -535,9 +535,7 @@ export class CustomMenubarControl extends MenubarControl { } async run(): Promise { - if (that.menubar) { - that.menubar.toggleFocus(); - } + that.menubar?.toggleFocus(); } })); } @@ -849,9 +847,7 @@ export class CustomMenubarControl extends MenubarControl { this.container.classList.remove('inactive'); } else { this.container.classList.add('inactive'); - if (this.menubar) { - this.menubar.blur(); - } + this.menubar?.blur(); } } } @@ -928,8 +924,6 @@ export class CustomMenubarControl extends MenubarControl { } toggleFocus() { - if (this.menubar) { - this.menubar.toggleFocus(); - } + this.menubar?.toggleFocus(); } } diff --git a/src/vs/workbench/common/editor/diffEditorInput.ts b/src/vs/workbench/common/editor/diffEditorInput.ts index 878ebaca82559..c9917b2f6b9f0 100644 --- a/src/vs/workbench/common/editor/diffEditorInput.ts +++ b/src/vs/workbench/common/editor/diffEditorInput.ts @@ -171,9 +171,7 @@ export class DiffEditorInput extends SideBySideEditorInput implements IDiffEdito // inputs that need to be loaded again and thus we always recreate the model and dispose // the previous one - if any. const resolvedModel = await this.createModel(); - if (this.cachedModel) { - this.cachedModel.dispose(); - } + this.cachedModel?.dispose(); this.cachedModel = resolvedModel; diff --git a/src/vs/workbench/common/notifications.ts b/src/vs/workbench/common/notifications.ts index 815fe8a43d108..0536faa369e77 100644 --- a/src/vs/workbench/common/notifications.ts +++ b/src/vs/workbench/common/notifications.ts @@ -195,9 +195,7 @@ export class NotificationsModel extends Disposable implements INotificationsMode // Deduplicate const duplicate = this.findNotification(item); - if (duplicate) { - duplicate.close(); - } + duplicate?.close(); // Add to list as first entry this._notifications.splice(0, 0, item); diff --git a/src/vs/workbench/contrib/bulkEdit/browser/preview/bulkEdit.contribution.ts b/src/vs/workbench/contrib/bulkEdit/browser/preview/bulkEdit.contribution.ts index 57a34f2c7d063..7f26aedafc434 100644 --- a/src/vs/workbench/contrib/bulkEdit/browser/preview/bulkEdit.contribution.ts +++ b/src/vs/workbench/contrib/bulkEdit/browser/preview/bulkEdit.contribution.ts @@ -189,9 +189,7 @@ registerAction2(class ApplyAction extends Action2 { async run(accessor: ServicesAccessor): Promise { const viewsService = accessor.get(IViewsService); const view = await getBulkEditPane(viewsService); - if (view) { - view.accept(); - } + view?.accept(); } }); @@ -215,9 +213,7 @@ registerAction2(class DiscardAction extends Action2 { async run(accessor: ServicesAccessor): Promise { const viewsService = accessor.get(IViewsService); const view = await getBulkEditPane(viewsService); - if (view) { - view.discard(); - } + view?.discard(); } }); @@ -246,9 +242,7 @@ registerAction2(class ToggleAction extends Action2 { async run(accessor: ServicesAccessor): Promise { const viewsService = accessor.get(IViewsService); const view = await getBulkEditPane(viewsService); - if (view) { - view.toggleChecked(); - } + view?.toggleChecked(); } }); @@ -275,9 +269,7 @@ registerAction2(class GroupByFile extends Action2 { async run(accessor: ServicesAccessor): Promise { const viewsService = accessor.get(IViewsService); const view = await getBulkEditPane(viewsService); - if (view) { - view.groupByFile(); - } + view?.groupByFile(); } }); @@ -302,9 +294,7 @@ registerAction2(class GroupByType extends Action2 { async run(accessor: ServicesAccessor): Promise { const viewsService = accessor.get(IViewsService); const view = await getBulkEditPane(viewsService); - if (view) { - view.groupByType(); - } + view?.groupByType(); } }); @@ -328,9 +318,7 @@ registerAction2(class ToggleGrouping extends Action2 { async run(accessor: ServicesAccessor): Promise { const viewsService = accessor.get(IViewsService); const view = await getBulkEditPane(viewsService); - if (view) { - view.toggleGrouping(); - } + view?.toggleGrouping(); } }); diff --git a/src/vs/workbench/contrib/codeEditor/browser/accessibility/accessibility.ts b/src/vs/workbench/contrib/codeEditor/browser/accessibility/accessibility.ts index d2542d854ba5f..fc37bc604af62 100644 --- a/src/vs/workbench/contrib/codeEditor/browser/accessibility/accessibility.ts +++ b/src/vs/workbench/contrib/codeEditor/browser/accessibility/accessibility.ts @@ -307,9 +307,7 @@ class ShowAccessibilityHelpAction extends Action2 { if (activeEditor) { const controller = AccessibilityHelpController.get(activeEditor); - if (controller) { - controller.show(); - } + controller?.show(); } } } diff --git a/src/vs/workbench/contrib/codeEditor/browser/inspectEditorTokens/inspectEditorTokens.ts b/src/vs/workbench/contrib/codeEditor/browser/inspectEditorTokens/inspectEditorTokens.ts index 9a655b6983a44..34ca4a85e99c4 100644 --- a/src/vs/workbench/contrib/codeEditor/browser/inspectEditorTokens/inspectEditorTokens.ts +++ b/src/vs/workbench/contrib/codeEditor/browser/inspectEditorTokens/inspectEditorTokens.ts @@ -126,9 +126,7 @@ class InspectEditorTokens extends EditorAction { public run(accessor: ServicesAccessor, editor: ICodeEditor): void { const controller = InspectEditorTokensController.get(editor); - if (controller) { - controller.toggle(); - } + controller?.toggle(); } } diff --git a/src/vs/workbench/contrib/comments/browser/commentNode.ts b/src/vs/workbench/contrib/comments/browser/commentNode.ts index 674ea47d4062c..a9b5e980e4b30 100644 --- a/src/vs/workbench/contrib/comments/browser/commentNode.ts +++ b/src/vs/workbench/contrib/comments/browser/commentNode.ts @@ -281,9 +281,7 @@ export class CommentNode extends Disposable { private createReactionPicker(reactionGroup: languages.CommentReaction[]): ToggleReactionsAction { const toggleReactionAction = this._register(new ToggleReactionsAction(() => { - if (toggleReactionActionViewItem) { - toggleReactionActionViewItem.show(); - } + toggleReactionActionViewItem?.show(); }, nls.localize('commentToggleReaction', "Toggle Reaction"))); let reactionMenuActions: Action[] = []; @@ -438,9 +436,7 @@ export class CommentNode extends Disposable { } this._body.classList.remove('hidden'); - if (this._commentEditorModel) { - this._commentEditorModel.dispose(); - } + this._commentEditorModel?.dispose(); this._commentEditorDisposables.forEach(dispose => dispose.dispose()); this._commentEditorDisposables = []; @@ -547,13 +543,9 @@ export class CommentNode extends Disposable { } // update comment reactions - if (this._reactionActionsContainer) { - this._reactionActionsContainer.remove(); - } + this._reactionActionsContainer?.remove(); - if (this._reactionsActionBar) { - this._reactionsActionBar.clear(); - } + this._reactionsActionBar?.clear(); if (this.comment.commentReactions && this.comment.commentReactions.some(reaction => !!reaction.count)) { this.createReactionsContainer(this._commentDetailsContainer); diff --git a/src/vs/workbench/contrib/comments/browser/commentReply.ts b/src/vs/workbench/contrib/comments/browser/commentReply.ts index 68eda2e6e390b..c085e3ccf0c2d 100644 --- a/src/vs/workbench/contrib/comments/browser/commentReply.ts +++ b/src/vs/workbench/contrib/comments/browser/commentReply.ts @@ -163,9 +163,7 @@ export class CommentReply extends Disposable { } async submitComment(): Promise { - if (this._commentFormActions) { - this._commentFormActions.triggerDefaultAction(); - } + this._commentFormActions?.triggerDefaultAction(); } setCommentEditorDecorations() { diff --git a/src/vs/workbench/contrib/comments/browser/commentsEditorContribution.ts b/src/vs/workbench/contrib/comments/browser/commentsEditorContribution.ts index 5f859a45b0a53..280430dba930f 100644 --- a/src/vs/workbench/contrib/comments/browser/commentsEditorContribution.ts +++ b/src/vs/workbench/contrib/comments/browser/commentsEditorContribution.ts @@ -595,9 +595,7 @@ export class CommentController implements IEditorContribution { this._computeCommentingRangeScheduler = new Delayer(200); this.localToDispose.add({ dispose: () => { - if (this._computeCommentingRangeScheduler) { - this._computeCommentingRangeScheduler.cancel(); - } + this._computeCommentingRangeScheduler?.cancel(); this._computeCommentingRangeScheduler = null; } }); @@ -974,9 +972,7 @@ export class NextCommentThreadAction extends EditorAction { public run(accessor: ServicesAccessor, editor: ICodeEditor): void { const controller = CommentController.get(editor); - if (controller) { - controller.nextCommentThread(); - } + controller?.nextCommentThread(); } } @@ -997,9 +993,7 @@ export class PreviousCommentThreadAction extends EditorAction { public run(accessor: ServicesAccessor, editor: ICodeEditor): void { const controller = CommentController.get(editor); - if (controller) { - controller.previousCommentThread(); - } + controller?.previousCommentThread(); } } diff --git a/src/vs/workbench/contrib/debug/browser/breakpointEditorContribution.ts b/src/vs/workbench/contrib/debug/browser/breakpointEditorContribution.ts index 8fdc2c1f3036d..defa4f43cd02b 100644 --- a/src/vs/workbench/contrib/debug/browser/breakpointEditorContribution.ts +++ b/src/vs/workbench/contrib/debug/browser/breakpointEditorContribution.ts @@ -510,9 +510,7 @@ export class BreakpointEditorContribution implements IBreakpointEditorContributi activeCodeEditor.changeDecorations((changeAccessor) => { const decorationIds = changeAccessor.deltaDecorations(this.breakpointDecorations.map(bpd => bpd.decorationId), desiredBreakpointDecorations); this.breakpointDecorations.forEach(bpd => { - if (bpd.inlineWidget) { - bpd.inlineWidget.dispose(); - } + bpd.inlineWidget?.dispose(); }); this.breakpointDecorations = decorationIds.map((decorationId, index) => { let inlineWidget: InlineBreakpointWidget | undefined = undefined; @@ -613,9 +611,7 @@ export class BreakpointEditorContribution implements IBreakpointEditorContributi // breakpoint widget showBreakpointWidget(lineNumber: number, column: number | undefined, context?: BreakpointWidgetContext): void { - if (this.breakpointWidget) { - this.breakpointWidget.dispose(); - } + this.breakpointWidget?.dispose(); this.breakpointWidget = this.instantiationService.createInstance(BreakpointWidget, this.editor, lineNumber, column, context); this.breakpointWidget.show({ lineNumber, column: 1 }); @@ -632,9 +628,7 @@ export class BreakpointEditorContribution implements IBreakpointEditorContributi } dispose(): void { - if (this.breakpointWidget) { - this.breakpointWidget.dispose(); - } + this.breakpointWidget?.dispose(); this.editor.removeDecorations(this.breakpointDecorations.map(bpd => bpd.decorationId)); dispose(this.toDispose); } diff --git a/src/vs/workbench/contrib/debug/browser/breakpointsView.ts b/src/vs/workbench/contrib/debug/browser/breakpointsView.ts index 8772e62d4f9ea..5e00363d50503 100644 --- a/src/vs/workbench/contrib/debug/browser/breakpointsView.ts +++ b/src/vs/workbench/contrib/debug/browser/breakpointsView.ts @@ -221,9 +221,7 @@ export class BreakpointsView extends ViewPane { override focus(): void { super.focus(); - if (this.list) { - this.list.domFocus(); - } + this.list?.domFocus(); } renderInputBox(data: InputBoxData | undefined): void { diff --git a/src/vs/workbench/contrib/debug/browser/debugService.ts b/src/vs/workbench/contrib/debug/browser/debugService.ts index f6db1acdb8023..ffdaa1c43eb87 100644 --- a/src/vs/workbench/contrib/debug/browser/debugService.ts +++ b/src/vs/workbench/contrib/debug/browser/debugService.ts @@ -174,9 +174,7 @@ export class DebugService implements IDebugService { })); this.disposables.add(this.model.onDidChangeCallStack(() => { const numberOfSessions = this.model.getSessions().filter(s => !s.parentSession).length; - if (this.activity) { - this.activity.dispose(); - } + this.activity?.dispose(); if (numberOfSessions > 0) { const viewContainer = this.viewDescriptorService.getViewContainerByViewId(CALLSTACK_VIEW_ID); if (viewContainer) { diff --git a/src/vs/workbench/contrib/debug/browser/debugStatus.ts b/src/vs/workbench/contrib/debug/browser/debugStatus.ts index c4a8ef6be746a..1addcfce1eced 100644 --- a/src/vs/workbench/contrib/debug/browser/debugStatus.ts +++ b/src/vs/workbench/contrib/debug/browser/debugStatus.ts @@ -72,9 +72,7 @@ export class DebugStatusContribution implements IWorkbenchContribution { } dispose(): void { - if (this.entryAccessor) { - this.entryAccessor.dispose(); - } + this.entryAccessor?.dispose(); dispose(this.toDispose); } } diff --git a/src/vs/workbench/contrib/debug/browser/debugToolBar.ts b/src/vs/workbench/contrib/debug/browser/debugToolBar.ts index 3fd1c0238b8a8..89a1fcc4f5d5e 100644 --- a/src/vs/workbench/contrib/debug/browser/debugToolBar.ts +++ b/src/vs/workbench/contrib/debug/browser/debugToolBar.ts @@ -259,9 +259,7 @@ export class DebugToolBar extends Themable implements IWorkbenchContribution { override dispose(): void { super.dispose(); - if (this.$el) { - this.$el.remove(); - } + this.$el?.remove(); if (this.disposeOnUpdate) { dispose(this.disposeOnUpdate); } diff --git a/src/vs/workbench/contrib/debug/browser/rawDebugSession.ts b/src/vs/workbench/contrib/debug/browser/rawDebugSession.ts index 848245e39784d..78921744a50df 100644 --- a/src/vs/workbench/contrib/debug/browser/rawDebugSession.ts +++ b/src/vs/workbench/contrib/debug/browser/rawDebugSession.ts @@ -709,9 +709,7 @@ export class RawDebugSession implements IDisposable { let cancelationListener: IDisposable; const requestId = this.debugAdapter.sendRequest(command, args, (response: DebugProtocol.Response) => { - if (cancelationListener) { - cancelationListener.dispose(); - } + cancelationListener?.dispose(); if (response.success) { completeDispatch(response); diff --git a/src/vs/workbench/contrib/debug/browser/repl.ts b/src/vs/workbench/contrib/debug/browser/repl.ts index 7fcf2fa1c089d..8f27f11bcf60b 100644 --- a/src/vs/workbench/contrib/debug/browser/repl.ts +++ b/src/vs/workbench/contrib/debug/browser/repl.ts @@ -226,9 +226,7 @@ export class Repl extends ViewPane implements IHistoryNavigationWidget { private async onDidFocusSession(session: IDebugSession | undefined): Promise { if (session) { sessionsToIgnore.delete(session); - if (this.completionItemProvider) { - this.completionItemProvider.dispose(); - } + this.completionItemProvider?.dispose(); if (session.capabilities.supportsCompletionsRequest) { this.completionItemProvider = this.languageFeaturesService.completionProvider.register({ scheme: DEBUG_SCHEME, pattern: '**/replinput', hasAccessToAllModels: true }, { triggerCharacters: session.capabilities.completionTriggerCharacters || ['.'], @@ -408,9 +406,7 @@ export class Repl extends ViewPane implements IHistoryNavigationWidget { } } if (session) { - if (this.replElementsChangeListener) { - this.replElementsChangeListener.dispose(); - } + this.replElementsChangeListener?.dispose(); this.replElementsChangeListener = session.onDidChangeReplElements(() => { this.refreshReplElements(session!.getReplElements().length === 0); }); @@ -748,9 +744,7 @@ export class Repl extends ViewPane implements IHistoryNavigationWidget { override dispose(): void { this.replInput.dispose(); - if (this.replElementsChangeListener) { - this.replElementsChangeListener.dispose(); - } + this.replElementsChangeListener?.dispose(); this.refreshScheduler.dispose(); this.modelChangeListener.dispose(); super.dispose(); diff --git a/src/vs/workbench/contrib/debug/browser/replFilter.ts b/src/vs/workbench/contrib/debug/browser/replFilter.ts index 84b1faf07e3c0..368979c2d24ee 100644 --- a/src/vs/workbench/contrib/debug/browser/replFilter.ts +++ b/src/vs/workbench/contrib/debug/browser/replFilter.ts @@ -159,15 +159,11 @@ export class ReplFilterActionViewItem extends BaseActionViewItem { } override focus(): void { - if (this.filterInputBox) { - this.filterInputBox.focus(); - } + this.filterInputBox?.focus(); } override blur(): void { - if (this.filterInputBox) { - this.filterInputBox.blur(); - } + this.filterInputBox?.blur(); } override setFocusable(): void { diff --git a/src/vs/workbench/contrib/debug/common/debugContentProvider.ts b/src/vs/workbench/contrib/debug/common/debugContentProvider.ts index 5cdb5c988cbb9..e7c4d271d2e7e 100644 --- a/src/vs/workbench/contrib/debug/common/debugContentProvider.ts +++ b/src/vs/workbench/contrib/debug/common/debugContentProvider.ts @@ -110,9 +110,7 @@ export class DebugContentProvider implements IWorkbenchContribution, ITextModelC // cancel and dispose an existing update const cancellationSource = this.pendingUpdates.get(model.id); - if (cancellationSource) { - cancellationSource.cancel(); - } + cancellationSource?.cancel(); // create and keep update token const myToken = new CancellationTokenSource(); diff --git a/src/vs/workbench/contrib/experiments/test/electron-browser/experimentService.test.ts b/src/vs/workbench/contrib/experiments/test/electron-browser/experimentService.test.ts index 7c111e51eda3e..2388b7ee9e051 100644 --- a/src/vs/workbench/contrib/experiments/test/electron-browser/experimentService.test.ts +++ b/src/vs/workbench/contrib/experiments/test/electron-browser/experimentService.test.ts @@ -106,9 +106,7 @@ suite('Experiment Service', () => { }); teardown(() => { - if (testObject) { - testObject.dispose(); - } + testObject?.dispose(); }); }); diff --git a/src/vs/workbench/contrib/extensions/browser/extensionEditor.ts b/src/vs/workbench/contrib/extensions/browser/extensionEditor.ts index d155971ec3aca..8e4020470415c 100644 --- a/src/vs/workbench/contrib/extensions/browser/extensionEditor.ts +++ b/src/vs/workbench/contrib/extensions/browser/extensionEditor.ts @@ -1737,9 +1737,7 @@ registerAction2(class ShowExtensionEditorFindAction extends Action2 { } run(accessor: ServicesAccessor): any { const extensionEditor = getExtensionEditor(accessor); - if (extensionEditor) { - extensionEditor.showFind(); - } + extensionEditor?.showFind(); } }); diff --git a/src/vs/workbench/contrib/extensions/browser/extensionsViewlet.ts b/src/vs/workbench/contrib/extensions/browser/extensionsViewlet.ts index ae27fb19d2bb8..27a701f84cb4c 100644 --- a/src/vs/workbench/contrib/extensions/browser/extensionsViewlet.ts +++ b/src/vs/workbench/contrib/extensions/browser/extensionsViewlet.ts @@ -586,9 +586,7 @@ export class ExtensionsViewPaneContainer extends ViewPaneContainer implements IE } override focus(): void { - if (this.searchBox) { - this.searchBox.focus(); - } + this.searchBox?.focus(); } override layout(dimension: Dimension): void { diff --git a/src/vs/workbench/contrib/extensions/browser/extensionsWidgets.ts b/src/vs/workbench/contrib/extensions/browser/extensionsWidgets.ts index 0271565b5fd79..64d97457b0378 100644 --- a/src/vs/workbench/contrib/extensions/browser/extensionsWidgets.ts +++ b/src/vs/workbench/contrib/extensions/browser/extensionsWidgets.ts @@ -388,9 +388,7 @@ export class ExtensionPackCountWidget extends ExtensionWidget { } private clear(): void { - if (this.element) { - this.element.remove(); - } + this.element?.remove(); } render(): void { diff --git a/src/vs/workbench/contrib/extensions/test/electron-browser/extensionRecommendationsService.test.ts b/src/vs/workbench/contrib/extensions/test/electron-browser/extensionRecommendationsService.test.ts index 030f0b5ca8740..d9176de598a83 100644 --- a/src/vs/workbench/contrib/extensions/test/electron-browser/extensionRecommendationsService.test.ts +++ b/src/vs/workbench/contrib/extensions/test/electron-browser/extensionRecommendationsService.test.ts @@ -258,9 +258,7 @@ suite('ExtensionRecommendationsService Test', () => { }); suiteTeardown(() => { - if (experimentService) { - experimentService.dispose(); - } + experimentService?.dispose(); }); setup(() => { diff --git a/src/vs/workbench/contrib/files/browser/editors/textFileSaveErrorHandler.ts b/src/vs/workbench/contrib/files/browser/editors/textFileSaveErrorHandler.ts index 659469ef96865..c82b09ff0e15e 100644 --- a/src/vs/workbench/contrib/files/browser/editors/textFileSaveErrorHandler.ts +++ b/src/vs/workbench/contrib/files/browser/editors/textFileSaveErrorHandler.ts @@ -196,9 +196,7 @@ const pendingResolveSaveConflictMessages: INotificationHandle[] = []; function clearPendingResolveSaveConflictMessages(): void { while (pendingResolveSaveConflictMessages.length > 0) { const item = pendingResolveSaveConflictMessages.pop(); - if (item) { - item.close(); - } + item?.close(); } } diff --git a/src/vs/workbench/contrib/files/browser/explorerService.ts b/src/vs/workbench/contrib/files/browser/explorerService.ts index bfa4654c1e2b2..549f75f919f08 100644 --- a/src/vs/workbench/contrib/files/browser/explorerService.ts +++ b/src/vs/workbench/contrib/files/browser/explorerService.ts @@ -121,9 +121,7 @@ export class ExplorerService implements IExplorerService { } })); this.disposables.add(this.model.onDidChangeRoots(() => { - if (this.view) { - this.view.setTreeInput(); - } + this.view?.setTreeInput(); })); // Refresh explorer when window gets focus to compensate for missing file events #126817 diff --git a/src/vs/workbench/contrib/files/browser/views/explorerView.ts b/src/vs/workbench/contrib/files/browser/views/explorerView.ts index 6e15cf4d9c84b..16b99312386bb 100644 --- a/src/vs/workbench/contrib/files/browser/views/explorerView.ts +++ b/src/vs/workbench/contrib/files/browser/views/explorerView.ts @@ -889,9 +889,7 @@ export class ExplorerView extends ViewPane implements IExplorerView { } override dispose(): void { - if (this.dragHandler) { - this.dragHandler.dispose(); - } + this.dragHandler?.dispose(); super.dispose(); } } diff --git a/src/vs/workbench/contrib/inlayHints/browser/inlayHintsAccessibilty.ts b/src/vs/workbench/contrib/inlayHints/browser/inlayHintsAccessibilty.ts index e3d83192f5121..1cd411eb22c43 100644 --- a/src/vs/workbench/contrib/inlayHints/browser/inlayHintsAccessibilty.ts +++ b/src/vs/workbench/contrib/inlayHints/browser/inlayHintsAccessibilty.ts @@ -185,9 +185,7 @@ registerAction2(class StartReadHints extends EditorAction2 { runEditorCommand(_accessor: ServicesAccessor, editor: ICodeEditor) { const ctrl = InlayHintsAccessibility.get(editor); - if (ctrl) { - ctrl.startInlayHintsReading(); - } + ctrl?.startInlayHintsReading(); } }); @@ -211,9 +209,7 @@ registerAction2(class StopReadHints extends EditorAction2 { runEditorCommand(_accessor: ServicesAccessor, editor: ICodeEditor) { const ctrl = InlayHintsAccessibility.get(editor); - if (ctrl) { - ctrl.stopInlayHintsReading(); - } + ctrl?.stopInlayHintsReading(); } }); diff --git a/src/vs/workbench/contrib/interactive/browser/interactiveEditor.ts b/src/vs/workbench/contrib/interactive/browser/interactiveEditor.ts index 549ca51417f58..f11557510585f 100644 --- a/src/vs/workbench/contrib/interactive/browser/interactiveEditor.ts +++ b/src/vs/workbench/contrib/interactive/browser/interactiveEditor.ts @@ -316,13 +316,9 @@ export class InteractiveEditor extends EditorPane { // there currently is a widget which we still own so // we need to hide it before getting a new widget - if (this.#notebookWidget.value) { - this.#notebookWidget.value.onWillHide(); - } + this.#notebookWidget.value?.onWillHide(); - if (this.#codeEditorWidget) { - this.#codeEditorWidget.dispose(); - } + this.#codeEditorWidget?.dispose(); this.#widgetDisposableStore.clear(); @@ -665,9 +661,7 @@ export class InteractiveEditor extends EditorPane { this.#notebookWidget.value.onWillHide(); } - if (this.#codeEditorWidget) { - this.#codeEditorWidget.dispose(); - } + this.#codeEditorWidget?.dispose(); this.#notebookWidget = { value: undefined }; this.#widgetDisposableStore.clear(); diff --git a/src/vs/workbench/contrib/markers/browser/markersView.ts b/src/vs/workbench/contrib/markers/browser/markersView.ts index 1b322657c386a..826270e143a62 100644 --- a/src/vs/workbench/contrib/markers/browser/markersView.ts +++ b/src/vs/workbench/contrib/markers/browser/markersView.ts @@ -427,9 +427,7 @@ export class MarkersView extends ViewPane implements IMarkersView { for (const element of elements) { if (element instanceof Marker) { const viewModel = this.markersViewModel.getViewModel(element); - if (viewModel) { - viewModel.showLightBulb(); - } + viewModel?.showLightBulb(); } } })); diff --git a/src/vs/workbench/contrib/markers/browser/markersViewActions.ts b/src/vs/workbench/contrib/markers/browser/markersViewActions.ts index a885796864786..d1d3e232cf839 100644 --- a/src/vs/workbench/contrib/markers/browser/markersViewActions.ts +++ b/src/vs/workbench/contrib/markers/browser/markersViewActions.ts @@ -284,15 +284,11 @@ export class MarkersFilterActionViewItem extends BaseActionViewItem { } override focus(): void { - if (this.filterInputBox) { - this.filterInputBox.focus(); - } + this.filterInputBox?.focus(); } override blur(): void { - if (this.filterInputBox) { - this.filterInputBox.blur(); - } + this.filterInputBox?.blur(); } override setFocusable(): void { diff --git a/src/vs/workbench/contrib/notebook/browser/diff/notebookTextDiffEditor.ts b/src/vs/workbench/contrib/notebook/browser/diff/notebookTextDiffEditor.ts index bfaa6a816605d..9c4bcd48daeb2 100644 --- a/src/vs/workbench/contrib/notebook/browser/diff/notebookTextDiffEditor.ts +++ b/src/vs/workbench/contrib/notebook/browser/diff/notebookTextDiffEditor.ts @@ -430,9 +430,7 @@ export class NotebookTextDiffEditor extends EditorPane implements INotebookTextD } private async _createModifiedWebview(id: string, resource: URI): Promise { - if (this._modifiedWebview) { - this._modifiedWebview.dispose(); - } + this._modifiedWebview?.dispose(); this._modifiedWebview = this.instantiationService.createInstance(BackLayerWebView, this, id, resource, { ...this._notebookOptions.computeDiffWebviewOptions(), @@ -449,9 +447,7 @@ export class NotebookTextDiffEditor extends EditorPane implements INotebookTextD } private async _createOriginalWebview(id: string, resource: URI): Promise { - if (this._originalWebview) { - this._originalWebview.dispose(); - } + this._originalWebview?.dispose(); this._originalWebview = this.instantiationService.createInstance(BackLayerWebView, this, id, resource, { ...this._notebookOptions.computeDiffWebviewOptions(), diff --git a/src/vs/workbench/contrib/notebook/browser/notebookEditor.ts b/src/vs/workbench/contrib/notebook/browser/notebookEditor.ts index 084590f8a0c3d..d82c4b964b958 100644 --- a/src/vs/workbench/contrib/notebook/browser/notebookEditor.ts +++ b/src/vs/workbench/contrib/notebook/browser/notebookEditor.ts @@ -182,9 +182,7 @@ export class NotebookEditor extends EditorPane implements IEditorPaneWithSelecti // there currently is a widget which we still own so // we need to hide it before getting a new widget - if (this._widget.value) { - this._widget.value.onWillHide(); - } + this._widget.value?.onWillHide(); this._widget = >this._instantiationService.invokeFunction(this._notebookWidgetService.retrieveWidget, group, input); diff --git a/src/vs/workbench/contrib/notebook/browser/notebookEditorWidget.ts b/src/vs/workbench/contrib/notebook/browser/notebookEditorWidget.ts index fc6500ceba850..80053311f5ad5 100644 --- a/src/vs/workbench/contrib/notebook/browser/notebookEditorWidget.ts +++ b/src/vs/workbench/contrib/notebook/browser/notebookEditorWidget.ts @@ -2530,9 +2530,7 @@ export class NotebookEditorWidget extends Disposable implements INotebookEditorD } findStop() { - if (this._webview) { - this._webview.findStop(); - } + this._webview?.findStop(); } //#endregion diff --git a/src/vs/workbench/contrib/notebook/browser/viewModel/baseCellViewModel.ts b/src/vs/workbench/contrib/notebook/browser/viewModel/baseCellViewModel.ts index b41c7a096f530..178477466b7eb 100644 --- a/src/vs/workbench/contrib/notebook/browser/viewModel/baseCellViewModel.ts +++ b/src/vs/workbench/contrib/notebook/browser/viewModel/baseCellViewModel.ts @@ -608,9 +608,7 @@ export abstract class BaseCellViewModel extends Disposable { this._undoRedoService.removeElements(this.uri); } - if (this._textModelRef) { - this._textModelRef.dispose(); - } + this._textModelRef?.dispose(); } toJSON(): object { diff --git a/src/vs/workbench/contrib/output/browser/outputView.ts b/src/vs/workbench/contrib/output/browser/outputView.ts index a3b51602a063b..c6909ba055679 100644 --- a/src/vs/workbench/contrib/output/browser/outputView.ts +++ b/src/vs/workbench/contrib/output/browser/outputView.ts @@ -149,9 +149,7 @@ export class OutputViewPane extends ViewPane { const input = this.createInput(channel); if (!this.editor.input || !input.matches(this.editor.input)) { - if (this.editorPromise) { - this.editorPromise.cancel(); - } + this.editorPromise?.cancel(); this.editorPromise = createCancelablePromise(token => this.editor.setInput(this.createInput(channel), { preserveFocus: true }, Object.create(null), token) .then(() => this.editor)); } diff --git a/src/vs/workbench/contrib/output/common/outputChannelModel.ts b/src/vs/workbench/contrib/output/common/outputChannelModel.ts index 58f8374650b18..0f6012d68426f 100644 --- a/src/vs/workbench/contrib/output/common/outputChannelModel.ts +++ b/src/vs/workbench/contrib/output/common/outputChannelModel.ts @@ -278,9 +278,7 @@ export class FileOutputChannelModel extends Disposable implements IOutputChannel } protected cancelModelUpdate(): void { - if (this.modelUpdateCancellationSource.value) { - this.modelUpdateCancellationSource.value.cancel(); - } + this.modelUpdateCancellationSource.value?.cancel(); this.modelUpdateCancellationSource.value = undefined; this.appendThrottler.cancel(); this.replacePromise = undefined; diff --git a/src/vs/workbench/contrib/preferences/browser/preferences.contribution.ts b/src/vs/workbench/contrib/preferences/browser/preferences.contribution.ts index 55c802041c093..e1aab482fb591 100644 --- a/src/vs/workbench/contrib/preferences/browser/preferences.contribution.ts +++ b/src/vs/workbench/contrib/preferences/browser/preferences.contribution.ts @@ -613,9 +613,7 @@ class PreferencesActionsContribution extends Disposable implements IWorkbenchCon function settingsEditorFocusSearch(accessor: ServicesAccessor) { const preferencesEditor = getPreferencesEditor(accessor); - if (preferencesEditor) { - preferencesEditor.focusSearch(); - } + preferencesEditor?.focusSearch(); } registerAction2(class extends Action2 { @@ -655,9 +653,7 @@ class PreferencesActionsContribution extends Disposable implements IWorkbenchCon run(accessor: ServicesAccessor) { const preferencesEditor = getPreferencesEditor(accessor); - if (preferencesEditor) { - preferencesEditor.clearSearchResults(); - } + preferencesEditor?.clearSearchResults(); } }); diff --git a/src/vs/workbench/contrib/preferences/browser/settingsEditor2.ts b/src/vs/workbench/contrib/preferences/browser/settingsEditor2.ts index a506b12de3d08..8d38a90bd0612 100644 --- a/src/vs/workbench/contrib/preferences/browser/settingsEditor2.ts +++ b/src/vs/workbench/contrib/preferences/browser/settingsEditor2.ts @@ -1208,9 +1208,7 @@ export class SettingsEditor2 extends EditorPane { } } - if (this.searchResultModel) { - this.searchResultModel.updateChildren(); - } + this.searchResultModel?.updateChildren(); if (this.settingsTreeModel) { this.settingsTreeModel.update(resolvedSettingsRoot); diff --git a/src/vs/workbench/contrib/preferences/browser/settingsTree.ts b/src/vs/workbench/contrib/preferences/browser/settingsTree.ts index 2ad3516e3e981..fb547d47f159d 100644 --- a/src/vs/workbench/contrib/preferences/browser/settingsTree.ts +++ b/src/vs/workbench/contrib/preferences/browser/settingsTree.ts @@ -1006,9 +1006,7 @@ export abstract class AbstractSettingRenderer extends Disposable implements ITre } disposeElement(_element: ITreeNode, _index: number, template: IDisposableTemplate, _height: number | undefined): void { - if ((template as ISettingItemTemplate).elementDisposables) { - (template as ISettingItemTemplate).elementDisposables.clear(); - } + (template as ISettingItemTemplate).elementDisposables?.clear(); } } diff --git a/src/vs/workbench/contrib/preferences/browser/settingsWidgets.ts b/src/vs/workbench/contrib/preferences/browser/settingsWidgets.ts index 756f928dbc431..521bb5b72b187 100644 --- a/src/vs/workbench/contrib/preferences/browser/settingsWidgets.ts +++ b/src/vs/workbench/contrib/preferences/browser/settingsWidgets.ts @@ -624,9 +624,7 @@ export class ListSettingWidget extends AbstractListSettingWidget this.listDisposables.add(DOM.addDisposableListener(rowElement, DOM.EventType.DRAG_END, (ev) => { counter = 0; rowElement.classList.remove('drag-hover'); - if (ev.dataTransfer) { - ev.dataTransfer.clearData(); - } + ev.dataTransfer?.clearData(); if (this.dragDetails) { this.dragDetails = undefined; } diff --git a/src/vs/workbench/contrib/relauncher/browser/relauncher.contribution.ts b/src/vs/workbench/contrib/relauncher/browser/relauncher.contribution.ts index 2f96395016ab3..8e749ba806c1c 100644 --- a/src/vs/workbench/contrib/relauncher/browser/relauncher.contribution.ts +++ b/src/vs/workbench/contrib/relauncher/browser/relauncher.contribution.ts @@ -185,9 +185,7 @@ export class WorkspaceChangeExtHostRelauncher extends Disposable implements IWor }); this._register(toDisposable(() => { - if (this.onDidChangeWorkspaceFoldersUnbind) { - this.onDidChangeWorkspaceFoldersUnbind.dispose(); - } + this.onDidChangeWorkspaceFoldersUnbind?.dispose(); })); } diff --git a/src/vs/workbench/contrib/remote/browser/remote.ts b/src/vs/workbench/contrib/remote/browser/remote.ts index e5ebb7468a58a..8d3bf4279805c 100644 --- a/src/vs/workbench/contrib/remote/browser/remote.ts +++ b/src/vs/workbench/contrib/remote/browser/remote.ts @@ -766,9 +766,7 @@ export class RemoteAgentConnectionStatusListener extends Disposable implements I const reconnectButton = { label: nls.localize('reconnectNow', "Reconnect Now"), callback: () => { - if (reconnectWaitEvent) { - reconnectWaitEvent.skipWait(); - } + reconnectWaitEvent?.skipWait(); } }; @@ -808,9 +806,7 @@ export class RemoteAgentConnectionStatusListener extends Disposable implements I // ReconnectionRunning -> ConnectionGain, ReconnectionPermanentFailure connection.onDidStateChange((e) => { - if (visibleProgress) { - visibleProgress.stopTimer(); - } + visibleProgress?.stopTimer(); if (disposableListener) { disposableListener.dispose(); diff --git a/src/vs/workbench/contrib/remote/browser/remoteExplorer.ts b/src/vs/workbench/contrib/remote/browser/remoteExplorer.ts index 10abb46d2322d..b7fcc95447ba8 100644 --- a/src/vs/workbench/contrib/remote/browser/remoteExplorer.ts +++ b/src/vs/workbench/contrib/remote/browser/remoteExplorer.ts @@ -112,9 +112,7 @@ export class ForwardedPortsView extends Disposable implements IWorkbenchContribu } private async updateActivityBadge() { - if (this._activityBadge) { - this._activityBadge.dispose(); - } + this._activityBadge?.dispose(); if (this.remoteExplorerService.tunnelModel.forwarded.size > 0) { this._activityBadge = this.activityService.showViewActivity(TUNNEL_VIEW_ID, { badge: new NumberBadge(this.remoteExplorerService.tunnelModel.forwarded.size, n => n === 1 ? nls.localize('1forwardedPort', "1 forwarded port") : nls.localize('nForwardedPorts', "{0} forwarded ports", n)) @@ -334,9 +332,7 @@ class OnAutoForwardedAction extends Disposable { return; } - if (this.lastNotification) { - this.lastNotification.close(); - } + this.lastNotification?.close(); let message = this.basicMessage(tunnel); const choices = [this.openBrowserChoice(tunnel)]; if (!isWeb) { @@ -391,9 +387,7 @@ class OnAutoForwardedAction extends Disposable { if (!newTunnel) { return; } - if (this.lastNotification) { - this.lastNotification.close(); - } + this.lastNotification?.close(); this.lastShownPort = newTunnel.tunnelRemotePort; this.lastNotification = this.notificationService.prompt(Severity.Info, this.basicMessage(newTunnel) + this.linkMessage(), @@ -453,9 +447,7 @@ class OutputAutomaticPortForwarding extends Disposable { if (!this.urlFinder && !this.remoteExplorerService.portsFeaturesEnabled) { return; } - if (this.portsFeatures) { - this.portsFeatures.dispose(); - } + this.portsFeatures?.dispose(); this.urlFinder = this._register(new UrlFinder(this.terminalService, this.debugService)); this._register(this.urlFinder.onDidMatchLocalUrl(async (localUrl) => { if (mapHasAddressLocalhostOrAllInterfaces(this.remoteExplorerService.tunnelModel.detected, localUrl.host, localUrl.port)) { @@ -543,9 +535,7 @@ class ProcAutomaticPortForwarding extends Disposable { if (this.candidateListener || !this.remoteExplorerService.portsFeaturesEnabled) { return; } - if (this.portsFeatures) { - this.portsFeatures.dispose(); - } + this.portsFeatures?.dispose(); // Capture list of starting candidates so we don't auto forward them later. await this.setInitialCandidates(); diff --git a/src/vs/workbench/contrib/search/browser/patternInputWidget.ts b/src/vs/workbench/contrib/search/browser/patternInputWidget.ts index 5e9bedd56093e..30e8ca1e9ea5b 100644 --- a/src/vs/workbench/contrib/search/browser/patternInputWidget.ts +++ b/src/vs/workbench/contrib/search/browser/patternInputWidget.ts @@ -70,9 +70,7 @@ export class PatternInputWidget extends Widget implements IThemable { override dispose(): void { super.dispose(); - if (this.inputFocusTracker) { - this.inputFocusTracker.dispose(); - } + this.inputFocusTracker?.dispose(); } setWidth(newWidth: number): void { diff --git a/src/vs/workbench/contrib/search/browser/replaceService.ts b/src/vs/workbench/contrib/search/browser/replaceService.ts index ba8ebda0f190c..d653f37720370 100644 --- a/src/vs/workbench/contrib/search/browser/replaceService.ts +++ b/src/vs/workbench/contrib/search/browser/replaceService.ts @@ -128,9 +128,7 @@ export class ReplaceService implements IReplaceService { }); const input = editor?.input; const disposable = fileMatch.onDispose(() => { - if (input) { - input.dispose(); - } + input?.dispose(); disposable.dispose(); }); await this.updateReplacePreview(fileMatch); diff --git a/src/vs/workbench/contrib/search/browser/search.contribution.ts b/src/vs/workbench/contrib/search/browser/search.contribution.ts index 099169c6ab35b..9a7057668d8ac 100644 --- a/src/vs/workbench/contrib/search/browser/search.contribution.ts +++ b/src/vs/workbench/contrib/search/browser/search.contribution.ts @@ -88,9 +88,7 @@ KeybindingsRegistry.registerCommandAndKeybindingRule({ primary: KeyMod.CtrlCmd | KeyCode.UpArrow, handler: (accessor, args: any) => { const searchView = getSearchView(accessor.get(IViewsService)); - if (searchView) { - searchView.focusPreviousInputBox(); - } + searchView?.focusPreviousInputBox(); } }); @@ -576,9 +574,7 @@ CommandsRegistry.registerCommand({ if (mode === 'view') { const searchView = await openSearchView(accessor.get(IViewsService), true); - if (searchView) { - searchView.searchInFolders(); - } + searchView?.searchInFolders(); } else { return accessor.get(ICommandService).executeCommand(SearchEditorConstants.OpenEditorCommandId, { diff --git a/src/vs/workbench/contrib/search/browser/searchActions.ts b/src/vs/workbench/contrib/search/browser/searchActions.ts index 4b503feac044e..4c60e7d9bd957 100644 --- a/src/vs/workbench/contrib/search/browser/searchActions.ts +++ b/src/vs/workbench/contrib/search/browser/searchActions.ts @@ -65,30 +65,22 @@ function doAppendKeyBindingLabel(label: string, keyBinding: ResolvedKeybinding | export const toggleCaseSensitiveCommand = (accessor: ServicesAccessor) => { const searchView = getSearchView(accessor.get(IViewsService)); - if (searchView) { - searchView.toggleCaseSensitive(); - } + searchView?.toggleCaseSensitive(); }; export const toggleWholeWordCommand = (accessor: ServicesAccessor) => { const searchView = getSearchView(accessor.get(IViewsService)); - if (searchView) { - searchView.toggleWholeWords(); - } + searchView?.toggleWholeWords(); }; export const toggleRegexCommand = (accessor: ServicesAccessor) => { const searchView = getSearchView(accessor.get(IViewsService)); - if (searchView) { - searchView.toggleRegex(); - } + searchView?.toggleRegex(); }; export const togglePreserveCaseCommand = (accessor: ServicesAccessor) => { const searchView = getSearchView(accessor.get(IViewsService)); - if (searchView) { - searchView.togglePreserveCase(); - } + searchView?.togglePreserveCase(); }; export class FocusNextInputAction extends Action { @@ -110,9 +102,7 @@ export class FocusNextInputAction extends Action { } const searchView = getSearchView(this.viewsService); - if (searchView) { - searchView.focusNextInputBox(); - } + searchView?.focusNextInputBox(); } } @@ -135,9 +125,7 @@ export class FocusPreviousInputAction extends Action { } const searchView = getSearchView(this.viewsService); - if (searchView) { - searchView.focusPreviousInputBox(); - } + searchView?.focusPreviousInputBox(); } } @@ -275,17 +263,13 @@ export function expandAll(accessor: ServicesAccessor) { export function clearSearchResults(accessor: ServicesAccessor) { const viewsService = accessor.get(IViewsService); const searchView = getSearchView(viewsService); - if (searchView) { - searchView.clearSearchResults(); - } + searchView?.clearSearchResults(); } export function cancelSearch(accessor: ServicesAccessor) { const viewsService = accessor.get(IViewsService); const searchView = getSearchView(viewsService); - if (searchView) { - searchView.cancelSearch(); - } + searchView?.cancelSearch(); } export function refreshSearch(accessor: ServicesAccessor) { @@ -352,9 +336,7 @@ export class FocusNextSearchResultAction extends Action { } return openSearchView(this.viewsService).then(searchView => { - if (searchView) { - searchView.selectNextMatch(); - } + searchView?.selectNextMatch(); }); } } @@ -378,9 +360,7 @@ export class FocusPreviousSearchResultAction extends Action { } return openSearchView(this.viewsService).then(searchView => { - if (searchView) { - searchView.selectPreviousMatch(); - } + searchView?.selectPreviousMatch(); }); } } @@ -819,9 +799,7 @@ export const clearHistoryCommand: ICommandHandler = accessor => { export const focusSearchListCommand: ICommandHandler = accessor => { const viewsService = accessor.get(IViewsService); openSearchView(viewsService).then(searchView => { - if (searchView) { - searchView.moveFocusToResults(); - } + searchView?.moveFocusToResults(); }); }; diff --git a/src/vs/workbench/contrib/tasks/browser/abstractTaskService.ts b/src/vs/workbench/contrib/tasks/browser/abstractTaskService.ts index 7f856c3e91aad..80dff9689b0bd 100644 --- a/src/vs/workbench/contrib/tasks/browser/abstractTaskService.ts +++ b/src/vs/workbench/contrib/tasks/browser/abstractTaskService.ts @@ -594,9 +594,7 @@ export abstract class AbstractTaskService extends Disposable implements ITaskSer } protected _disposeTaskSystemListeners(): void { - if (this._taskSystemListener) { - this._taskSystemListener.dispose(); - } + this._taskSystemListener?.dispose(); } public registerTaskProvider(provider: ITaskProvider, type: string): IDisposable { @@ -1394,9 +1392,7 @@ export abstract class AbstractTaskService extends Disposable implements ITaskSer const twoTabs = insertSpaces ? ' '.repeat(tabSize * 2) : '\t\t'; stringValue = twoTabs + stringified.slice(0, stringified.length - 1) + twoTabs + stringified.slice(stringified.length - 1); } finally { - if (reference) { - reference.dispose(); - } + reference?.dispose(); } return stringValue; } diff --git a/src/vs/workbench/contrib/terminal/browser/terminalEditor.ts b/src/vs/workbench/contrib/terminal/browser/terminalEditor.ts index 61412cfb781e7..0bdd65b70ebf9 100644 --- a/src/vs/workbench/contrib/terminal/browser/terminalEditor.ts +++ b/src/vs/workbench/contrib/terminal/browser/terminalEditor.ts @@ -137,9 +137,7 @@ export class TerminalEditor extends EditorPane { // Drop selection and focus terminal on Linux to enable middle button paste when click // occurs on the selection itself. const terminal = this._terminalEditorService.activeInstance; - if (terminal) { - terminal.focus(); - } + terminal?.focus(); } else if (event.which === 3) { const rightClickBehavior = this._terminalService.configHelper.config.rightClickBehavior; if (rightClickBehavior === 'nothing') { diff --git a/src/vs/workbench/contrib/terminal/browser/terminalFindWidget.ts b/src/vs/workbench/contrib/terminal/browser/terminalFindWidget.ts index ec5a3cb0aa919..07efa9f55271b 100644 --- a/src/vs/workbench/contrib/terminal/browser/terminalFindWidget.ts +++ b/src/vs/workbench/contrib/terminal/browser/terminalFindWidget.ts @@ -87,9 +87,7 @@ export class TerminalFindWidget extends SimpleFindWidget { super.hide(); this._findWidgetVisible.reset(); const instance = this._terminalService.activeInstance; - if (instance) { - instance.focus(); - } + instance?.focus(); // Terminals in a group currently share a find widget, so hide // all decorations for terminals in this group const activeGroup = this._terminalGroupService.activeGroup; diff --git a/src/vs/workbench/contrib/terminal/browser/terminalView.ts b/src/vs/workbench/contrib/terminal/browser/terminalView.ts index 81916e856effe..7a2505d71bf2f 100644 --- a/src/vs/workbench/contrib/terminal/browser/terminalView.ts +++ b/src/vs/workbench/contrib/terminal/browser/terminalView.ts @@ -240,9 +240,7 @@ export class TerminalViewPane extends ViewPane { return this._instantiationService.createInstance(SingleTerminalTabActionViewItem, action, actions); } case TerminalCommandId.CreateWithProfileButton: { - if (this._tabButtons) { - this._tabButtons.dispose(); - } + this._tabButtons?.dispose(); const actions = getTerminalActionBarArgs(TerminalLocation.Panel, this._terminalProfileService.availableProfiles, this._getDefaultProfileName(), this._terminalProfileService.contributedProfiles, this._instantiationService, this._terminalService, this._contextKeyService, this._commandService, this._dropdownMenu); this._tabButtons = new DropdownWithPrimaryActionViewItem(actions.primaryAction, actions.dropdownAction, actions.dropdownMenuActions, actions.className, this._contextMenuService, {}, this._keybindingService, this._notificationService, this._contextKeyService, this._themeService); diff --git a/src/vs/workbench/contrib/welcomeOverlay/browser/welcomeOverlay.ts b/src/vs/workbench/contrib/welcomeOverlay/browser/welcomeOverlay.ts index f3a0b3d96ac2c..78cd06a4e0f55 100644 --- a/src/vs/workbench/contrib/welcomeOverlay/browser/welcomeOverlay.ts +++ b/src/vs/workbench/contrib/welcomeOverlay/browser/welcomeOverlay.ts @@ -144,9 +144,7 @@ export class HideWelcomeOverlayAction extends Action { } public override run(): Promise { - if (welcomeOverlay) { - welcomeOverlay.hide(); - } + welcomeOverlay?.hide(); return Promise.resolve(); } } diff --git a/src/vs/workbench/contrib/welcomeViews/common/viewsWelcomeContribution.ts b/src/vs/workbench/contrib/welcomeViews/common/viewsWelcomeContribution.ts index e296e0d82a177..13b7e3560be56 100644 --- a/src/vs/workbench/contrib/welcomeViews/common/viewsWelcomeContribution.ts +++ b/src/vs/workbench/contrib/welcomeViews/common/viewsWelcomeContribution.ts @@ -27,9 +27,7 @@ export class ViewsWelcomeContribution extends Disposable implements IWorkbenchCo for (const welcome of contribution.value) { const disposable = this.viewWelcomeContents.get(welcome); - if (disposable) { - disposable.dispose(); - } + disposable?.dispose(); } } diff --git a/src/vs/workbench/services/decorations/test/browser/decorationsService.test.ts b/src/vs/workbench/services/decorations/test/browser/decorationsService.test.ts index c98a7d6919534..c1a086d323f4c 100644 --- a/src/vs/workbench/services/decorations/test/browser/decorationsService.test.ts +++ b/src/vs/workbench/services/decorations/test/browser/decorationsService.test.ts @@ -20,9 +20,7 @@ suite('DecorationsService', function () { let service: DecorationsService; setup(function () { - if (service) { - service.dispose(); - } + service?.dispose(); service = new DecorationsService( new class extends mock() { override extUri = resources.extUri; diff --git a/src/vs/workbench/services/extensions/common/abstractExtensionService.ts b/src/vs/workbench/services/extensions/common/abstractExtensionService.ts index 24259163505e0..c53aba431d567 100644 --- a/src/vs/workbench/services/extensions/common/abstractExtensionService.ts +++ b/src/vs/workbench/services/extensions/common/abstractExtensionService.ts @@ -538,9 +538,7 @@ export abstract class AbstractExtensionService extends Disposable implements IEx } } finally { this._inHandleDeltaExtensions = false; - if (lock) { - lock.dispose(); - } + lock?.dispose(); } } diff --git a/src/vs/workbench/services/extensions/electron-sandbox/electronExtensionService.ts b/src/vs/workbench/services/extensions/electron-sandbox/electronExtensionService.ts index ee051e3d1f17a..4077c1661e40a 100644 --- a/src/vs/workbench/services/extensions/electron-sandbox/electronExtensionService.ts +++ b/src/vs/workbench/services/extensions/electron-sandbox/electronExtensionService.ts @@ -615,9 +615,7 @@ export abstract class ElectronExtensionService extends AbstractExtensionService // Dispose the management connection to avoid reconnecting after the extension host exits const connection = this._remoteAgentService.getConnection(); - if (connection) { - connection.dispose(); - } + connection?.dispose(); if (this._isExtensionDevTestFromCli) { // When CLI testing make sure to exit with proper exit code diff --git a/src/vs/workbench/services/progress/browser/progressService.ts b/src/vs/workbench/services/progress/browser/progressService.ts index c39c0a727da34..faca26a6b7663 100644 --- a/src/vs/workbench/services/progress/browser/progressService.ts +++ b/src/vs/workbench/services/progress/browser/progressService.ts @@ -505,9 +505,7 @@ export class ProgressService extends Disposable implements IProgressService { // Infinite else { - if (discreteProgressRunner) { - discreteProgressRunner.done(); - } + discreteProgressRunner?.done(); progressIndicator.showWhile(promise, options.delay); } diff --git a/src/vs/workbench/services/search/common/fileSearchManager.ts b/src/vs/workbench/services/search/common/fileSearchManager.ts index c5c8b2d10b4d3..4a1199ecbaf21 100644 --- a/src/vs/workbench/services/search/common/fileSearchManager.ts +++ b/src/vs/workbench/services/search/common/fileSearchManager.ts @@ -300,9 +300,7 @@ export class FileSearchManager { clearCache(cacheKey: string): void { const sessionTokenSource = this.getSessionTokenSource(cacheKey); - if (sessionTokenSource) { - sessionTokenSource.cancel(); - } + sessionTokenSource?.cancel(); } private getSessionTokenSource(cacheKey: string | undefined): CancellationTokenSource | undefined { diff --git a/src/vs/workbench/services/search/node/fileSearch.ts b/src/vs/workbench/services/search/node/fileSearch.ts index a7afc5cae5b5e..76eec9e5ad6ab 100644 --- a/src/vs/workbench/services/search/node/fileSearch.ts +++ b/src/vs/workbench/services/search/node/fileSearch.ts @@ -315,9 +315,7 @@ export class FileWalker { if (err || last) { onData = () => { }; - if (this.cmdSW) { - this.cmdSW.stop(); - } + this.cmdSW?.stop(); } cb(err, stdout, last); }; diff --git a/src/vs/workbench/services/search/node/ripgrepTextSearchEngine.ts b/src/vs/workbench/services/search/node/ripgrepTextSearchEngine.ts index 466b5ec5349ee..6224ae3a1d2b7 100644 --- a/src/vs/workbench/services/search/node/ripgrepTextSearchEngine.ts +++ b/src/vs/workbench/services/search/node/ripgrepTextSearchEngine.ts @@ -66,13 +66,9 @@ export class RipgrepTextSearchEngine { const cancel = () => { isDone = true; - if (rgProc) { - rgProc.kill(); - } + rgProc?.kill(); - if (ripgrepParser) { - ripgrepParser.cancel(); - } + ripgrepParser?.cancel(); }; let limitHit = false; diff --git a/src/vs/workbench/services/textfile/common/textFileEditorModelManager.ts b/src/vs/workbench/services/textfile/common/textFileEditorModelManager.ts index 900a7bba75b90..a778f289a95a0 100644 --- a/src/vs/workbench/services/textfile/common/textFileEditorModelManager.ts +++ b/src/vs/workbench/services/textfile/common/textFileEditorModelManager.ts @@ -501,9 +501,7 @@ export class TextFileEditorModelManager extends Disposable implements ITextFileE // dispose any previously stored dispose listener for this resource const disposeListener = this.mapResourceToDisposeListener.get(resource); - if (disposeListener) { - disposeListener.dispose(); - } + disposeListener?.dispose(); // store in cache but remove when model gets disposed this.mapResourceToModel.set(resource, model); diff --git a/src/vs/workbench/services/workspaces/common/workspaceTrust.ts b/src/vs/workbench/services/workspaces/common/workspaceTrust.ts index eefe8b7ffcd9b..ba2e171525419 100644 --- a/src/vs/workbench/services/workspaces/common/workspaceTrust.ts +++ b/src/vs/workbench/services/workspaces/common/workspaceTrust.ts @@ -873,9 +873,7 @@ class WorkspaceTrustMemento { set acceptsOutOfWorkspaceFiles(value: boolean) { this._mementoObject[this._acceptsOutOfWorkspaceFilesKey] = value; - if (this._memento) { - this._memento.saveMemento(); - } + this._memento?.saveMemento(); } get isEmptyWorkspaceTrusted(): boolean | undefined { @@ -885,9 +883,7 @@ class WorkspaceTrustMemento { set isEmptyWorkspaceTrusted(value: boolean | undefined) { this._mementoObject[this._isEmptyWorkspaceTrustedKey] = value; - if (this._memento) { - this._memento.saveMemento(); - } + this._memento?.saveMemento(); } }