Skip to content

Commit 5238c31

Browse files
committed
Add flag for verbosity to disable messages by default
Some of these messages dont need to be shown.
1 parent 0ce8832 commit 5238c31

File tree

5 files changed

+47
-9
lines changed

5 files changed

+47
-9
lines changed

vscode-dotnet-runtime-extension/src/extension.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ namespace configKeys
9898
export const cacheTimeToLiveMultiplier = 'cacheTimeToLiveMultiplier';
9999
export const showResetDataCommand = 'showResetDataCommand';
100100
export const suppressOutput = 'suppressOutput';
101+
export const highVerbosity = 'highVerbosity';
101102
}
102103

103104
namespace commandKeys
@@ -155,6 +156,7 @@ export function activate(vsCodeContext: vscode.ExtensionContext, extensionContex
155156

156157
const allowInvalidPathSetting = extensionConfiguration.get<boolean>(configKeys.allowInvalidPaths);
157158
const suppressOutput = extensionConfiguration.get<boolean>(configKeys.suppressOutput) ?? false;
159+
const highVerbosity = extensionConfiguration.get<boolean>(configKeys.highVerbosity) ?? false;
158160
const isExtensionTelemetryEnabled = enableExtensionTelemetry(extensionConfiguration, configKeys.enableTelemetry);
159161
const displayWorker = extensionContext ? extensionContext.displayWorker : new WindowDisplayWorker();
160162

@@ -175,7 +177,7 @@ export function activate(vsCodeContext: vscode.ExtensionContext, extensionContex
175177
packageJson
176178
} as IEventStreamContext;
177179
const [globalEventStream, outputChannel, loggingObserver,
178-
eventStreamObservers, telemetryObserver, _] = registerEventStream(eventStreamContext, vsCodeExtensionContext, utilContext, suppressOutput);
180+
eventStreamObservers, telemetryObserver, _] = registerEventStream(eventStreamContext, vsCodeExtensionContext, utilContext, suppressOutput, highVerbosity);
179181

180182

181183
// Setting up command-shared classes for Runtime & SDK Acquisition

vscode-dotnet-runtime-library/src/EventStream/EventStreamEvents.ts

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -331,16 +331,19 @@ abstract class DotnetAcquisitionFinalErrorBase extends DotnetAcquisitionError
331331
export class DotnetGlobalSDKAcquisitionError extends DotnetAcquisitionFinalErrorBase
332332
{
333333
public eventName = 'DotnetGlobalSDKAcquisitionError';
334+
public verboseOutputOnly = true;
334335
}
335336

336337
export class DotnetRuntimeFinalAcquisitionError extends DotnetAcquisitionFinalErrorBase
337338
{
338339
public eventName = 'DotnetRuntimeFinalAcquisitionError';
340+
public verboseOutputOnly = true;
339341
}
340342

341343
export class DotnetASPNetRuntimeFinalAcquisitionError extends DotnetAcquisitionFinalErrorBase
342344
{
343345
public eventName = 'DotnetASPNetRuntimeFinalAcquisitionError';
346+
public verboseOutputOnly = true;
344347
}
345348

346349
export abstract class DotnetNonAcquisitionError extends IEvent
@@ -828,6 +831,7 @@ export class DotnetInstallScriptAcquisitionCompleted extends DotnetAcquisitionSu
828831
export class DotnetExistingPathResolutionCompleted extends DotnetAcquisitionSuccessEvent
829832
{
830833
public readonly eventName = 'DotnetExistingPathResolutionCompleted';
834+
public verboseOutputOnly = true;
831835

832836
constructor(public readonly resolvedPath: string) { super(); }
833837

@@ -1673,9 +1677,17 @@ export class DotnetAcquisitionPartialInstallation extends DotnetAcquisitionMessa
16731677
export class DotnetAcquisitionInProgress extends IEvent
16741678
{
16751679
public readonly type = EventType.DotnetAcquisitionInProgress;
1680+
public verboseOutputOnly = true;
16761681

16771682
public readonly eventName = 'DotnetAcquisitionInProgress';
1678-
constructor(public readonly install: DotnetInstall, public readonly requestingExtensionId: string | null) { super(); }
1683+
constructor(public readonly install: DotnetInstall, public readonly requestingExtensionId: string | null)
1684+
{
1685+
super();
1686+
if (requestingExtensionId === 'user')
1687+
{
1688+
this.verboseOutputOnly = false;
1689+
}
1690+
}
16791691

16801692
public getProperties()
16811693
{
@@ -1691,8 +1703,15 @@ export class DotnetAcquisitionAlreadyInstalled extends IEvent
16911703
{
16921704
public readonly eventName = 'DotnetAcquisitionAlreadyInstalled';
16931705
public readonly type = EventType.DotnetAcquisitionAlreadyInstalled;
1694-
1695-
constructor(public readonly install: DotnetInstall, public readonly requestingExtensionId: string | null) { super(); }
1706+
public verboseOutputOnly = true;
1707+
constructor(public readonly install: DotnetInstall, public readonly requestingExtensionId: string | null)
1708+
{
1709+
super();
1710+
if (requestingExtensionId === 'user')
1711+
{
1712+
this.verboseOutputOnly = false;
1713+
}
1714+
}
16961715

16971716
public getProperties()
16981717
{

vscode-dotnet-runtime-library/src/EventStream/EventStreamRegistration.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export interface IEventStreamContext
3636
}
3737

3838
export function registerEventStream(context: IEventStreamContext, extensionContext: IVSCodeExtensionContext,
39-
utilityContext: IUtilityContext, suppressOutput = false): [EventStream, vscode.OutputChannel, LoggingObserver, IEventStreamObserver[], TelemetryObserver | null, ModalEventRepublisher]
39+
utilityContext: IUtilityContext, suppressOutput = false, highVerbosity = false): [EventStream, vscode.OutputChannel, LoggingObserver, IEventStreamObserver[], TelemetryObserver | null, ModalEventRepublisher]
4040
{
4141
const outputChannel = vscode.window.createOutputChannel(context.displayChannelName);
4242
if (!fs.existsSync(context.logPath))
@@ -49,7 +49,7 @@ export function registerEventStream(context: IEventStreamContext, extensionConte
4949
const eventStreamObservers: IEventStreamObserver[] =
5050
[
5151
new StatusBarObserver(vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left, Number.MIN_VALUE), context.showLogCommand),
52-
new OutputChannelObserver(outputChannel, suppressOutput),
52+
new OutputChannelObserver(outputChannel, suppressOutput, highVerbosity),
5353
loggingObserver
5454
];
5555

vscode-dotnet-runtime-library/src/EventStream/OutputChannelObserver.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,15 @@ export class OutputChannelObserver implements IEventStreamObserver
2727
private readonly inProgressDownloads: string[] = [];
2828
private downloadProgressInterval: NodeJS.Timeout | undefined;
2929

30-
constructor(private readonly outputChannel: IOutputChannel, private readonly suppressOutput: boolean = false)
30+
constructor(private readonly outputChannel: IOutputChannel, private readonly suppressOutput: boolean = false, private readonly highVerbosity: boolean = false)
3131
{
3232
}
3333

3434

3535
public post(event: IEvent): void
3636
{
37-
if (this.suppressOutput)
37+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
38+
if (this.suppressOutput || ((event as any)?.verboseOutputOnly && this.highVerbosity))
3839
{
3940
return;
4041
}

vscode-dotnet-runtime-library/src/test/unit/OutputChannelObserver.test.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*--------------------------------------------------------------------------------------------*/
55
import * as chai from 'chai';
66
import { DotnetInstall } from '../../Acquisition/DotnetInstall';
7-
import { DotnetAcquisitionCompleted, DotnetAcquisitionStarted, DotnetExistingPathResolutionCompleted, DotnetFileIntegrityFailureEvent } from '../../EventStream/EventStreamEvents';
7+
import { DotnetAcquisitionCompleted, DotnetAcquisitionStarted, DotnetASPNetRuntimeFinalAcquisitionError, DotnetExistingPathResolutionCompleted, DotnetFileIntegrityFailureEvent } from '../../EventStream/EventStreamEvents';
88
import { OutputChannelObserver } from '../../EventStream/OutputChannelObserver';
99
import { MockOutputChannel } from '../mocks/MockOutputChannel';
1010

@@ -67,4 +67,20 @@ suite('OutputChannelObserver Unit Tests', function ()
6767
assert.isNotEmpty(mockOutputChannel.appendedLines, 'Output should be written with default behavior');
6868
assert.include(mockOutputChannel.appendedLines.join(''), 'Test warning message', 'The warning message should be in the output');
6969
}).timeout(defaultTimeoutTime);
70+
71+
test('It handles verbose-only events based on highVerbosity setting', async () =>
72+
{
73+
const mockOutputChannel1 = new MockOutputChannel();
74+
const mockOutputChannel2 = new MockOutputChannel();
75+
const observerVerbose = new OutputChannelObserver(mockOutputChannel1, false, true);
76+
const observerNonVerbose = new OutputChannelObserver(mockOutputChannel2, false, false);
77+
78+
const verboseEvent = new DotnetASPNetRuntimeFinalAcquisitionError(new Error('Test error message'), '', { installId: '8.0~x64', isGlobal: false, architecture: 'x64', version: '8.0', installMode: 'runtime' } as DotnetInstall);
79+
80+
observerVerbose.post(verboseEvent);
81+
observerNonVerbose.post(verboseEvent);
82+
83+
assert.include(mockOutputChannel1.appendedLines, 'Test error', 'Verbose-only events should display when highVerbosity is true');
84+
assert.notInclude(mockOutputChannel2.appendedLines, 'Test error', 'Verbose-only events should not display when highVerbosity is false');
85+
}).timeout(defaultTimeoutTime);
7086
});

0 commit comments

Comments
 (0)