Skip to content

Commit 279c8d0

Browse files
Merge pull request #250 from laravel/debug-info-for-errors
Include debug info when copying error
2 parents d8cfde6 + 09d3b2a commit 279c8d0

File tree

4 files changed

+45
-3
lines changed

4 files changed

+45
-3
lines changed

src/extension.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { updateDiagnostics } from "./diagnostic/diagnostic";
1616
import { hoverProviders } from "./hover/HoverProvider";
1717
import { linkProviders } from "./link/LinkProvider";
1818
import { configAffected } from "./support/config";
19+
import { collectDebugInfo } from "./support/debug";
1920
import { disposeWatchers } from "./support/fileWatcher";
2021
import { info } from "./support/logger";
2122
import { setParserBinaryPath } from "./support/parser";
@@ -134,6 +135,8 @@ export function activate(context: vscode.ExtensionContext) {
134135
vscode.commands.registerCommand("laravel.open", openFileCommand),
135136
);
136137

138+
collectDebugInfo();
139+
137140
vscode.workspace.onDidChangeConfiguration((event) => {
138141
if (configAffected(event, "phpCommand", "phpEnvironment")) {
139142
clearDefaultPhpCommand();

src/support/debug.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import os from "os";
2+
import { getCommandTemplate, runInLaravel } from "./php";
3+
4+
export const debugInfo: Record<string, string> = {};
5+
6+
export const collectDebugInfo = () => {
7+
debugInfo["os"] = os.platform();
8+
debugInfo["arch"] = os.arch();
9+
10+
runInLaravel(`
11+
echo json_encode([
12+
'php_version' => phpversion(),
13+
'laravel_version' => app()->version(),
14+
]);
15+
`).then((output) => {
16+
if (output) {
17+
for (const key in output as Record<string, string>) {
18+
// @ts-ignore
19+
debugInfo[key] = output[key];
20+
}
21+
}
22+
23+
debugInfo["php_command"] = getCommandTemplate();
24+
});
25+
};

src/support/php.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,10 @@ const getHashedFile = (code: string) => {
273273
return fixFilePath(hashedFile);
274274
};
275275

276+
export const getCommandTemplate = (): string => {
277+
return config<string>("phpCommand", "") || getDefaultPhpCommand();
278+
};
279+
276280
export const runPhp = (
277281
code: string,
278282
description: string | null = null,
@@ -282,8 +286,7 @@ export const runPhp = (
282286
code = "<?php\n\n" + code;
283287
}
284288

285-
const commandTemplate =
286-
config<string>("phpCommand", "") || getDefaultPhpCommand();
289+
const commandTemplate = getCommandTemplate();
287290

288291
const hashedFile = getHashedFile(code);
289292

src/support/popup.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as vscode from "vscode";
22
import { config } from "./config";
3+
import { debugInfo } from "./debug";
34
import { channel, error } from "./logger";
45

56
let showErrorPopups = config<boolean>("showErrorPopups", false);
@@ -28,7 +29,17 @@ export const showErrorPopup = (...errors: string[]) => {
2829
{
2930
title: "Copy Error to Clipboard",
3031
command: () => {
31-
vscode.env.clipboard.writeText(errors.join("\n"));
32+
const finalMessage = [
33+
"Debug Info",
34+
"",
35+
JSON.stringify(debugInfo, null, 2),
36+
"",
37+
"-".repeat(40),
38+
"",
39+
...errors,
40+
];
41+
42+
vscode.env.clipboard.writeText(finalMessage.join("\n"));
3243
},
3344
},
3445
{

0 commit comments

Comments
 (0)