Skip to content

Commit

Permalink
Add option to configure huge project limits
Browse files Browse the repository at this point in the history
  • Loading branch information
jakubfijalkowski committed Oct 1, 2018
1 parent 6c6c4c9 commit 23ac608
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 15 deletions.
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,11 @@
"default": true,
"description": "Specifies whether the run and debug test CodeLens should be show be shown."
},
"csharp.maxProjectFileCountForDiagnosticAnalysis": {
"type": "number",
"default": 1000,
"description": "Specifies the maximum number of files for which diagnostics are reported for the whole workspace. If this limit is exceeded, diagnostics will be shown for currently opened files only. Specify 0 or less to disable the limit completely."
},
"omnisharp.path": {
"type": [
"string",
Expand Down
24 changes: 14 additions & 10 deletions src/features/diagnosticsProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { toRange } from '../omnisharp/typeConvertion';
import * as vscode from 'vscode';
import CompositeDisposable from '../CompositeDisposable';
import { IDisposable } from '../Disposable';
import OptionProvider from '../observers/OptionProvider';

export class Advisor {

Expand All @@ -19,7 +20,7 @@ export class Advisor {
private _packageRestoreCounter: number = 0;
private _projectSourceFileCounts: { [path: string]: number } = Object.create(null);

constructor(server: OmniSharpServer) {
constructor(server: OmniSharpServer, private optionProvider: OptionProvider) {
this._server = server;

let d1 = server.onProjectChange(this._onProjectChange, this);
Expand Down Expand Up @@ -98,16 +99,19 @@ export class Advisor {
}

private _isHugeProject(): boolean {
let sourceFileCount = 0;
for (let key in this._projectSourceFileCounts) {
sourceFileCount += this._projectSourceFileCounts[key];
if (sourceFileCount > 1000) {
return true;
let opts = this.optionProvider.GetLatestOptions();
let fileLimit = opts.maxProjectFileCountForDiagnosticAnalysis;
if (fileLimit > 0) {
let sourceFileCount = 0;
for (let key in this._projectSourceFileCounts) {
sourceFileCount += this._projectSourceFileCounts[key];
if (sourceFileCount > fileLimit) {
return true;
}
}
}

return false;
}
return false;
}
}

export default function reportDiagnostics(server: OmniSharpServer, advisor: Advisor): IDisposable {
Expand Down Expand Up @@ -166,7 +170,7 @@ class DiagnosticsProvider extends AbstractSupport {

private _onDidChangeActiveTextEditor(textEditor: vscode.TextEditor): void {
// active text editor can be undefined.
if (textEditor != undefined && textEditor.document != null) {
if (textEditor != undefined && textEditor.document != null) {
this._onDocumentAddOrChange(textEditor.document);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/omnisharp/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,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); // create before server is started
const advisor = new Advisor(server, optionProvider); // create before server is started
const disposables = new CompositeDisposable();
let localDisposables: CompositeDisposable;

Expand Down
12 changes: 8 additions & 4 deletions src/omnisharp/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ export class Options {
public minFindSymbolsFilterLength: number,
public maxFindSymbolsItems: number,
public defaultLaunchSolution?: string,
public monoPath?: string) { }
public monoPath?: string,
public maxProjectFileCountForDiagnosticAnalysis?: number | null) { }


public static Read(vscode: vscode): Options {
Expand Down Expand Up @@ -68,9 +69,11 @@ export class Options {
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

const maxProjectFileCountForDiagnosticAnalysis = csharpConfig.get<number>('maxProjectFileCountForDiagnosticAnalysis', 1000);

return new Options(
path,
useGlobalMono,
path,
useGlobalMono,
waitForDebugger,
loggingLevel,
autoStart,
Expand All @@ -86,6 +89,7 @@ export class Options {
maxFindSymbolsItems,
defaultLaunchSolution,
monoPath,
maxProjectFileCountForDiagnosticAnalysis,
);
}

Expand Down Expand Up @@ -119,7 +123,7 @@ export class Options {
return toUseGlobalMonoValue(omnisharpConfig.get<boolean>('useMono'));
}
else if (csharpConfig.has('omnisharpUsesMono')) {
// BACKCOMPAT: If 'csharp.omnisharpUsesMono' setting was found, true maps to "always" and false maps to "auto"
// BACKCOMPAT: If 'csharp.omnisharpUsesMono' setting was found, true maps to "always" and false maps to "auto"
return toUseGlobalMonoValue(csharpConfig.get<boolean>('omnisharpUsesMono'));
}
else {
Expand Down

0 comments on commit 23ac608

Please sign in to comment.