From 8769645fa14698326294c14b0c62441f98b5d97a Mon Sep 17 00:00:00 2001 From: "String.Epsilon" Date: Tue, 13 Dec 2022 08:11:19 +0100 Subject: [PATCH] Use showOmnisharpLogOnError setting in all channels Addresses #4608, #3708 --- src/main.ts | 6 ++--- src/observers/CsharpChannelObserver.ts | 10 ++++++++- src/observers/DotnetChannelObserver.ts | 10 ++++++++- src/observers/DotnetTestChannelObserver.ts | 10 ++++++++- src/observers/OmnisharpChannelObserver.ts | 5 ++++- .../logging/CsharpChannelObserver.test.ts | 22 +++++++++++-------- .../logging/DotnetChannelObserver.test.ts | 18 +++++++++------ .../logging/DotnetTestChannelObserver.test.ts | 22 +++++++++++-------- 8 files changed, 71 insertions(+), 32 deletions(-) diff --git a/src/main.ts b/src/main.ts index 4448194f2..6419cfa75 100644 --- a/src/main.ts +++ b/src/main.ts @@ -69,19 +69,19 @@ export async function activate(context: vscode.ExtensionContext): Promise { switch (event.type) { case EventType.PackageInstallStart: @@ -16,7 +21,10 @@ export class CsharpChannelObserver extends BaseChannelObserver { case EventType.DebuggerNotInstalledFailure: case EventType.DebuggerPrerequisiteFailure: case EventType.ProjectJsonDeprecatedWarning: - this.showChannel(true); + let csharpConfig = this.vscode.workspace.getConfiguration('csharp'); + if (csharpConfig.get('showOmnisharpLogOnError')) { + this.showChannel(true); + } break; } } diff --git a/src/observers/DotnetChannelObserver.ts b/src/observers/DotnetChannelObserver.ts index c187fa0ba..5cdf44916 100644 --- a/src/observers/DotnetChannelObserver.ts +++ b/src/observers/DotnetChannelObserver.ts @@ -6,13 +6,21 @@ import { BaseChannelObserver } from "./BaseChannelObserver"; import { BaseEvent } from "../omnisharp/loggingEvents"; import { EventType } from "../omnisharp/EventType"; +import { OutputChannel, vscode } from "../vscodeAdapter"; export class DotNetChannelObserver extends BaseChannelObserver { + constructor(channel: OutputChannel, private vscode: vscode) { + super(channel); + } + public post = (event: BaseEvent) => { switch (event.type) { case EventType.CommandDotNetRestoreStart: this.clearChannel(); - this.showChannel(true); + let csharpConfig = this.vscode.workspace.getConfiguration('csharp'); + if (csharpConfig.get('showOmnisharpLogOnError')) { + this.showChannel(true); + } break; } } diff --git a/src/observers/DotnetTestChannelObserver.ts b/src/observers/DotnetTestChannelObserver.ts index 3156f5600..a92da759b 100644 --- a/src/observers/DotnetTestChannelObserver.ts +++ b/src/observers/DotnetTestChannelObserver.ts @@ -6,8 +6,13 @@ import { BaseChannelObserver } from "./BaseChannelObserver"; import { BaseEvent } from "../omnisharp/loggingEvents"; import { EventType } from "../omnisharp/EventType"; +import { OutputChannel , vscode } from "../vscodeAdapter"; export default class DotnetTestChannelObserver extends BaseChannelObserver { + constructor(channel: OutputChannel, private vscode: vscode) { + super(channel); + } + public post = (event: BaseEvent) => { switch (event.type) { case EventType.DotNetTestRunStart: @@ -17,7 +22,10 @@ export default class DotnetTestChannelObserver extends BaseChannelObserver { case EventType.DotNetTestsInClassDebugStart: case EventType.DotNetTestRunInContextStart: case EventType.DotNetTestDebugInContextStart: - this.showChannel(true); + let csharpConfig = this.vscode.workspace.getConfiguration('csharp'); + if (csharpConfig.get('showOmnisharpLogOnError')) { + this.showChannel(true); + } break; } } diff --git a/src/observers/OmnisharpChannelObserver.ts b/src/observers/OmnisharpChannelObserver.ts index 016a751ec..9de37d08c 100644 --- a/src/observers/OmnisharpChannelObserver.ts +++ b/src/observers/OmnisharpChannelObserver.ts @@ -17,7 +17,10 @@ export class OmnisharpChannelObserver extends BaseChannelObserver { switch (event.type) { case EventType.ShowOmniSharpChannel: case EventType.OmnisharpFailure: - this.showChannel(true); + let csharpConfig = this.vscode.workspace.getConfiguration('csharp'); + if (csharpConfig.get('showOmnisharpLogOnError')) { + this.showChannel(true); + } break; case EventType.OmnisharpServerOnStdErr: this.handleOmnisharpServerOnStdErr(event); diff --git a/test/unitTests/logging/CsharpChannelObserver.test.ts b/test/unitTests/logging/CsharpChannelObserver.test.ts index c6f8229cb..66e517d91 100644 --- a/test/unitTests/logging/CsharpChannelObserver.test.ts +++ b/test/unitTests/logging/CsharpChannelObserver.test.ts @@ -4,7 +4,7 @@ *--------------------------------------------------------------------------------------------*/ import { should, expect } from 'chai'; -import { getNullChannel } from '../testAssets/Fakes'; +import { getNullChannel, getVSCodeWithConfig, updateConfig } from '../testAssets/Fakes'; import { CsharpChannelObserver } from '../../../src/observers/CsharpChannelObserver'; import { InstallationFailure, DebuggerNotInstalledFailure, DebuggerPrerequisiteFailure, ProjectJsonDeprecatedWarning, BaseEvent, PackageInstallStart, IntegrityCheckFailure } from '../../../src/omnisharp/loggingEvents'; @@ -21,14 +21,18 @@ suite("CsharpChannelObserver", () => { test(`${event.constructor.name}: Channel is shown and preserve focus is set to true`, () => { let hasShown = false; let preserveFocus = false; - let observer = new CsharpChannelObserver({ - ...getNullChannel(), - show: (preserve) => { - hasShown = true; - preserveFocus = preserve; - } - }); - + let vscode = getVSCodeWithConfig(); + let observer = new CsharpChannelObserver( + { + ...getNullChannel(), + show: (preserve) => { + hasShown = true; + preserveFocus = preserve; + } + }, + vscode + ); + updateConfig(vscode, "csharp", "showOmnisharpLogOnError", true); observer.post(event); expect(hasShown).to.be.true; expect(preserveFocus).to.be.true; diff --git a/test/unitTests/logging/DotnetChannelObserver.test.ts b/test/unitTests/logging/DotnetChannelObserver.test.ts index 1453201a7..f73e5d8ad 100644 --- a/test/unitTests/logging/DotnetChannelObserver.test.ts +++ b/test/unitTests/logging/DotnetChannelObserver.test.ts @@ -5,19 +5,23 @@ import { should, expect } from 'chai'; import { DotNetChannelObserver } from "../../../src/observers/DotnetChannelObserver"; -import { getNullChannel } from '../testAssets/Fakes'; +import { getNullChannel, getVSCodeWithConfig, updateConfig } from '../testAssets/Fakes'; import { CommandDotNetRestoreStart } from '../../../src/omnisharp/loggingEvents'; suite("DotnetChannelObserver", () => { suiteSetup(() => should()); let hasShown: boolean; let hasCleared: boolean; - - let observer = new DotNetChannelObserver({ - ...getNullChannel(), - clear: () => { hasCleared = true; }, - show: () => { hasShown = true; } - }); + let vscode = getVSCodeWithConfig(); + let observer = new DotNetChannelObserver( + { + ...getNullChannel(), + clear: () => { hasCleared = true; }, + show: () => { hasShown = true; } + }, + vscode + ); + updateConfig(vscode, "csharp", "showOmnisharpLogOnError", true); setup(() => { hasShown = false; diff --git a/test/unitTests/logging/DotnetTestChannelObserver.test.ts b/test/unitTests/logging/DotnetTestChannelObserver.test.ts index a34fede2c..89fce85ab 100644 --- a/test/unitTests/logging/DotnetTestChannelObserver.test.ts +++ b/test/unitTests/logging/DotnetTestChannelObserver.test.ts @@ -4,21 +4,25 @@ *--------------------------------------------------------------------------------------------*/ import { expect } from 'chai'; -import { getNullChannel } from '../testAssets/Fakes'; +import { getNullChannel, getVSCodeWithConfig, updateConfig } from '../testAssets/Fakes'; import { BaseEvent, DotNetTestsInClassDebugStart, DotNetTestRunStart, DotNetTestRunFailure, DotNetTestsInClassRunStart, DotNetTestDebugStart } from '../../../src/omnisharp/loggingEvents'; import DotnetTestChannelObserver from '../../../src/observers/DotnetTestChannelObserver'; suite("DotnetTestChannelObserver", () => { let hasShown: boolean; let preserveFocus: boolean; - - let observer = new DotnetTestChannelObserver({ - ...getNullChannel(), - show: (preserve) => { - hasShown = true; - preserveFocus = preserve; - } - }); + let vscode = getVSCodeWithConfig(); + let observer = new DotnetTestChannelObserver( + { + ...getNullChannel(), + show: (preserve) => { + hasShown = true; + preserveFocus = preserve; + } + }, + vscode + ); + updateConfig(vscode, "csharp", "showOmnisharpLogOnError", true); setup(() => { hasShown = false;