From b416cdcd1e2444d3860e816d6b9ca605df53947d Mon Sep 17 00:00:00 2001 From: Winston Liu Date: Thu, 18 Aug 2022 23:06:20 -0700 Subject: [PATCH 01/11] Clear nullability warnings in TelemetryObserver --- src/observers/TelemetryObserver.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/observers/TelemetryObserver.ts b/src/observers/TelemetryObserver.ts index fd7f8889d..3c93663a5 100644 --- a/src/observers/TelemetryObserver.ts +++ b/src/observers/TelemetryObserver.ts @@ -19,8 +19,8 @@ export interface ITelemetryReporter { export class TelemetryObserver { private reporter: ITelemetryReporter; private platformInfo: PlatformInformation; - private solutionId: string; - private dotnetInfo: DotnetInfo; + private solutionId?: string; + private dotnetInfo?: DotnetInfo; constructor(platformInfo: PlatformInformation, reporterCreator: () => ITelemetryReporter) { this.platformInfo = platformInfo; @@ -64,7 +64,7 @@ export class TelemetryObserver { } private handleTelemetryEventMeasures(event: TelemetryEventWithMeasures) { - this.reporter.sendTelemetryEvent(event.eventName, null, event.measures); + this.reporter.sendTelemetryEvent(event.eventName, undefined, event.measures); } private async handleOmnisharpInitialisation(event: OmnisharpInitialisation) { @@ -90,16 +90,16 @@ export class TelemetryObserver { private handleTestExecutionCountReport(event: TestExecutionCountReport) { if (event.debugCounts) { - this.reporter.sendTelemetryEvent('DebugTest', null, event.debugCounts); + this.reporter.sendTelemetryEvent('DebugTest', undefined, event.debugCounts); } if (event.runCounts) { - this.reporter.sendTelemetryEvent('RunTest', null, event.runCounts); + this.reporter.sendTelemetryEvent('RunTest', undefined, event.runCounts); } } private handleProjectConfigurationReceived(event: ProjectConfiguration, telemetryProps: { [key: string]: string }) { let projectConfig = event.projectConfiguration; - telemetryProps['SolutionId'] = this.solutionId; + telemetryProps['SolutionId'] = this.solutionId ?? ""; telemetryProps['ProjectId'] = projectConfig.ProjectId; telemetryProps['SessionId'] = projectConfig.SessionId; telemetryProps['OutputType'] = projectConfig.OutputKind?.toString() ?? ""; From 550232c8f3a91a68e5f69cad8feb5266cc0ec2e3 Mon Sep 17 00:00:00 2001 From: Winston Liu Date: Thu, 18 Aug 2022 23:07:32 -0700 Subject: [PATCH 02/11] Specify options as nullable --- src/observers/OptionProvider.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/observers/OptionProvider.ts b/src/observers/OptionProvider.ts index e8eeec809..1b1d0b26f 100644 --- a/src/observers/OptionProvider.ts +++ b/src/observers/OptionProvider.ts @@ -6,7 +6,7 @@ import { Options } from "../omnisharp/options"; import { Subscription, Observable } from "rxjs"; export default class OptionProvider { - private options: Options; + private options?: Options; private subscription: Subscription; constructor(optionObservable: Observable) { @@ -24,4 +24,4 @@ export default class OptionProvider { public dispose = () => { this.subscription.unsubscribe(); } -} \ No newline at end of file +} From f208ed7f732549bb73b87535d5532482c15c28c6 Mon Sep 17 00:00:00 2001 From: Winston Liu Date: Thu, 18 Aug 2022 23:09:55 -0700 Subject: [PATCH 03/11] Don't compare undefined against 0 --- src/observers/OmnisharpLoggerObserver.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/observers/OmnisharpLoggerObserver.ts b/src/observers/OmnisharpLoggerObserver.ts index 664f8c1ca..b5ef3c32c 100644 --- a/src/observers/OmnisharpLoggerObserver.ts +++ b/src/observers/OmnisharpLoggerObserver.ts @@ -83,7 +83,7 @@ export class OmnisharpLoggerObserver extends BaseLoggerObserver { this.logger.append(`OmniSharp server started`); if (event.hostVersion) { this.logger.append(` with ${event.hostIsMono ? 'Mono' : '.NET'} ${event.hostVersion}`); - if (event.hostPath?.length > 0) { + if (event.hostPath && event.hostPath.length > 0) { this.logger.append(` (${event.hostPath})`); } } From c74b2ed6937000d5b222f2cd578796e8b8e8bbf4 Mon Sep 17 00:00:00 2001 From: Winston Liu Date: Thu, 18 Aug 2022 23:10:46 -0700 Subject: [PATCH 04/11] Initialize dots to 0 --- src/observers/CsharpLoggerObserver.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/observers/CsharpLoggerObserver.ts b/src/observers/CsharpLoggerObserver.ts index 07ae69116..831d501da 100644 --- a/src/observers/CsharpLoggerObserver.ts +++ b/src/observers/CsharpLoggerObserver.ts @@ -9,7 +9,7 @@ import { PackageError } from "../packageManager/PackageError"; import { EventType } from "../omnisharp/EventType"; export class CsharpLoggerObserver extends BaseLoggerObserver { - private dots: number; + private dots: number = 0; public post = (event: Event.BaseEvent) => { switch (event.type) { @@ -146,4 +146,4 @@ export class CsharpLoggerObserver extends BaseLoggerObserver { private handleDocumentSynchronizationFailure(event: Event.DocumentSynchronizationFailure) { this.logger.appendLine(`Failed to synchronize document '${event.documentPath}': ${event.errorMessage}`); } -} \ No newline at end of file +} From 48f00daf9105f6e513f269a13662db521ec4c969 Mon Sep 17 00:00:00 2001 From: Winston Liu Date: Thu, 18 Aug 2022 23:11:09 -0700 Subject: [PATCH 05/11] Set text to an empty string --- src/observers/BaseStatusBarItemObserver.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/observers/BaseStatusBarItemObserver.ts b/src/observers/BaseStatusBarItemObserver.ts index 3919f163d..825afc70a 100644 --- a/src/observers/BaseStatusBarItemObserver.ts +++ b/src/observers/BaseStatusBarItemObserver.ts @@ -20,7 +20,7 @@ export abstract class BaseStatusBarItemObserver { } public ResetAndHideStatusBar() { - this.statusBarItem.text = undefined; + this.statusBarItem.text = ''; this.statusBarItem.command = undefined; this.statusBarItem.color = undefined; this.statusBarItem.tooltip = undefined; @@ -28,4 +28,4 @@ export abstract class BaseStatusBarItemObserver { } abstract post: (event: BaseEvent) => void; -} \ No newline at end of file +} From 48f2276d55d05c076bfda34878aa1f93af67b58d Mon Sep 17 00:00:00 2001 From: Winston Liu Date: Thu, 18 Aug 2022 23:11:37 -0700 Subject: [PATCH 06/11] null -> undefined --- src/observers/BackgroundWorkStatusBarObserver.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/observers/BackgroundWorkStatusBarObserver.ts b/src/observers/BackgroundWorkStatusBarObserver.ts index c49a419fe..46cddee14 100644 --- a/src/observers/BackgroundWorkStatusBarObserver.ts +++ b/src/observers/BackgroundWorkStatusBarObserver.ts @@ -15,7 +15,7 @@ export class BackgroundWorkStatusBarObserver extends BaseStatusBarItemObserver { if (asProjectEvent.message.Status === DiagnosticStatus.Processing) { let projectFile = asProjectEvent.message.ProjectFilePath.replace(/^.*[\\\/]/, ''); - this.SetAndShowStatusBar(`$(sync~spin) Analyzing ${projectFile}`, 'o.showOutput', null, `Analyzing ${projectFile}`); + this.SetAndShowStatusBar(`$(sync~spin) Analyzing ${projectFile}`, 'o.showOutput', undefined, `Analyzing ${projectFile}`); } else { this.ResetAndHideStatusBar(); @@ -23,4 +23,3 @@ export class BackgroundWorkStatusBarObserver extends BaseStatusBarItemObserver { } } } - From e772b13f1354e69889b780de0df66e13211d4e9d Mon Sep 17 00:00:00 2001 From: Winston Liu Date: Thu, 18 Aug 2022 23:14:02 -0700 Subject: [PATCH 07/11] Use optional chaining --- src/observers/utils/ShowInformationMessage.ts | 6 +++--- src/observers/utils/ShowWarningMessage.ts | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/observers/utils/ShowInformationMessage.ts b/src/observers/utils/ShowInformationMessage.ts index 02537f3e7..9e4a94c38 100644 --- a/src/observers/utils/ShowInformationMessage.ts +++ b/src/observers/utils/ShowInformationMessage.ts @@ -8,12 +8,12 @@ import MessageItemWithCommand from "./MessageItemWithCommand"; export default async function showInformationMessage(vscode: vscode, message: string, ...items: MessageItemWithCommand[]) { try { - let value = await vscode.window.showInformationMessage(message, ...items); - if (value && value.command) { + const value = await vscode.window.showInformationMessage(message, ...items); + if (value?.command) { vscode.commands.executeCommand(value.command); } } catch (err) { console.log(err); } -} \ No newline at end of file +} diff --git a/src/observers/utils/ShowWarningMessage.ts b/src/observers/utils/ShowWarningMessage.ts index 563caff49..9bf6bc602 100644 --- a/src/observers/utils/ShowWarningMessage.ts +++ b/src/observers/utils/ShowWarningMessage.ts @@ -8,12 +8,12 @@ import MessageItemWithCommand from "./MessageItemWithCommand"; export default async function showWarningMessage(vscode: vscode, message: string, ...items: MessageItemWithCommand[]) { try { - let value = await vscode.window.showWarningMessage(message, ...items); - if (value && value.command) { + const value = await vscode.window.showWarningMessage(message, ...items); + if (value?.command) { await vscode.commands.executeCommand(value.command); } } catch (err) { console.log(err); } -} \ No newline at end of file +} From baf161183173067bff221768d81e1db1111b4b58 Mon Sep 17 00:00:00 2001 From: Winston Liu Date: Thu, 18 Aug 2022 23:46:33 -0700 Subject: [PATCH 08/11] Fix tests --- .../logging/BackgroundWorkStatusBarObserver.test.ts | 4 ++-- .../logging/OmnisharpStatusBarObserver.test.ts | 8 ++++---- .../unitTests/logging/ProjectStatusBarObserver.test.ts | 10 +++++----- test/unitTests/testAssets/Fakes.ts | 4 ++-- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/test/unitTests/logging/BackgroundWorkStatusBarObserver.test.ts b/test/unitTests/logging/BackgroundWorkStatusBarObserver.test.ts index 1a29ccef8..24840441e 100644 --- a/test/unitTests/logging/BackgroundWorkStatusBarObserver.test.ts +++ b/test/unitTests/logging/BackgroundWorkStatusBarObserver.test.ts @@ -38,6 +38,6 @@ suite('BackgroundWorkStatusBarObserver', () => { observer.post(event); expect(hideCalled).to.be.true; expect(showCalled).to.be.false; - expect(statusBarItem.text).to.be.undefined; + expect(statusBarItem.text).to.be.equal(''); }); -}); \ No newline at end of file +}); diff --git a/test/unitTests/logging/OmnisharpStatusBarObserver.test.ts b/test/unitTests/logging/OmnisharpStatusBarObserver.test.ts index 703062a8d..e6d1041f3 100644 --- a/test/unitTests/logging/OmnisharpStatusBarObserver.test.ts +++ b/test/unitTests/logging/OmnisharpStatusBarObserver.test.ts @@ -14,7 +14,7 @@ suite('OmnisharpStatusBarObserver', () => { let hideCalled: boolean; setup(() => { - statusBarItem.text = undefined; + statusBarItem.text = ''; statusBarItem.color = undefined; statusBarItem.command = undefined; statusBarItem.tooltip = undefined; @@ -84,7 +84,7 @@ suite('OmnisharpStatusBarObserver', () => { let event = new OmnisharpServerOnStop(); observer.post(event); expect(hideCalled).to.be.true; - expect(statusBarItem.text).to.be.undefined; + expect(statusBarItem.text).to.be.equal(''); expect(statusBarItem.command).to.be.undefined; expect(statusBarItem.color).to.be.undefined; }); @@ -118,8 +118,8 @@ suite('OmnisharpStatusBarObserver', () => { observer.post(successEvent); expect(hideCalled).to.be.true; - expect(statusBarItem.text).to.be.undefined; + expect(statusBarItem.text).to.be.equal(''); expect(statusBarItem.command).to.be.undefined; expect(statusBarItem.color).to.be.undefined; }); -}); \ No newline at end of file +}); diff --git a/test/unitTests/logging/ProjectStatusBarObserver.test.ts b/test/unitTests/logging/ProjectStatusBarObserver.test.ts index 156dd91f7..bceb1b80a 100644 --- a/test/unitTests/logging/ProjectStatusBarObserver.test.ts +++ b/test/unitTests/logging/ProjectStatusBarObserver.test.ts @@ -29,7 +29,7 @@ suite('ProjectStatusBarObserver', () => { let event = new OmnisharpServerOnStop(); observer.post(event); expect(hideCalled).to.be.true; - expect(statusBarItem.text).to.be.undefined; + expect(statusBarItem.text).to.be.equal(''); expect(statusBarItem.command).to.be.undefined; expect(statusBarItem.color).to.be.undefined; }); @@ -44,10 +44,10 @@ suite('ProjectStatusBarObserver', () => { suite('WorkspaceInformationUpdated', () => { test('Project status is hidden if there is no MSBuild Object', () => { - let event = getWorkspaceInformationUpdated(null); + let event = getWorkspaceInformationUpdated(undefined); observer.post(event); expect(hideCalled).to.be.true; - expect(statusBarItem.text).to.be.undefined; + expect(statusBarItem.text).to.be.equal(''); expect(statusBarItem.command).to.be.undefined; }); @@ -55,8 +55,8 @@ suite('ProjectStatusBarObserver', () => { let event = getWorkspaceInformationUpdated(getMSBuildWorkspaceInformation("somePath", [])); observer.post(event); expect(showCalled).to.be.true; - expect(statusBarItem.text).to.contain(event.info.MsBuild.SolutionPath); + expect(statusBarItem.text).to.contain(event.info.MsBuild?.SolutionPath); expect(statusBarItem.command).to.equal('o.pickProjectAndStart'); }); }); -}); \ No newline at end of file +}); diff --git a/test/unitTests/testAssets/Fakes.ts b/test/unitTests/testAssets/Fakes.ts index d293b9bef..a84a6a172 100644 --- a/test/unitTests/testAssets/Fakes.ts +++ b/test/unitTests/testAssets/Fakes.ts @@ -175,7 +175,7 @@ export function getMSBuildWorkspaceInformation(msBuildSolutionPath: string, msBu }; } -export function getWorkspaceInformationUpdated(msbuild: protocol.MsBuildWorkspaceInformation): WorkspaceInformationUpdated { +export function getWorkspaceInformationUpdated(msbuild: protocol.MsBuildWorkspaceInformation | undefined): WorkspaceInformationUpdated { let a: protocol.WorkspaceInformationResponse = { MsBuild: msbuild }; @@ -212,4 +212,4 @@ export function getVSCodeWithConfig() { export function updateConfig(vscode: vscode.vscode, section: string, config: string, value: any) { let workspaceConfig = vscode.workspace.getConfiguration(section); workspaceConfig.update(config, value); -} \ No newline at end of file +} From aa98db62bd73ac1c18173fa4b7f35fa6c2c0de5e Mon Sep 17 00:00:00 2001 From: Winston Liu Date: Thu, 18 Aug 2022 23:54:26 -0700 Subject: [PATCH 09/11] Make Fakes.ts strict-compliant while we're here --- test/unitTests/testAssets/Fakes.ts | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/test/unitTests/testAssets/Fakes.ts b/test/unitTests/testAssets/Fakes.ts index a84a6a172..1e8be2394 100644 --- a/test/unitTests/testAssets/Fakes.ts +++ b/test/unitTests/testAssets/Fakes.ts @@ -148,9 +148,9 @@ export function getFakeVsCode(): vscode.vscode { }, version: "", env: { - appName: null, - appRoot: null, - language: null, + appName: "", + appRoot: "", + language: "", clipboard: { writeText: () => { throw new Error("Not Implemented"); @@ -159,8 +159,8 @@ export function getFakeVsCode(): vscode.vscode { throw new Error("Not Implemented"); } }, - machineId: null, - sessionId: null, + machineId: "", + sessionId: "", openExternal: () => { throw new Error("Not Implemented"); } @@ -175,12 +175,10 @@ export function getMSBuildWorkspaceInformation(msBuildSolutionPath: string, msBu }; } -export function getWorkspaceInformationUpdated(msbuild: protocol.MsBuildWorkspaceInformation | undefined): WorkspaceInformationUpdated { - let a: protocol.WorkspaceInformationResponse = { - MsBuild: msbuild - }; - - return new WorkspaceInformationUpdated(a); +export function getWorkspaceInformationUpdated(MsBuild: protocol.MsBuildWorkspaceInformation | undefined): WorkspaceInformationUpdated { + return new WorkspaceInformationUpdated({ + MsBuild, + }); } export function getVSCodeWithConfig() { @@ -203,7 +201,7 @@ export function getVSCodeWithConfig() { return _csharpConfig; } - return undefined; + throw new Error(`Unexpected section ${section}`); }; return vscode; From fff795d40b8f92f4e9b7398ebf9b58bde5eec0fe Mon Sep 17 00:00:00 2001 From: Winston Liu Date: Fri, 19 Aug 2022 00:10:15 -0700 Subject: [PATCH 10/11] Add razor as an allowed config option --- test/unitTests/testAssets/Fakes.ts | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/test/unitTests/testAssets/Fakes.ts b/test/unitTests/testAssets/Fakes.ts index 1e8be2394..137bf83a7 100644 --- a/test/unitTests/testAssets/Fakes.ts +++ b/test/unitTests/testAssets/Fakes.ts @@ -38,9 +38,7 @@ export const getWorkspaceConfiguration = (): vscode.WorkspaceConfiguration => { let configuration: vscode.WorkspaceConfiguration = { get(section: string, defaultValue?: T): T | undefined { let result = values[section]; - return result === undefined && defaultValue !== undefined - ? defaultValue - : result; + return result ?? defaultValue; }, has: (section: string) => { return values[section] !== undefined; @@ -187,18 +185,17 @@ export function getVSCodeWithConfig() { const _vscodeConfig = getWorkspaceConfiguration(); const _omnisharpConfig = getWorkspaceConfiguration(); const _csharpConfig = getWorkspaceConfiguration(); + const _razorConfig = getWorkspaceConfiguration(); vscode.workspace.getConfiguration = (section?, resource?) => { - if (!section) { + if (section === undefined) { return _vscodeConfig; - } - - if (section === 'omnisharp') { + } else if (section === 'omnisharp') { return _omnisharpConfig; - } - - if (section === 'csharp') { + } else if (section === 'csharp') { return _csharpConfig; + } else if (section === 'razor') { + return _razorConfig; } throw new Error(`Unexpected section ${section}`); From 6b9a034f2489d8168dbbd39093631dbc9f56a7eb Mon Sep 17 00:00:00 2001 From: Winston Liu Date: Fri, 19 Aug 2022 00:55:33 -0700 Subject: [PATCH 11/11] Another null vs undefined fix --- test/unitTests/options.test.ts | 12 ++++++------ test/unitTests/testAssets/Fakes.ts | 6 +++--- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/test/unitTests/options.test.ts b/test/unitTests/options.test.ts index 611363ebd..71879ce07 100644 --- a/test/unitTests/options.test.ts +++ b/test/unitTests/options.test.ts @@ -40,7 +40,7 @@ suite("Options tests", () => { test('Verify return no excluded paths when files.exclude empty', () => { const vscode = getVSCodeWithConfig(); - updateConfig(vscode, null, 'files.exclude', {}); + updateConfig(vscode, undefined, 'files.exclude', {}); const excludedPaths = Options.getExcludedPaths(vscode); expect(excludedPaths).to.be.empty; @@ -48,7 +48,7 @@ suite("Options tests", () => { test('Verify return excluded paths when files.exclude populated', () => { const vscode = getVSCodeWithConfig(); - updateConfig(vscode, null, 'files.exclude', { "**/node_modules": true, "**/assets": false }); + updateConfig(vscode, undefined, 'files.exclude', { "**/node_modules": true, "**/assets": false }); const excludedPaths = Options.getExcludedPaths(vscode); expect(excludedPaths).to.equalTo(["**/node_modules"]); @@ -56,8 +56,8 @@ suite("Options tests", () => { test('Verify return no excluded paths when files.exclude and search.exclude empty', () => { const vscode = getVSCodeWithConfig(); - updateConfig(vscode, null, 'files.exclude', {}); - updateConfig(vscode, null, 'search.exclude', {}); + updateConfig(vscode, undefined, 'files.exclude', {}); + updateConfig(vscode, undefined, 'search.exclude', {}); const excludedPaths = Options.getExcludedPaths(vscode, true); expect(excludedPaths).to.be.empty; @@ -65,8 +65,8 @@ suite("Options tests", () => { test('Verify return excluded paths when files.exclude and search.exclude populated', () => { const vscode = getVSCodeWithConfig(); - updateConfig(vscode, null, 'files.exclude', { "/Library": true }); - updateConfig(vscode, null, 'search.exclude', { "**/node_modules": true, "**/assets": false }); + updateConfig(vscode, undefined, 'files.exclude', { "/Library": true }); + updateConfig(vscode, undefined, 'search.exclude', { "**/node_modules": true, "**/assets": false }); const excludedPaths = Options.getExcludedPaths(vscode, true); expect(excludedPaths).to.be.equalTo(["/Library", "**/node_modules"]); diff --git a/test/unitTests/testAssets/Fakes.ts b/test/unitTests/testAssets/Fakes.ts index 137bf83a7..3a8973c22 100644 --- a/test/unitTests/testAssets/Fakes.ts +++ b/test/unitTests/testAssets/Fakes.ts @@ -187,7 +187,7 @@ export function getVSCodeWithConfig() { const _csharpConfig = getWorkspaceConfiguration(); const _razorConfig = getWorkspaceConfiguration(); - vscode.workspace.getConfiguration = (section?, resource?) => { + vscode.workspace.getConfiguration = (section, resource) => { if (section === undefined) { return _vscodeConfig; } else if (section === 'omnisharp') { @@ -204,7 +204,7 @@ export function getVSCodeWithConfig() { return vscode; } -export function updateConfig(vscode: vscode.vscode, section: string, config: string, value: any) { - let workspaceConfig = vscode.workspace.getConfiguration(section); +export function updateConfig(vscode: vscode.vscode, section: string | undefined, config: string, value: any) { + const workspaceConfig = vscode.workspace.getConfiguration(section); workspaceConfig.update(config, value); }