Skip to content

Commit

Permalink
chore: refactor vscode apex replay to use arrow (#5304)
Browse files Browse the repository at this point in the history
@W-14564471@
Refactor vscode apex replay denugger to use arrow functions

Co-authored-by: Cristina Cañizales <[email protected]>
  • Loading branch information
peternhale and CristiCanizales authored Jan 9, 2024
1 parent deadca1 commit 0ac3c72
Show file tree
Hide file tree
Showing 11 changed files with 80 additions and 81 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"rules": {
"prefer-arrow/prefer-arrow-functions": ["error", {}],
"@typescript-eslint/await-thenable": "warn",
"@typescript-eslint/no-floating-promises": "warn",
"@typescript-eslint/no-unsafe-argument": "warn",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ import {
import { existsSync } from 'fs';
import * as vscode from 'vscode';

export function getDialogStartingPath(
export const getDialogStartingPath = (
extContext: vscode.ExtensionContext
): vscode.Uri | undefined {
): vscode.Uri | undefined => {
if (workspaceUtils.hasRootWorkspace()) {
// If the user has already selected a document through getLogFileName then
// use that path if it still exists.
Expand All @@ -37,21 +37,21 @@ export function getDialogStartingPath(
const stateFolderUri = getUriFor(pathToStateFolder);
return stateFolderUri;
}
}
};

function getLastOpenedLogFolder(
const getLastOpenedLogFolder = (
extContext: vscode.ExtensionContext
): string | undefined {
): string | undefined => {
const pathToLastOpenedLogFolder = extContext.workspaceState.get<string>(
LAST_OPENED_LOG_FOLDER_KEY
);
return pathToLastOpenedLogFolder;
}
};

function folderExists(path: string): boolean {
const folderExists = (path: string): boolean => {
return existsSync(path);
}
};

function getUriFor(path: string): vscode.Uri {
const getUriFor = (path: string): vscode.Uri => {
return vscode.Uri.file(path);
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -804,9 +804,9 @@ const lock = new AsyncLock();
// This is the function registered for vscode.debug.onDidChangeBreakpoints. This
// particular event fires breakpoint events without an active debug session which
// allows us to manipulate checkpoints prior to the debug session.
export async function processBreakpointChangedForCheckpoints(
export const processBreakpointChangedForCheckpoints = async (
breakpointsChangedEvent: vscode.BreakpointsChangeEvent
): Promise<void> {
): Promise<void> => {
for (const bp of breakpointsChangedEvent.removed) {
if (bp.condition && bp.condition.toLowerCase().indexOf(CHECKPOINT) >= 0) {
await lock.acquire(CHECKPOINTS_LOCK_STRING, async () => {
Expand Down Expand Up @@ -878,11 +878,11 @@ export async function processBreakpointChangedForCheckpoints(
});
}
}
}
};

export function parseCheckpointInfoFromBreakpoint(
export const parseCheckpointInfoFromBreakpoint = (
breakpoint: vscode.SourceBreakpoint
): ApexExecutionOverlayAction {
): ApexExecutionOverlayAction => {
// declare the overlayAction with defaults
const checkpointOverlayAction: ApexExecutionOverlayAction = {
ActionScript: '',
Expand Down Expand Up @@ -914,9 +914,9 @@ export function parseCheckpointInfoFromBreakpoint(
checkpointOverlayAction.ActionScript = logMessage;
}
return checkpointOverlayAction;
}
};

function setTypeRefsForEnabledCheckpoints(): boolean {
const setTypeRefsForEnabledCheckpoints = (): boolean => {
let everythingSet = true;
for (const cpNode of checkpointService.getChildren() as CheckpointNode[]) {
if (cpNode.isCheckpointEnabled()) {
Expand All @@ -942,7 +942,7 @@ function setTypeRefsForEnabledCheckpoints(): boolean {
}
}
return everythingSet;
}
};

// The order of operations here should be to
// 1. Get the source/line information
Expand All @@ -965,7 +965,7 @@ let creatingCheckpoints = false;
// that may be on the checkpoint are the condition (which needs to get set to Checkpoint)
// and the logMessage. The logMessage is scrapped since this ends up being taken over by
// checkpoints for user input SOQL or Apex.
export async function sfdxToggleCheckpoint() {
export const sfdxToggleCheckpoint = async() => {
if (creatingCheckpoints) {
writeToDebuggerOutputWindow(
nls.localize('checkpoint_upload_in_progress'),
Expand Down Expand Up @@ -1017,29 +1017,29 @@ export async function sfdxToggleCheckpoint() {
await vscode.debug.addBreakpoints(bpAdd);
}
return;
}
};

// This methods was broken out of sfdxToggleCheckpoint for testing purposes.
function fetchActiveEditorUri(): vscode.Uri | undefined {
const fetchActiveEditorUri = (): vscode.Uri | undefined => {
const editor = vscode.window.activeTextEditor;
if (editor) {
return editor.document.uri;
}
}
};

// This methods was broken out of sfdxToggleCheckpoint for testing purposes.
function fetchActiveSelectionLineNumber(): number | undefined {
const fetchActiveSelectionLineNumber = (): number | undefined => {
const editor = vscode.window.activeTextEditor;
if (editor && editor.selection) {
return editor.selection.start.line;
}
return undefined;
}
};

function fetchExistingBreakpointForUriAndLineNumber(
const fetchExistingBreakpointForUriAndLineNumber = (
uriInput: vscode.Uri,
lineInput: number
): vscode.Breakpoint | undefined {
): vscode.Breakpoint | undefined => {
for (const bp of vscode.debug.breakpoints) {
if (bp instanceof vscode.SourceBreakpoint) {
// Uri comparison doesn't work even if they're contain the same
Expand All @@ -1053,18 +1053,18 @@ function fetchExistingBreakpointForUriAndLineNumber(
}
}
return undefined;
}
};

// See https://github.com/Microsoft/vscode-languageserver-node/issues/105
function code2ProtocolConverter(value: vscode.Uri) {
const code2ProtocolConverter = (value: vscode.Uri) => {
if (/^win32/.test(process.platform)) {
// The *first* : is also being encoded which is not the standard for URI on Windows
// Here we transform it back to the standard way
return value.toString().replace('%3A', ':');
} else {
return value.toString();
}
}
};

export const checkpointUtils = {
fetchActiveEditorUri,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
import * as vscode from 'vscode';
import { DebugConfigurationProvider } from '../adapter/debugConfigurationProvider';

export function launchFromLogFile(
export const launchFromLogFile = (
logFile?: string,
stopOnEntry: boolean = true
) {
) => {
if (
!vscode.debug.activeDebugSession &&
vscode.workspace.workspaceFolders &&
Expand All @@ -22,4 +22,4 @@ export function launchFromLogFile(
DebugConfigurationProvider.getConfig(logFile, stopOnEntry)
);
}
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -164,14 +164,14 @@ export class TestDebuggerExecutor extends LibraryCommandletExecutor<string[]> {
}
}

export async function setupAndDebugTests(
export const setupAndDebugTests = async (
className: string,
methodName?: string
): Promise<void> {
): Promise<void> => {
const executor = new TestDebuggerExecutor();
const response = {
type: 'CONTINUE',
data: [className, methodName]
} as ContinueResponse<string[]>;
await executor.execute(response);
}
};
52 changes: 25 additions & 27 deletions packages/salesforcedx-vscode-apex-replay-debugger/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,13 @@ const sfdxCoreExtension = vscode.extensions.getExtension(
'salesforce.salesforcedx-vscode-core'
);

function registerCommands(): vscode.Disposable {
const registerCommands = (): vscode.Disposable => {
const dialogStartingPathUri = getDialogStartingPath(extContext);
const promptForLogCmd = vscode.commands.registerCommand(
'extension.replay-debugger.getLogFileName',
async () => {
const fileUris:
| vscode.Uri[]
| undefined = await vscode.window.showOpenDialog({
const fileUris: vscode.Uri[] | undefined =
await vscode.window.showOpenDialog({
canSelectFiles: true,
canSelectFolders: false,
canSelectMany: false,
Expand Down Expand Up @@ -97,9 +96,8 @@ function registerCommands(): vscode.Disposable {
const launchFromLastLogFileCmd = vscode.commands.registerCommand(
'sfdx.launch.replay.debugger.last.logfile',
() => {
const lastOpenedLog = extContext.workspaceState.get<string>(
LAST_OPENED_LOG_KEY
);
const lastOpenedLog =
extContext.workspaceState.get<string>(LAST_OPENED_LOG_KEY);
return launchFromLogFile(lastOpenedLog);
}
);
Expand All @@ -121,30 +119,30 @@ function registerCommands(): vscode.Disposable {
sfdxCreateCheckpointsCmd,
sfdxToggleCheckpointCmd
);
}
};

export function updateLastOpened(
export const updateLastOpened = (
extensionContext: vscode.ExtensionContext,
logPath: string
) {
) => {
extensionContext.workspaceState.update(LAST_OPENED_LOG_KEY, logPath);
extensionContext.workspaceState.update(
LAST_OPENED_LOG_FOLDER_KEY,
path.dirname(logPath)
);
}
};

export async function getDebuggerType(
export const getDebuggerType = async (
session: vscode.DebugSession
): Promise<string> {
): Promise<string> => {
let type = session.type;
if (type === LIVESHARE_DEBUGGER_TYPE) {
type = await session.customRequest(LIVESHARE_DEBUG_TYPE_REQUEST);
}
return type;
}
};

function registerDebugHandlers(): vscode.Disposable {
const registerDebugHandlers = (): vscode.Disposable => {
const customEventHandler = vscode.debug.onDidReceiveDebugSessionCustomEvent(
async event => {
if (event && event.session) {
Expand All @@ -171,9 +169,9 @@ function registerDebugHandlers(): vscode.Disposable {
);

return vscode.Disposable.from(customEventHandler);
}
};

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

Expand Down Expand Up @@ -231,9 +229,9 @@ export async function activate(extensionContext: vscode.ExtensionContext) {
}

telemetryService.sendExtensionActivationEvent(extensionHRStart);
}
};

export async function retrieveLineBreakpointInfo(): Promise<boolean> {
export const retrieveLineBreakpointInfo = async (): Promise<boolean> => {
const sfdxApex = vscode.extensions.getExtension(
'salesforce.salesforcedx-vscode-apex'
);
Expand Down Expand Up @@ -289,17 +287,17 @@ export async function retrieveLineBreakpointInfo(): Promise<boolean> {
writeToDebuggerOutputWindow(errorMessage, true, VSCodeWindowTypeEnum.Error);
return false;
}
}
};

function imposeSlightDelay(ms = 0) {
const imposeSlightDelay = (ms = 0) => {
return new Promise(r => setTimeout(r, ms));
}
};

export function writeToDebuggerOutputWindow(
export const writeToDebuggerOutputWindow = (
output: string,
showVSCodeWindow?: boolean,
vsCodeWindowType?: VSCodeWindowTypeEnum
) {
) => {
channelService.appendLine(output);
channelService.showChannelOutput();
if (showVSCodeWindow && vsCodeWindowType) {
Expand All @@ -318,9 +316,9 @@ export function writeToDebuggerOutputWindow(
}
}
}
}
};

export function deactivate() {
export const deactivate = () => {
console.log('Apex Replay Debugger Extension Deactivated');
telemetryService.sendExtensionDeactivationEvent();
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ 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;
Expand All @@ -32,7 +32,7 @@ function loadMessageBundle(config?: Config): Message {
}

return base;
}
};

export const nls = new Localization(
loadMessageBundle(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
import { SFDX_CORE_CONFIGURATION_NAME } from '@salesforce/salesforcedx-utils-vscode';
import * as vscode from 'vscode';

export function retrieveTestCodeCoverage(): boolean {
export const retrieveTestCodeCoverage = (): boolean => {
return vscode.workspace
.getConfiguration(SFDX_CORE_CONFIGURATION_NAME)
.get<boolean>('retrieve-test-code-coverage', false);
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@ class MockJorje {
}

public languageClientUtils = {
getStatus() {
getStatus: () => {
return {
isReady() {
isReady: () => {
return true;
},
failedToInitialize() {
failedToInitialize: () => {
return false;
},
getStatusMessage() {
getStatusMessage: () => {
return '';
}
};
Expand Down
Loading

0 comments on commit 0ac3c72

Please sign in to comment.