Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Integration-test Advisor project analysis file limit
Browse files Browse the repository at this point in the history
jakubfijalkowski committed Oct 24, 2018
1 parent 877f314 commit 3080763
Showing 4 changed files with 81 additions and 5 deletions.
8 changes: 4 additions & 4 deletions src/features/diagnosticsProvider.ts
Original file line number Diff line number Diff line change
@@ -45,7 +45,7 @@ export class Advisor {
public shouldValidateProject(): boolean {
return this._isServerStarted()
&& !this._isRestoringPackages()
&& !this._isHugeProject();
&& !this._isOverFileLimit();
}

private _updateProjectFileCount(path: string, fileCount: number): void {
@@ -100,7 +100,7 @@ export class Advisor {
return this._server.isRunning();
}

private _isHugeProject(): boolean {
private _isOverFileLimit(): boolean {
let opts = this.optionProvider.GetLatestOptions();
let fileLimit = opts.maxProjectFileCountForDiagnosticAnalysis;
if (fileLimit > 0) {
@@ -112,8 +112,8 @@ export class Advisor {
}
}
}
return false;
}
return false;
}
}

export default function reportDiagnostics(server: OmniSharpServer, advisor: Advisor): IDisposable {
3 changes: 2 additions & 1 deletion src/omnisharp/extension.ts
Original file line number Diff line number Diff line change
@@ -40,6 +40,7 @@ import { OmniSharpMonoResolver } from './OmniSharpMonoResolver';
import { getMonoVersion } from '../utils/getMonoVersion';

export let omnisharp: OmniSharpServer;
export let advisor: Advisor;

export async function activate(context: vscode.ExtensionContext, packageJSON: any, platformInfo: PlatformInformation, provider: NetworkSettingsProvider, eventStream: EventStream, optionProvider: OptionProvider, extensionPath: string) {
const documentSelector: vscode.DocumentSelector = {
@@ -50,7 +51,7 @@ export async function activate(context: vscode.ExtensionContext, packageJSON: an
let omnisharpMonoResolver = new OmniSharpMonoResolver(getMonoVersion);
const server = new OmniSharpServer(vscode, provider, packageJSON, platformInfo, eventStream, optionProvider, extensionPath, omnisharpMonoResolver);
omnisharp = server;
const advisor = new Advisor(server, optionProvider); // create before server is started
advisor = new Advisor(server, optionProvider); // create before server is started
const disposables = new CompositeDisposable();
let localDisposables: CompositeDisposable;

74 changes: 74 additions & 0 deletions test/integrationTests/diagnostics.integration.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import * as vscode from 'vscode';

import { expect } from 'chai';
import * as path from 'path';
import { activateCSharpExtension } from './integrationHelpers';
import testAssetWorkspace from './testAssets/testAssetWorkspace';

import { advisor } from "../../src/omnisharp/extension";

const chai = require('chai');
chai.use(require('chai-arrays'));
chai.use(require('chai-fs'));

function setLimit(to: number | null) {
let csharpConfig = vscode.workspace.getConfiguration('csharp');
return csharpConfig.update('maxProjectFileCountForDiagnosticAnalysis', to);
}

suite(`Diagnostics Provider ${testAssetWorkspace.description}`, function () {
suiteSetup(async function () {
await testAssetWorkspace.restore();
await activateCSharpExtension();

let fileName = 'completion.cs';
let dir = testAssetWorkspace.projects[0].projectDirectoryPath;
let fileUri = vscode.Uri.file(path.join(dir, fileName));
await vscode.commands.executeCommand('vscode.open', fileUri);
});

suiteTeardown(async () => {
await testAssetWorkspace.cleanupWorkspace();
});

test('Reports errors from whole project when maxProjectFileCountForDiagnosticAnalysis is higher than the file count', async () => {
await setLimit(1000);

expect(advisor.shouldValidateProject()).to.be.true;
});

test('Reports errors from individual files when maxProjectFileCountForDiagnosticAnalysis is higher than the file count', async () => {
await setLimit(1000);

expect(advisor.shouldValidateFiles()).to.be.true;
});

test('Does not report errors from whole project when maxProjectFileCountForDiagnosticAnalysis is lower than the file count', async () => {
await setLimit(1);

expect(advisor.shouldValidateProject()).to.be.false;
});

test('Reports errors from individual files when maxProjectFileCountForDiagnosticAnalysis is lower than the file count', async () => {
await setLimit(1);

expect(advisor.shouldValidateFiles()).to.be.true;
});

test('Reports errors from whole project when maxProjectFileCountForDiagnosticAnalysis is null', async () => {
await setLimit(null);

expect(advisor.shouldValidateProject()).to.be.true;
});

test('Reports errors from individual files when maxProjectFileCountForDiagnosticAnalysis is null', async () => {
await setLimit(null);

expect(advisor.shouldValidateFiles()).to.be.true;
});
});
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"omnisharp.defaultLaunchSolution": "b_SecondInOrder_SlnFile.sln",
"omnisharp.path": "latest",
"csharp.maxProjectFileCountForDiagnosticAnalysis": 1000,
}

0 comments on commit 3080763

Please sign in to comment.