jackMort / jackMort/ChatGPT.nvim

ChatGPTCompleteCode - Pressing Enter (<CR>) to accept code completion causes the line to be overwritten.

Open
#476 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Lua
Stars
4k
Forks
317
PR merge metrics
No merged PRs in 30d

Description

I am hoping I just have my nvim misconfigured, but when I call ChatGPTCompleteCode code while in insert mode and the cursor on the line with some code, then accept the suggestion, it overwrites the line that the cursor is on.

https://github.com/user-attachments/assets/a80e8ef2-f5c7-4eb3-ad4a-bbdd0b363937

Below is my chatgpt.lua file
```
return {
"jackMort/ChatGPT.nvim",
event = "VeryLazy",
config = function()
require("chatgpt").setup({
api_key_cmd = 'echo $OPENAI_API_KEY',
})
-- Define custom leader key mappings
local map = vim.api.nvim_set_keymap
local opts = { noremap = true, silent = true }
-- Map ctn to :ChatGPTCompleteCode
map('n', 'ctn', ':ChatGPTCompleteCode', opts)

end,
dependencies = {
"MunifTanjim/nui.nvim",
"nvim-lua/plenary.nvim",
"folke/trouble.nvim", -- optional
"nvim-telescope/telescope.nvim"
}
}
```

Below is my nvim-cmp.lua file that I am including in case it is relevant:
```
return{
{
'hrsh7th/nvim-cmp',
lazy = false,
priority = 100,
dependencies = {
'hrsh7th/cmp-nvim-lsp',
'hrsh7th/cmp-buffer',
'hrsh7th/cmp-path',
'hrsh7th/cmp-nvim-lsp',
'hrsh7th/cmp-nvim-lsp-signature-help',
'onsails/lspkind.nvim',
'ray-x/cmp-treesitter',
'L3MON4D3/LuaSnip'
},
event = "InsertEnter",
config = function()
local cmp = require 'cmp'
local luasnip = require 'luasnip'
cmp.setup {
snippet = {
expand = function(args)
luasnip.lsp_expand(args.body)
end,
},
formatting = {
format = require 'lspkind'.cmp_format {
mode = "symbol_text",
menu = {
nvim_lsp = "[LSP]",
buffer = "[Buffer]",
latex_symbols = "[Latex]",
luasnip = "[LuaSnip]",
}
}
},
window = {
completion = cmp.config.window.bordered(),
documentation = cmp.config.window.bordered(),
},
view = {
entries = {
name = 'custom',
selection_order = 'near_cursor'
}
},
mapping = cmp.mapping.preset.insert({
[''] = cmp.mapping.scroll_docs(-4),
[''] = cmp.mapping.scroll_docs(4),
[''] = cmp.mapping.complete(),
[''] = cmp.mapping.confirm {
behavior = cmp.ConfirmBehavior.Replace,
select = false,
},
[''] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_next_item()
elseif luasnip.expand_or_jumpable() then
luasnip.expand_or_jump()
else
fallback()
end
end, { 'i', 's' }),
[''] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_prev_item()
elseif luasnip.jumpable(-1) then
luasnip.jump(-1)
else
fallback()
end
end, { 'i', 's' }),
}),
sources = cmp.config.sources({
{ name = 'nvim_lsp' },
{ name = 'luasnip' },
{ name = 'buffer' },
{ name = 'calc' },
{ name = 'path' },
{ name = 'treesitter' },
})
}
end
}

}

```
My Plugins:
![image](https://github.com/user-attachments/assets/a89233e0-4d2d-493a-b989-d2e8fbe75505)

Telescope FG result for :
![image](https://github.com/user-attachments/assets/deb9e6e7-7af7-41e4-a3ae-bbf5cfa7b7ca)

I was hoping that I could use this like Copilot or Cursor's code completion, but because this is happening, I have been unable to take advantage of this feature.

Hopefully I simply missed some configuration that I have to write in.

Contributor guide

No contributing guide indexed for this repository

Research direction

Reproduce the overwrite using the supplied chatgpt.lua and nvim-cmp.lua configurations, focusing first on the mappings for ChatGPTCompleteCode and nvim-cmp. The issue is done when accepting a code completion preserves the existing line instead of replacing it.

Written by the indexing model from the issue text.

Assessment

Tech stack
lua, vim
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.