Giter Club home page Giter Club logo

neocodeium's Introduction

NeoCodeium

⚑ Free AI completion plugin powered by codeium ⚑


Motivation and differences with codeium.vim

Motivation

The primary reason for creating NeoCodeium was to address the issue of flickering suggestions in the official plugin. This flickering was particularly annoying when dealing with multiline virtual text. Additionally, I desired a feature that would allow accepted Codeium suggestions to be repeatable using the ., because I use it as my main completion plugin and only manually invoke nvim-cmp.

Differences

  • Supports only neovim (written in lua).
  • Flickering has been removed in most scenarios, resulting in a snappier experience.
  • Completions on the current line can now be repeated using the . key.
  • Performance improvements have been achieved through cache techniques.
  • The suggestion count label is displayed in the number column, making it closer to the context.
  • Default keymaps have been removed.
  • Possibility to complete only word/line of the suggestion.
  • By default, there is no debounce, allowing suggestions to appear while typing. If you don't like this behavior, set debounce = true in the setup.

Note

Requires neovim 0.10+ to work.

πŸ“¦ Installation

Here’s an example for πŸ’€lazy plugin manager. If you're using a different plugin manager, please refer to its documentation for installation instructions.

-- add this to the file where you setup your other plugins:
{
  "monkoose/neocodeium",
  event = "VeryLazy",
  config = function()
    local neocodeium = require("neocodeium")
    neocodeium.setup()
    vim.keymap.set("i", "<A-f>", neocodeium.accept)
  end,
}

Now you can use Alt-f in insert mode to accept codeium suggestions.

Note: To obtain an API token, you’ll need to run :NeoCodeium auth.

πŸš€ Usage

πŸ“’ API

In addition to the already mentioned accept() function, the plugin also provides a few others:

local neocodeium = require("neocodeium")

-- Accepts the suggestion
neocodeium.accept()

-- Accepts only part of the suggestion if the full suggestion doesn't make sense
neocodeium.accept_word()
neocodeium.accept_line()

-- Clears the current suggestion
neocodeium.clear()

-- Cycles through suggestions by `n` (1 by default) items. Use a negative value to cycle in reverse order
neocodeium.cycle(n)

-- Same as `cycle()`, but also tries to show a suggestion if none is visible.
-- Mostly useful with the enabled `manual` option
neocodeium.cycle_or_complete(n)

-- Checks if a suggestion's virtual text is visible or not (useful for some complex mappings)
neocodeium.visible()

⌨️ Keymaps

NeoCodeium doesn’t enforce any keymaps, which means you’ll need to add them yourself. While codeium.vim and copilot.vim set the <Tab> keymap as the default key for accepting a suggestion, but <Tab> has some downsides to consider (but nothing stops you from using it):

  • Risk of Interference: There’s a high chance of it conflicting with other plugins (such as snippets, nvim-cmp, etc.).
  • Not Consistent: It doesn’t work in the :h command-line-window.
  • Indentation Challenges: It is harder to indent with the tab at the start of a line.

Suggested keymaps:

vim.keymap.set("i", "<A-f>", function()
    require("neocodeium").accept()
end)
vim.keymap.set("i", "<A-w>", function()
    require("neocodeium").accept_word()
end)
vim.keymap.set("i", "<A-a>", function()
    require("neocodeium").accept_line()
end)
vim.keymap.set("i", "<A-e>", function()
    require("neocodeium").cycle_or_complete()
end)
vim.keymap.set("i", "<A-r>", function()
    require("neocodeium").cycle_or_complete(-1)
end)
vim.keymap.set("i", "<A-c>", function()
    require("neocodeium").clear()
end)

πŸ”€ Commands

NeoCodeium provides :NeoCodeium user command, which has some useful actions:

  • :NeoCodeium auth - authenticates the user and saves the API token.
  • :NeoCodeium disable - disables NeoCodeium completion.
  • :NeoCodeium enable - enables NeoCodeium completion.
  • :NeoCodeium toggle - toggles NeoCodeium completion.
  • :NeoCodeium disable_buffer - disables NeoCodeium completion in the current buffer.
  • :NeoCodeium enable_buffer - enables NeoCodeium completion in the current buffer.
  • :NeoCodeium open_log - opens new tab with the log output. More information is in the logging section.
  • :NeoCodeium restart - restarts Codeium server (useful when server stops responding for any reason).

You can also use such commands in your lua scripts by calling require("neocodeium.commands").<command_name>().

🎨 Highlight groups

NeoCodeium offers a couple of highlight groups. Feel free to adjust them to your preference and to match your chosen color scheme:

  • NeoCodeiumSuggestion - virtual text color of the plugin suggestions (default: #808080)
  • NeoCodeiumLabel - color of the label that indicates the number of suggestions (default: inverted DiagnosticInfo)

using alongside nvim-cmp

If you are using NeoCodeium with manual = false (it is default), it is useful to set nvim-cmp to manual completion and clear NeoCodeium suggestions on opening nvim-cmp popup menu. You can achieve this with following code in the place where nvim-cmp is configured:

local cmp = require("cmp")
local neocodeium = require("neocodeium")
local commands = require("neocodeium.commands")

cmp.event:on("menu_opened", function()
    commands.disable()
    neocodeium.clear()
end)

cmp.event:on("menu_closed", function()
    commands.enable()
end)

cmp.setup({
    completion = {
        autocomplete = false,
    },
})

πŸ“„ Logging

While running NeoCodeium logs some messages into a temporary file. It can be viewed with the :NeoCodeium open_log command. By default only errors and warnings are logged.

You can set the logging level to one of trace, debug, info, warn or error by exporting the NEOCODEIUM_LOG_LEVEL environment variable.

Example:

NEOCODEIUM_LOG_LEVEL=info nvim

βš’οΈ Setup

NeoCodeium comes with the following default options:

-- NeoCodeium Configuration
require("neocodeium").setup({
  -- Enable NeoCodeium on startup
  enabled = true,
  -- Path to a custom Codeium server binary (you can download one from:
  -- https://github.com/Exafunction/codeium/releases)
  bin = nil,
  -- When set to `true`, autosuggestions are disabled.
  -- Use `require'neodecodeium'.cycle_or_complete()` to show suggestions manually
  manual = false,
  -- Information about the API server to use
  server = {
    -- API URL to use (for Enterprise mode)
    api_url = nil,
    -- Portal URL to use (for registering a user and downloading the binary)
    portal_url = nil,
  },
  -- Set to `false` to disable showing the number of suggestions label
  -- at the line column
  show_label = true,
  -- Set to `true` to enable suggestions debounce
  debounce = false,
  -- Maximum number of lines parsed from loaded buffers (current buffer always fully parsed)
  -- Set to `0` to disable parsing non-current buffers (may lower suggestion quality)
  -- Set it to `-1` to parse all lines
  max_lines = 10000,
  -- Set to `true` to disable some non-important messages, like "NeoCodeium: server started..."
  silent = false,
  -- Set to `false` to disable suggestions in buffers with specific filetypes
  filetypes = {
    help = false,
    gitcommit = false,
    gitrebase = false,
    ["."] = false,
  },
})

πŸš— Roadmap

  • Add vimdoc help
  • Add the command to open buffer with the log output
  • Add :checkhealth
  • Add support for Codeium Chat

πŸ’ Credits

  • codeium.vim - The main source for understanding how to use Codeium.

🌟 License

MIT license

neocodeium's People

Contributors

monkoose avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

neocodeium's Issues

Error: Attempt to concatenate field `stderr` (a nil value)

πŸ‘Ž Problem

When running NeoCodeium auth, it produces an error and does not allow me to paste the copied token
Picture

πŸ”’ Steps to reproduce

nvim --clean
:set rtp+=~/.local/share/nvim/lazy/neocodeium
:lua require('neocodeium').setup()
:lua vim.keymap.set('i', '', function() require('neocodeium').accept() end)

Picture_1

πŸ‘ Expected behavior

To allow me to paste the copied token

Neovim version (nvim -v)

nightly

Operating system (uname -om)

Linux x86_64

:checkhealth neocodeium

OK

Relevant log output

`NeoCodeium: log file is empty`

[Bug] Suggestions never appear

πŸ‘Ž Problem

No matter what I do the suggestions never appear, ive tried enabled = true, false, cycling completions manually etc and im definitely logged in with my API key.

Ive also restarted the server and ran the other enable ex commands.

πŸ”’ Steps to reproduce

I'm using mostly the default setup.

πŸ‘ Expected behavior

Suggestions should appear

Neovim version (nvim -v)

Stabled 0.10

Operating system (uname -om)

macOS arm64

:checkhealth neocodeium

OK

Relevant log output

No log appears no matter what.

Question: behavior when working with `nvim-cmp`

In my configuration with codeium.vim and nvim-cmp I have the following in the nvim-cmp spec

      -- Make codeium suggestions appear only when `nvim-cmp` menu is closed
      cmp.event:on("menu_opened", function()
        vim.g.codeium_manual = true
        vim.fn["codeium#Clear"]()
      end)
      cmp.event:on("menu_closed", function()
        vim.g.codeium_manual = false
        vim.fn["codeium#Complete"]()
      end)

I tried something similar with neocodeium with the following in the spec

      -- Make codeium suggestions appear only when `nvim-cmp` menu is closed
      cmp.event:on("menu_opened", function()
        neocodeium.clear()
      end)
      cmp.event:on("menu_closed", function()
        neocodeium.cycle_or_complete()
      end)

But seems to not be working. After playing around a bit, I noticed that even without the above code snippet, if I manually call neocodeium.clear(), then neocodeium.cycle_or_complete() does not work unless I type in a letter. On the other hand with codeium.vim you can call vim.fn["codeium#Complete"]() even after you've done vim.fn["codeium#Clear"]() without typing any letter.

Is there a way to simulate the behavior achieved with codeium.vim with neocodeium as well?

Problem with cyrilllic

πŸ‘Ž Problem

Hi again!

I describe problems with the Cyrillic alphabet. When calling neocodeium.accept, some letters are skipped and must be entered manually. Although in virtual text the addition is correct

Before calling accept

2024-05-23_15-56_1

After

2024-05-23_15-56

πŸ”’ Steps to reproduce

To reproduce this, you need to initiate a hint by writing any word in Cyrillic (for example, "ΠΏΡ€ΠΈΠ²Π΅Ρ‚"). Then call the accept.

When writing β€œΠŸΡ€ΠΈΠ²Π΅Ρ‚,” neocodeium adds the word β€œΠΌΠΈΡ€β€ to the virtual text, but after calling accept, only β€œΠΌΠΈβ€ is added

πŸ‘ Expected behavior

Correct addition

Thanks for your time!

Neovim version (nvim -v)

nightly

Operating system (uname -om)

Linux x86_64

:checkhealth neocodeium

OK

Relevant log output

No response

Manual option doesn't seem to work

I try to set manual = true option since I want to trigger it manually but when I press alt + n nothing happen. It works when manual = false though.

It feel a lot snappier than codeium.vim btw, good plugin

here is my config.

{
    "monkoose/neocodeium",
    opts = {
      manual = true,
      show_label = true,
      debounce = true,
      max_lines = 10000,
      filetypes = {
        help = false,
        gitcommit = false,
        gitrebase = false,
        TelescopePrompt = false,
        ["dap-repl"] = false,
        ["."] = false,
      },
    },
    config = function(_, opts)
      local neocodeium = require("neocodeium")
      neocodeium.setup(opts)
      -- keymaps
      vim.keymap.set("i", "<M-a>", function()
        neocodeium.accept()
      end, { expr = true, silent = true })
      vim.keymap.set("i", "<M-n>", function()
        neocodeium.cycle_or_complete()
      end, { expr = true, silent = true })
      vim.keymap.set("i", "<M-p>", function()
        neocodeium.cycle_or_complete(-1)
      end, { expr = true, silent = true })
    end,
  }

Disable while recording macro

Problem

When recording a macro, neocodium still makes suggestions. It's a bit distracting, especially since you would not want to use AI suggestions during a recording anyway.

It's possible to automatically enable/disable Neocodium via autocommand, but a plugin-side solution is probably cleaner.

Expected behavior

Automatically disable neocodium while recording a macro. Potentially make this an option? (though I personally cannot really think of a case where you'd want AI suggestions while recording.)

Shipping broken, api key doesn't work

πŸ‘Ž Problem

When you enter an API key it gives a bunch of garbled text and says it's invalid even when it's not

πŸ”’ Steps to reproduce

  • Install using instructions in readme with lazy.nvim
  • After it extracts binary, you have to enter the token
  • When you enter the token, it says it's invalid

πŸ‘ Expected behavior

For the token to be valid

Neovim version (nvim -v)

0.11.0-dev

Operating system (uname -om)

Linux x86_64

:checkhealth neocodeium

OK

Relevant log output

No response

Doesn't work in .go files

Doesn't work in files with .go filetype, but at the same time works perfectly well and produces golang code in files with .mod.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.