jackMort / ChatGPT.nvim

ChatGPT Neovim Plugin: Effortless Natural Language Generation with OpenAI's ChatGPT API
Apache License 2.0
3.75k stars 312 forks source link

haskell-tools.nvim error with ChatGPTEditWithInstructions in ChatGPT.nvim #218

Closed johnhampton closed 10 months ago

johnhampton commented 1 year ago

The ChatGPTEditWithInstructions feature does not work properly with haskell-tools.nvim. When I try to use it on haskell code, I encounter an error and the syntax highlighting breaks. The error message is as follows:

Error executing vim.schedule lua callback: ...imPackages/start/ChatGPT.nvim/lua/chatgpt/code_edits.lua:70: FileType Autocommands for "haskell": Vim(append):haskell-tools: Could not determine the name of buffer 10.
stack traceback:
        [C]: in function 'nvim_buf_set_option'
        ...imPackages/start/ChatGPT.nvim/lua/chatgpt/code_edits.lua:70: in function ''
        vim/_editor.lua: in function <vim/_editor.lua:0>
Pasted image 20230613072454

haskell-tools throws an error because it checks if a buffer has a name before it attaches, and the ChatGPT buffers don't have names. I verified that adding names to the ChatGPT buffers resolves the issue. Here is the code change I made to give names to the buffers:

diff --git a/lua/chatgpt/code_edits.lua b/lua/chatgpt/code_edits.lua
index 3692188..4011429 100644
--- a/lua/chatgpt/code_edits.lua
+++ b/lua/chatgpt/code_edits.lua
@@ -88,6 +88,9 @@ M.edit_with_instructions = function(output_lines, bufnr, selection, ...)
   local settings_panel = Settings.get_settings_panel("edits", openai_params)
   input_window = Popup(Config.options.popup_window)
   output_window = Popup(Config.options.popup_window)
+  vim.api.nvim_buf_set_name(input_window.bufnr, "ChatGPTInput")
+  vim.api.nvim_buf_set_name(output_window.bufnr, "ChatGPTOutput")
+
   instructions_input = ChatInput(Config.options.popup_input, {
     prompt = Config.options.popup_input.prompt,
     on_close = function()

To fix this issue, can buffer names be added to the ChatGPT buffers?