Skip to content

Commit 82e9c29

Browse files
committed
cursor logging stuff
1 parent 2e6aa73 commit 82e9c29

File tree

1 file changed

+46
-20
lines changed

1 file changed

+46
-20
lines changed

src/utils/console.ts

+46-20
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,56 @@
33
const originalConsoleLog = console.log;
44
const originalConsoleError = console.error;
55

6-
function ensureSerializable(arg: any) {
7-
if (arg === undefined) return "undefined";
8-
if (arg === null) return null;
9-
10-
if (typeof arg === "object") {
11-
try {
12-
JSON.stringify(arg);
13-
return arg;
14-
} catch (e) {
15-
return String(arg);
16-
}
17-
}
18-
19-
return arg;
20-
}
21-
226
export function setupJsonConsole() {
237
console.log = function (...args) {
24-
const serializedArgs = args.map(ensureSerializable);
25-
originalConsoleLog(JSON.stringify(serializedArgs));
8+
const message = args
9+
.map((arg) => {
10+
if (typeof arg === "object" || Array.isArray(arg)) {
11+
try {
12+
return JSON.stringify(arg);
13+
} catch (e) {
14+
return String(arg);
15+
}
16+
}
17+
return String(arg);
18+
})
19+
.join(" ");
20+
21+
originalConsoleLog(
22+
JSON.stringify({
23+
jsonrpc: "2.0",
24+
method: "window/logMessage",
25+
params: {
26+
type: 3,
27+
message: message,
28+
},
29+
})
30+
);
2631
};
2732

2833
console.error = function (...args) {
29-
const serializedArgs = args.map(ensureSerializable);
30-
originalConsoleError(JSON.stringify(serializedArgs));
34+
const message = args
35+
.map((arg) => {
36+
if (typeof arg === "object" || Array.isArray(arg)) {
37+
try {
38+
return JSON.stringify(arg);
39+
} catch (e) {
40+
return String(arg);
41+
}
42+
}
43+
return String(arg);
44+
})
45+
.join(" ");
46+
47+
originalConsoleError(
48+
JSON.stringify({
49+
jsonrpc: "2.0",
50+
method: "window/logMessage",
51+
params: {
52+
type: 1,
53+
message: message,
54+
},
55+
})
56+
);
3157
};
3258
}

0 commit comments

Comments
 (0)