fix: edit_file cannot find old str
This commit is contained in:
@@ -59,18 +59,21 @@ M.func = vim.schedule_wrap(function(input, opts)
|
|||||||
if not provider then return false, "morph provider not found" end
|
if not provider then return false, "morph provider not found" end
|
||||||
if not provider.is_env_set() then return false, "morph provider not set" end
|
if not provider.is_env_set() then return false, "morph provider not set" end
|
||||||
|
|
||||||
local original_code
|
|
||||||
local ok, lines = pcall(Utils.read_file_from_buf_or_disk, input.target_file)
|
local ok, lines = pcall(Utils.read_file_from_buf_or_disk, input.target_file)
|
||||||
if not ok then
|
if not ok then
|
||||||
local f = io.open(input.target_file, "r")
|
local f = io.open(input.target_file, "r")
|
||||||
if f then
|
if f then
|
||||||
original_code = f:read("*all")
|
local original_code = f:read("*all")
|
||||||
f:close()
|
f:close()
|
||||||
|
lines = vim.split(original_code, "\n")
|
||||||
end
|
end
|
||||||
else
|
|
||||||
original_code = table.concat(lines or {}, "\n")
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if lines and #lines > 0 then
|
||||||
|
if lines[#lines] == "" then lines = vim.list_slice(lines, 0, #lines - 1) end
|
||||||
|
end
|
||||||
|
local original_code = table.concat(lines or {}, "\n")
|
||||||
|
|
||||||
local provider_conf = Providers.parse_config(provider)
|
local provider_conf = Providers.parse_config(provider)
|
||||||
|
|
||||||
local body = {
|
local body = {
|
||||||
|
|||||||
Reference in New Issue
Block a user