From 53d79d915822707cb080a2f2943946cdf43b0528 Mon Sep 17 00:00:00 2001 From: Peter Hale Date: Thu, 9 Nov 2023 08:37:51 -0700 Subject: [PATCH] chore: apply review suggestions --- packages/salesforcedx-vscode-apex/src/index.ts | 9 +++------ .../salesforcedx-vscode-apex/test/jest/index.test.ts | 11 ++--------- 2 files changed, 5 insertions(+), 15 deletions(-) diff --git a/packages/salesforcedx-vscode-apex/src/index.ts b/packages/salesforcedx-vscode-apex/src/index.ts index 81fa8453e3..a31d0b3182 100644 --- a/packages/salesforcedx-vscode-apex/src/index.ts +++ b/packages/salesforcedx-vscode-apex/src/index.ts @@ -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(); @@ -284,7 +282,7 @@ async function registerTestView(): Promise { } export async function deactivate() { - await getClient()?.stop(); + await languageClientUtils.getClientInstance()?.stop(); telemetryService.sendExtensionDeactivationEvent(); } @@ -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 => { @@ -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( diff --git a/packages/salesforcedx-vscode-apex/test/jest/index.test.ts b/packages/salesforcedx-vscode-apex/test/jest/index.test.ts index 142d4bbbba..85afccb1ae 100644 --- a/packages/salesforcedx-vscode-apex/test/jest/index.test.ts +++ b/packages/salesforcedx-vscode-apex/test/jest/index.test.ts @@ -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 () => {