Skip to content

Commit

Permalink
Use showOmnisharpLogOnError setting in all channels
Browse files Browse the repository at this point in the history
  • Loading branch information
StringEpsilon committed Dec 13, 2022
1 parent 2c61b60 commit 8769645
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 32 deletions.
6 changes: 3 additions & 3 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,19 +69,19 @@ export async function activate(context: vscode.ExtensionContext): Promise<CSharp
let optionProvider = new OptionProvider(optionStream);

let dotnetChannel = vscode.window.createOutputChannel('.NET');
let dotnetChannelObserver = new DotNetChannelObserver(dotnetChannel);
let dotnetChannelObserver = new DotNetChannelObserver(dotnetChannel, vscode);
let dotnetLoggerObserver = new DotnetLoggerObserver(dotnetChannel);
eventStream.subscribe(dotnetChannelObserver.post);
eventStream.subscribe(dotnetLoggerObserver.post);

let dotnetTestChannel = vscode.window.createOutputChannel(".NET Test Log");
let dotnetTestChannelObserver = new DotNetTestChannelObserver(dotnetTestChannel);
let dotnetTestChannelObserver = new DotNetTestChannelObserver(dotnetTestChannel, vscode);
let dotnetTestLoggerObserver = new DotNetTestLoggerObserver(dotnetTestChannel);
eventStream.subscribe(dotnetTestChannelObserver.post);
eventStream.subscribe(dotnetTestLoggerObserver.post);

let csharpChannel = vscode.window.createOutputChannel('C#');
let csharpchannelObserver = new CsharpChannelObserver(csharpChannel);
let csharpchannelObserver = new CsharpChannelObserver(csharpChannel,vscode);
let csharpLogObserver = new CsharpLoggerObserver(csharpChannel);
eventStream.subscribe(csharpchannelObserver.post);
eventStream.subscribe(csharpLogObserver.post);
Expand Down
10 changes: 9 additions & 1 deletion src/observers/CsharpChannelObserver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,13 @@
import { BaseChannelObserver } from "./BaseChannelObserver";
import { EventType } from "../omnisharp/EventType";
import { BaseEvent } from "../omnisharp/loggingEvents";
import { OutputChannel, vscode } from "../vscodeAdapter";

export class CsharpChannelObserver extends BaseChannelObserver {
constructor(channel: OutputChannel, private vscode: vscode) {
super(channel);
}

public post = (event: BaseEvent) => {
switch (event.type) {
case EventType.PackageInstallStart:
Expand All @@ -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<boolean>('showOmnisharpLogOnError')) {
this.showChannel(true);
}
break;
}
}
Expand Down
10 changes: 9 additions & 1 deletion src/observers/DotnetChannelObserver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<boolean>('showOmnisharpLogOnError')) {
this.showChannel(true);
}
break;
}
}
Expand Down
10 changes: 9 additions & 1 deletion src/observers/DotnetTestChannelObserver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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<boolean>('showOmnisharpLogOnError')) {
this.showChannel(true);
}
break;
}
}
Expand Down
5 changes: 4 additions & 1 deletion src/observers/OmnisharpChannelObserver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<boolean>('showOmnisharpLogOnError')) {
this.showChannel(true);
}
break;
case EventType.OmnisharpServerOnStdErr:
this.handleOmnisharpServerOnStdErr(<OmnisharpServerOnStdErr>event);
Expand Down
22 changes: 13 additions & 9 deletions test/unitTests/logging/CsharpChannelObserver.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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;
Expand Down
18 changes: 11 additions & 7 deletions test/unitTests/logging/DotnetChannelObserver.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
22 changes: 13 additions & 9 deletions test/unitTests/logging/DotnetTestChannelObserver.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 8769645

Please sign in to comment.