Skip to content

Commit

Permalink
Merge pull request #449 from lukecotter/feat-open-viewer-from-dirty-e…
Browse files Browse the repository at this point in the history
…ditor

feat: open viewer from dirty editor
  • Loading branch information
lcottercertinia authored Nov 20, 2023
2 parents ae24555 + 0ed9000 commit 35a10ba
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 14 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -295,6 +298,7 @@ Skipped due to adopting odd numbering for pre releases and even number for relea

<!-- Unreleased -->

[#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
Expand Down
28 changes: 18 additions & 10 deletions lana/src/commands/LogView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,15 @@ export class LogView {
static async createView(
wsPath: string,
context: Context,
logPath: string,
beforeSendLog?: Promise<void>,
logPath?: string,
logData?: string,
): Promise<WebviewPanel> {
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');
Expand All @@ -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;
}

Expand Down Expand Up @@ -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,
},
});
}
Expand Down
2 changes: 1 addition & 1 deletion lana/src/commands/RetrieveLogFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
8 changes: 5 additions & 3 deletions lana/src/commands/ShowLogAnalysis.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -32,11 +33,12 @@ export class ShowLogAnalysis {
}

private static async command(context: Context, uri: Uri): Promise<void> {
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.',
Expand Down

0 comments on commit 35a10ba

Please sign in to comment.