Update file_insert_lines
Renamed `start_line` parameter to `position`
This commit is contained in:
parent
3b20e00330
commit
a805c92131
@ -179,16 +179,16 @@ var AvailableTools = map[string]AvailableTool{
|
|||||||
Type: "string",
|
Type: "string",
|
||||||
Description: "Path of the file to be modified, relative to the current working directory.",
|
Description: "Path of the file to be modified, relative to the current working directory.",
|
||||||
},
|
},
|
||||||
"start_line": {
|
"position": {
|
||||||
Type: "integer",
|
Type: "integer",
|
||||||
Description: `Which line to begin inserting lines at (existing line will be moved to after content).`,
|
Description: `Which line to insert content *before*.`,
|
||||||
},
|
},
|
||||||
"content": {
|
"content": {
|
||||||
Type: "string",
|
Type: "string",
|
||||||
Description: `The content to insert.`,
|
Description: `The content to insert.`,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Required: []string{"path", "start", "content"},
|
Required: []string{"path", "position", "content"},
|
||||||
},
|
},
|
||||||
}},
|
}},
|
||||||
Impl: func(args map[string]interface{}) (string, error) {
|
Impl: func(args map[string]interface{}) (string, error) {
|
||||||
@ -200,14 +200,14 @@ var AvailableTools = map[string]AvailableTool{
|
|||||||
if !ok {
|
if !ok {
|
||||||
return "", fmt.Errorf("Invalid path in function arguments: %v", tmp)
|
return "", fmt.Errorf("Invalid path in function arguments: %v", tmp)
|
||||||
}
|
}
|
||||||
var start_line int
|
var position int
|
||||||
tmp, ok = args["start_line"]
|
tmp, ok = args["position"]
|
||||||
if ok {
|
if ok {
|
||||||
tmp, ok := tmp.(float64)
|
tmp, ok := tmp.(float64)
|
||||||
if !ok {
|
if !ok {
|
||||||
return "", fmt.Errorf("Invalid start_line in function arguments: %v", tmp)
|
return "", fmt.Errorf("Invalid position in function arguments: %v", tmp)
|
||||||
}
|
}
|
||||||
start_line = int(tmp)
|
position = int(tmp)
|
||||||
}
|
}
|
||||||
var content string
|
var content string
|
||||||
tmp, ok = args["content"]
|
tmp, ok = args["content"]
|
||||||
@ -217,7 +217,7 @@ var AvailableTools = map[string]AvailableTool{
|
|||||||
return "", fmt.Errorf("Invalid content in function arguments: %v", tmp)
|
return "", fmt.Errorf("Invalid content in function arguments: %v", tmp)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return FileInsertLines(path, start_line, content), nil
|
return FileInsertLines(path, position, content), nil
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"file_replace_lines": {
|
"file_replace_lines": {
|
||||||
@ -484,7 +484,7 @@ func WriteFile(path string, content string) string {
|
|||||||
return resultToJson(FunctionResult{})
|
return resultToJson(FunctionResult{})
|
||||||
}
|
}
|
||||||
|
|
||||||
func FileInsertLines(path string, startLine int, content string) string {
|
func FileInsertLines(path string, position int, content string) string {
|
||||||
ok, res := isPathWithinCWD(path)
|
ok, res := isPathWithinCWD(path)
|
||||||
if !ok {
|
if !ok {
|
||||||
return resultToJson(*res)
|
return resultToJson(*res)
|
||||||
@ -503,15 +503,15 @@ func FileInsertLines(path string, startLine int, content string) string {
|
|||||||
data = []byte{}
|
data = []byte{}
|
||||||
}
|
}
|
||||||
|
|
||||||
if startLine < 1 {
|
if position < 1 {
|
||||||
return resultToJson(FunctionResult{Message: "start_line cannot be less than 1"})
|
return resultToJson(FunctionResult{Message: "start_line cannot be less than 1"})
|
||||||
}
|
}
|
||||||
|
|
||||||
lines := strings.Split(string(data), "\n")
|
lines := strings.Split(string(data), "\n")
|
||||||
contentLines := strings.Split(strings.Trim(content, "\n"), "\n")
|
contentLines := strings.Split(strings.Trim(content, "\n"), "\n")
|
||||||
|
|
||||||
before := lines[:startLine-1]
|
before := lines[:position-1]
|
||||||
after := lines[startLine-1:]
|
after := lines[position-1:]
|
||||||
lines = append(before, append(contentLines, after...)...)
|
lines = append(before, append(contentLines, after...)...)
|
||||||
|
|
||||||
newContent := strings.Join(lines, "\n")
|
newContent := strings.Join(lines, "\n")
|
||||||
|
Loading…
Reference in New Issue
Block a user