summaryrefslogtreecommitdiffhomepage
path: root/internal/llm/tools/edit.go
diff options
context:
space:
mode:
authoradamdottv <[email protected]>2025-05-12 09:44:56 -0500
committeradamdottv <[email protected]>2025-05-12 09:44:56 -0500
commitdfe5fd8d970f76af9db0a7bf9a1e6f0bc01a291c (patch)
treeebf8123a492626a31b7767b18a60594879cd70b0 /internal/llm/tools/edit.go
parented9fba99c9e230094ed5d468c88f81469d60c911 (diff)
downloadopencode-dfe5fd8d970f76af9db0a7bf9a1e6f0bc01a291c.tar.gz
opencode-dfe5fd8d970f76af9db0a7bf9a1e6f0bc01a291c.zip
wip: refactoring
Diffstat (limited to 'internal/llm/tools/edit.go')
-rw-r--r--internal/llm/tools/edit.go27
1 files changed, 15 insertions, 12 deletions
diff --git a/internal/llm/tools/edit.go b/internal/llm/tools/edit.go
index 44787f525..df5c94290 100644
--- a/internal/llm/tools/edit.go
+++ b/internal/llm/tools/edit.go
@@ -37,7 +37,7 @@ type EditResponseMetadata struct {
type editTool struct {
lspClients map[string]*lsp.Client
permissions permission.Service
- files history.Service
+ history history.Service
}
const (
@@ -95,7 +95,7 @@ func NewEditTool(lspClients map[string]*lsp.Client, permissions permission.Servi
return &editTool{
lspClients: lspClients,
permissions: permissions,
- files: files,
+ history: files,
}
}
@@ -202,6 +202,7 @@ func (e *editTool) createNewFile(ctx context.Context, filePath, content string)
permissionPath = rootDir
}
p := e.permissions.Request(
+ ctx,
permission.CreatePermissionRequest{
SessionID: sessionID,
Path: permissionPath,
@@ -224,14 +225,14 @@ func (e *editTool) createNewFile(ctx context.Context, filePath, content string)
}
// File can't be in the history so we create a new file history
- _, err = e.files.Create(ctx, sessionID, filePath, "")
+ _, err = e.history.Create(ctx, sessionID, filePath, "")
if err != nil {
// Log error but don't fail the operation
return ToolResponse{}, fmt.Errorf("error creating file history: %w", err)
}
// Add the new content to the file history
- _, err = e.files.CreateVersion(ctx, sessionID, filePath, content)
+ _, err = e.history.CreateVersion(ctx, sessionID, filePath, content)
if err != nil {
// Log error but don't fail the operation
slog.Debug("Error creating file history version", "error", err)
@@ -313,6 +314,7 @@ func (e *editTool) deleteContent(ctx context.Context, filePath, oldString string
permissionPath = rootDir
}
p := e.permissions.Request(
+ ctx,
permission.CreatePermissionRequest{
SessionID: sessionID,
Path: permissionPath,
@@ -335,9 +337,9 @@ func (e *editTool) deleteContent(ctx context.Context, filePath, oldString string
}
// Check if file exists in history
- file, err := e.files.GetByPathAndSession(ctx, filePath, sessionID)
+ file, err := e.history.GetLatestByPathAndSession(ctx, filePath, sessionID)
if err != nil {
- _, err = e.files.Create(ctx, sessionID, filePath, oldContent)
+ _, err = e.history.Create(ctx, sessionID, filePath, oldContent)
if err != nil {
// Log error but don't fail the operation
return ToolResponse{}, fmt.Errorf("error creating file history: %w", err)
@@ -345,13 +347,13 @@ func (e *editTool) deleteContent(ctx context.Context, filePath, oldString string
}
if file.Content != oldContent {
// User Manually changed the content store an intermediate version
- _, err = e.files.CreateVersion(ctx, sessionID, filePath, oldContent)
+ _, err = e.history.CreateVersion(ctx, sessionID, filePath, oldContent)
if err != nil {
slog.Debug("Error creating file history version", "error", err)
}
}
// Store the new version
- _, err = e.files.CreateVersion(ctx, sessionID, filePath, "")
+ _, err = e.history.CreateVersion(ctx, sessionID, filePath, "")
if err != nil {
slog.Debug("Error creating file history version", "error", err)
}
@@ -433,6 +435,7 @@ func (e *editTool) replaceContent(ctx context.Context, filePath, oldString, newS
permissionPath = rootDir
}
p := e.permissions.Request(
+ ctx,
permission.CreatePermissionRequest{
SessionID: sessionID,
Path: permissionPath,
@@ -455,9 +458,9 @@ func (e *editTool) replaceContent(ctx context.Context, filePath, oldString, newS
}
// Check if file exists in history
- file, err := e.files.GetByPathAndSession(ctx, filePath, sessionID)
+ file, err := e.history.GetLatestByPathAndSession(ctx, filePath, sessionID)
if err != nil {
- _, err = e.files.Create(ctx, sessionID, filePath, oldContent)
+ _, err = e.history.Create(ctx, sessionID, filePath, oldContent)
if err != nil {
// Log error but don't fail the operation
return ToolResponse{}, fmt.Errorf("error creating file history: %w", err)
@@ -465,13 +468,13 @@ func (e *editTool) replaceContent(ctx context.Context, filePath, oldString, newS
}
if file.Content != oldContent {
// User Manually changed the content store an intermediate version
- _, err = e.files.CreateVersion(ctx, sessionID, filePath, oldContent)
+ _, err = e.history.CreateVersion(ctx, sessionID, filePath, oldContent)
if err != nil {
slog.Debug("Error creating file history version", "error", err)
}
}
// Store the new version
- _, err = e.files.CreateVersion(ctx, sessionID, filePath, newContent)
+ _, err = e.history.CreateVersion(ctx, sessionID, filePath, newContent)
if err != nil {
slog.Debug("Error creating file history version", "error", err)
}