diff --git a/lua/chatgpt/api.lua b/lua/chatgpt/api.lua index 4eeff7f2..b972ee92 100644 --- a/lua/chatgpt/api.lua +++ b/lua/chatgpt/api.lua @@ -169,24 +169,24 @@ end local function loadConfigFromCommand(command, optionName, callback, defaultValue) local cmd = splitCommandIntoTable(command) - job - :new({ - command = cmd[1], - args = vim.list_slice(cmd, 2, #cmd), - on_exit = function(j, exit_code) - if exit_code ~= 0 then - logger.warn("Config '" .. optionName .. "' did not return a value when executed") - return - end - local value = j:result()[1]:gsub("%s+$", "") - if value ~= nil and value ~= "" then - callback(value) - elseif defaultValue ~= nil and defaultValue ~= "" then - callback(defaultValue) - end - end, - }) - :start() + local j = job:new({ + command = cmd[1], + args = vim.list_slice(cmd, 2, #cmd), + on_exit = function(j, exit_code) + if exit_code ~= 0 then + logger.warn("Config '" .. optionName .. "' did not return a value when executed") + return + end + local value = j:result()[1]:gsub("%s+$", "") + if value ~= nil and value ~= "" then + callback(value) + elseif defaultValue ~= nil and defaultValue ~= "" then + callback(defaultValue) + end + end, + }) + j:start() + j:wait() -- we should wait the job to finish. Otherwise we can't ensure correctly reading config before using it. end local function loadConfigFromEnv(envName, configName) diff --git a/lua/chatgpt/code_edits.lua b/lua/chatgpt/code_edits.lua index 2200916f..07202bf3 100644 --- a/lua/chatgpt/code_edits.lua +++ b/lua/chatgpt/code_edits.lua @@ -310,7 +310,12 @@ M.edit_with_instructions = function(output_lines, bufnr, selection, ...) for _, winid in ipairs({ input_window.winid, output_window.winid }) do vim.api.nvim_set_current_win(winid) if diff_mode then + -- set local wrap to be previous option to make it mroe readable(wrap=true is often more readable in diff mode). + local previous_wrap = vim.o.wrap vim.api.nvim_command("diffthis") + if vim.o.wrap ~= previous_wrap then + vim.o.wrap = previous_wrap + end else vim.api.nvim_command("diffoff") end