Remove last empty line in GetFileContentFn (#80) All checks were successful release-nightly / release-image (push) Successful in 1m21s
All checks were successful
release-nightly / release-image (push) Successful in 1m21s
Normally, each file should be end with a blank line, but git does not consider it as a new line, so we should not return it to llm, or it may generate wrong information when editing the existing file. Reviewed-on: #80 Reviewed-by: hiifong <i@hiif.ong> Co-authored-by: yp05327 <576951401@qq.com> Co-committed-by: yp05327 <576951401@qq.com>
This commit was merged in pull request #80.
This commit is contained in:
@@ -149,6 +149,16 @@ func GetFileContentFn(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallTo | ||||
}) | ||||
| ||||
} | ||||
if err := scanner.Err(); err != nil { | ||||
return to.ErrorResult(fmt.Errorf("scan content err: %v", err)) | ||||
} | ||||
| ||||
// remove the last blank line if exists | ||||
// git does not consider the last line as a new line | ||||
if contentLines[len(contentLines)-1].Content == "" { | ||||
contentLines = contentLines[:len(contentLines)-1] | ||||
} | ||||
| ||||
contentBytes, err := json.MarshalIndent(contentLines, "", " ") | ||||
if err != nil { | ||||
return to.ErrorResult(fmt.Errorf("marshal content lines err: %v", err)) | ||||
|
Reference in New Issue
Block a user