Skip to content

Commit b2b670c

Browse files
committed
fix(fmt): redirect console.dirxml in the LSP server
1 parent 5adb718 commit b2b670c

2 files changed

Lines changed: 6 additions & 0 deletions

File tree

‎packages/rstack/src/fmt/lsp/server.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ const redirectConsoleToConnection = (connection: Connection): void => {
6969
}
7070
console.dir = (item: unknown, options?: object): void =>
7171
connection.console.log(inspect(item, options));
72+
// `dir` and `dirxml` are the only methods that write to a standard stream
73+
// without going through the five rerouted above; in Node, `dirxml` is `log`.
74+
console.dirxml = (...args: unknown[]): void =>
75+
connection.console.log(serializeConsoleArguments(args));
7276
console.trace = (...args: unknown[]): void => {
7377
const stack = new Error().stack?.replace(/(.+\n){2}/, '') ?? '';
7478
const message = args.length === 0 ? 'Trace' : `Trace: ${serializeConsoleArguments(args)}`;

‎packages/rstack/tests/cli/fmt/lsp.test.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,8 @@ test(
155155
`import { define } from 'rstack';
156156
157157
console.log('hello from config');
158+
// Bypasses a patched \`console.log\`, so it needs its own reroute.
159+
console.dirxml('xml from config');
158160
159161
define.fmt({ singleQuote: true });
160162
`,

0 commit comments

Comments
 (0)