Skip to content

Commit

Permalink
chore: apply review suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
peternhale committed Nov 9, 2023
1 parent 2403fd4 commit 53d79d9
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 15 deletions.
9 changes: 3 additions & 6 deletions packages/salesforcedx-vscode-apex/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ import { telemetryService } from './telemetry';
import { getTestOutlineProvider } from './views/testOutlineProvider';
import { ApexTestRunner, TestRunType } from './views/testRunner';

export const getClient = () => languageClientUtils.getClientInstance();

export async function activate(extensionContext: vscode.ExtensionContext) {
const extensionHRStart = process.hrtime();
const languageServerStatusBarItem = new ApexLSPStatusBarItem();
Expand Down Expand Up @@ -284,7 +282,7 @@ async function registerTestView(): Promise<vscode.Disposable> {
}

export async function deactivate() {
await getClient()?.stop();
await languageClientUtils.getClientInstance()?.stop();
telemetryService.sendExtensionDeactivationEvent();
}

Expand All @@ -296,13 +294,12 @@ async function createLanguageClient(
void lsoh.resolveAnyFoundOrphanLanguageServers();
// Initialize Apex language server
try {

const langClientHRStart = process.hrtime();
languageClientUtils.setClientInstance(await languageServer.createLanguageServer(
extensionContext
));

const languageClient = getClient();
const languageClient = languageClientUtils.getClientInstance();

if (languageClient) {
languageClient.errorHandler?.addListener('error', message => {
Expand Down Expand Up @@ -334,7 +331,7 @@ async function createLanguageClient(
languageClient,
languageServerStatusBarItem
);
extensionContext.subscriptions.push(getClient()!);
extensionContext.subscriptions.push(languageClientUtils.getClientInstance()!);
} else {
languageClientUtils.setStatus(ClientStatus.Error, `${nls.localize('apex_language_server_failed_activate')} - ${nls.localize('unknown')}`);
languageServerStatusBarItem.error(
Expand Down
11 changes: 2 additions & 9 deletions packages/salesforcedx-vscode-apex/test/jest/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,18 +70,11 @@ describe('indexDoneHandler', () => {
});
});

class MockApexLanguageClient {
constructor() { }
start() { }
stop() { }
}

describe('deactivate', () => {
let stopSpy: jest.SpyInstance;
beforeEach(() => {
const lc = new MockApexLanguageClient() as ApexLanguageClient;
languageClientUtils.setClientInstance(lc);
stopSpy = jest.spyOn(lc, 'stop');
stopSpy = jest.fn();
jest.spyOn(languageClientUtils, 'getClientInstance').mockReturnValue({ stop: stopSpy } as unknown as ApexLanguageClient);
});

it('should call stop on the language client', async () => {
Expand Down

0 comments on commit 53d79d9

Please sign in to comment.