From a95ce4c3428abbba10c6290e228a3ecfea8c8f73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Fija=C5=82kowski?= Date: Thu, 25 Oct 2018 19:19:23 +0200 Subject: [PATCH] Change the Advisor global var to Advisor returned from CSharpExtensionExports --- src/CSharpExtensionExports.ts | 4 ++++ src/main.ts | 14 +++++++---- src/omnisharp/extension.ts | 13 ++++++----- .../diagnostics.integration.test.ts | 23 ++++++++++++------- test/integrationTests/integrationHelpers.ts | 11 +++++++-- 5 files changed, 44 insertions(+), 21 deletions(-) diff --git a/src/CSharpExtensionExports.ts b/src/CSharpExtensionExports.ts index f5eefaf41f..51f992acb9 100644 --- a/src/CSharpExtensionExports.ts +++ b/src/CSharpExtensionExports.ts @@ -3,6 +3,10 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ +import { Advisor } from "./features/diagnosticsProvider"; + export default interface CSharpExtensionExports { initializationFinished: () => Promise; + + getAdvisor: () => Promise; } \ No newline at end of file diff --git a/src/main.ts b/src/main.ts index 6b5e7ba523..08fb6f1939 100644 --- a/src/main.ts +++ b/src/main.ts @@ -30,7 +30,7 @@ import { ProjectStatusBarObserver } from './observers/ProjectStatusBarObserver'; import CSharpExtensionExports from './CSharpExtensionExports'; import { vscodeNetworkSettingsProvider, NetworkSettingsProvider } from './NetworkSettings'; import { ErrorMessageObserver } from './observers/ErrorMessageObserver'; -import OptionProvider from './observers/OptionProvider'; +import OptionProvider from './observers/OptionProvider'; import DotNetTestChannelObserver from './observers/DotnetTestChannelObserver'; import DotNetTestLoggerObserver from './observers/DotnetTestLoggerObserver'; import { ShowOmniSharpConfigChangePrompt } from './observers/OptionChangeObserver'; @@ -65,7 +65,7 @@ export async function activate(context: vscode.ExtensionContext): Promise { - let omniSharp = await omniSharpPromise; - await omniSharp.waitForEmptyEventQueue(); + let langService = await langServicePromise; + await langService.server.waitForEmptyEventQueue(); await coreClrDebugPromise; + }, + getAdvisor: async () => { + let langService = await langServicePromise; + return langService.advisor; } }; } diff --git a/src/omnisharp/extension.ts b/src/omnisharp/extension.ts index de2443995f..3e4559c97c 100644 --- a/src/omnisharp/extension.ts +++ b/src/omnisharp/extension.ts @@ -39,8 +39,10 @@ import { StructureProvider } from '../features/structureProvider'; import { OmniSharpMonoResolver } from './OmniSharpMonoResolver'; import { getMonoVersion } from '../utils/getMonoVersion'; -export let omnisharp: OmniSharpServer; -export let advisor: Advisor; +export interface ActivationResult { + readonly server: OmniSharpServer; + readonly 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,8 +52,7 @@ export async function activate(context: vscode.ExtensionContext, packageJSON: an const options = optionProvider.GetLatestOptions(); let omnisharpMonoResolver = new OmniSharpMonoResolver(getMonoVersion); const server = new OmniSharpServer(vscode, provider, packageJSON, platformInfo, eventStream, optionProvider, extensionPath, omnisharpMonoResolver); - omnisharp = server; - advisor = new Advisor(server, optionProvider); // create before server is started + const advisor = new Advisor(server, optionProvider); // create before server is started const disposables = new CompositeDisposable(); let localDisposables: CompositeDisposable; @@ -177,7 +178,7 @@ export async function activate(context: vscode.ExtensionContext, packageJSON: an context.subscriptions.push(disposables); - return new Promise(resolve => + return new Promise(resolve => server.onServerStart(e => - resolve(server))); + resolve({ server, advisor }))); } \ No newline at end of file diff --git a/test/integrationTests/diagnostics.integration.test.ts b/test/integrationTests/diagnostics.integration.test.ts index f5534b8054..ffef306d4a 100644 --- a/test/integrationTests/diagnostics.integration.test.ts +++ b/test/integrationTests/diagnostics.integration.test.ts @@ -10,7 +10,7 @@ import * as path from 'path'; import { activateCSharpExtension } from './integrationHelpers'; import testAssetWorkspace from './testAssets/testAssetWorkspace'; -import * as OmniSharp from "../../src/omnisharp/extension"; +import { Advisor } from '../../src/features/diagnosticsProvider'; const chai = require('chai'); chai.use(require('chai-arrays')); @@ -22,9 +22,16 @@ function setLimit(to: number | null) { } suite(`Diagnostics Provider ${testAssetWorkspace.description}`, function () { + let advisor: Advisor; + suiteSetup(async function () { await testAssetWorkspace.restore(); - await activateCSharpExtension(); + let activationResult = await activateCSharpExtension(); + if (!activationResult) { + throw new Error('Cannot activate extension.'); + } else { + advisor = activationResult.advisor; + } let fileName = 'completion.cs'; let dir = testAssetWorkspace.projects[0].projectDirectoryPath; @@ -39,36 +46,36 @@ suite(`Diagnostics Provider ${testAssetWorkspace.description}`, function () { test('Reports errors from whole project when maxProjectFileCountForDiagnosticAnalysis is higher than the file count', async () => { await setLimit(1000); - expect(OmniSharp.advisor.shouldValidateProject()).to.be.true; + 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(OmniSharp.advisor.shouldValidateFiles()).to.be.true; + 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(OmniSharp.advisor.shouldValidateProject()).to.be.false; + 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(OmniSharp.advisor.shouldValidateFiles()).to.be.true; + expect(advisor.shouldValidateFiles()).to.be.true; }); test('Reports errors from whole project when maxProjectFileCountForDiagnosticAnalysis is null', async () => { await setLimit(null); - expect(OmniSharp.advisor.shouldValidateProject()).to.be.true; + expect(advisor.shouldValidateProject()).to.be.true; }); test('Reports errors from individual files when maxProjectFileCountForDiagnosticAnalysis is null', async () => { await setLimit(null); - expect(OmniSharp.advisor.shouldValidateFiles()).to.be.true; + expect(advisor.shouldValidateFiles()).to.be.true; }); }); \ No newline at end of file diff --git a/test/integrationTests/integrationHelpers.ts b/test/integrationTests/integrationHelpers.ts index 382e5eb66c..510172857e 100644 --- a/test/integrationTests/integrationHelpers.ts +++ b/test/integrationTests/integrationHelpers.ts @@ -5,8 +5,13 @@ import * as vscode from 'vscode'; import CSharpExtensionExports from '../../src/CSharpExtensionExports'; +import { Advisor } from '../../src/features/diagnosticsProvider'; -export async function activateCSharpExtension(): Promise { +export interface ActivationResult { + readonly advisor: Advisor; +} + +export async function activateCSharpExtension(): Promise { const csharpExtension = vscode.extensions.getExtension("ms-vscode.csharp"); if (!csharpExtension.isActive) { @@ -16,8 +21,10 @@ export async function activateCSharpExtension(): Promise { try { await csharpExtension.exports.initializationFinished(); console.log("ms-vscode.csharp activated"); + return { advisor: await csharpExtension.exports.getAdvisor() }; } catch (err) { console.log(JSON.stringify(err)); + return undefined; } -} \ No newline at end of file +}