nvim: Add smartpaste to LLM prompts
Will paste and try to integrate _anything_ into the curent buffer. Wrong programming language, no formatting, pseudo code, natural language instructions, anything.
This commit is contained in:
parent
cd414e5289
commit
3812750980
1 changed files with 72 additions and 0 deletions
|
|
@ -142,6 +142,78 @@ return {
|
|||
},
|
||||
},
|
||||
},
|
||||
prompt_library = {
|
||||
|
||||
["Smart Paste"] = {
|
||||
strategy = "inline",
|
||||
description = "Paste code smartly",
|
||||
opts = { short_name = "paste" },
|
||||
prompts = {
|
||||
{
|
||||
role = "user",
|
||||
content = [[
|
||||
You are a smart code paste agent within Neovim.
|
||||
|
||||
## **Task:** Intelligently integrate content from the user's clipboard into the current buffer.
|
||||
|
||||
## **Instructions:**
|
||||
|
||||
- You may receive code in various programming languages or even natural language instructions.
|
||||
- If the clipboard content is in a different language than the current buffer, translate it to the appropriate language smartly.
|
||||
- If the clipboard content contains pseudo code generate code accordingly.
|
||||
- If the clipboard content contains natural language instructions, interpret and follow them to modify the code in the current buffer.
|
||||
- **ONLY** generate the **new** lines of code required for seamless integration.
|
||||
- Ensure the inserted code is syntactically correct and logically consistent with the existing code.
|
||||
- Do **NOT** include surrounding code or line numbers.
|
||||
- Make sure all brackets and quotes are closed properly.
|
||||
|
||||
## **Output:**
|
||||
|
||||
- Provide only the necessary lines of code for insertion.
|
||||
- If you can't generate code just return nothing.
|
||||
- Ensure the response is proper and well-formatted.
|
||||
]],
|
||||
},
|
||||
{
|
||||
role = "user",
|
||||
content = function(context)
|
||||
local lines = require("codecompanion.helpers.actions").get_code(
|
||||
1,
|
||||
context.line_count,
|
||||
{ show_line_numbers = true }
|
||||
)
|
||||
local selection_info = ""
|
||||
local clipboard = vim.fn.getreg("+")
|
||||
|
||||
if context.is_visual then
|
||||
selection_info = string.format(
|
||||
"Currently selected lines: %d-%d",
|
||||
context.start_line,
|
||||
context.end_line
|
||||
)
|
||||
else
|
||||
selection_info = string.format(
|
||||
"Current cursor line: %d and Current cursor column is %d",
|
||||
context.cursor_pos[1],
|
||||
context.cursor_pos[2]
|
||||
)
|
||||
end
|
||||
|
||||
return string.format(
|
||||
"I have the following code:\n\n```%s\n%s\n```\n\nClipboard content:\n\n```\n%s\n```\n\n%s",
|
||||
context.filetype,
|
||||
lines,
|
||||
clipboard,
|
||||
selection_info
|
||||
)
|
||||
end,
|
||||
opts = {
|
||||
contains_code = true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
keys = {
|
||||
{ "<leader>aa", "<cmd>CodeCompanionActions<cr>", desc = "Actions", silent = true, mode = { "n", "v" } },
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue