Skip to content

Commit 35a10ba

Browse files
Merge pull request #449 from lukecotter/feat-open-viewer-from-dirty-editor
feat: open viewer from dirty editor
2 parents ae24555 + 0ed9000 commit 35a10ba

4 files changed

Lines changed: 28 additions & 14 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1616

1717
### Changed
1818

19+
- Open Apex Log Analyzer from a dirty vscode editor ([#213][#213])
20+
- Supports opening Apex Log Analyzer when a log is dragged and dropped into Salesforce Code Builder.
21+
- 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.
1922
- Make dragging more obvious on the Timeline by showing different cursors ([#423][#423])
2023
- Show the pointer cursor by default when hovering the Timeline.
2124
- 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
295298

296299
<!-- Unreleased -->
297300

301+
[#213]: https://github.com/certinia/debug-log-analyzer/issues/213
298302
[#86]: https://github.com/certinia/debug-log-analyzer/issues/86
299303
[#115]: https://github.com/certinia/debug-log-analyzer/issues/115
300304
[#423]: https://github.com/certinia/debug-log-analyzer/issues/423

lana/src/commands/LogView.ts

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,15 @@ export class LogView {
2626
static async createView(
2727
wsPath: string,
2828
context: Context,
29-
logPath: string,
3029
beforeSendLog?: Promise<void>,
30+
logPath?: string,
31+
logData?: string,
3132
): Promise<WebviewPanel> {
32-
const panel = WebView.apply('logFile', 'Log: ' + basename(logPath), [
33-
Uri.file(join(context.context.extensionPath, 'out')),
34-
Uri.file(dirname(logPath)),
35-
]);
33+
const panel = WebView.apply(
34+
'logFile',
35+
'Log: ' + logPath ? basename(logPath || '') : 'Untitled',
36+
[Uri.file(join(context.context.extensionPath, 'out')), Uri.file(dirname(logPath || ''))],
37+
);
3638

3739
const logViewerRoot = join(context.context.extensionPath, 'out');
3840
const index = join(logViewerRoot, 'index.html');
@@ -55,7 +57,7 @@ export class LogView {
5557
switch (request.cmd) {
5658
case 'fetchLog': {
5759
await beforeSendLog;
58-
LogView.sendLog(panel, context, logPath);
60+
LogView.sendLog(panel, context, logPath, logData);
5961
break;
6062
}
6163

@@ -141,20 +143,26 @@ export class LogView {
141143
});
142144
}
143145

144-
private static sendLog(panel: WebviewPanel, context: Context, logFilePath: string) {
145-
if (!existsSync(logFilePath)) {
146+
private static sendLog(
147+
panel: WebviewPanel,
148+
context: Context,
149+
logFilePath?: string,
150+
logData?: string,
151+
) {
152+
if (!logData && !existsSync(logFilePath || '')) {
146153
context.display.showErrorMessage('Log file could not be found.', {
147154
modal: true,
148155
});
149156
}
150157

151-
const filePath = parse(logFilePath);
158+
const filePath = parse(logFilePath || '');
152159
panel.webview.postMessage({
153160
command: 'fetchLog',
154161
data: {
155162
logName: filePath.name,
156-
logUri: panel.webview.asWebviewUri(Uri.file(logFilePath)).toString(true),
163+
logUri: logFilePath ? panel.webview.asWebviewUri(Uri.file(logFilePath)).toString(true) : '',
157164
logPath: logFilePath,
165+
logData: logData,
158166
},
159167
});
160168
}

lana/src/commands/RetrieveLogFile.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ export class RetrieveLogFile {
6060
if (logFileId) {
6161
const logFilePath = this.getLogFilePath(ws, logFileId);
6262
const writeLogFile = this.writeLogFile(ws, logFilePath);
63-
return LogView.createView(ws, context, logFilePath, writeLogFile);
63+
return LogView.createView(ws, context, writeLogFile, logFilePath);
6464
}
6565
}
6666

lana/src/commands/ShowLogAnalysis.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/*
22
* Copyright (c) 2020 Certinia Inc. All rights reserved.
33
*/
4+
import { existsSync } from 'fs';
45
import { Uri, window } from 'vscode';
56

67
import { appName } from '../AppSettings.js';
@@ -32,11 +33,12 @@ export class ShowLogAnalysis {
3233
}
3334

3435
private static async command(context: Context, uri: Uri): Promise<void> {
35-
const filePath = uri?.fsPath || window?.activeTextEditor?.document.fileName;
36+
const filePath = uri?.fsPath || window?.activeTextEditor?.document.fileName || '';
37+
const fileContent = !existsSync(filePath) ? window?.activeTextEditor?.document.getText() : '';
3638

37-
if (filePath) {
39+
if (filePath || fileContent) {
3840
const ws = await QuickPickWorkspace.pickOrReturn(context);
39-
LogView.createView(ws, context, filePath);
41+
LogView.createView(ws, context, Promise.resolve(), filePath, fileContent);
4042
} else {
4143
context.display.showErrorMessage(
4244
'No file selected or the file is too large. Try again using the file explorer or text editor command.',

0 commit comments

Comments
 (0)