feat(suggestions): add tags around json (#1441)

This commit is contained in:
yetone
2025-03-01 13:11:12 +08:00
committed by GitHub
parent 86feaf3e38
commit 5bb055795f
2 changed files with 34 additions and 0 deletions

View File

@@ -110,6 +110,7 @@ L5: pass
{
role = "assistant",
content = [[
<suggestions>
[
[
{
@@ -136,6 +137,7 @@ L5: pass
},
]
]
</suggestions>
]],
},
}
@@ -165,6 +167,7 @@ L5: pass
if cursor_row ~= doc.position.row or cursor_col ~= doc.position.col then return end
-- Clean up markdown code blocks
full_response = Utils.trim_think_content(full_response)
full_response = full_response:gsub("<suggestions>\n(.-)\n</suggestions>", "%1")
full_response = full_response:gsub("^```%w*\n(.-)\n```$", "%1")
full_response = full_response:gsub("(.-)\n```\n?$", "%1")
-- Remove everything before the first '[' to ensure we get just the JSON array

View File

@@ -36,6 +36,37 @@ Your task is to suggest code modifications at the cursor position. Follow these
start_row: The starting row of the code snippet you want to replace, start from 1, inclusive
end_row: The ending row of the code snippet you want to replace, start from 1, inclusive
content: The suggested code you want to replace the original code with
3. JSON must be wrapped with <suggestions></suggestions> tags, for example:
{% raw %}
<suggestions>
[
[
{
"start_row": 1,
"end_row": 1,
"content": "Your suggested code here"
},
{
"start_row": 3,
"end_row": 9,
"content": "Your suggested code here"
}
],
[
{
"start_row": 2,
"end_row": 6,
"content": "Your suggested code here"
},
{
"start_row": 9,
"end_row": 22,
"content": "Your suggested code here"
}
]
]
</suggestions>
{% endraw %}
Guidelines:
1. Make sure you have maintained the user's existing whitespace and indentation. This is REALLY IMPORTANT!