Skip to content

Commit

Permalink
Allow users to disable the "some projects have trouble loading" popup
Browse files Browse the repository at this point in the history
  • Loading branch information
Ravi Chande committed Apr 10, 2018
1 parent c65c4c5 commit 0a16e60
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 6 deletions.
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,11 @@
"type": "boolean",
"default": true,
"description": "Specifes whether OmniSharp should use VS Code editor settings for C# code formatting (use of tabs, indentation size)."
},
"omnisharp.disableMsBuildDiagnosticWarning": {
"type": "boolean",
"default": false,
"description": "Specifies whether notifications should be shown if OmniSharp encounters warnings or errors loading a project. Note that these warnings/errors are always emitted to the OmniSharp log"
}
}
},
Expand Down
3 changes: 2 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import TelemetryReporter from 'vscode-extension-telemetry';
import { addJSONProviders } from './features/json/jsonContributions';
import { ProjectStatusBarObserver } from './observers/ProjectStatusBarObserver';
import CSharpExtensionExports from './CSharpExtensionExports';
import { Options } from './omnisharp/options';

export async function activate(context: vscode.ExtensionContext): Promise<CSharpExtensionExports> {

Expand Down Expand Up @@ -59,7 +60,7 @@ export async function activate(context: vscode.ExtensionContext): Promise<CSharp
eventStream.subscribe(omnisharpLogObserver.post);
eventStream.subscribe(omnisharpChannelObserver.post);

let warningMessageObserver = new WarningMessageObserver(vscode);
let warningMessageObserver = new WarningMessageObserver(vscode, () => Options.Read().disableMsBuildDiagnosticWarning || false);
eventStream.subscribe(warningMessageObserver.post);

let informationMessageObserver = new InformationMessageObserver(vscode);
Expand Down
4 changes: 2 additions & 2 deletions src/observers/WarningMessageObserver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export interface MessageItemWithCommand extends MessageItem {
export class WarningMessageObserver {
private warningMessageDebouncer: Subject<BaseEvent>;

constructor(private vscode: vscode, scheduler?: Scheduler) {
constructor(private vscode: vscode, private disableMsBuildDiagnosticWarning: () => boolean, scheduler?: Scheduler) {
this.warningMessageDebouncer = new Subject<BaseEvent>();
this.warningMessageDebouncer.debounce(1500, scheduler).subscribe(async event => {
let message = "Some projects have trouble loading. Please review the output for more details.";
Expand All @@ -37,7 +37,7 @@ export class WarningMessageObserver {
}

private handleOmnisharpServerMsBuildProjectDiagnostics(event: OmnisharpServerMsBuildProjectDiagnostics) {
if (event.diagnostics.Errors.length > 0) {
if (!this.disableMsBuildDiagnosticWarning() && event.diagnostics.Errors.length > 0) {
this.warningMessageDebouncer.onNext(event);
}
}
Expand Down
8 changes: 6 additions & 2 deletions src/omnisharp/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ export class Options {
public useFormatting?: boolean,
public showReferencesCodeLens?: boolean,
public showTestsCodeLens?: boolean,
public disableCodeActions?: boolean) { }
public disableCodeActions?: boolean,
public disableMsBuildDiagnosticWarning?: boolean) { }

public static Read(): Options {
// Extra effort is taken below to ensure that legacy versions of options
Expand Down Expand Up @@ -59,6 +60,8 @@ export class Options {

const disableCodeActions = csharpConfig.get<boolean>('disableCodeActions', false);

const disableMsBuildDiagnosticWarning = omnisharpConfig.get<boolean>('disableMsBuildDiagnosticWarning');

return new Options(path,
useMono,
waitForDebugger,
Expand All @@ -70,6 +73,7 @@ export class Options {
useFormatting,
showReferencesCodeLens,
showTestsCodeLens,
disableCodeActions);
disableCodeActions,
disableMsBuildDiagnosticWarning);
}
}
11 changes: 10 additions & 1 deletion test/unitTests/logging/WarningMessageObserver.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ suite('WarningMessageObserver', () => {
scheduler = new rx.HistoricalScheduler(0, (x, y) => {
return x > y ? 1 : -1;
});
observer = new WarningMessageObserver(vscode, scheduler);
observer = new WarningMessageObserver(vscode, () => false, scheduler);
warningMessage = undefined;
invokedCommand = undefined;
commandDone = new Promise<void>(resolve => {
Expand All @@ -70,6 +70,15 @@ suite('WarningMessageObserver', () => {
expect(invokedCommand).to.be.undefined;
});

test('OmnisharpServerMsBuildProjectDiagnostics: No event is posted if warning is disabled', () => {
let newObserver = new WarningMessageObserver(vscode, () => true, scheduler);
let event = getOmnisharpMSBuildProjectDiagnosticsEvent("someFile",
[getMSBuildDiagnosticsMessage("warningFile", "", "", 0, 0, 0, 0)],
[getMSBuildDiagnosticsMessage("warningFile", "", "", 0, 0, 0, 0)]);
newObserver.post(event);
expect(warningMessage).to.be.undefined;
});

[
getOmnisharpMSBuildProjectDiagnosticsEvent("someFile",
[getMSBuildDiagnosticsMessage("warningFile", "", "", 1, 2, 3, 4)],
Expand Down

0 comments on commit 0a16e60

Please sign in to comment.