From 6634b20178c7faf8cea9bfbc8956f7e06231623b Mon Sep 17 00:00:00 2001 From: you-n-g Date: Wed, 11 Oct 2023 00:39:33 +0800 Subject: [PATCH 1/3] Fix async reading config --- lua/chatgpt/api.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lua/chatgpt/api.lua b/lua/chatgpt/api.lua index 4eeff7f2..8920e3b6 100644 --- a/lua/chatgpt/api.lua +++ b/lua/chatgpt/api.lua @@ -169,8 +169,7 @@ end local function loadConfigFromCommand(command, optionName, callback, defaultValue) local cmd = splitCommandIntoTable(command) - job - :new({ + local j = job:new({ command = cmd[1], args = vim.list_slice(cmd, 2, #cmd), on_exit = function(j, exit_code) @@ -186,7 +185,8 @@ local function loadConfigFromCommand(command, optionName, callback, defaultValue end end, }) - :start() + 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) From 87106ac20dce09f53ca340cbda835582199f2ae5 Mon Sep 17 00:00:00 2001 From: Young Date: Tue, 24 Oct 2023 21:31:18 +0800 Subject: [PATCH 2/3] Format code --- lua/chatgpt/api.lua | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/lua/chatgpt/api.lua b/lua/chatgpt/api.lua index 8920e3b6..b972ee92 100644 --- a/lua/chatgpt/api.lua +++ b/lua/chatgpt/api.lua @@ -170,21 +170,21 @@ end local function loadConfigFromCommand(command, optionName, callback, defaultValue) local cmd = splitCommandIntoTable(command) 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, - }) + 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 From a5a7192c53d942423c059545b2034b1016d8effa Mon Sep 17 00:00:00 2001 From: Young Date: Tue, 14 Nov 2023 22:33:01 +0800 Subject: [PATCH 3/3] Make diff more friendly --- lua/chatgpt/code_edits.lua | 5 +++++ 1 file changed, 5 insertions(+) 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