Skip to content

luozhiya/fittencode.nvim

This branch is 194 commits behind master.

Repository files navigation

fittencode.nvim

Fitten Code AI Programming Assistant for Neovim, helps you to use AI for automatic completion in Neovim, with support for functions like login, logout, shortcut key completion.

fittencode-KMP-demo

✨ Features

  • πŸš€ Fast completion thanks to Fitten Code
  • πŸ› Asynchronous I/O for improved performance
  • 🐣 Support for Actions
    • 1️⃣ Document code
    • 2️⃣ Edit code
    • 3️⃣ Explain code
    • 4️⃣ Find bugs
    • 5️⃣ Generate unit test
    • 6️⃣ Implement features
    • 7️⃣ Improve code
    • 8️⃣ Refactor code
    • 9️⃣ Start chat
  • ⭐️ Accept all suggestions with Tab
  • πŸ§ͺ Accept line with Ctrl + 👫
  • πŸ”Ž Accept word with Ctrl + πŸ‘ͺ
  • ❄️ Undo accepted text
  • 🧨 Automatic scrolling when previewing or completing code
  • 🍭 Multiple HTTP/REST backends such as curl, libcurl (WIP)
  • πŸ›°οΈ Run as a coc.nvim (WIP) source or nvim-cmp source

⚑️ Requirements

  • Neovim >= 0.8.0
  • curl

πŸ“¦ Installation

Install the plugin with your preferred package manager:

For example with lazy.nvim:

{
  'luozhiya/fittencode.nvim',
  config = function()
    require('fittencode').setup()
  end,
}

For example with packer.nvim:

use {
  'luozhiya/fittencode.nvim',
  config = function()
    require('fittencode').setup()
  end,
}

βš™οΈ Configuration

defaults

fittencode.nvim comes with the following defaults:

{
  action = {
    document_code = {
      -- Show "Fitten Code - Document Code" in the editor context menu, when you right-click on the code.
      show_in_editor_context_menu = true,
    },
    edit_code = {
      -- Show "Fitten Code - Edit Code" in the editor context menu, when you right-click on the code.
      show_in_editor_context_menu = true,
    },
    explain_code = {
      -- Show "Fitten Code - Explain Code" in the editor context menu, when you right-click on the code.
      show_in_editor_context_menu = true,
    },
    find_bugs = {
      -- Show "Fitten Code - Find Bugs" in the editor context menu, when you right-click on the code.
      show_in_editor_context_menu = true,
    },
    generate_unit_test = {
      -- Show "Fitten Code - Generate UnitTest" in the editor context menu, when you right-click on the code.
      show_in_editor_context_menu = true,
    },
    start_chat = {
      -- Show "Fitten Code - Start Chat" in the editor context menu, when you right-click on the code.
      show_in_editor_context_menu = true,
    },
  },
  disable_specific_inline_completion = {
    -- Disable auto-completion for some specific file suffixes by entering them below
    -- For example, `suffixes = {'lua', 'cpp'}`
    suffixes = {},
  },
  inline_completion = {
    -- Enable inline code completion.
    ---@type boolean
    enable = true,
    -- Disable auto completion when the cursor is within the line.
    ---@type boolean
    disable_completion_within_the_line = false,
    -- Disable auto completion when pressing Backspace or Delete.
    ---@type boolean
    disable_completion_when_delete = false,
  },
  delay_completion = {
    -- Delay time for inline completion (in milliseconds).
    ---@type integer
    delaytime = 0,
  },
  -- Enable/Disable the default keymaps in inline completion.
  use_default_keymaps = true,
  -- Setting for source completion.
  source_completion = {
    -- Enable source completion.
    enable = true,
  },
  -- Set the mode of the completion.
  -- Available options:
  -- - 'inline' (default)
  -- - 'source'
  completion_mode = 'inline',
  ---@class LogOptions
  log = {
    -- Log level.
    level = vim.log.levels.WARN,
    -- Max log file size in MB, default is 10MB
    max_size = 10,
  },
}

inline mode

Set updatetime to a lower value to improve performance:

-- Neovim default updatetime is 4000
vim.opt.updatetime = 200

source mode

require('fittencode').setup({
  completion_mode ='source',
})
require('cmp').setup({
  sources = { name = 'fittencode', group_index = 1 },
  mapping = {
    ['<cr>'] = cmp.mapping.confirm({ behavior = cmp.ConfirmBehavior.Insert, select = false }),
  }
})

πŸš€ Usage

Account Commands

Command Description
Fitten register If you haven't registered yet, please run the command to register.
Fitten login Try the command Fitten login <user> <password> to login.
Fitten logout Logout account

Action Commands

  • Try the command Fitten generate_unit_test <test_framework> <language> to generate unit test with specific test framework and language.
Command Description
Fitten document_code Document code
Fitten edit_code Edit code
Fitten explain_code Explain code
Fitten find_bugs Find bugs
Fitten generate_unit_test Generate unit test
Fitten implement_features Implement features
Fitten improve_code Improve code
Fitten refactor_code Refactor code
Fitten guess_programming_language Guess programming language
Fitten analyze_data Analyze data
Fitten start_chat Start chat

Default Mappings

Mappings Action
Tab Accept all suggestions
Ctrl + 👫 Accept line
Ctrl + πŸ‘ͺ Accept word
Alt + \ Manually triggering completion

✏️ APIs

fittencode.nvim provides a set of APIs to help you integrate it with other plugins or scripts.

  • Access the APIs by calling require('fittencode').<api_name>().

Parameters Types

-- Log levels
vim.log = {
  levels = {
    TRACE = 0,
    DEBUG = 1,
    INFO = 2,
    WARN = 3,
    ERROR = 4,
    OFF = 5,
  },
}

---@class ActionOptions
---@field prompt? string
---@field content? string
---@field language? string

---@class GenerateUnitTestOptions : ActionOptions
---@field test_framework string

---@class ImplementFeaturesOptions : ActionOptions
---@field feature_type string

List of APIs

API Prototype Description
login(username, password) Login to Fitten Code AI
logout() Logout from Fitten Code AI
register() Register to Fitten Code AI
set_log_level(level) Set the log level
get_current_status() Get the current status of the InlineEngine and ActionEngine
triggering_completion() Manually triggering completion
has_suggestion() Check if there is a suggestion
accept_all_suggestions() Accept all suggestions
accept_line() Accept line
accept_word() Accept word
document_code(ActionOptions) Document code
edit_code(ActionOptions) Edit code
explain_code(ActionOptions) Explain code
find_bugs(ActionOptions) Find bugs
generate_unit_test(GenerateUnitTestOptions) Generate unit test
implement_features(ImplementFeaturesOptions) Implement features
improve_code(ActionOptions) Improve code
refactor_code(ActionOptions) Refactor code
guess_programming_language(ActionOptions) Guess programming language
analyze_data(ActionOptions) Analyze data
start_chat(ActionOptions) Start chat
stop_eval() Stop the evaluation

πŸŽ‰ Special Thanks

About

Fitten Code AI Programming Assistant for Neovim

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published