Skip to content

Make plugin work with Neovim #51

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 additions & 1 deletion plugin/chatgpt.vim
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ if !exists("g:chat_gpt_model")
endif

if !exists("g:chat_gpt_lang")
let g:chat_gpt_lang = v:none
if has('nvim')
let g:chat_gpt_lang = v:null
else
let g:chat_gpt_lang = v:none
endif
endif

if !exists("g:chat_gpt_split_direction")
Expand Down Expand Up @@ -403,3 +407,29 @@ endfunction


command! -nargs=1 GptBe call SetPersona(<q-args>)

" Menu for ChatGPT using inputlist for Neovim
if has('nvim')
function! s:ChatGPTMenuSink(choice)
let choices = {}

for index in range(len(g:promptKeys))
let choices[index+1] = g:promptKeys[index]
Copy link
Preview

Copilot AI Jul 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using range(len(g:promptKeys)) includes an extra index equal to the length, which can lead to an out-of-bounds lookup on g:promptKeys. Consider using range(0, len(g:promptKeys) - 1) or adjust the loop boundary accordingly.

Suggested change
let choices[index+1] = g:promptKeys[index]
if index < len(g:promptKeys)
let choices[index+1] = g:promptKeys[index]
endif

Copilot uses AI. Check for mistakes.

endfor

if a:choice > 0 && a:choice <= len(g:promptKeys)
call SendHighlightedCodeToChatGPT(choices[a:choice], input('Prompt > '))
Comment on lines +414 to +421
Copy link
Preview

Copilot AI Jul 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Building a sequential menu mapping via a Dictionary can be less clear than using a List. You might consider using a List for ordered choices and indexing directly, which simplifies both construction and lookup.

Suggested change
let choices = {}
for index in range(len(g:promptKeys))
let choices[index+1] = g:promptKeys[index]
endfor
if a:choice > 0 && a:choice <= len(g:promptKeys)
call SendHighlightedCodeToChatGPT(choices[a:choice], input('Prompt > '))
let choices = []
for index in range(len(g:promptKeys))
call add(choices, g:promptKeys[index])
endfor
if a:choice > 0 && a:choice <= len(g:promptKeys)
call SendHighlightedCodeToChatGPT(choices[a:choice - 1], input('Prompt > '))

Copilot uses AI. Check for mistakes.

endif
endfunction

function! ChatGPTMenu() range
let menu_choices = ['ChatGPT-Vim', '-----------']

for index in range(len(g:promptKeys))
call add(menu_choices, string(index + 1) . ". " . Capitalize(g:promptKeys[index]))
endfor

let choice = inputlist(menu_choices)
call s:ChatGPTMenuSink(choice)
endfunction
endif