Skip to content

Commit

Permalink
Merge pull request #4333 from JoeRobich/show-log-setting
Browse files Browse the repository at this point in the history
Add setting to control whether to show the OmniSharp log on error
  • Loading branch information
JoeRobich authored Jan 14, 2021
2 parents 3117b4e + 9b9b08c commit e8cfe10
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 7 deletions.
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -702,6 +702,11 @@
"description": "Enable/disable Semantic Highlighting for C# files (Razor files currently unsupported). Defaults to false. Close open files for changes to take effect.",
"scope": "window"
},
"csharp.showOmnisharpLogOnError": {
"type": "boolean",
"default": true,
"description": "Shows the OmniSharp log in the Output pane when OmniSharp reports an error."
},
"omnisharp.path": {
"type": [
"string",
Expand Down
2 changes: 1 addition & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export async function activate(context: vscode.ExtensionContext): Promise<CSharp

let omnisharpChannel = vscode.window.createOutputChannel('OmniSharp Log');
let omnisharpLogObserver = new OmnisharpLoggerObserver(omnisharpChannel);
let omnisharpChannelObserver = new OmnisharpChannelObserver(omnisharpChannel);
let omnisharpChannelObserver = new OmnisharpChannelObserver(omnisharpChannel, vscode);
eventStream.subscribe(omnisharpLogObserver.post);
eventStream.subscribe(omnisharpChannelObserver.post);

Expand Down
17 changes: 15 additions & 2 deletions src/observers/OmnisharpChannelObserver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,34 @@
*--------------------------------------------------------------------------------------------*/

import { BaseChannelObserver } from "./BaseChannelObserver";
import { BaseEvent } from '../omnisharp/loggingEvents';
import { vscode, OutputChannel } from '../vscodeAdapter';
import { BaseEvent, OmnisharpServerOnStdErr } from '../omnisharp/loggingEvents';
import { EventType } from "../omnisharp/EventType";

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

public post = (event: BaseEvent) => {
switch (event.type) {
case EventType.ShowOmniSharpChannel:
case EventType.OmnisharpFailure:
case EventType.OmnisharpServerOnStdErr:
this.showChannel(true);
break;
case EventType.OmnisharpServerOnStdErr:
this.handleOmnisharpServerOnStdErr(<OmnisharpServerOnStdErr>event);
break;
case EventType.OmnisharpRestart:
this.clearChannel();
break;
}
}

private async handleOmnisharpServerOnStdErr(event: OmnisharpServerOnStdErr) {
let csharpConfig = this.vscode.workspace.getConfiguration('csharp');
if (csharpConfig.get<boolean>('showOmnisharpLogOnError')) {
this.showChannel(true);
}
}
}
4 changes: 4 additions & 0 deletions src/omnisharp/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export class Options {
public showTestsCodeLens: boolean,
public disableCodeActions: boolean,
public disableMSBuildDiagnosticWarning: boolean,
public showOmnisharpLogOnError: boolean,
public minFindSymbolsFilterLength: number,
public maxFindSymbolsItems: number,
public razorDisabled: boolean,
Expand Down Expand Up @@ -86,6 +87,8 @@ export class Options {

const disableMSBuildDiagnosticWarning = omnisharpConfig.get<boolean>('disableMSBuildDiagnosticWarning', false);

const showOmnisharpLogOnError = csharpConfig.get<boolean>('showOmnisharpLogOnError', true);

const minFindSymbolsFilterLength = omnisharpConfig.get<number>('minFindSymbolsFilterLength', 0);
const maxFindSymbolsItems = omnisharpConfig.get<number>('maxFindSymbolsItems', 1000); // The limit is applied only when this setting is set to a number greater than zero

Expand Down Expand Up @@ -114,6 +117,7 @@ export class Options {
showTestsCodeLens,
disableCodeActions,
disableMSBuildDiagnosticWarning,
showOmnisharpLogOnError,
minFindSymbolsFilterLength,
maxFindSymbolsItems,
razorDisabled,
Expand Down
2 changes: 1 addition & 1 deletion test/unitTests/Fakes/FakeOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
import { Options } from "../../../src/omnisharp/options";

export function getEmptyOptions(): Options {
return new Options("", "", false, "", false, 0, 0, false, false, false, false, false, false, false, 0, 0, false, false, false, false, false, false, false, undefined, "", "");
return new Options("", "", false, "", false, 0, 0, false, false, false, false, false, false, false, false, 0, 0, false, false, false, false, false, false, false, undefined, "", "");
}
18 changes: 16 additions & 2 deletions test/unitTests/logging/OmnisharpChannelObserver.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { expect } from 'chai';
import { getNullChannel } from '../testAssets/Fakes';
import { vscode } from '.,/../../src/vscodeAdapter';
import { getNullChannel, updateConfig, getVSCodeWithConfig } from '../testAssets/Fakes';
import { OmnisharpChannelObserver } from '../../../src/observers/OmnisharpChannelObserver';
import { OmnisharpFailure, ShowOmniSharpChannel, BaseEvent, OmnisharpRestart, OmnisharpServerOnStdErr } from '../../../src/omnisharp/loggingEvents';

Expand All @@ -12,20 +13,24 @@ suite("OmnisharpChannelObserver", () => {
let hasShown: boolean;
let hasCleared: boolean;
let preserveFocus: boolean;
let vscode: vscode;
let observer: OmnisharpChannelObserver;

setup(() => {
hasShown = false;
hasCleared = false;
preserveFocus = false;
vscode = getVSCodeWithConfig();
observer = new OmnisharpChannelObserver({
...getNullChannel(),
show: (preserve) => {
hasShown = true;
preserveFocus = preserve;
},
clear: () => { hasCleared = true; }
});
}, vscode);

updateConfig(vscode, "csharp", "showOmnisharpLogOnError", true);
});

[
Expand All @@ -41,6 +46,15 @@ suite("OmnisharpChannelObserver", () => {
});
});

test(`OmnisharpServerOnStdErr: Channel is not shown when disabled in configuration`, () => {
updateConfig(vscode, "csharp", "showOmnisharpLogOnError", false);

expect(hasShown).to.be.false;
observer.post(new OmnisharpServerOnStdErr("std err"));
expect(hasShown).to.be.false;
expect(preserveFocus).to.be.false;
});

[
new OmnisharpRestart()
].forEach((event: BaseEvent) => {
Expand Down
2 changes: 1 addition & 1 deletion test/unitTests/options.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ suite("Options tests", () => {
options.showReferencesCodeLens.should.equal(true);
options.showTestsCodeLens.should.equal(true);
options.disableCodeActions.should.equal(false);
options.disableCodeActions.should.equal(false);
options.showOmnisharpLogOnError.should.equal(true);
options.minFindSymbolsFilterLength.should.equal(0);
options.maxFindSymbolsItems.should.equal(1000);
options.enableMsBuildLoadProjectsOnDemand.should.equal(false);
Expand Down

0 comments on commit e8cfe10

Please sign in to comment.