From 9b9b08cbcd53af8f71c05a6fb062758cfdce0fa5 Mon Sep 17 00:00:00 2001 From: Joey Robichaud Date: Tue, 5 Jan 2021 16:51:15 -0800 Subject: [PATCH] Add setting to control whether to show the OmniSharp log on error --- package.json | 5 +++++ src/main.ts | 2 +- src/observers/OmnisharpChannelObserver.ts | 17 +++++++++++++++-- src/omnisharp/options.ts | 4 ++++ test/unitTests/Fakes/FakeOptions.ts | 2 +- .../logging/OmnisharpChannelObserver.test.ts | 18 ++++++++++++++++-- test/unitTests/options.test.ts | 2 +- 7 files changed, 43 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index b1ac5087b..46d65e6e6 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/main.ts b/src/main.ts index f56559cfa..cb7f4a138 100644 --- a/src/main.ts +++ b/src/main.ts @@ -80,7 +80,7 @@ export async function activate(context: vscode.ExtensionContext): Promise { switch (event.type) { case EventType.ShowOmniSharpChannel: case EventType.OmnisharpFailure: - case EventType.OmnisharpServerOnStdErr: this.showChannel(true); break; + case EventType.OmnisharpServerOnStdErr: + this.handleOmnisharpServerOnStdErr(event); + break; case EventType.OmnisharpRestart: this.clearChannel(); break; } } + + private async handleOmnisharpServerOnStdErr(event: OmnisharpServerOnStdErr) { + let csharpConfig = this.vscode.workspace.getConfiguration('csharp'); + if (csharpConfig.get('showOmnisharpLogOnError')) { + this.showChannel(true); + } + } } \ No newline at end of file diff --git a/src/omnisharp/options.ts b/src/omnisharp/options.ts index da928a45c..0d5d9fc50 100644 --- a/src/omnisharp/options.ts +++ b/src/omnisharp/options.ts @@ -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, @@ -86,6 +87,8 @@ export class Options { const disableMSBuildDiagnosticWarning = omnisharpConfig.get('disableMSBuildDiagnosticWarning', false); + const showOmnisharpLogOnError = csharpConfig.get('showOmnisharpLogOnError', true); + const minFindSymbolsFilterLength = omnisharpConfig.get('minFindSymbolsFilterLength', 0); const maxFindSymbolsItems = omnisharpConfig.get('maxFindSymbolsItems', 1000); // The limit is applied only when this setting is set to a number greater than zero @@ -114,6 +117,7 @@ export class Options { showTestsCodeLens, disableCodeActions, disableMSBuildDiagnosticWarning, + showOmnisharpLogOnError, minFindSymbolsFilterLength, maxFindSymbolsItems, razorDisabled, diff --git a/test/unitTests/Fakes/FakeOptions.ts b/test/unitTests/Fakes/FakeOptions.ts index 72dd48d32..59fe2c817 100644 --- a/test/unitTests/Fakes/FakeOptions.ts +++ b/test/unitTests/Fakes/FakeOptions.ts @@ -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, "", ""); } diff --git a/test/unitTests/logging/OmnisharpChannelObserver.test.ts b/test/unitTests/logging/OmnisharpChannelObserver.test.ts index dcbb0687c..a05889a8d 100644 --- a/test/unitTests/logging/OmnisharpChannelObserver.test.ts +++ b/test/unitTests/logging/OmnisharpChannelObserver.test.ts @@ -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'; @@ -12,12 +13,14 @@ 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) => { @@ -25,7 +28,9 @@ suite("OmnisharpChannelObserver", () => { preserveFocus = preserve; }, clear: () => { hasCleared = true; } - }); + }, vscode); + + updateConfig(vscode, "csharp", "showOmnisharpLogOnError", true); }); [ @@ -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) => { diff --git a/test/unitTests/options.test.ts b/test/unitTests/options.test.ts index a314a1dbc..d2a6d0d3e 100644 --- a/test/unitTests/options.test.ts +++ b/test/unitTests/options.test.ts @@ -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);