Skip to content

Commit

Permalink
Change the Advisor global var to Advisor returned from CSharpExtensio…
Browse files Browse the repository at this point in the history
…nExports
  • Loading branch information
jakubfijalkowski committed Oct 25, 2018
1 parent b5bd9b2 commit a95ce4c
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 21 deletions.
4 changes: 4 additions & 0 deletions src/CSharpExtensionExports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void>;

getAdvisor: () => Promise<Advisor>;
}
14 changes: 9 additions & 5 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -65,7 +65,7 @@ export async function activate(context: vscode.ExtensionContext): Promise<CSharp
let dotnetTestLoggerObserver = new DotNetTestLoggerObserver(dotnetTestChannel);
eventStream.subscribe(dotnetTestChannelObserver.post);
eventStream.subscribe(dotnetTestLoggerObserver.post);

let csharpChannel = vscode.window.createOutputChannel('C#');
let csharpchannelObserver = new CsharpChannelObserver(csharpChannel);
let csharpLogObserver = new CsharpLoggerObserver(csharpChannel);
Expand Down Expand Up @@ -119,7 +119,7 @@ export async function activate(context: vscode.ExtensionContext): Promise<CSharp
let runtimeDependenciesExist = await ensureRuntimeDependencies(extension, eventStream, platformInfo, networkSettingsProvider);

// activate language services
let omniSharpPromise = OmniSharp.activate(context, extension.packageJSON, platformInfo, networkSettingsProvider, eventStream, optionProvider, extension.extensionPath);
let langServicePromise = OmniSharp.activate(context, extension.packageJSON, platformInfo, networkSettingsProvider, eventStream, optionProvider, extension.extensionPath);

// register JSON completion & hover providers for project.json
context.subscriptions.push(addJSONProviders());
Expand Down Expand Up @@ -147,9 +147,13 @@ export async function activate(context: vscode.ExtensionContext): Promise<CSharp

return {
initializationFinished: async () => {
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;
}
};
}
Expand Down
13 changes: 7 additions & 6 deletions src/omnisharp/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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;

Expand Down Expand Up @@ -177,7 +178,7 @@ export async function activate(context: vscode.ExtensionContext, packageJSON: an

context.subscriptions.push(disposables);

return new Promise<OmniSharpServer>(resolve =>
return new Promise<ActivationResult>(resolve =>
server.onServerStart(e =>
resolve(server)));
resolve({ server, advisor })));
}
23 changes: 15 additions & 8 deletions test/integrationTests/diagnostics.integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand All @@ -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;
Expand All @@ -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;
});
});
11 changes: 9 additions & 2 deletions test/integrationTests/integrationHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> {
export interface ActivationResult {
readonly advisor: Advisor;
}

export async function activateCSharpExtension(): Promise<ActivationResult | undefined> {
const csharpExtension = vscode.extensions.getExtension<CSharpExtensionExports>("ms-vscode.csharp");

if (!csharpExtension.isActive) {
Expand All @@ -16,8 +21,10 @@ export async function activateCSharpExtension(): Promise<void> {
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;
}
}
}

0 comments on commit a95ce4c

Please sign in to comment.