From 1cba911717c27aac7c693cafe0a97e81906c1e41 Mon Sep 17 00:00:00 2001 From: Benjamin Pasero Date: Mon, 2 Sep 2019 09:24:43 +0200 Subject: [PATCH] Strict init (#80190) * strict init * more strict props --- src/vs/base/browser/ui/iconLabel/iconLabel.ts | 12 ++++++------ .../base/browser/ui/progressbar/progressbar.ts | 6 +++--- src/vs/base/node/config.ts | 18 +++++++++--------- src/vs/base/parts/storage/node/storage.ts | 4 ++-- src/vs/editor/contrib/find/findWidget.ts | 2 +- .../common/configurationModels.ts | 2 +- .../contextview/browser/contextMenuHandler.ts | 4 ++-- .../files/node/diskFileSystemProvider.ts | 2 +- .../node/watcher/nodejs/watcherService.ts | 4 ++-- .../node/watcher/nsfw/nsfwWatcherService.ts | 4 ++-- .../files/node/watcher/nsfw/watcherService.ts | 9 ++++++--- .../watcher/unix/chokidarWatcherService.ts | 10 +++++----- .../files/node/watcher/unix/watcherService.ts | 11 ++++++++--- .../lifecycle/electron-main/lifecycleMain.ts | 6 +++--- src/vs/platform/storage/node/storageIpc.ts | 2 +- .../storage/node/storageMainService.ts | 2 +- .../api/browser/mainThreadDebugService.ts | 2 +- src/vs/workbench/browser/part.ts | 4 ++-- .../browser/parts/editor/baseEditor.ts | 6 +++--- .../parts/editor/editor.contribution.ts | 2 +- .../browser/parts/editor/editorCommands.ts | 5 ++++- .../browser/parts/editor/editorControl.ts | 4 ++-- .../browser/parts/editor/editorDropTarget.ts | 10 +++++----- .../browser/parts/editor/textDiffEditor.ts | 4 ++-- .../browser/parts/editor/titleControl.ts | 2 +- .../browser/parts/views/viewsViewlet.ts | 2 +- src/vs/workbench/browser/web.simpleservices.ts | 2 +- .../workbench/common/editor/diffEditorInput.ts | 4 ++-- src/vs/workbench/common/editor/editorGroup.ts | 4 ++-- .../common/editor/resourceEditorInput.ts | 4 ++-- .../common/editor/textDiffEditorModel.ts | 2 +- .../common/editor/untitledEditorInput.ts | 4 ++-- .../files/common/editors/fileEditorInput.ts | 2 +- .../contrib/markers/browser/markersModel.ts | 2 +- .../common/preferencesContribution.ts | 2 +- .../quickopen/browser/commandsHandler.ts | 12 ++++++------ .../common/relauncher.contribution.ts | 18 +++++++++--------- .../contrib/search/browser/openFileHandler.ts | 14 +++++++------- .../electron-browser/workspaceStatsService.ts | 2 +- .../electron-browser/telemetryOptOut.ts | 10 ++++------ src/vs/workbench/electron-browser/window.ts | 10 +++++----- .../backup/common/backupFileService.ts | 10 +++++----- .../credentials/browser/credentialsService.ts | 2 +- .../common/preferencesEditorInput.ts | 2 +- src/vs/workbench/test/workbenchTestServices.ts | 1 + 45 files changed, 128 insertions(+), 118 deletions(-) diff --git a/src/vs/base/browser/ui/iconLabel/iconLabel.ts b/src/vs/base/browser/ui/iconLabel/iconLabel.ts index ec4a3c2f6de..b9fc4154234 100644 --- a/src/vs/base/browser/ui/iconLabel/iconLabel.ts +++ b/src/vs/base/browser/ui/iconLabel/iconLabel.ts @@ -27,11 +27,11 @@ export interface IIconLabelValueOptions { } class FastLabelNode { - private disposed: boolean; - private _textContent: string; - private _className: string; - private _title: string; - private _empty: boolean; + private disposed: boolean | undefined; + private _textContent: string | undefined; + private _className: string | undefined; + private _title: string | undefined; + private _empty: boolean | undefined; constructor(private _element: HTMLElement) { } @@ -89,7 +89,7 @@ export class IconLabel extends Disposable { private domNode: FastLabelNode; private labelDescriptionContainer: FastLabelNode; private labelNode: FastLabelNode | HighlightedLabel; - private descriptionNode: FastLabelNode | HighlightedLabel; + private descriptionNode: FastLabelNode | HighlightedLabel | undefined; private descriptionNodeFactory: () => FastLabelNode | HighlightedLabel; constructor(container: HTMLElement, options?: IIconLabelCreationOptions) { diff --git a/src/vs/base/browser/ui/progressbar/progressbar.ts b/src/vs/base/browser/ui/progressbar/progressbar.ts index ce3a86a4d30..405bfe80c05 100644 --- a/src/vs/base/browser/ui/progressbar/progressbar.ts +++ b/src/vs/base/browser/ui/progressbar/progressbar.ts @@ -36,8 +36,8 @@ const defaultOpts = { export class ProgressBar extends Disposable { private options: IProgressBarOptions; private workedVal: number; - private element: HTMLElement; - private bit: HTMLElement; + private element!: HTMLElement; + private bit!: HTMLElement; private totalWork: number | undefined; private progressBarBackground: Color | undefined; private showDelayedScheduler: RunOnceScheduler; @@ -232,4 +232,4 @@ export class ProgressBar extends Disposable { this.bit.style.backgroundColor = background; } } -} \ No newline at end of file +} diff --git a/src/vs/base/node/config.ts b/src/vs/base/node/config.ts index 4e12fd565ea..6fac5849f96 100644 --- a/src/vs/base/node/config.ts +++ b/src/vs/base/node/config.ts @@ -42,11 +42,11 @@ export interface IConfigOptions { * - configurable defaults */ export class ConfigWatcher extends Disposable implements IConfigWatcher { - private cache: T; - private parseErrors: json.ParseError[]; - private disposed: boolean; - private loaded: boolean; - private timeoutHandle: NodeJS.Timer | null; + private cache: T | undefined; + private parseErrors: json.ParseError[] | undefined; + private disposed: boolean | undefined; + private loaded: boolean | undefined; + private timeoutHandle: NodeJS.Timer | null | undefined; private readonly _onDidUpdateConfiguration: Emitter>; constructor(private _path: string, private options: IConfigOptions = { defaultConfig: Object.create(null), onError: error => console.error(error) }) { @@ -62,7 +62,7 @@ export class ConfigWatcher extends Disposable implements IConfigWatcher { } get hasParseErrors(): boolean { - return this.parseErrors && this.parseErrors.length > 0; + return !!this.parseErrors && this.parseErrors.length > 0; } get onDidUpdateConfiguration(): Event> { @@ -161,7 +161,7 @@ export class ConfigWatcher extends Disposable implements IConfigWatcher { if (!objects.equals(currentConfig, this.cache)) { this.updateCache(currentConfig); - this._onDidUpdateConfiguration.fire({ config: this.cache }); + this._onDidUpdateConfiguration.fire({ config: currentConfig }); } if (callback) { @@ -173,7 +173,7 @@ export class ConfigWatcher extends Disposable implements IConfigWatcher { getConfig(): T { this.ensureLoaded(); - return this.cache; + return this.cache!; } private ensureLoaded(): void { @@ -186,4 +186,4 @@ export class ConfigWatcher extends Disposable implements IConfigWatcher { this.disposed = true; super.dispose(); } -} \ No newline at end of file +} diff --git a/src/vs/base/parts/storage/node/storage.ts b/src/vs/base/parts/storage/node/storage.ts index edf313654aa..85a3ef2d9ac 100644 --- a/src/vs/base/parts/storage/node/storage.ts +++ b/src/vs/base/parts/storage/node/storage.ts @@ -420,8 +420,8 @@ export class SQLiteStorageDatabase implements IStorageDatabase { } class SQLiteStorageDatabaseLogger { - private readonly logTrace: (msg: string) => void; - private readonly logError: (error: string | Error) => void; + private readonly logTrace: ((msg: string) => void) | undefined; + private readonly logError: ((error: string | Error) => void) | undefined; constructor(options?: ISQLiteStorageDatabaseLoggingOptions) { if (options && typeof options.logTrace === 'function') { diff --git a/src/vs/editor/contrib/find/findWidget.ts b/src/vs/editor/contrib/find/findWidget.ts index d35752a078d..383f158c1de 100644 --- a/src/vs/editor/contrib/find/findWidget.ts +++ b/src/vs/editor/contrib/find/findWidget.ts @@ -111,7 +111,7 @@ export class FindWidget extends Widget implements IOverlayWidget, IHorizontalSas private readonly _notificationService: INotificationService; private _domNode!: HTMLElement; - private _cachedHeight: number | null; + private _cachedHeight: number | null = null; private _findInput!: FindInput; private _replaceInput!: ReplaceInput; diff --git a/src/vs/platform/configuration/common/configurationModels.ts b/src/vs/platform/configuration/common/configurationModels.ts index 373a2e1b086..c4749186815 100644 --- a/src/vs/platform/configuration/common/configurationModels.ts +++ b/src/vs/platform/configuration/common/configurationModels.ts @@ -441,7 +441,7 @@ export class Configuration { return this._defaultConfiguration; } - private _userConfiguration: ConfigurationModel | null; + private _userConfiguration: ConfigurationModel | null = null; get userConfiguration(): ConfigurationModel { if (!this._userConfiguration) { this._userConfiguration = this._remoteUserConfiguration.isEmpty() ? this._localUserConfiguration : this._localUserConfiguration.merge(this._remoteUserConfiguration); diff --git a/src/vs/platform/contextview/browser/contextMenuHandler.ts b/src/vs/platform/contextview/browser/contextMenuHandler.ts index 8ab9ccc2d82..921a5f810a5 100644 --- a/src/vs/platform/contextview/browser/contextMenuHandler.ts +++ b/src/vs/platform/contextview/browser/contextMenuHandler.ts @@ -24,8 +24,8 @@ export interface IContextMenuHandlerOptions { } export class ContextMenuHandler { - private focusToReturn: HTMLElement; - private block: HTMLElement | null; + private focusToReturn: HTMLElement | null = null; + private block: HTMLElement | null = null; private options: IContextMenuHandlerOptions = { blockMouse: true }; constructor( diff --git a/src/vs/platform/files/node/diskFileSystemProvider.ts b/src/vs/platform/files/node/diskFileSystemProvider.ts index 12d5847389d..d66ef03839c 100644 --- a/src/vs/platform/files/node/diskFileSystemProvider.ts +++ b/src/vs/platform/files/node/diskFileSystemProvider.ts @@ -38,7 +38,7 @@ export class DiskFileSystemProvider extends Disposable implements IFileSystemPro onDidChangeCapabilities: Event = Event.None; - protected _capabilities: FileSystemProviderCapabilities; + protected _capabilities: FileSystemProviderCapabilities | undefined; get capabilities(): FileSystemProviderCapabilities { if (!this._capabilities) { this._capabilities = diff --git a/src/vs/platform/files/node/watcher/nodejs/watcherService.ts b/src/vs/platform/files/node/watcher/nodejs/watcherService.ts index 58c4a327734..b2bf3498400 100644 --- a/src/vs/platform/files/node/watcher/nodejs/watcherService.ts +++ b/src/vs/platform/files/node/watcher/nodejs/watcherService.ts @@ -13,7 +13,7 @@ import { ThrottledDelayer } from 'vs/base/common/async'; import { join, basename } from 'vs/base/common/path'; export class FileWatcher extends Disposable { - private isDisposed: boolean; + private isDisposed: boolean | undefined; private fileChangesDelayer: ThrottledDelayer = this._register(new ThrottledDelayer(CHANGE_BUFFER_DELAY * 2 /* sync on delay from underlying library */)); private fileChangesBuffer: IDiskFileChange[] = []; @@ -125,4 +125,4 @@ export class FileWatcher extends Disposable { super.dispose(); } -} \ No newline at end of file +} diff --git a/src/vs/platform/files/node/watcher/nsfw/nsfwWatcherService.ts b/src/vs/platform/files/node/watcher/nsfw/nsfwWatcherService.ts index a9db893575b..916a0492077 100644 --- a/src/vs/platform/files/node/watcher/nsfw/nsfwWatcherService.ts +++ b/src/vs/platform/files/node/watcher/nsfw/nsfwWatcherService.ts @@ -36,8 +36,8 @@ export class NsfwWatcherService implements IWatcherService { private static readonly FS_EVENT_DELAY = 50; // aggregate and only emit events when changes have stopped for this duration (in ms) private _pathWatchers: { [watchPath: string]: IPathWatcher } = {}; - private _verboseLogging: boolean; - private enospcErrorLogged: boolean; + private _verboseLogging: boolean | undefined; + private enospcErrorLogged: boolean | undefined; private _onWatchEvent = new Emitter(); readonly onWatchEvent = this._onWatchEvent.event; diff --git a/src/vs/platform/files/node/watcher/nsfw/watcherService.ts b/src/vs/platform/files/node/watcher/nsfw/watcherService.ts index 8b4673d1934..7a32b3e04b1 100644 --- a/src/vs/platform/files/node/watcher/nsfw/watcherService.ts +++ b/src/vs/platform/files/node/watcher/nsfw/watcherService.ts @@ -12,9 +12,10 @@ import { IWatcherRequest } from 'vs/platform/files/node/watcher/nsfw/watcher'; import { getPathFromAmdModule } from 'vs/base/common/amd'; export class FileWatcher extends Disposable { + private static readonly MAX_RESTARTS = 5; - private service: WatcherChannelClient; + private service: WatcherChannelClient | undefined; private isDisposed: boolean; private restartCounter: number; @@ -77,7 +78,7 @@ export class FileWatcher extends Disposable { setVerboseLogging(verboseLogging: boolean): void { this.verboseLogging = verboseLogging; - if (!this.isDisposed) { + if (!this.isDisposed && this.service) { this.service.setVerboseLogging(verboseLogging); } } @@ -89,7 +90,9 @@ export class FileWatcher extends Disposable { setFolders(folders: IWatcherRequest[]): void { this.folders = folders; - this.service.setRoots(folders); + if (this.service) { + this.service.setRoots(folders); + } } dispose(): void { diff --git a/src/vs/platform/files/node/watcher/unix/chokidarWatcherService.ts b/src/vs/platform/files/node/watcher/unix/chokidarWatcherService.ts index a03e76ba178..5976158610b 100644 --- a/src/vs/platform/files/node/watcher/unix/chokidarWatcherService.ts +++ b/src/vs/platform/files/node/watcher/unix/chokidarWatcherService.ts @@ -37,11 +37,11 @@ export class ChokidarWatcherService implements IWatcherService { private _pollingInterval?: number; private _usePolling?: boolean; - private _verboseLogging: boolean; + private _verboseLogging: boolean | undefined; - private spamCheckStartTime: number; - private spamWarningLogged: boolean; - private enospcErrorLogged: boolean; + private spamCheckStartTime: number | undefined; + private spamWarningLogged: boolean | undefined; + private enospcErrorLogged: boolean | undefined; private _onWatchEvent = new Emitter(); readonly onWatchEvent = this._onWatchEvent.event; @@ -231,7 +231,7 @@ export class ChokidarWatcherService implements IWatcherService { if (undeliveredFileEvents.length === 0) { this.spamWarningLogged = false; this.spamCheckStartTime = now; - } else if (!this.spamWarningLogged && this.spamCheckStartTime + ChokidarWatcherService.EVENT_SPAM_WARNING_THRESHOLD < now) { + } else if (!this.spamWarningLogged && typeof this.spamCheckStartTime === 'number' && this.spamCheckStartTime + ChokidarWatcherService.EVENT_SPAM_WARNING_THRESHOLD < now) { this.spamWarningLogged = true; this.warn(`Watcher is busy catching up with ${undeliveredFileEvents.length} file changes in 60 seconds. Latest changed path is "${event.path}"`); } diff --git a/src/vs/platform/files/node/watcher/unix/watcherService.ts b/src/vs/platform/files/node/watcher/unix/watcherService.ts index 18d55aec1d8..5fd8d4e39aa 100644 --- a/src/vs/platform/files/node/watcher/unix/watcherService.ts +++ b/src/vs/platform/files/node/watcher/unix/watcherService.ts @@ -16,7 +16,7 @@ export class FileWatcher extends Disposable { private isDisposed: boolean; private restartCounter: number; - private service: WatcherChannelClient; + private service: WatcherChannelClient | undefined; constructor( private folders: IWatcherRequest[], @@ -81,13 +81,18 @@ export class FileWatcher extends Disposable { setVerboseLogging(verboseLogging: boolean): void { this.verboseLogging = verboseLogging; - this.service.setVerboseLogging(verboseLogging); + + if (this.service) { + this.service.setVerboseLogging(verboseLogging); + } } setFolders(folders: IWatcherRequest[]): void { this.folders = folders; - this.service.setRoots(folders); + if (this.service) { + this.service.setRoots(folders); + } } dispose(): void { diff --git a/src/vs/platform/lifecycle/electron-main/lifecycleMain.ts b/src/vs/platform/lifecycle/electron-main/lifecycleMain.ts index bdecf24ff13..72f2d7c124f 100644 --- a/src/vs/platform/lifecycle/electron-main/lifecycleMain.ts +++ b/src/vs/platform/lifecycle/electron-main/lifecycleMain.ts @@ -139,10 +139,10 @@ export class LifecycleService extends Disposable implements ILifecycleService { private oneTimeListenerTokenGenerator = 0; private windowCounter = 0; - private pendingQuitPromise: Promise | null; - private pendingQuitPromiseResolve: { (veto: boolean): void } | null; + private pendingQuitPromise: Promise | null = null; + private pendingQuitPromiseResolve: { (veto: boolean): void } | null = null; - private pendingWillShutdownPromise: Promise | null; + private pendingWillShutdownPromise: Promise | null = null; private _quitRequested = false; get quitRequested(): boolean { return this._quitRequested; } diff --git a/src/vs/platform/storage/node/storageIpc.ts b/src/vs/platform/storage/node/storageIpc.ts index ac5926cc249..f74005b5ed4 100644 --- a/src/vs/platform/storage/node/storageIpc.ts +++ b/src/vs/platform/storage/node/storageIpc.ts @@ -152,7 +152,7 @@ export class GlobalStorageDatabaseChannelClient extends Disposable implements IS private readonly _onDidChangeItemsExternal: Emitter = this._register(new Emitter()); readonly onDidChangeItemsExternal: Event = this._onDidChangeItemsExternal.event; - private onDidChangeItemsOnMainListener: IDisposable; + private onDidChangeItemsOnMainListener: IDisposable | undefined; constructor(private channel: IChannel) { super(); diff --git a/src/vs/platform/storage/node/storageMainService.ts b/src/vs/platform/storage/node/storageMainService.ts index 95274a2350b..70cdeef730d 100644 --- a/src/vs/platform/storage/node/storageMainService.ts +++ b/src/vs/platform/storage/node/storageMainService.ts @@ -99,7 +99,7 @@ export class StorageMainService extends Disposable implements IStorageMainServic private storage: IStorage; - private initializePromise: Promise; + private initializePromise: Promise | undefined; constructor( @ILogService private readonly logService: ILogService, diff --git a/src/vs/workbench/api/browser/mainThreadDebugService.ts b/src/vs/workbench/api/browser/mainThreadDebugService.ts index 2f0f5283bfd..fc830d3ddc2 100644 --- a/src/vs/workbench/api/browser/mainThreadDebugService.ts +++ b/src/vs/workbench/api/browser/mainThreadDebugService.ts @@ -21,7 +21,7 @@ export class MainThreadDebugService implements MainThreadDebugServiceShape, IDeb private readonly _proxy: ExtHostDebugServiceShape; private readonly _toDispose = new DisposableStore(); - private _breakpointEventsActive: boolean; + private _breakpointEventsActive: boolean | undefined; private readonly _debugAdapters: Map; private _debugAdaptersHandleCounter = 1; private readonly _debugConfigurationProviders: Map; diff --git a/src/vs/workbench/browser/part.ts b/src/vs/workbench/browser/part.ts index c78ad168cb7..da759cd76e1 100644 --- a/src/vs/workbench/browser/part.ts +++ b/src/vs/workbench/browser/part.ts @@ -33,8 +33,8 @@ export abstract class Part extends Component implements ISerializableView { get dimension(): Dimension { return this._dimension; } private parent: HTMLElement; - private titleArea: HTMLElement | null; - private contentArea: HTMLElement | null; + private titleArea: HTMLElement | null = null; + private contentArea: HTMLElement | null = null; private partLayout: PartLayout; constructor( diff --git a/src/vs/workbench/browser/parts/editor/baseEditor.ts b/src/vs/workbench/browser/parts/editor/baseEditor.ts index 53f5fa55ce7..8bbf5ca5b64 100644 --- a/src/vs/workbench/browser/parts/editor/baseEditor.ts +++ b/src/vs/workbench/browser/parts/editor/baseEditor.ts @@ -41,8 +41,8 @@ export abstract class BaseEditor extends Panel implements IEditor { readonly onDidSizeConstraintsChange: Event<{ width: number; height: number; } | undefined> = Event.None; - protected _input: EditorInput | null; - protected _options: EditorOptions | null; + protected _input: EditorInput | null = null; + protected _options: EditorOptions | null = null; private _group?: IEditorGroup; @@ -172,7 +172,7 @@ interface MapGroupToMemento { } export class EditorMemento implements IEditorMemento { - private cache: LRUCache>; + private cache: LRUCache> | undefined; private cleanedUp = false; constructor( diff --git a/src/vs/workbench/browser/parts/editor/editor.contribution.ts b/src/vs/workbench/browser/parts/editor/editor.contribution.ts index 162e7f25cb8..915c264daea 100644 --- a/src/vs/workbench/browser/parts/editor/editor.contribution.ts +++ b/src/vs/workbench/browser/parts/editor/editor.contribution.ts @@ -229,7 +229,7 @@ registry.registerWorkbenchAction(new SyncActionDescriptor(ChangeEOLAction, Chang registry.registerWorkbenchAction(new SyncActionDescriptor(ChangeEncodingAction, ChangeEncodingAction.ID, ChangeEncodingAction.LABEL), 'Change File Encoding'); export class QuickOpenActionContributor extends ActionBarContributor { - private openToSideActionInstance: OpenToSideFromQuickOpenAction; + private openToSideActionInstance: OpenToSideFromQuickOpenAction | undefined; constructor(@IInstantiationService private readonly instantiationService: IInstantiationService) { super(); diff --git a/src/vs/workbench/browser/parts/editor/editorCommands.ts b/src/vs/workbench/browser/parts/editor/editorCommands.ts index 638c44e147e..654a9c96650 100644 --- a/src/vs/workbench/browser/parts/editor/editorCommands.ts +++ b/src/vs/workbench/browser/parts/editor/editorCommands.ts @@ -263,7 +263,10 @@ function registerDiffEditorCommands(): void { const candidates = [editorService.activeControl, ...editorService.visibleControls].filter(e => e instanceof TextDiffEditor); if (candidates.length > 0) { - next ? (candidates[0]).getDiffNavigator().next() : (candidates[0]).getDiffNavigator().previous(); + const navigator = (candidates[0]).getDiffNavigator(); + if (navigator) { + next ? navigator.next() : navigator.previous(); + } } } diff --git a/src/vs/workbench/browser/parts/editor/editorControl.ts b/src/vs/workbench/browser/parts/editor/editorControl.ts index 9b59e8e38f7..9f29b3a6523 100644 --- a/src/vs/workbench/browser/parts/editor/editorControl.ts +++ b/src/vs/workbench/browser/parts/editor/editorControl.ts @@ -35,11 +35,11 @@ export class EditorControl extends Disposable { private _onDidSizeConstraintsChange = this._register(new Emitter<{ width: number; height: number; } | undefined>()); get onDidSizeConstraintsChange(): Event<{ width: number; height: number; } | undefined> { return this._onDidSizeConstraintsChange.event; } - private _activeControl: BaseEditor | null; + private _activeControl: BaseEditor | null = null; private controls: BaseEditor[] = []; private readonly activeControlDisposables = this._register(new DisposableStore()); - private dimension: Dimension; + private dimension: Dimension | undefined; private editorOperation: LongRunningOperation; constructor( diff --git a/src/vs/workbench/browser/parts/editor/editorDropTarget.ts b/src/vs/workbench/browser/parts/editor/editorDropTarget.ts index 97cabc264b6..2113a4e7c50 100644 --- a/src/vs/workbench/browser/parts/editor/editorDropTarget.ts +++ b/src/vs/workbench/browser/parts/editor/editorDropTarget.ts @@ -25,11 +25,11 @@ class DropOverlay extends Themable { private static OVERLAY_ID = 'monaco-workbench-editor-drop-overlay'; - private container: HTMLElement; - private overlay: HTMLElement; + private container!: HTMLElement; + private overlay!: HTMLElement; - private currentDropOperation?: IDropOperation; - private _disposed: boolean; + private currentDropOperation: IDropOperation | undefined; + private _disposed: boolean | undefined; private cleanupOverlayScheduler: RunOnceScheduler; @@ -50,7 +50,7 @@ class DropOverlay extends Themable { } get disposed(): boolean { - return this._disposed; + return !!this._disposed; } private create(): void { diff --git a/src/vs/workbench/browser/parts/editor/textDiffEditor.ts b/src/vs/workbench/browser/parts/editor/textDiffEditor.ts index 7b791423c5e..3b69c58802d 100644 --- a/src/vs/workbench/browser/parts/editor/textDiffEditor.ts +++ b/src/vs/workbench/browser/parts/editor/textDiffEditor.ts @@ -40,7 +40,7 @@ export class TextDiffEditor extends BaseTextEditor implements ITextDiffEditor { static readonly ID = TEXT_DIFF_EDITOR_ID; - private diffNavigator: DiffNavigator; + private diffNavigator: DiffNavigator | undefined; private readonly diffNavigatorDisposables = this._register(new DisposableStore()); constructor( @@ -257,7 +257,7 @@ export class TextDiffEditor extends BaseTextEditor implements ITextDiffEditor { super.clearInput(); } - getDiffNavigator(): DiffNavigator { + getDiffNavigator(): DiffNavigator | undefined { return this.diffNavigator; } diff --git a/src/vs/workbench/browser/parts/editor/titleControl.ts b/src/vs/workbench/browser/parts/editor/titleControl.ts index 967a587184f..97d9bb6aee1 100644 --- a/src/vs/workbench/browser/parts/editor/titleControl.ts +++ b/src/vs/workbench/browser/parts/editor/titleControl.ts @@ -57,7 +57,7 @@ export abstract class TitleControl extends Themable { private currentPrimaryEditorActionIds: string[] = []; private currentSecondaryEditorActionIds: string[] = []; - protected editorActionsToolbar: ToolBar; + private editorActionsToolbar: ToolBar; private resourceContext: ResourceContextKey; private editorPinnedContext: IContextKey; diff --git a/src/vs/workbench/browser/parts/views/viewsViewlet.ts b/src/vs/workbench/browser/parts/views/viewsViewlet.ts index 3100093436c..6413ac3173f 100644 --- a/src/vs/workbench/browser/parts/views/viewsViewlet.ts +++ b/src/vs/workbench/browser/parts/views/viewsViewlet.ts @@ -39,7 +39,7 @@ export abstract class ViewContainerViewlet extends PanelViewlet implements IView private readonly viewletState: MementoObject; private didLayout = false; - private dimension: DOM.Dimension; + private dimension: DOM.Dimension | undefined; private areExtensionsReady: boolean = false; private readonly visibleViewsCountFromCache: number | undefined; diff --git a/src/vs/workbench/browser/web.simpleservices.ts b/src/vs/workbench/browser/web.simpleservices.ts index d2729c92609..caf44465e73 100644 --- a/src/vs/workbench/browser/web.simpleservices.ts +++ b/src/vs/workbench/browser/web.simpleservices.ts @@ -41,7 +41,7 @@ export class SimpleUpdateService implements IUpdateService { _serviceBrand: undefined; onStateChange = Event.None; - state: State; + state!: State; checkForUpdates(context: any): Promise { return Promise.resolve(undefined); diff --git a/src/vs/workbench/common/editor/diffEditorInput.ts b/src/vs/workbench/common/editor/diffEditorInput.ts index 477d54e754c..bd2b9376854 100644 --- a/src/vs/workbench/common/editor/diffEditorInput.ts +++ b/src/vs/workbench/common/editor/diffEditorInput.ts @@ -16,7 +16,7 @@ export class DiffEditorInput extends SideBySideEditorInput { static readonly ID = 'workbench.editors.diffEditorInput'; - private cachedModel: DiffEditorModel | null; + private cachedModel: DiffEditorModel | null = null; constructor(name: string, description: string | undefined, original: EditorInput, modified: EditorInput, private readonly forceOpenAsBinary?: boolean) { super(name, description, original, modified); @@ -86,4 +86,4 @@ export class DiffEditorInput extends SideBySideEditorInput { super.dispose(); } -} \ No newline at end of file +} diff --git a/src/vs/workbench/common/editor/editorGroup.ts b/src/vs/workbench/common/editor/editorGroup.ts index 5b207d4a79d..a8b139501be 100644 --- a/src/vs/workbench/common/editor/editorGroup.ts +++ b/src/vs/workbench/common/editor/editorGroup.ts @@ -94,8 +94,8 @@ export class EditorGroup extends Disposable { private mru: EditorInput[] = []; private mapResourceToEditorCount: ResourceMap = new ResourceMap(); - private preview: EditorInput | null; // editor in preview state - private active: EditorInput | null; // editor in active state + private preview: EditorInput | null = null; // editor in preview state + private active: EditorInput | null = null; // editor in active state private editorOpenPositioning: 'left' | 'right' | 'first' | 'last'; private focusRecentEditorAfterClose: boolean; diff --git a/src/vs/workbench/common/editor/resourceEditorInput.ts b/src/vs/workbench/common/editor/resourceEditorInput.ts index 8ea157dffc2..1d7712d1c4e 100644 --- a/src/vs/workbench/common/editor/resourceEditorInput.ts +++ b/src/vs/workbench/common/editor/resourceEditorInput.ts @@ -17,8 +17,8 @@ export class ResourceEditorInput extends EditorInput implements IModeSupport { static readonly ID: string = 'workbench.editors.resourceEditorInput'; - private cachedModel: ResourceEditorModel | null; - private modelReference: Promise> | null; + private cachedModel: ResourceEditorModel | null = null; + private modelReference: Promise> | null = null; constructor( private name: string, diff --git a/src/vs/workbench/common/editor/textDiffEditorModel.ts b/src/vs/workbench/common/editor/textDiffEditorModel.ts index 1f48d92db29..7f359e23f8a 100644 --- a/src/vs/workbench/common/editor/textDiffEditorModel.ts +++ b/src/vs/workbench/common/editor/textDiffEditorModel.ts @@ -17,7 +17,7 @@ export class TextDiffEditorModel extends DiffEditorModel { protected readonly _originalModel: BaseTextEditorModel; protected readonly _modifiedModel: BaseTextEditorModel; - private _textDiffEditorModel: IDiffEditorModel | null; + private _textDiffEditorModel: IDiffEditorModel | null = null; constructor(originalModel: BaseTextEditorModel, modifiedModel: BaseTextEditorModel) { super(originalModel, modifiedModel); diff --git a/src/vs/workbench/common/editor/untitledEditorInput.ts b/src/vs/workbench/common/editor/untitledEditorInput.ts index 1a0af06b7a7..adae5eddbd3 100644 --- a/src/vs/workbench/common/editor/untitledEditorInput.ts +++ b/src/vs/workbench/common/editor/untitledEditorInput.ts @@ -23,8 +23,8 @@ export class UntitledEditorInput extends EditorInput implements IEncodingSupport static readonly ID: string = 'workbench.editors.untitledEditorInput'; - private cachedModel: UntitledEditorModel | null; - private modelResolve: Promise | null; + private cachedModel: UntitledEditorModel | null = null; + private modelResolve: Promise | null = null; private readonly _onDidModelChangeContent: Emitter = this._register(new Emitter()); readonly onDidModelChangeContent: Event = this._onDidModelChangeContent.event; diff --git a/src/vs/workbench/contrib/files/common/editors/fileEditorInput.ts b/src/vs/workbench/contrib/files/common/editors/fileEditorInput.ts index b95d1949bdf..e395251dc29 100644 --- a/src/vs/workbench/contrib/files/common/editors/fileEditorInput.ts +++ b/src/vs/workbench/contrib/files/common/editors/fileEditorInput.ts @@ -33,7 +33,7 @@ export class FileEditorInput extends EditorInput implements IFileEditorInput { private forceOpenAs: ForceOpenAs = ForceOpenAs.None; - private textModelReference: Promise> | null; + private textModelReference: Promise> | null = null; private name: string; /** diff --git a/src/vs/workbench/contrib/markers/browser/markersModel.ts b/src/vs/workbench/contrib/markers/browser/markersModel.ts index 857e74d0cad..9d0c046913a 100644 --- a/src/vs/workbench/contrib/markers/browser/markersModel.ts +++ b/src/vs/workbench/contrib/markers/browser/markersModel.ts @@ -58,7 +58,7 @@ export class Marker { get resource(): URI { return this.marker.resource; } get range(): IRange { return this.marker; } - private _lines: string[]; + private _lines: string[] | undefined; get lines(): string[] { if (!this._lines) { this._lines = this.marker.message.split(/\r\n|\r|\n/g); diff --git a/src/vs/workbench/contrib/preferences/common/preferencesContribution.ts b/src/vs/workbench/contrib/preferences/common/preferencesContribution.ts index 6e7f43ffcfa..cde13f2ab32 100644 --- a/src/vs/workbench/contrib/preferences/common/preferencesContribution.ts +++ b/src/vs/workbench/contrib/preferences/common/preferencesContribution.ts @@ -26,7 +26,7 @@ import { FOLDER_SETTINGS_PATH, IPreferencesService, USE_SPLIT_JSON_SETTING } fro const schemaRegistry = Registry.as(JSONContributionRegistry.Extensions.JSONContribution); export class PreferencesContribution implements IWorkbenchContribution { - private editorOpeningListener: IDisposable; + private editorOpeningListener: IDisposable | undefined; private settingsListener: IDisposable; constructor( diff --git a/src/vs/workbench/contrib/quickopen/browser/commandsHandler.ts b/src/vs/workbench/contrib/quickopen/browser/commandsHandler.ts index 3aa5697ed25..7b7803814e0 100644 --- a/src/vs/workbench/contrib/quickopen/browser/commandsHandler.ts +++ b/src/vs/workbench/contrib/quickopen/browser/commandsHandler.ts @@ -217,8 +217,8 @@ class CommandPaletteEditorAction extends EditorAction { } abstract class BaseCommandEntry extends QuickOpenEntryGroup { - private description: string; - private alias: string; + private description: string | undefined; + private alias: string | undefined; private labelLowercase: string; private readonly keybindingAriaLabel?: string; @@ -258,7 +258,7 @@ abstract class BaseCommandEntry extends QuickOpenEntryGroup { return this.labelLowercase; } - getDescription(): string { + getDescription(): string | undefined { return this.description; } @@ -270,7 +270,7 @@ abstract class BaseCommandEntry extends QuickOpenEntryGroup { return this.keybinding; } - getDetail(): string { + getDetail(): string | undefined { return this.alias; } @@ -381,13 +381,13 @@ export class CommandsHandler extends QuickOpenHandler implements IDisposable { static readonly ID = 'workbench.picker.commands'; - private commandHistoryEnabled: boolean; + private commandHistoryEnabled: boolean | undefined; private readonly commandsHistory: CommandsHistory; private readonly disposables = new DisposableStore(); private readonly disposeOnClose = new DisposableStore(); - private waitedForExtensionsRegistered: boolean; + private waitedForExtensionsRegistered: boolean | undefined; constructor( @IEditorService private readonly editorService: IEditorService, diff --git a/src/vs/workbench/contrib/relauncher/common/relauncher.contribution.ts b/src/vs/workbench/contrib/relauncher/common/relauncher.contribution.ts index 2ec3089894f..d691ca646e3 100644 --- a/src/vs/workbench/contrib/relauncher/common/relauncher.contribution.ts +++ b/src/vs/workbench/contrib/relauncher/common/relauncher.contribution.ts @@ -29,15 +29,15 @@ interface IConfiguration extends IWindowsConfiguration { export class SettingsChangeRelauncher extends Disposable implements IWorkbenchContribution { - private titleBarStyle: 'native' | 'custom'; - private nativeTabs: boolean; - private nativeFullScreen: boolean; - private clickThroughInactive: boolean; - private updateMode: string; - private enableCrashReporter: boolean; - private treeHorizontalScrolling: boolean; - private useGridLayout: boolean; - private debugConsoleWordWrap: boolean; + private titleBarStyle: 'native' | 'custom' | undefined; + private nativeTabs: boolean | undefined; + private nativeFullScreen: boolean | undefined; + private clickThroughInactive: boolean | undefined; + private updateMode: string | undefined; + private enableCrashReporter: boolean | undefined; + private treeHorizontalScrolling: boolean | undefined; + private useGridLayout: boolean | undefined; + private debugConsoleWordWrap: boolean | undefined; constructor( @IWindowsService private readonly windowsService: IWindowsService, diff --git a/src/vs/workbench/contrib/search/browser/openFileHandler.ts b/src/vs/workbench/contrib/search/browser/openFileHandler.ts index 39d390233dd..0374b69749f 100644 --- a/src/vs/workbench/contrib/search/browser/openFileHandler.ts +++ b/src/vs/workbench/contrib/search/browser/openFileHandler.ts @@ -114,7 +114,7 @@ export interface IOpenFileOptions { export class OpenFileHandler extends QuickOpenHandler { private options: IOpenFileOptions | undefined; private queryBuilder: QueryBuilder; - private cacheState: CacheState; + private cacheState: CacheState | undefined; constructor( @IInstantiationService private readonly instantiationService: IInstantiationService, @@ -143,7 +143,7 @@ export class OpenFileHandler extends QuickOpenHandler { } // Do find results - return this.doFindResults(query, token, this.cacheState.cacheKey, maxSortedResults); + return this.doFindResults(query, token, this.cacheState ? this.cacheState.cacheKey : undefined, maxSortedResults); } private async doFindResults(query: IPreparedQuery, token: CancellationToken, cacheKey?: string, maxSortedResults?: number): Promise { @@ -246,7 +246,7 @@ export class OpenFileHandler extends QuickOpenHandler { } get isCacheLoaded(): boolean { - return this.cacheState && this.cacheState.isLoaded; + return !!this.cacheState && this.cacheState.isLoaded; } getGroupLabel(): string { @@ -279,14 +279,14 @@ export class CacheState { private loadingPhase = LoadingPhase.Created; private promise: Promise | undefined; - constructor(cacheQuery: (cacheKey: string) => IFileQuery, private doLoad: (query: IFileQuery) => Promise, private doDispose: (cacheKey: string) => Promise, private previous: CacheState | null) { + constructor(cacheQuery: (cacheKey: string) => IFileQuery, private doLoad: (query: IFileQuery) => Promise, private doDispose: (cacheKey: string) => Promise, private previous: CacheState | undefined) { this.query = cacheQuery(this._cacheKey); if (this.previous) { const current = objects.assign({}, this.query, { cacheKey: null }); const previous = objects.assign({}, this.previous.query, { cacheKey: null }); if (!objects.equals(current, previous)) { this.previous.dispose(); - this.previous = null; + this.previous = undefined; } } } @@ -315,7 +315,7 @@ export class CacheState { this.loadingPhase = LoadingPhase.Loaded; if (this.previous) { this.previous.dispose(); - this.previous = null; + this.previous = undefined; } }, err => { this.loadingPhase = LoadingPhase.Errored; @@ -337,7 +337,7 @@ export class CacheState { } if (this.previous) { this.previous.dispose(); - this.previous = null; + this.previous = undefined; } } } diff --git a/src/vs/workbench/contrib/stats/electron-browser/workspaceStatsService.ts b/src/vs/workbench/contrib/stats/electron-browser/workspaceStatsService.ts index cf904ae6e7b..a597f6e017e 100644 --- a/src/vs/workbench/contrib/stats/electron-browser/workspaceStatsService.ts +++ b/src/vs/workbench/contrib/stats/electron-browser/workspaceStatsService.ts @@ -91,7 +91,7 @@ const PyModulesToLookFor = [ export class WorkspaceStatsService implements IWorkspaceStatsService { _serviceBrand: undefined; - private _tags: Tags; + private _tags: Tags | undefined; constructor( @IFileService private readonly fileService: IFileService, diff --git a/src/vs/workbench/contrib/welcome/gettingStarted/electron-browser/telemetryOptOut.ts b/src/vs/workbench/contrib/welcome/gettingStarted/electron-browser/telemetryOptOut.ts index f137c1a6fce..5afb3bb9954 100644 --- a/src/vs/workbench/contrib/welcome/gettingStarted/electron-browser/telemetryOptOut.ts +++ b/src/vs/workbench/contrib/welcome/gettingStarted/electron-browser/telemetryOptOut.ts @@ -22,8 +22,7 @@ import { CancellationToken } from 'vs/base/common/cancellation'; export class TelemetryOptOut implements IWorkbenchContribution { private static TELEMETRY_OPT_OUT_SHOWN = 'workbench.telemetryOptOutShown'; - private privacyUrl: string; - private optOutUrl: string; + private privacyUrl: string | undefined; constructor( @IStorageService storageService: IStorageService, @@ -50,7 +49,6 @@ export class TelemetryOptOut implements IWorkbenchContribution { } storageService.store(TelemetryOptOut.TELEMETRY_OPT_OUT_SHOWN, true, StorageScope.GLOBAL); - this.optOutUrl = product.telemetryOptOutUrl; this.privacyUrl = product.privacyStatementUrl || product.telemetryOptOutUrl; if (experimentState && experimentState.state === ExperimentState.Run && telemetryService.isOptedIn) { @@ -58,15 +56,15 @@ export class TelemetryOptOut implements IWorkbenchContribution { return; } - const optOutNotice = localize('telemetryOptOut.optOutNotice', "Help improve VS Code by allowing Microsoft to collect usage data. Read our [privacy statement]({0}) and learn how to [opt out]({1}).", this.privacyUrl, this.optOutUrl); - const optInNotice = localize('telemetryOptOut.optInNotice', "Help improve VS Code by allowing Microsoft to collect usage data. Read our [privacy statement]({0}) and learn how to [opt in]({1}).", this.privacyUrl, this.optOutUrl); + const optOutNotice = localize('telemetryOptOut.optOutNotice', "Help improve VS Code by allowing Microsoft to collect usage data. Read our [privacy statement]({0}) and learn how to [opt out]({1}).", this.privacyUrl, product.telemetryOptOutUrl); + const optInNotice = localize('telemetryOptOut.optInNotice', "Help improve VS Code by allowing Microsoft to collect usage data. Read our [privacy statement]({0}) and learn how to [opt in]({1}).", this.privacyUrl, product.telemetryOptOutUrl); notificationService.prompt( Severity.Info, telemetryService.isOptedIn ? optOutNotice : optInNotice, [{ label: localize('telemetryOptOut.readMore', "Read More"), - run: () => openerService.open(URI.parse(this.optOutUrl)) + run: () => openerService.open(URI.parse(product.telemetryOptOutUrl)) }], { sticky: true } ); diff --git a/src/vs/workbench/electron-browser/window.ts b/src/vs/workbench/electron-browser/window.ts index 7f13270ca83..53858c70631 100644 --- a/src/vs/workbench/electron-browser/window.ts +++ b/src/vs/workbench/electron-browser/window.ts @@ -70,12 +70,12 @@ const TextInputActions: IAction[] = [ export class ElectronWindow extends Disposable { - private touchBarMenu?: IMenu; - private touchBarUpdater: RunOnceScheduler; + private touchBarMenu: IMenu | undefined; + private touchBarUpdater: RunOnceScheduler | undefined; private readonly touchBarDisposables = this._register(new DisposableStore()); - private lastInstalledTouchedBar: ICommandAction[][]; + private lastInstalledTouchedBar: ICommandAction[][] | undefined; - private previousConfiguredZoomLevel: number; + private previousConfiguredZoomLevel: number | undefined; private addFoldersScheduler: RunOnceScheduler; private pendingFoldersToAdd: URI[]; @@ -406,7 +406,7 @@ export class ElectronWindow extends Disposable { if (!this.touchBarMenu) { this.touchBarMenu = this.editorService.invokeWithinEditorContext(accessor => this.menuService.createMenu(MenuId.TouchBarContext, accessor.get(IContextKeyService))); this.touchBarDisposables.add(this.touchBarMenu); - this.touchBarDisposables.add(this.touchBarMenu.onDidChange(() => this.touchBarUpdater.schedule())); + this.touchBarDisposables.add(this.touchBarMenu.onDidChange(() => this.touchBarUpdater!.schedule())); } const actions: Array = []; diff --git a/src/vs/workbench/services/backup/common/backupFileService.ts b/src/vs/workbench/services/backup/common/backupFileService.ts index 4f782cf641f..de81c2b7d58 100644 --- a/src/vs/workbench/services/backup/common/backupFileService.ts +++ b/src/vs/workbench/services/backup/common/backupFileService.ts @@ -113,7 +113,7 @@ export class BackupFileService implements IBackupFileService { @IWorkbenchEnvironmentService private environmentService: IWorkbenchEnvironmentService, @IFileService protected fileService: IFileService ) { - this.initialize(); + this.impl = this.initialize(); } protected hashPath(resource: URI): string { @@ -122,13 +122,13 @@ export class BackupFileService implements IBackupFileService { return hash(str).toString(16); } - private initialize(): void { + private initialize(): IBackupFileService { const backupWorkspaceResource = this.environmentService.configuration.backupWorkspaceResource; if (backupWorkspaceResource) { - this.impl = new BackupFileServiceImpl(backupWorkspaceResource, this.hashPath, this.fileService); - } else { - this.impl = new InMemoryBackupFileService(this.hashPath); + return new BackupFileServiceImpl(backupWorkspaceResource, this.hashPath, this.fileService); } + + return new InMemoryBackupFileService(this.hashPath); } reinitialize(): void { diff --git a/src/vs/workbench/services/credentials/browser/credentialsService.ts b/src/vs/workbench/services/credentials/browser/credentialsService.ts index 82fe116286e..3bc3637a2b6 100644 --- a/src/vs/workbench/services/credentials/browser/credentialsService.ts +++ b/src/vs/workbench/services/credentials/browser/credentialsService.ts @@ -60,7 +60,7 @@ class LocalStorageCredentialsProvider implements ICredentialsProvider { static readonly CREDENTIALS_OPENED_KEY = 'credentials.provider'; - private _credentials: ICredential[]; + private _credentials: ICredential[] | undefined; private get credentials(): ICredential[] { if (!this._credentials) { try { diff --git a/src/vs/workbench/services/preferences/common/preferencesEditorInput.ts b/src/vs/workbench/services/preferences/common/preferencesEditorInput.ts index ee813e14fe5..41edfc30a95 100644 --- a/src/vs/workbench/services/preferences/common/preferencesEditorInput.ts +++ b/src/vs/workbench/services/preferences/common/preferencesEditorInput.ts @@ -60,7 +60,7 @@ export class KeybindingsEditorInput extends EditorInput { static readonly ID: string = 'workbench.input.keybindings'; readonly keybindingsModel: KeybindingsEditorModel; - searchOptions: IKeybindingsEditorSearchOptions | null; + searchOptions: IKeybindingsEditorSearchOptions | null = null; constructor(@IInstantiationService instantiationService: IInstantiationService) { super(); diff --git a/src/vs/workbench/test/workbenchTestServices.ts b/src/vs/workbench/test/workbenchTestServices.ts index 69c2ed28f11..4014dc4da45 100644 --- a/src/vs/workbench/test/workbenchTestServices.ts +++ b/src/vs/workbench/test/workbenchTestServices.ts @@ -106,6 +106,7 @@ export class TestContextService implements IWorkspaceContextService { constructor(workspace: any = TestWorkspace, options: any = null) { this.workspace = workspace; this.options = options || Object.create(null); + this._onDidChangeWorkspaceName = new Emitter(); this._onDidChangeWorkspaceFolders = new Emitter(); this._onDidChangeWorkbenchState = new Emitter(); } -- GitLab