From 657ef1e1193fc321ed6161d3ee737baa60af55a1 Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Tue, 27 Jan 2026 18:07:35 +0800 Subject: [PATCH] Should format error in `comments` and `doc` panel (#18761) --- website/static/worker.mjs | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/website/static/worker.mjs b/website/static/worker.mjs index 52b83cf95..08c922026 100644 --- a/website/static/worker.mjs +++ b/website/static/worker.mjs @@ -170,23 +170,31 @@ async function handleFormatMessage(message) { } if (!isDocExplorer && message.debug.doc) { - try { - response.debug.doc = await prettier.__debug.formatDoc( - await prettier.__debug.printToDoc(message.code, options), - { plugins }, - ); - } catch { - response.debug.doc = ""; + if (formatResult.error) { + response.debug.doc = formatResult.formatted; + } else { + try { + response.debug.doc = await prettier.__debug.formatDoc( + await prettier.__debug.printToDoc(message.code, options), + { plugins }, + ); + } catch { + response.debug.doc = ""; + } } } if (!isDocExplorer && message.debug.comments) { - response.debug.comments = ( - await formatCode(JSON.stringify(formatResult.comments || []), { - parser: "json", - plugins, - }) - ).formatted; + if (formatResult.error) { + response.debug.comments = formatResult.formatted; + } else { + response.debug.comments = ( + await formatCode(JSON.stringify(formatResult.comments || []), { + parser: "json", + plugins, + }) + ).formatted; + } } if (!isDocExplorer && message.debug.reformat) {