alexanderweiss / nova-prettier

Prettier extension for Nova
MIT License
35 stars 6 forks source link

Bug: Hang/Crash with 200K JSON file #80

Open FlyboyArt opened 2 years ago

FlyboyArt commented 2 years ago

The title says it all, I have a perfectly valid JSON file (online validated @ https://jsonlint.com) and when I load it into Nova and try to Prettify it, Nova hangs and and eventually wants to shut the extension down. The file that causes the hang/crash is attached.

Other text editors seem to handle it just fine so it's just this implementation of Prettify that has trouble.

Thanks for looking into this, Art

quotes.json.gz

alexanderweiss commented 2 years ago

This is because Nova doesn't support keeping the cursor position. That means the extension has to do a complete diff, which is slow for very large files or files with many/large changes. I don't think there's much that can be done about it other than providing an option to format without maintaining cursor position, but I think that's kind of confusing & weird.

FlyboyArt commented 2 years ago

As opposed to crashing I think an option would be useful. The other choice ti to use a different editor for formatting JSON files which seems a waste after choosing to depend on Nova for my main editor. Perhaps placing the cursor at the top of the file after formatting by default?

alexanderweiss commented 2 years ago

An option is definitely possible, but I don't think it's a good default as it would make format on saved completely unusable.