Fix up some of the new formatting stuff

This commit is contained in:
Gregory Schier
2024-10-22 08:07:56 -07:00
parent e216214085
commit 57a05d5486
7 changed files with 70 additions and 17 deletions

View File

@@ -5,7 +5,24 @@ const INDENT = ' ';
export async function tryFormatJson(text: string): Promise<string> {
if (text === '') return text;
return invokeCmd('cmd_format_json', { text });
try {
const result = await invokeCmd<string>('cmd_format_json', { text });
return result;
// eslint-disable-next-line @typescript-eslint/no-unused-vars
} catch (err) {
console.warn("Failed to format JSON", err);
// Nothing
}
try {
return JSON.stringify(JSON.parse(text), null, 2);
// eslint-disable-next-line @typescript-eslint/no-unused-vars
} catch (err) {
// Nothing
}
return text;
}
export async function tryFormatXml(text: string): Promise<string> {