Skip to content

Commit e8cfe10

Browse files
authored
Merge pull request #4333 from JoeRobich/show-log-setting
Add setting to control whether to show the OmniSharp log on error
2 parents 3117b4e + 9b9b08c commit e8cfe10

File tree

7 files changed

+43
-7
lines changed

7 files changed

+43
-7
lines changed

package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -702,6 +702,11 @@
702702
"description": "Enable/disable Semantic Highlighting for C# files (Razor files currently unsupported). Defaults to false. Close open files for changes to take effect.",
703703
"scope": "window"
704704
},
705+
"csharp.showOmnisharpLogOnError": {
706+
"type": "boolean",
707+
"default": true,
708+
"description": "Shows the OmniSharp log in the Output pane when OmniSharp reports an error."
709+
},
705710
"omnisharp.path": {
706711
"type": [
707712
"string",

src/main.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ export async function activate(context: vscode.ExtensionContext): Promise<CSharp
8080

8181
let omnisharpChannel = vscode.window.createOutputChannel('OmniSharp Log');
8282
let omnisharpLogObserver = new OmnisharpLoggerObserver(omnisharpChannel);
83-
let omnisharpChannelObserver = new OmnisharpChannelObserver(omnisharpChannel);
83+
let omnisharpChannelObserver = new OmnisharpChannelObserver(omnisharpChannel, vscode);
8484
eventStream.subscribe(omnisharpLogObserver.post);
8585
eventStream.subscribe(omnisharpChannelObserver.post);
8686

src/observers/OmnisharpChannelObserver.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,34 @@
44
*--------------------------------------------------------------------------------------------*/
55

66
import { BaseChannelObserver } from "./BaseChannelObserver";
7-
import { BaseEvent } from '../omnisharp/loggingEvents';
7+
import { vscode, OutputChannel } from '../vscodeAdapter';
8+
import { BaseEvent, OmnisharpServerOnStdErr } from '../omnisharp/loggingEvents';
89
import { EventType } from "../omnisharp/EventType";
910

1011
export class OmnisharpChannelObserver extends BaseChannelObserver {
12+
constructor(channel: OutputChannel, private vscode: vscode) {
13+
super(channel);
14+
}
1115

1216
public post = (event: BaseEvent) => {
1317
switch (event.type) {
1418
case EventType.ShowOmniSharpChannel:
1519
case EventType.OmnisharpFailure:
16-
case EventType.OmnisharpServerOnStdErr:
1720
this.showChannel(true);
1821
break;
22+
case EventType.OmnisharpServerOnStdErr:
23+
this.handleOmnisharpServerOnStdErr(<OmnisharpServerOnStdErr>event);
24+
break;
1925
case EventType.OmnisharpRestart:
2026
this.clearChannel();
2127
break;
2228
}
2329
}
30+
31+
private async handleOmnisharpServerOnStdErr(event: OmnisharpServerOnStdErr) {
32+
let csharpConfig = this.vscode.workspace.getConfiguration('csharp');
33+
if (csharpConfig.get<boolean>('showOmnisharpLogOnError')) {
34+
this.showChannel(true);
35+
}
36+
}
2437
}

src/omnisharp/options.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export class Options {
2121
public showTestsCodeLens: boolean,
2222
public disableCodeActions: boolean,
2323
public disableMSBuildDiagnosticWarning: boolean,
24+
public showOmnisharpLogOnError: boolean,
2425
public minFindSymbolsFilterLength: number,
2526
public maxFindSymbolsItems: number,
2627
public razorDisabled: boolean,
@@ -86,6 +87,8 @@ export class Options {
8687

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

90+
const showOmnisharpLogOnError = csharpConfig.get<boolean>('showOmnisharpLogOnError', true);
91+
8992
const minFindSymbolsFilterLength = omnisharpConfig.get<number>('minFindSymbolsFilterLength', 0);
9093
const maxFindSymbolsItems = omnisharpConfig.get<number>('maxFindSymbolsItems', 1000); // The limit is applied only when this setting is set to a number greater than zero
9194

@@ -114,6 +117,7 @@ export class Options {
114117
showTestsCodeLens,
115118
disableCodeActions,
116119
disableMSBuildDiagnosticWarning,
120+
showOmnisharpLogOnError,
117121
minFindSymbolsFilterLength,
118122
maxFindSymbolsItems,
119123
razorDisabled,

test/unitTests/Fakes/FakeOptions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@
66
import { Options } from "../../../src/omnisharp/options";
77

88
export function getEmptyOptions(): Options {
9-
return new Options("", "", false, "", false, 0, 0, false, false, false, false, false, false, false, 0, 0, false, false, false, false, false, false, false, undefined, "", "");
9+
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, "", "");
1010
}

test/unitTests/logging/OmnisharpChannelObserver.test.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55
import { expect } from 'chai';
6-
import { getNullChannel } from '../testAssets/Fakes';
6+
import { vscode } from '.,/../../src/vscodeAdapter';
7+
import { getNullChannel, updateConfig, getVSCodeWithConfig } from '../testAssets/Fakes';
78
import { OmnisharpChannelObserver } from '../../../src/observers/OmnisharpChannelObserver';
89
import { OmnisharpFailure, ShowOmniSharpChannel, BaseEvent, OmnisharpRestart, OmnisharpServerOnStdErr } from '../../../src/omnisharp/loggingEvents';
910

@@ -12,20 +13,24 @@ suite("OmnisharpChannelObserver", () => {
1213
let hasShown: boolean;
1314
let hasCleared: boolean;
1415
let preserveFocus: boolean;
16+
let vscode: vscode;
1517
let observer: OmnisharpChannelObserver;
1618

1719
setup(() => {
1820
hasShown = false;
1921
hasCleared = false;
2022
preserveFocus = false;
23+
vscode = getVSCodeWithConfig();
2124
observer = new OmnisharpChannelObserver({
2225
...getNullChannel(),
2326
show: (preserve) => {
2427
hasShown = true;
2528
preserveFocus = preserve;
2629
},
2730
clear: () => { hasCleared = true; }
28-
});
31+
}, vscode);
32+
33+
updateConfig(vscode, "csharp", "showOmnisharpLogOnError", true);
2934
});
3035

3136
[
@@ -41,6 +46,15 @@ suite("OmnisharpChannelObserver", () => {
4146
});
4247
});
4348

49+
test(`OmnisharpServerOnStdErr: Channel is not shown when disabled in configuration`, () => {
50+
updateConfig(vscode, "csharp", "showOmnisharpLogOnError", false);
51+
52+
expect(hasShown).to.be.false;
53+
observer.post(new OmnisharpServerOnStdErr("std err"));
54+
expect(hasShown).to.be.false;
55+
expect(preserveFocus).to.be.false;
56+
});
57+
4458
[
4559
new OmnisharpRestart()
4660
].forEach((event: BaseEvent) => {

test/unitTests/options.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ suite("Options tests", () => {
2626
options.showReferencesCodeLens.should.equal(true);
2727
options.showTestsCodeLens.should.equal(true);
2828
options.disableCodeActions.should.equal(false);
29-
options.disableCodeActions.should.equal(false);
29+
options.showOmnisharpLogOnError.should.equal(true);
3030
options.minFindSymbolsFilterLength.should.equal(0);
3131
options.maxFindSymbolsItems.should.equal(1000);
3232
options.enableMsBuildLoadProjectsOnDemand.should.equal(false);

0 commit comments

Comments
 (0)