Skip to content

Commit

Permalink
feat: implement delete_file and replace_in_file
Browse files Browse the repository at this point in the history
  • Loading branch information
default-anton committed Feb 1, 2025
1 parent 871a953 commit ca2a725
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 11 deletions.
6 changes: 1 addition & 5 deletions lua/llm-sidekick/tools/create_file.lua
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,7 @@ local spec = {

return {
spec = spec,
start = function(tool_call)
local line_count = vim.api.nvim_buf_line_count(0)
tool_call.state.file_path_lnum = line_count + 4
tool_call.state.create_lnum = line_count + 7

start = function(_)
chat.paste_at_end("\n\n**Path:**\n```\n")
end,
delta = function(tool_call)
Expand Down
16 changes: 13 additions & 3 deletions lua/llm-sidekick/tools/delete_file.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
local chat = require("llm-sidekick.chat")

local spec = {
name = "delete_file",
description = [[
Expand All @@ -22,11 +24,19 @@ local spec = {

return {
spec = spec,
start = function(tool)
start = function(_)
chat.paste_at_end("\n\n**Path:**\n```\n")
end,
delta = function(tool)
delta = function(tool_call)
local path_written = tool_call.state.path_written or 0

if tool_call.input.path and path_written < #tool_call.input.path then
chat.paste_at_end(tool_call.input.path:sub(path_written + 1))
tool_call.state.path_written = #tool_call.input.path
end
end,
stop = function(tool)
stop = function(_)
chat.paste_at_end("\n```\n**Delete:**\n```\nN/A\n```\n")
end,
callback = function(tool)
-- tool.input
Expand Down
35 changes: 32 additions & 3 deletions lua/llm-sidekick/tools/replace_in_file.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
local markdown = require("llm-sidekick.markdown")
local chat = require("llm-sidekick.chat")

local spec = {
name = "replace_in_file",
description = [[
Expand Down Expand Up @@ -40,11 +43,37 @@ local spec = {

return {
spec = spec,
start = function(tool)
start = function(_)
chat.paste_at_end("\n\n**Path:**\n```\n")
end,
delta = function(tool)
delta = function(tool_call)
local path_written = tool_call.state.path_written or 0
local find_written = tool_call.state.find_written or 0
local replace_written = tool_call.state.replace_written or 0

if tool_call.input.path and path_written < #tool_call.input.path then
chat.paste_at_end(tool_call.input.path:sub(path_written + 1))
tool_call.state.path_written = #tool_call.input.path
end

if tool_call.input.find and find_written < #tool_call.input.find then
if find_written == 0 then
chat.paste_at_end("\n```\n**Find:**\n```\n")
end
chat.paste_at_end(tool_call.input.find:sub(find_written + 1))
tool_call.state.find_written = #tool_call.input.find
end

if tool_call.input.replace and replace_written < #tool_call.input.replace then
if replace_written == 0 then
chat.paste_at_end("\n```\n**Replace:**\n```\n")
end
chat.paste_at_end(tool_call.input.replace:sub(replace_written + 1))
tool_call.state.replace_written = #tool_call.input.replace
end
end,
stop = function(tool)
stop = function(_)
chat.paste_at_end("\n```\n")
end,
callback = function(tool)
-- tool.input
Expand Down

0 comments on commit ca2a725

Please sign in to comment.