Skip to content

Commit

Permalink
fix: renamed context to extensionContext (#4165)
Browse files Browse the repository at this point in the history
* fix: renamed context to extensionContext
  • Loading branch information
jeffb-sfdc authored Jun 2, 2022
1 parent 03f43fc commit c8edf0f
Show file tree
Hide file tree
Showing 46 changed files with 248 additions and 241 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ export class WorkspaceContextUtil {
return AuthUtil.getInstance();
}

public async initialize(context: vscode.ExtensionContext) {
context.subscriptions.push(
public async initialize(extensionContext: vscode.ExtensionContext) {
extensionContext.subscriptions.push(
this.cliConfigWatcher,
this.onOrgChangeEmitter,
this.cliConfigWatcher
Expand Down
10 changes: 5 additions & 5 deletions packages/salesforcedx-utils-vscode/src/telemetry/telemetry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export class TelemetryBuilder {

export class TelemetryService {
private static instance: TelemetryService;
private context: ExtensionContext | undefined;
private extensionContext: ExtensionContext | undefined;
private reporter: TelemetryReporter | undefined;
private aiKey: string = '';
private version: string = '';
Expand All @@ -72,16 +72,16 @@ export class TelemetryService {

/**
* Initialize Telemetry Service during extension activation.
* @param context extension context
* @param extensionContext extension context
* @param extensionName extension name
*/
public async initializeService(
context: ExtensionContext,
extensionContext: ExtensionContext,
extensionName: string,
aiKey: string,
version: string
): Promise<void> {
this.context = context;
this.extensionContext = extensionContext;
this.extensionName = extensionName;
this.aiKey = aiKey;
this.version = version;
Expand Down Expand Up @@ -111,7 +111,7 @@ export class TelemetryService {
this.aiKey,
true
);
this.context.subscriptions.push(this.reporter);
this.extensionContext.subscriptions.push(this.reporter);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ describe('WorkspaceContext', () => {

let getUsernameStub: SinonStub;
let getUsernameOrAliasStub: SinonStub;
let workspaceContextUtil: any;
let workspaceContextUtil: typeof WorkspaceContextUtil;
let authUtil: any;

beforeEach(async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class MockEnvironmentVariableCollection {
}
}

export class MockContext {
export class MockExtensionContext {
constructor(mm: boolean) {
this.globalState = new MockMemento(mm);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import { expect } from 'chai';
import * as proxyquire from 'proxyquire';
import { SinonStub, stub } from 'sinon';
import { MockContext } from './MockContext';
import { MockExtensionContext } from './MockExtensionContext';

const mShowInformation = stub();
mShowInformation.returns(Promise.resolve());
Expand Down Expand Up @@ -38,7 +38,7 @@ const vscodeStub = {
describe('Telemetry dev mode', () => {
const extensionName = 'salesforcedx-test';
let telemetryService: any;
let mockContext: MockContext;
let mockExtensionContext: MockExtensionContext;
let teleStub: SinonStub;
let cliStub: SinonStub;

Expand Down Expand Up @@ -78,20 +78,20 @@ describe('Telemetry dev mode', () => {

it('Should not initialize telemetry reporter', async () => {
// create vscode extensionContext
mockContext = new MockContext(true);
mockExtensionContext = new MockExtensionContext(true);

await telemetryService.initializeService(mockContext, extensionName);
await telemetryService.initializeService(mockExtensionContext, extensionName);

const telemetryReporter = telemetryService.getReporter();
expect(typeof telemetryReporter).to.be.eql('undefined');
expect(teleStub.firstCall.args).to.eql([true]);
});

it('Should disable CLI telemetry', async () => {
mockContext = new MockContext(true);
mockExtensionContext = new MockExtensionContext(true);

cliStub.returns(Promise.resolve(false));
await telemetryService.initializeService(mockContext, extensionName);
await telemetryService.initializeService(mockExtensionContext, extensionName);

expect(teleStub.firstCall.args).to.eql([false]);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
SinonStub,
stub
} from 'sinon';
import { MockContext } from './MockContext';
import { MockExtensionContext } from './MockExtensionContext';

const mShowInformation = stub();
mShowInformation.returns(Promise.resolve());
Expand Down Expand Up @@ -52,7 +52,7 @@ describe('Telemetry production mode', () => {
let telemetryService: any;
let telemetryBuilder: any;
let sb: SinonSandbox;
let mockContext: MockContext;
let mockExtensionContext: MockExtensionContext;
let teleStub: SinonStub;
let cliStub: SinonStub;
let vscodeFlagStub: SinonStub;
Expand Down Expand Up @@ -93,7 +93,7 @@ describe('Telemetry production mode', () => {
);
cliStub = sb.stub(telemetryService, 'checkCliTelemetry');
// create vscode extensionContext
mockContext = new MockContext(true);
mockExtensionContext = new MockExtensionContext(true);
cliStub.returns(Promise.resolve(true));
vscodeFlagStub.returns(true);
});
Expand All @@ -103,7 +103,7 @@ describe('Telemetry production mode', () => {
});

xit('Should send telemetry data', async () => {
await telemetryService.initializeService(mockContext, extensionName);
await telemetryService.initializeService(mockExtensionContext, extensionName);

telemetryService.sendExtensionActivationEvent([0, 678]);
assert.calledOnce(reporter);
Expand All @@ -113,7 +113,7 @@ describe('Telemetry production mode', () => {
xit('Should not send telemetry data', async () => {
cliStub.returns(Promise.resolve(false));
vscodeFlagStub.returns(false);
await telemetryService.initializeService(mockContext, extensionName);
await telemetryService.initializeService(mockExtensionContext, extensionName);

const telemetryEnabled = await telemetryService.isTelemetryEnabled();
expect(telemetryEnabled).to.be.eql(false);
Expand All @@ -124,7 +124,7 @@ describe('Telemetry production mode', () => {
});

xit('Should send correct data format on sendExtensionActivationEvent', async () => {
await telemetryService.initializeService(mockContext, extensionName);
await telemetryService.initializeService(mockExtensionContext, extensionName);

telemetryService.sendExtensionActivationEvent([0, 678]);
assert.calledOnce(reporter);
Expand All @@ -143,7 +143,7 @@ describe('Telemetry production mode', () => {
});

xit('Should send correct data format on sendExtensionDeactivationEvent', async () => {
await telemetryService.initializeService(mockContext, extensionName);
await telemetryService.initializeService(mockExtensionContext, extensionName);

telemetryService.sendExtensionDeactivationEvent();
assert.calledOnce(reporter);
Expand All @@ -156,7 +156,7 @@ describe('Telemetry production mode', () => {
});

xit('Should send correct data format on sendCommandEvent', async () => {
await telemetryService.initializeService(mockContext, extensionName);
await telemetryService.initializeService(mockExtensionContext, extensionName);

telemetryService.sendCommandEvent('create_apex_class_command', [0, 678]);
assert.calledOnce(reporter);
Expand All @@ -176,7 +176,7 @@ describe('Telemetry production mode', () => {
});

xit('Should send correct data format on sendCommandEvent with additional props', async () => {
await telemetryService.initializeService(mockContext, extensionName);
await telemetryService.initializeService(mockExtensionContext, extensionName);
const additionalProps = {
dirType: 'testDirectoryType',
secondParam: 'value'
Expand Down Expand Up @@ -206,7 +206,7 @@ describe('Telemetry production mode', () => {
});

xit('Should send correct data format on sendCommandEvent with additional measurements', async () => {
await telemetryService.initializeService(mockContext, extensionName);
await telemetryService.initializeService(mockExtensionContext, extensionName);
const additionalMeasures = {
value: 3,
count: 10
Expand Down Expand Up @@ -239,7 +239,7 @@ describe('Telemetry production mode', () => {
});

xit('should send correct data format on sendEventData', async () => {
await telemetryService.initializeService(mockContext, extensionName);
await telemetryService.initializeService(mockExtensionContext, extensionName);

const eventName = 'eventName';
const property = { property: 'property for event' };
Expand All @@ -251,7 +251,7 @@ describe('Telemetry production mode', () => {
});

xit('Should send data sendExceptionEvent', async () => {
await telemetryService.initializeService(mockContext, extensionName);
await telemetryService.initializeService(mockExtensionContext, extensionName);

telemetryService.sendException(
'error_name',
Expand All @@ -269,7 +269,7 @@ describe('Telemetry production mode', () => {
xit('Should not send telemetry data when CLI telemetry is disabled', async () => {
cliStub.returns(Promise.resolve(false));
vscodeFlagStub.returns(false);
await telemetryService.initializeService(mockContext, extensionName);
await telemetryService.initializeService(mockExtensionContext, extensionName);

const telemetryEnabled = await telemetryService.isTelemetryEnabled();
expect(telemetryEnabled).to.be.eql(false);
Expand All @@ -281,9 +281,9 @@ describe('Telemetry production mode', () => {

xit('Should show telemetry info message', async () => {
// create vscode extensionContext in which telemetry msg has never been previously shown
mockContext = new MockContext(false);
mockExtensionContext = new MockExtensionContext(false);

await telemetryService.initializeService(mockContext, extensionName);
await telemetryService.initializeService(mockExtensionContext, extensionName);

const telemetryEnabled = telemetryService.isTelemetryEnabled();
expect(telemetryEnabled).to.be.eql(true);
Expand All @@ -295,9 +295,9 @@ describe('Telemetry production mode', () => {

xit('Should not show telemetry info message', async () => {
// create vscode extensionContext in which telemetry msg has been previously shown
mockContext = new MockContext(true);
mockExtensionContext = new MockExtensionContext(true);

await telemetryService.initializeService(mockContext, extensionName);
await telemetryService.initializeService(mockExtensionContext, extensionName);

const telemetryEnabled = telemetryService.isTelemetryEnabled();
expect(telemetryEnabled).to.be.eql(true);
Expand Down
12 changes: 6 additions & 6 deletions packages/salesforcedx-vscode-apex-debugger/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ function notifyDebuggerSessionFileChanged(): void {
}
}

function registerIsvAuthWatcher(context: vscode.ExtensionContext) {
function registerIsvAuthWatcher(extensionContext: vscode.ExtensionContext) {
if (
vscode.workspace.workspaceFolders instanceof Array &&
vscode.workspace.workspaceFolders.length > 0
Expand All @@ -251,17 +251,17 @@ function registerIsvAuthWatcher(context: vscode.ExtensionContext) {
isvAuthWatcher.onDidChange(uri => setupGlobalDefaultUserIsvAuth());
isvAuthWatcher.onDidCreate(uri => setupGlobalDefaultUserIsvAuth());
isvAuthWatcher.onDidDelete(uri => setupGlobalDefaultUserIsvAuth());
context.subscriptions.push(isvAuthWatcher);
extensionContext.subscriptions.push(isvAuthWatcher);
}
}

export async function activate(context: vscode.ExtensionContext) {
export async function activate(extensionContext: vscode.ExtensionContext) {
console.log('Apex Debugger Extension Activated');
const extensionHRStart = process.hrtime();
const commands = registerCommands();
const fileWatchers = registerFileWatchers();
context.subscriptions.push(commands, fileWatchers);
context.subscriptions.push(
extensionContext.subscriptions.push(commands, fileWatchers);
extensionContext.subscriptions.push(
vscode.debug.registerDebugConfigurationProvider(
'apex',
new DebugConfigurationProvider()
Expand All @@ -275,7 +275,7 @@ export async function activate(context: vscode.ExtensionContext) {
// this is done in core because it shares access to GlobalCliEnvironment with the commands
// (VS Code does not seem to allow sharing npm modules between extensions)
try {
registerIsvAuthWatcher(context);
registerIsvAuthWatcher(extensionContext);
console.log('Configured file watcher for .sfdx/sfdx-config.json');
await setupGlobalDefaultUserIsvAuth();
} catch (e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import * as vscode from 'vscode';
export class WorkspaceContext {
protected static instance?: WorkspaceContext;

public async initialize(context: vscode.ExtensionContext) {
await WorkspaceContextUtil.getInstance().initialize(context);
public async initialize(extensionContext: vscode.ExtensionContext) {
await WorkspaceContextUtil.getInstance().initialize(extensionContext);
}

public static getInstance(forceNew = false): WorkspaceContext {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import { setupAndDebugTests } from './commands/quickLaunch';
import { workspaceContext } from './context';
import { nls } from './messages';
import { telemetryService } from './telemetry';

let extContext: vscode.ExtensionContext;

export enum VSCodeWindowTypeEnum {
Expand Down Expand Up @@ -172,11 +173,11 @@ function registerDebugHandlers(): vscode.Disposable {
return vscode.Disposable.from(customEventHandler);
}

export async function activate(context: vscode.ExtensionContext) {
export async function activate(extensionContext: vscode.ExtensionContext) {
console.log('Apex Replay Debugger Extension Activated');
const extensionHRStart = process.hrtime();

extContext = context;
extContext = extensionContext;
const commands = registerCommands();
const debugHandlers = registerDebugHandlers();
const debugConfigProvider = vscode.debug.registerDebugConfigurationProvider(
Expand All @@ -192,7 +193,7 @@ export async function activate(context: vscode.ExtensionContext) {
);

// Workspace Context
await workspaceContext.initialize(context);
await workspaceContext.initialize(extensionContext);

// Debug Tests command
const debugTests = vscode.commands.registerCommand(
Expand All @@ -211,7 +212,7 @@ export async function activate(context: vscode.ExtensionContext) {
}
);

context.subscriptions.push(
extensionContext.subscriptions.push(
commands,
debugHandlers,
debugConfigProvider,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import * as vscode from 'vscode';
export class WorkspaceContext {
protected static instance?: WorkspaceContext;

public async initialize(context: vscode.ExtensionContext) {
await WorkspaceContextUtil.getInstance().initialize(context);
public async initialize(extensionContext: vscode.ExtensionContext) {
await WorkspaceContextUtil.getInstance().initialize(extensionContext);
}

public static getInstance(forceNew = false): WorkspaceContext {
Expand Down
Loading

0 comments on commit c8edf0f

Please sign in to comment.