Skip to content

Commit f39a19f

Browse files
committed
fix: some json files takes over 10 seconds to beautify
1 parent 6fb8189 commit f39a19f

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

src/extensions/default/Phoenix-prettier/worker/prettier-helper.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,18 @@ async function prettify(params) {
8585
options.rangeStart = options.rangeStart || 0;
8686
options.rangeEnd = options.rangeEnd || params.text.length;
8787
await _loadPlugin(options._usePlugin);
88-
let { formatted, cursorOffset} = await prettier.formatWithCursor(params.text, options);
88+
const pluginName = options._usePlugin;
89+
delete options._usePlugin;
90+
let formatted, cursorOffset;
91+
if(pluginName === "json-stringify") {
92+
// json stringify impl of format with cursor has a bug where it will get stuck prettying for like 10 secs
93+
// for some rare files. so we use the original prettier without cursor fn
94+
formatted = await prettier.format(params.text, options);
95+
} else {
96+
let prettyResult = await prettier.formatWithCursor(params.text, options);
97+
formatted = prettyResult.formatted;
98+
cursorOffset = prettyResult.cursorOffset;
99+
}
89100
if(isFullFileBeautify){
90101
return {
91102
text: formatted,

0 commit comments

Comments
 (0)