From 1daaabc09d2a16f9f4cbcd279c8d60ed1196ae87 Mon Sep 17 00:00:00 2001 From: Luke Cotter <4013877+lukecotter@users.noreply.github.com> Date: Mon, 20 Nov 2023 17:22:46 +0000 Subject: [PATCH 1/2] feat: open viewer with editor content if file does not exist This is mainly to support drag and drop file in code builder. It also helps when a file is deleted on local disk or a log is copy and pasted into an editor window without saving. --- lana/src/commands/LogView.ts | 28 ++++++++++++++++++---------- lana/src/commands/RetrieveLogFile.ts | 2 +- lana/src/commands/ShowLogAnalysis.ts | 8 +++++--- 3 files changed, 24 insertions(+), 14 deletions(-) diff --git a/lana/src/commands/LogView.ts b/lana/src/commands/LogView.ts index 9e8e1c7c..5a171834 100644 --- a/lana/src/commands/LogView.ts +++ b/lana/src/commands/LogView.ts @@ -26,13 +26,15 @@ export class LogView { static async createView( wsPath: string, context: Context, - logPath: string, beforeSendLog?: Promise, + logPath?: string, + logData?: string, ): Promise { - const panel = WebView.apply('logFile', 'Log: ' + basename(logPath), [ - Uri.file(join(context.context.extensionPath, 'out')), - Uri.file(dirname(logPath)), - ]); + const panel = WebView.apply( + 'logFile', + 'Log: ' + logPath ? basename(logPath || '') : 'Untitled', + [Uri.file(join(context.context.extensionPath, 'out')), Uri.file(dirname(logPath || ''))], + ); const logViewerRoot = join(context.context.extensionPath, 'out'); const index = join(logViewerRoot, 'index.html'); @@ -55,7 +57,7 @@ export class LogView { switch (request.cmd) { case 'fetchLog': { await beforeSendLog; - LogView.sendLog(panel, context, logPath); + LogView.sendLog(panel, context, logPath, logData); break; } @@ -141,20 +143,26 @@ export class LogView { }); } - private static sendLog(panel: WebviewPanel, context: Context, logFilePath: string) { - if (!existsSync(logFilePath)) { + private static sendLog( + panel: WebviewPanel, + context: Context, + logFilePath?: string, + logData?: string, + ) { + if (!logData && !existsSync(logFilePath || '')) { context.display.showErrorMessage('Log file could not be found.', { modal: true, }); } - const filePath = parse(logFilePath); + const filePath = parse(logFilePath || ''); panel.webview.postMessage({ command: 'fetchLog', data: { logName: filePath.name, - logUri: panel.webview.asWebviewUri(Uri.file(logFilePath)).toString(true), + logUri: logFilePath ? panel.webview.asWebviewUri(Uri.file(logFilePath)).toString(true) : '', logPath: logFilePath, + logData: logData, }, }); } diff --git a/lana/src/commands/RetrieveLogFile.ts b/lana/src/commands/RetrieveLogFile.ts index 6cb40ed2..cf2d24e9 100644 --- a/lana/src/commands/RetrieveLogFile.ts +++ b/lana/src/commands/RetrieveLogFile.ts @@ -60,7 +60,7 @@ export class RetrieveLogFile { if (logFileId) { const logFilePath = this.getLogFilePath(ws, logFileId); const writeLogFile = this.writeLogFile(ws, logFilePath); - return LogView.createView(ws, context, logFilePath, writeLogFile); + return LogView.createView(ws, context, writeLogFile, logFilePath); } } diff --git a/lana/src/commands/ShowLogAnalysis.ts b/lana/src/commands/ShowLogAnalysis.ts index 6f3fd668..af21577d 100644 --- a/lana/src/commands/ShowLogAnalysis.ts +++ b/lana/src/commands/ShowLogAnalysis.ts @@ -1,6 +1,7 @@ /* * Copyright (c) 2020 Certinia Inc. All rights reserved. */ +import { existsSync } from 'fs'; import { Uri, window } from 'vscode'; import { appName } from '../AppSettings.js'; @@ -32,11 +33,12 @@ export class ShowLogAnalysis { } private static async command(context: Context, uri: Uri): Promise { - const filePath = uri?.fsPath || window?.activeTextEditor?.document.fileName; + const filePath = uri?.fsPath || window?.activeTextEditor?.document.fileName || ''; + const fileContent = !existsSync(filePath) ? window?.activeTextEditor?.document.getText() : ''; - if (filePath) { + if (filePath || fileContent) { const ws = await QuickPickWorkspace.pickOrReturn(context); - LogView.createView(ws, context, filePath); + LogView.createView(ws, context, Promise.resolve(), filePath, fileContent); } else { context.display.showErrorMessage( 'No file selected or the file is too large. Try again using the file explorer or text editor command.', From 0ed9000de67a46bb93b8f5a7734aebf197387aab Mon Sep 17 00:00:00 2001 From: Luke Cotter <4013877+lukecotter@users.noreply.github.com> Date: Mon, 20 Nov 2023 17:29:11 +0000 Subject: [PATCH 2/2] docs: update changelog --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f2ec140d..01844dbb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed +- Open Apex Log Analyzer from a dirty vscode editor ([#213][#213]) + - Supports opening Apex Log Analyzer when a log is dragged and dropped into Salesforce Code Builder. + - It allows for a log analysis to be shown when a file is deleted on local disk or a log is copy and pasted into an editor window without saving. - Make dragging more obvious on the Timeline by showing different cursors ([#423][#423]) - Show the pointer cursor by default when hovering the Timeline. - Show the grabbing cursor when the mouse is pressed down on the Timeline, to indicate drag is now possible. @@ -295,6 +298,7 @@ Skipped due to adopting odd numbering for pre releases and even number for relea +[#213]: https://github.com/certinia/debug-log-analyzer/issues/213 [#86]: https://github.com/certinia/debug-log-analyzer/issues/86 [#115]: https://github.com/certinia/debug-log-analyzer/issues/115 [#423]: https://github.com/certinia/debug-log-analyzer/issues/423