From 69ed6cd82a1935859826597fc1e3e57d879beec6 Mon Sep 17 00:00:00 2001 From: dyamito942 Date: Tue, 30 Aug 2022 19:44:15 -0400 Subject: [PATCH] Avoid writing partial hats file to vscode-hats.json --- src/util/addDecorationsToEditor.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/util/addDecorationsToEditor.ts b/src/util/addDecorationsToEditor.ts index 6a236de2e3..e9130e5ced 100644 --- a/src/util/addDecorationsToEditor.ts +++ b/src/util/addDecorationsToEditor.ts @@ -185,7 +185,15 @@ export function addDecorationsToEditors( if (!fs.existsSync(root)) { fs.mkdirSync(root); } - fs.writeFileSync(`${root}/vscode-hats.json`, JSON.stringify(serialized)); + // write to a hidden file first so eager file watchers don't get partial files. + // then perform a move to the proper location. this *should* be atomic? + // TODO: should we be deleting both of these files on cursorless startup? + fs.writeFileSync(`${root}/.vscode-hats.json`, JSON.stringify(serialized)); + fs.rename(`${root}/.vscode-hats.json`, `${root}/vscode-hats.json`, (err) => { + if (err) { + throw err; + } + }); decorationRanges.forEach((ranges, editor) => { decorations.hatStyleNames.forEach((hatStyleName) => {