gsuuon / model.nvim

Neovim plugin for interacting with LLM's and building editor integrated prompts.
MIT License
293 stars 21 forks source link

`:Mcancel` does not work for chats #58

Closed GordianDziwis closed 2 months ago

GordianDziwis commented 2 months ago

When aborting a completion with Mcancel the request continues in the background, so that on Mchat the old request will be inserted.

  1. Prompt: Give me 100 names.
  2. Mcancel -> Now the highlight changed and no text is inserted
  3. Mchat and prompt anything -> The first prompt is inserted
GordianDziwis commented 2 months ago

Ok, I have found the issue. Mcancel does not add a new line with ======, so Mchat gets confused. A workaround is, to add in mchat.lua in ftplugin


local function runOrEscape()
    local status, err = pcall(vim.cmd, 'Mcancel')
    vim.notify(vim.inspect(status))
    if status then
        local lastLine = vim.api.nvim_buf_line_count(0)
        vim.api.nvim_buf_set_lines(0, lastLine, lastLine, false, { "", "======", "", "" })
        vim.api.nvim_win_set_cursor(0, { lastLine + 4, 0 })
    else
        vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes('<esc>', true, false, true), 'n', false)
    end
end

vim.keymap.set('n', '<esc>', runOrEscape, { noremap = true, silent = true, buffer = true })
gsuuon commented 2 months ago

Hi! I'm not sure if I've understood correctly but this may be related to (or fixed by) #57 - is the issue just the half-completed assistant response? That PR should make partial assistant responses work correctly when continuing.