From 567a5d2b83dbfb664da8847e448abb38549f3011 Mon Sep 17 00:00:00 2001 From: radlinskii Date: Mon, 8 Jul 2024 19:39:31 +0200 Subject: [PATCH] ensure json is decoded correctly even if it's content is multiline --- lua/auto-session/init.lua | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lua/auto-session/init.lua b/lua/auto-session/init.lua index ddbdbb4..ba57c5c 100644 --- a/lua/auto-session/init.lua +++ b/lua/auto-session/init.lua @@ -621,7 +621,8 @@ local function write_to_session_control_json(session_file_name) local session_control_file = control_dir .. control_file local log_ending_state = function() - local content = vim.fn.readfile(session_control_file) + local file_lines = vim.fn.readfile(session_control_file) + local content = table.concat(file_lines, " ") local session_control = vim.json.decode(content[1] or "{}") or {} local sessions = { current = session_control.current, alternate = session_control.alternate } @@ -629,7 +630,8 @@ local function write_to_session_control_json(session_file_name) end if vim.fn.filereadable(session_control_file) == 1 then - local content = vim.fn.readfile(session_control_file) + local file_lines = vim.fn.readfile(session_control_file) + local content = table.concat(file_lines, " ") Lib.logger.debug { content = content } local json = vim.json.decode(content[1] or "{}") or {}