Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add setting to control whether to show the OmniSharp log on error #4333

Merged
merged 1 commit into from
Jan 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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