From 23ac60846168cc074860146a1fe3ce944627c028 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Fija=C5=82kowski?= Date: Mon, 1 Oct 2018 21:45:41 +0200 Subject: [PATCH] Add option to configure huge project limits --- package.json | 5 +++++ src/features/diagnosticsProvider.ts | 24 ++++++++++++++---------- src/omnisharp/extension.ts | 2 +- src/omnisharp/options.ts | 12 ++++++++---- 4 files changed, 28 insertions(+), 15 deletions(-) diff --git a/package.json b/package.json index 96eb3f2cee..61cd2bb9b1 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/features/diagnosticsProvider.ts b/src/features/diagnosticsProvider.ts index 8e910173ba..66896d3be0 100644 --- a/src/features/diagnosticsProvider.ts +++ b/src/features/diagnosticsProvider.ts @@ -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 { @@ -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); @@ -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 { @@ -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); } } diff --git a/src/omnisharp/extension.ts b/src/omnisharp/extension.ts index dd823265b2..3d3d1823d0 100644 --- a/src/omnisharp/extension.ts +++ b/src/omnisharp/extension.ts @@ -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; diff --git a/src/omnisharp/options.ts b/src/omnisharp/options.ts index 0f9dd11997..e44200f0d7 100644 --- a/src/omnisharp/options.ts +++ b/src/omnisharp/options.ts @@ -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 { @@ -68,9 +69,11 @@ export class Options { 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 + const maxProjectFileCountForDiagnosticAnalysis = csharpConfig.get('maxProjectFileCountForDiagnosticAnalysis', 1000); + return new Options( - path, - useGlobalMono, + path, + useGlobalMono, waitForDebugger, loggingLevel, autoStart, @@ -86,6 +89,7 @@ export class Options { maxFindSymbolsItems, defaultLaunchSolution, monoPath, + maxProjectFileCountForDiagnosticAnalysis, ); } @@ -119,7 +123,7 @@ export class Options { return toUseGlobalMonoValue(omnisharpConfig.get('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('omnisharpUsesMono')); } else {