From 5f99f4030f9c8cd63e0e9649057cc41c7fe560a6 Mon Sep 17 00:00:00 2001 From: Peter Hale Date: Thu, 28 Dec 2023 14:49:19 -0700 Subject: [PATCH] chore: move vscode apex debugger to arrow functions @W-14564471@ Refactor vscode apex debugger to arrow functions --- .../fix-these-rules.json | 1 + .../src/context/isvContext.ts | 10 ++-- .../src/index.ts | 48 +++++++++---------- .../src/messages/index.ts | 4 +- .../adapter/MockApexExtension.ts | 8 ++-- 5 files changed, 36 insertions(+), 35 deletions(-) diff --git a/packages/salesforcedx-vscode-apex-debugger/fix-these-rules.json b/packages/salesforcedx-vscode-apex-debugger/fix-these-rules.json index 158aeb45c5..43ffa95fb9 100644 --- a/packages/salesforcedx-vscode-apex-debugger/fix-these-rules.json +++ b/packages/salesforcedx-vscode-apex-debugger/fix-these-rules.json @@ -1,5 +1,6 @@ { "rules": { + "prefer-arrow/prefer-arrow-functions": ["error", {}], "@typescript-eslint/no-floating-promises": "warn", "@typescript-eslint/no-unsafe-argument": "warn", "@typescript-eslint/no-unsafe-assignment": "warn", diff --git a/packages/salesforcedx-vscode-apex-debugger/src/context/isvContext.ts b/packages/salesforcedx-vscode-apex-debugger/src/context/isvContext.ts index 3f29b4d2f1..1034ea7b37 100644 --- a/packages/salesforcedx-vscode-apex-debugger/src/context/isvContext.ts +++ b/packages/salesforcedx-vscode-apex-debugger/src/context/isvContext.ts @@ -8,7 +8,7 @@ import { IsvContextUtil } from '@salesforce/salesforcedx-apex-debugger/out/src/c import { projectPaths } from '@salesforce/salesforcedx-utils-vscode'; import * as vscode from 'vscode'; -export async function setupGlobalDefaultUserIsvAuth() { +export const setupGlobalDefaultUserIsvAuth = async () => { const isvUtil = new IsvContextUtil(); if ( vscode.workspace && @@ -19,7 +19,7 @@ export async function setupGlobalDefaultUserIsvAuth() { vscode.workspace.workspaceFolders[0].uri.fsPath ); - vscode.commands.executeCommand( + await vscode.commands.executeCommand( 'setContext', 'sfdx:isv_debug_project', isvDebugProject @@ -33,9 +33,9 @@ export async function setupGlobalDefaultUserIsvAuth() { // reset any auth isvUtil.resetCliEnvironmentVars(); -} +}; -export function registerIsvAuthWatcher(extensionContext: vscode.ExtensionContext) { +export const registerIsvAuthWatcher = (extensionContext: vscode.ExtensionContext) => { if ( vscode.workspace.workspaceFolders instanceof Array && vscode.workspace.workspaceFolders.length > 0 @@ -49,4 +49,4 @@ export function registerIsvAuthWatcher(extensionContext: vscode.ExtensionContext /* eslint-enable @typescript-eslint/no-unused-vars */ extensionContext.subscriptions.push(isvAuthWatcher); } -} +}; diff --git a/packages/salesforcedx-vscode-apex-debugger/src/index.ts b/packages/salesforcedx-vscode-apex-debugger/src/index.ts index 6465792879..b96b139e0a 100644 --- a/packages/salesforcedx-vscode-apex-debugger/src/index.ts +++ b/packages/salesforcedx-vscode-apex-debugger/src/index.ts @@ -34,17 +34,17 @@ const sfdxCoreExtension = vscode.extensions.getExtension( 'salesforce.salesforcedx-vscode-core' ); -export async function getDebuggerType( +export const getDebuggerType = async ( session: vscode.DebugSession -): Promise { +): Promise => { let type = session.type; if (type === LIVESHARE_DEBUGGER_TYPE) { type = await session.customRequest(LIVESHARE_DEBUG_TYPE_REQUEST); } return type; -} +}; -function registerCommands(): vscode.Disposable { +const registerCommands = (): vscode.Disposable => { const customEventHandler = vscode.debug.onDidReceiveDebugSessionCustomEvent( async event => { if (event && event.session) { @@ -89,7 +89,7 @@ function registerCommands(): vscode.Disposable { exceptionBreakpointCmd, startSessionHandler ); -} +}; export interface ExceptionBreakpointItem extends vscode.QuickPickItem { typeref: string; @@ -114,7 +114,7 @@ const EXCEPTION_BREAK_MODES: BreakModeItem[] = [ } ]; -async function configureExceptionBreakpoint(): Promise { +const configureExceptionBreakpoint = async (): Promise => { const sfdxApex = vscode.extensions.getExtension( 'salesforce.salesforcedx-vscode-apex' ); @@ -170,12 +170,12 @@ async function configureExceptionBreakpoint(): Promise { } } } -} +}; -export function mergeExceptionBreakpointInfos( +export const mergeExceptionBreakpointInfos = ( breakpointInfos: ExceptionBreakpointItem[], enabledBreakpointTyperefs: string[] -): ExceptionBreakpointItem[] { +): ExceptionBreakpointItem[] => { const processedBreakpointInfos: ExceptionBreakpointItem[] = []; if (enabledBreakpointTyperefs.length > 0) { for (let i = breakpointInfos.length - 1; i >= 0; i--) { @@ -190,11 +190,11 @@ export function mergeExceptionBreakpointInfos( } } return processedBreakpointInfos.concat(breakpointInfos); -} +}; -export function updateExceptionBreakpointCache( +export const updateExceptionBreakpointCache = ( selectedException: ExceptionBreakpointItem -) { +) => { if ( selectedException.breakMode === EXCEPTION_BREAKPOINT_BREAK_MODE_ALWAYS && !cachedExceptionBreakpoints.has(selectedException.typeref) @@ -209,16 +209,16 @@ export function updateExceptionBreakpointCache( ) { cachedExceptionBreakpoints.delete(selectedException.typeref); } -} +}; -export function getExceptionBreakpointCache(): Map< +export const getExceptionBreakpointCache = (): Map< string, ExceptionBreakpointItem -> { +> => { return cachedExceptionBreakpoints; -} +}; -function registerFileWatchers(): vscode.Disposable { +const registerFileWatchers = (): vscode.Disposable => { const clsWatcher = vscode.workspace.createFileSystemWatcher('**/*.cls'); /* eslint-disable @typescript-eslint/no-unused-vars */ clsWatcher.onDidChange(uri => notifyDebuggerSessionFileChanged()); @@ -230,15 +230,15 @@ function registerFileWatchers(): vscode.Disposable { trgWatcher.onDidDelete(uri => notifyDebuggerSessionFileChanged()); /* eslint-enable @typescript-eslint/no-unused-vars */ return vscode.Disposable.from(clsWatcher, trgWatcher); -} +}; -function notifyDebuggerSessionFileChanged(): void { +const notifyDebuggerSessionFileChanged = (): void => { if (vscode.debug.activeDebugSession) { vscode.debug.activeDebugSession.customRequest(HOTSWAP_REQUEST); } -} +}; -export async function activate(extensionContext: vscode.ExtensionContext) { +export const activate = async (extensionContext: vscode.ExtensionContext): Promise => { console.log('Apex Debugger Extension Activated'); const extensionHRStart = process.hrtime(); const commands = registerCommands(); @@ -276,9 +276,9 @@ export async function activate(extensionContext: vscode.ExtensionContext) { } telemetryService.sendExtensionActivationEvent(extensionHRStart); -} +}; -export function deactivate() { +export const deactivate = () => { console.log('Apex Debugger Extension Deactivated'); telemetryService.sendExtensionDeactivationEvent(); -} +}; diff --git a/packages/salesforcedx-vscode-apex-debugger/src/messages/index.ts b/packages/salesforcedx-vscode-apex-debugger/src/messages/index.ts index d20940e825..246ffa67e1 100644 --- a/packages/salesforcedx-vscode-apex-debugger/src/messages/index.ts +++ b/packages/salesforcedx-vscode-apex-debugger/src/messages/index.ts @@ -16,7 +16,7 @@ import { messages as enMessages } from './i18n'; import { messages as jaMessages } from './i18n.ja'; const supportedLocales = [DEFAULT_LOCALE, LOCALE_JA]; -function loadMessageBundle(config?: Config): Message { +const loadMessageBundle = (config?: Config): Message => { const base = new Message(enMessages); const localeConfig = config ? config.locale : DEFAULT_LOCALE; @@ -30,7 +30,7 @@ function loadMessageBundle(config?: Config): Message { } return base; -} +}; export const nls = new Localization( loadMessageBundle( diff --git a/packages/salesforcedx-vscode-apex-debugger/test/vscode-integration/adapter/MockApexExtension.ts b/packages/salesforcedx-vscode-apex-debugger/test/vscode-integration/adapter/MockApexExtension.ts index bccf84af82..c3beed39ce 100644 --- a/packages/salesforcedx-vscode-apex-debugger/test/vscode-integration/adapter/MockApexExtension.ts +++ b/packages/salesforcedx-vscode-apex-debugger/test/vscode-integration/adapter/MockApexExtension.ts @@ -38,15 +38,15 @@ class MockJorje { } public languageClientUtils = { - getStatus() { + getStatus: () => { return { - isReady() { + isReady: () => { return true; }, - failedToInitialize() { + failedToInitialize: () => { return false; }, - getStatusMessage() { + getStatusMessage: () => { return ''; } };