Exafunction / codeium.vim

Free, ultrafast Copilot alternative for Vim and Neovim
https://codeium.com
MIT License
3.68k stars 124 forks source link

Right arrow = Tab? #394

Closed FateUnix29 closed 6 days ago

FateUnix29 commented 1 week ago

Details: Using SSH NeoVim 0.9.5 I use PlugInstall (vim-plug) When pressing the right arrow, and when codeium is enabled in my init file.. It, instead of moving right, presses tab. I have no idea.

Additional info: Theres no bindings in my file Only in Insert mode Running Raspberry Pi OS (64 Bit) on an RPI 4B. Codeium is up to date during all of this I cannot find any issues on GitHub or information in :help codeium that would possibly explain any of this. Codeium is set to default settings, I have changed nothing. Disabling codeium with :Codeium Disable does not fix this issue. It is an issue with the plugin. Codeium is also authenticated. It doesn't seem discriminate. (It works on all file types I tried so far, including no file type.) If it somehow matters, I use an init.lua, not an init.vim. I just use the vim.cmd() method for vim-plug and what not.

jacoatvatfree commented 1 week ago

I see the same behaviour on Mac OS, also codeium seems to have gotten very quiet and no longer make suggestions. Reverting to 289eb72 and restarting neovim fixed it for me.

LeonardoMor commented 1 week ago

Somewhat related to #305

Yes. This is because there's still no good robust fall back mechanism. I've been giving some thought to this, but I don't like that solutions I've come up with imply forcing users to pass the bindings as plugin options as opposed to setting them in standard Vim fashion.

Since you're using Neovim, you can re-implement the bindings with proper fallback like this:

-- Disable Codeium default bindings
vim.g.codeium_disable_bindings = 1

local function set_keymap_codeium_opts(desc, opts)
    opts = opts or {}
    local codeium_default_options = {
        silent = true,
        expr = true,
        desc = desc,
    }
    return vim.tbl_extend("force", codeium_default_options, opts)
end

local function codeium_keymap_set(mode, keys, codeium_function, desc, opts, arg)
    opts = set_keymap_codeium_opts(desc, opts)
    vim.keymap.set(mode, keys, function()
        local status, completion_text = pcall(function()
            return vim.api.nvim_eval(
                "b:_codeium_completions.items[b:_codeium_completions.index].completionParts[0].text"
            )
        end)
        if not (status and completion_text and completion_text ~= "") then
            return vim.api.nvim_replace_termcodes(keys, true, true, true)
        end
        if arg ~= nil then
            return vim.fn[codeium_function](arg)
        end
        return vim.fn[codeium_function]()
    end, opts)
end

codeium_keymap_set("i", "<Tab>", "codeium#Accept", "Codeium Accept suggestion")
codeium_keymap_set("i", "<A-Bslash>", "codeium#Complete", "Codeium Trigger suggestion")
codeium_keymap_set("i", "<A-]>", "codeium#CycleCompletions", "Codeium Cycle completions forwards", {}, 1)
codeium_keymap_set("i", "<A-[>", "codeium#CycleCompletions", "Codeium Cycle completions backwards", {}, -1)
codeium_keymap_set("i", "<C-Bslash>", "codeium#Clear", "Codeium Clear completions")
codeium_keymap_set("n", "<leader>cd", "codeium#Chat", "Codeium Open Chat")
codeium_keymap_set(
    "i",
    "<Right>",
    "codeium#AcceptNextWord",
    "Codeium Accept next word",
    { noremap = true, replace_keycodes = false }
)
codeium_keymap_set(
    "i",
    "<C-Right>",
    "codeium#AcceptNextLine",
    "Codeium Accept next line",
    { noremap = true, replace_keycodes = false }
)

For now, I'll change the default bindings for partial completions to less common keys.

carlosmera24 commented 1 week ago

Thank's LeonardoMor, This work for me.

FateUnix29 commented 1 week ago

Oh! Thanks for noticing my issue. I'll try this. I didn't take too much of a thorough search of the issues, which explains the relation.

fortenforge commented 1 week ago

@LeonardoMor are you planning to make a PR soon? I might need to revert your change if we don't have a fix by tomorrow.

FateUnix29 commented 1 week ago

It works! Thank you.

LeonardoMor commented 1 week ago

@LeonardoMor are you planning to make a PR soon? I might need to revert your change if we don't have a fix by tomorrow.

For now, submitted #397 to not use Right in the default bindings for the partial completions.

I can do something better for the fallback, namely, just return the keys in the key map when there are no completions. But it'll take me a bit more time. The main issue here is that in order to get the keys that are set for Codeium functions, I have to parse the output of :imap, which might be a bit brittle. So I am investigating how to do this better. I'll submit a PR once I have a quality solution that doesn't introduce more bugs.

I'm sorry these partial completions have caused so many bugs. But things keep improving.

FateUnix29 commented 1 week ago

Actually no. It doesn't seem to work. It fixed the issue but now codeium itself is not doing any completions?

LeonardoMor commented 1 week ago

Actually no. It doesn't seem to work. It fixed the issue but now codeium itself is not doing any completions?

That is a different issue that's been around. See #376

Although there was a PR that was supposed to fix it, I still find issues with Neovim (works fine with Vim).

What's been working for me is:

After that I get completions.

FateUnix29 commented 1 week ago

Still nothing.

LeonardoMor commented 1 week ago

Still nothing.

It doesn't work for me either. But the mappings or the Lua code above is not what broke it.

LeonardoMor commented 1 week ago

@FateUnix29 See #399

timstoop commented 1 week ago

Just updated because pressing the arrow-right in insert mode without any suggestions gave me errors in vim and a -1 in my insert. Now when I press the arrow-right I get tabs, if there are no suggestions.

LeonardoMor commented 1 week ago

Just updated because pressing the arrow-right in insert mode without any suggestions gave me errors in vim and a -1 in my insert. Now when I press the arrow-right I get tabs, if there are no suggestions.

Yeah, the arrow key thing will be fixed once #398 is merged.

Are you using Vim or Neovim?

timstoop commented 1 week ago

Vim! Already applied #398 manually myself and works great now. Thanks for the work! Much appreciated.