Skip to content

Commit 322d0ff

Browse files
authored
Merge pull request #5349 from 50Wliu/users/winstonliu/observers-nullability
Observer nullability fixes
2 parents e8c5c24 + 6b9a034 commit 322d0ff

13 files changed

+58
-64
lines changed

src/observers/BackgroundWorkStatusBarObserver.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,11 @@ export class BackgroundWorkStatusBarObserver extends BaseStatusBarItemObserver {
1515

1616
if (asProjectEvent.message.Status === DiagnosticStatus.Processing) {
1717
let projectFile = asProjectEvent.message.ProjectFilePath.replace(/^.*[\\\/]/, '');
18-
this.SetAndShowStatusBar(`$(sync~spin) Analyzing ${projectFile}`, 'o.showOutput', null, `Analyzing ${projectFile}`);
18+
this.SetAndShowStatusBar(`$(sync~spin) Analyzing ${projectFile}`, 'o.showOutput', undefined, `Analyzing ${projectFile}`);
1919
}
2020
else {
2121
this.ResetAndHideStatusBar();
2222
}
2323
}
2424
}
2525
}
26-

src/observers/BaseStatusBarItemObserver.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ export abstract class BaseStatusBarItemObserver {
2020
}
2121

2222
public ResetAndHideStatusBar() {
23-
this.statusBarItem.text = undefined;
23+
this.statusBarItem.text = '';
2424
this.statusBarItem.command = undefined;
2525
this.statusBarItem.color = undefined;
2626
this.statusBarItem.tooltip = undefined;
2727
this.statusBarItem.hide();
2828
}
2929

3030
abstract post: (event: BaseEvent) => void;
31-
}
31+
}

src/observers/CsharpLoggerObserver.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { PackageError } from "../packageManager/PackageError";
99
import { EventType } from "../omnisharp/EventType";
1010

1111
export class CsharpLoggerObserver extends BaseLoggerObserver {
12-
private dots: number;
12+
private dots: number = 0;
1313

1414
public post = (event: Event.BaseEvent) => {
1515
switch (event.type) {
@@ -146,4 +146,4 @@ export class CsharpLoggerObserver extends BaseLoggerObserver {
146146
private handleDocumentSynchronizationFailure(event: Event.DocumentSynchronizationFailure) {
147147
this.logger.appendLine(`Failed to synchronize document '${event.documentPath}': ${event.errorMessage}`);
148148
}
149-
}
149+
}

src/observers/OmnisharpLoggerObserver.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ export class OmnisharpLoggerObserver extends BaseLoggerObserver {
8383
this.logger.append(`OmniSharp server started`);
8484
if (event.hostVersion) {
8585
this.logger.append(` with ${event.hostIsMono ? 'Mono' : '.NET'} ${event.hostVersion}`);
86-
if (event.hostPath?.length > 0) {
86+
if (event.hostPath && event.hostPath.length > 0) {
8787
this.logger.append(` (${event.hostPath})`);
8888
}
8989
}

src/observers/OptionProvider.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import { Options } from "../omnisharp/options";
77
import { Subscription, Observable } from "rxjs";
88
export default class OptionProvider {
9-
private options: Options;
9+
private options?: Options;
1010
private subscription: Subscription;
1111

1212
constructor(optionObservable: Observable<Options>) {
@@ -24,4 +24,4 @@ export default class OptionProvider {
2424
public dispose = () => {
2525
this.subscription.unsubscribe();
2626
}
27-
}
27+
}

src/observers/TelemetryObserver.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ export interface ITelemetryReporter {
1919
export class TelemetryObserver {
2020
private reporter: ITelemetryReporter;
2121
private platformInfo: PlatformInformation;
22-
private solutionId: string;
23-
private dotnetInfo: DotnetInfo;
22+
private solutionId?: string;
23+
private dotnetInfo?: DotnetInfo;
2424

2525
constructor(platformInfo: PlatformInformation, reporterCreator: () => ITelemetryReporter) {
2626
this.platformInfo = platformInfo;
@@ -64,7 +64,7 @@ export class TelemetryObserver {
6464
}
6565

6666
private handleTelemetryEventMeasures(event: TelemetryEventWithMeasures) {
67-
this.reporter.sendTelemetryEvent(event.eventName, null, event.measures);
67+
this.reporter.sendTelemetryEvent(event.eventName, undefined, event.measures);
6868
}
6969

7070
private async handleOmnisharpInitialisation(event: OmnisharpInitialisation) {
@@ -90,16 +90,16 @@ export class TelemetryObserver {
9090

9191
private handleTestExecutionCountReport(event: TestExecutionCountReport) {
9292
if (event.debugCounts) {
93-
this.reporter.sendTelemetryEvent('DebugTest', null, event.debugCounts);
93+
this.reporter.sendTelemetryEvent('DebugTest', undefined, event.debugCounts);
9494
}
9595
if (event.runCounts) {
96-
this.reporter.sendTelemetryEvent('RunTest', null, event.runCounts);
96+
this.reporter.sendTelemetryEvent('RunTest', undefined, event.runCounts);
9797
}
9898
}
9999

100100
private handleProjectConfigurationReceived(event: ProjectConfiguration, telemetryProps: { [key: string]: string }) {
101101
let projectConfig = event.projectConfiguration;
102-
telemetryProps['SolutionId'] = this.solutionId;
102+
telemetryProps['SolutionId'] = this.solutionId ?? "";
103103
telemetryProps['ProjectId'] = projectConfig.ProjectId;
104104
telemetryProps['SessionId'] = projectConfig.SessionId;
105105
telemetryProps['OutputType'] = projectConfig.OutputKind?.toString() ?? "";

src/observers/utils/ShowInformationMessage.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ import MessageItemWithCommand from "./MessageItemWithCommand";
88

99
export default async function showInformationMessage(vscode: vscode, message: string, ...items: MessageItemWithCommand[]) {
1010
try {
11-
let value = await vscode.window.showInformationMessage<MessageItemWithCommand>(message, ...items);
12-
if (value && value.command) {
11+
const value = await vscode.window.showInformationMessage<MessageItemWithCommand>(message, ...items);
12+
if (value?.command) {
1313
vscode.commands.executeCommand(value.command);
1414
}
1515
}
1616
catch (err) {
1717
console.log(err);
1818
}
19-
}
19+
}

src/observers/utils/ShowWarningMessage.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ import MessageItemWithCommand from "./MessageItemWithCommand";
88

99
export default async function showWarningMessage(vscode: vscode, message: string, ...items: MessageItemWithCommand[]) {
1010
try {
11-
let value = await vscode.window.showWarningMessage<MessageItemWithCommand>(message, ...items);
12-
if (value && value.command) {
11+
const value = await vscode.window.showWarningMessage<MessageItemWithCommand>(message, ...items);
12+
if (value?.command) {
1313
await vscode.commands.executeCommand<string>(value.command);
1414
}
1515
}
1616
catch (err) {
1717
console.log(err);
1818
}
19-
}
19+
}

test/unitTests/logging/BackgroundWorkStatusBarObserver.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,6 @@ suite('BackgroundWorkStatusBarObserver', () => {
3838
observer.post(event);
3939
expect(hideCalled).to.be.true;
4040
expect(showCalled).to.be.false;
41-
expect(statusBarItem.text).to.be.undefined;
41+
expect(statusBarItem.text).to.be.equal('');
4242
});
43-
});
43+
});

test/unitTests/logging/OmnisharpStatusBarObserver.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ suite('OmnisharpStatusBarObserver', () => {
1414
let hideCalled: boolean;
1515

1616
setup(() => {
17-
statusBarItem.text = undefined;
17+
statusBarItem.text = '';
1818
statusBarItem.color = undefined;
1919
statusBarItem.command = undefined;
2020
statusBarItem.tooltip = undefined;
@@ -84,7 +84,7 @@ suite('OmnisharpStatusBarObserver', () => {
8484
let event = new OmnisharpServerOnStop();
8585
observer.post(event);
8686
expect(hideCalled).to.be.true;
87-
expect(statusBarItem.text).to.be.undefined;
87+
expect(statusBarItem.text).to.be.equal('');
8888
expect(statusBarItem.command).to.be.undefined;
8989
expect(statusBarItem.color).to.be.undefined;
9090
});
@@ -118,8 +118,8 @@ suite('OmnisharpStatusBarObserver', () => {
118118
observer.post(successEvent);
119119

120120
expect(hideCalled).to.be.true;
121-
expect(statusBarItem.text).to.be.undefined;
121+
expect(statusBarItem.text).to.be.equal('');
122122
expect(statusBarItem.command).to.be.undefined;
123123
expect(statusBarItem.color).to.be.undefined;
124124
});
125-
});
125+
});

0 commit comments

Comments
 (0)