From aa44fc0a50de4317138f0ad9512b97620d0110cc Mon Sep 17 00:00:00 2001 From: eidheim Date: Wed, 7 Jul 2021 16:43:37 +0200 Subject: [PATCH] Reset stdout_buffer and related variables if prettier background process has to be recreated due to failure --- src/source.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/source.cpp b/src/source.cpp index 1f5b0ba..c8706bf 100644 --- a/src/source.cpp +++ b/src/source.cpp @@ -836,19 +836,22 @@ void Source::View::setup_format_style(bool is_generic_view) { result = {}; error = {}; } + static std::stringstream stdout_buffer; + static int curly_count = 0; + static bool key_or_value = false; if(prettier_background_process) { int exit_status; if(prettier_background_process->try_get_exit_status(exit_status)) prettier_background_process = {}; } if(!prettier_background_process) { + stdout_buffer = std::stringstream(); + curly_count = 0; + key_or_value = false; prettier_background_process = std::make_unique( "node -e \"const repl = require('repl');repl.start({prompt: '', ignoreUndefined: true, preview: false});\"", "", [](const char *bytes, size_t n) { - static std::stringstream stdout_buffer; - static int curly_count = 0; - static bool key_or_value = false; for(size_t i = 0; i < n; ++i) { if(!key_or_value) { if(bytes[i] == '{')