-
Notifications
You must be signed in to change notification settings - Fork 104
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add before & after cursor as context #120
Comments
Hi @felixkreuk , Thank you for this feature suggestion. This is already possible as of today, for example to insert the lines before and after the cursor, you can do the following: require('gen').prompts['Code_Completion'] = {
prompt = function()
local buf = vim.api.nvim_get_current_buf()
local row, col = unpack(vim.api.nvim_win_get_cursor(0))
local before = vim.api.nvim_buf_get_text(0, 0, 0, row-1, col+1, {})
local after = vim.api.nvim_buf_get_text(0, row-1, col+1, -1, -1, {})
local prompt = '<|fim_prefix|>' .. table.concat(before, "\n") .. '<|fim_suffix|>' .. table.concat(after, "\n") .. '<|fim_middle|>only output the middle part, not the prefix/suffix, nothing else, just the missing code including the $filetype code fence ```$filetype\n<resulting code>\n``` for example ```$filetype\nconsole.log("hello")\n```'
return prompt
end,
model = "qwen2.5-coder:7b-instruct",
extract = "```$filetype\n(.-)```"
}
vim.keymap.set('i', '<c-]>', '<esc>:Gen Code_Completion<CR>') Would that work for you? Thanks and best regards, |
having prompt be a function is pretty smart! but i'm not sure how to write my own function, because i cant figure out how to debug lua code in nvim D: |
Thanks, @aep . The following works for me: require('gen').prompts['Code_Completion'] = {
prompt = function()
local row, col = unpack(vim.api.nvim_win_get_cursor(0))
local before = vim.api.nvim_buf_get_text(0, 0, 0, row-1, col+1, {})
local after = vim.api.nvim_buf_get_text(0, row-1, col+1, -1, -1, {})
local prompt = '<|fim_prefix|>' .. table.concat(before, "\n") .. '<|fim_suffix|>' .. table.concat(after, "\n") .. '<|fim_middle|>only output the middle part, not the prefix/suffix, nothing else, just the missing code in between, do not repeate the provided text, include the $filetype code fence ```$filetype\n<resulting code>\n``` for example ```$filetype\nconsole.log("hello")\n```'
return prompt
end,
model = "qwen2.5-coder:32b",
extract = "```$filetype\n(.-)```"
}
vim.keymap.set('i', '<c-]>', '<esc>:Gen Code_Completion<CR>')
Note: You have to accept it with ctrl-enter. |
First, thanks a lot for this nifty plugin! :)
The use case would be to generate a code snippet at a specific line.
In this scenario, it may be redundant to give the whole file as context, but a few lines before and after the current cursor line might help.
Edit: other helpful contexts can be passing the current function/class/scope and cursor location, etc.
Apologies if this is already implemented and I missed it. Thanks again!
The text was updated successfully, but these errors were encountered: