Coder Social home page Coder Social logo

olimorris / codecompanion.nvim Goto Github PK

View Code? Open in Web Editor NEW
239.0 3.0 19.0 957 KB

✨ A Copilot Chat experience in Neovim. Supports Anthropic, Ollama and OpenAI LLMs

License: MIT License

Lua 99.22% Makefile 0.52% Vim Script 0.26% Shell 0.01%
neovim openai nvim-plugin anthropic ollama plugin copilot copilot-chat claude

codecompanion.nvim's People

Contributors

abayomi185 avatar davidgumberg avatar jpyke3 avatar lazymaniac avatar lucax88x avatar mrjones2014 avatar nuvic avatar olimorris avatar sdglbl 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  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

codecompanion.nvim's Issues

[Bug]: Some third-party OpenAI forwarding services may have a return data with an empty json.choices.

Your minimal.lua config

local root = vim.fn.fnamemodify("./.repro", ":p")

-- set stdpaths to use .repro
for , name in ipairs({ "config", "data", "state", "cache" }) do
vim.env[("XDG
%s_HOME"):format(name:upper())] = root .. "/" .. name
end

-- bootstrap lazy
local lazypath = root .. "/plugins/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
vim.fn.system({
"git",
"clone",
"--filter=blob:none",
"--single-branch",
"https://github.com/folke/lazy.nvim.git",
lazypath,
})
end
vim.opt.runtimepath:prepend(lazypath)

-- Your CodeCompanion setup
local plugins = {
{
"olimorris/codecompanion.nvim",
-- dir = "~/project/codecompanion.nvim",
dependencies = {
"nvim-lua/plenary.nvim",
"nvim-treesitter/nvim-treesitter",
"nvim-telescope/telescope.nvim", -- Optional
{
"stevearc/dressing.nvim", -- Optional: Improves the default Neovim UI
opts = {},
},
{
"folke/edgy.nvim",
event = "VeryLazy",
init = function()
vim.opt.laststatus = 3
vim.opt.splitkeep = "screen"
end,
opts = {
animate = {
enabled = false,
},
right = {
{ ft = "codecompanion", title = "Code Companion Chat", size = { width = 0.45 } },
},
},
},
},
cmds = { "CodeCompanion", "CodeCompanionChat", "CodeCompanionToggle", "CodeCompanionActions" },
keys = {
{ "aa", "CodeCompanionActions", mode = { "n", "v" }, desc = "Actions" },
{ "av", "CodeCompanionAdd", mode = { "v" }, desc = "Add Visual" },
{ "at", "CodeCompanionToggle", mode = { "n", "v" }, desc = "Toggle" },
},
config = function(_, _)
require("codecompanion").setup {
-- log_level = vim.log.levels.TRACE,
adapters = {
openai = require("codecompanion.adapters").use("openai", {
env = {
api_key = "cmd:gpg --decrypt ~/.openai-api-key.gpg 2>/dev/null",
},
url = os.getenv "OPENAI_API_BASE" .. "/chat/completions",
}),
},
actions = {
{
name = "Generate Git Message",
strategy = "inline",
description = "Generate a git commit message",
opts = { placement = "cursor" },
prompts = {
{
role = "system",
content = [[Generate a concise, past tense commit message for provided diffs without additional content.]],
-- content = [[You are an expert software engineer.
-- Review the provided context and diffs which are about to be committed to a git repo.
-- Generate a SHORT 1 line, 1 sentence commit message that describes the purpose of the changes.
-- The commit message MUST be in the past tense.
-- It must describe the changes which have been made in the diffs!
-- Reply with JUST the commit message, without quotes, comments, questions, etc!]],
},
{
role = "user",
content = [[ CONTEXT: ]] .. vim.fn.system "git diff --cached",
},
},
},
{
name = "(CN) Generate Git Message ",
strategy = "inline",
description = "Generate a git commit message",
opts = { placement = "cursor" },
prompts = {
{
role = "system",
content = [[使用中文生成提供的差异的简明过去式提交消息,不包含其他内容。]],
-- content = [[You are an expert software engineer.
-- Review the provided context and diffs which are about to be committed to a git repo.
-- Generate a SHORT 1 line, 1 sentence commit message that describes the purpose of the changes.
-- The commit message MUST be in the past tense.
-- It must describe the changes which have been made in the diffs!
-- Reply with JUST the commit message, without quotes, comments, questions, etc!]],
},
{
role = "user",
content = [[ CONTEXT: ]] .. vim.fn.system "git diff --cached",
},
},
},
},
}
end,
}
}

require("lazy").setup(plugins, {
root = root .. "/plugins",
})

-- setup treesitter
local ok, treesitter = pcall(require, "nvim-treesitter.configs")
if ok then
treesitter.setup({
ensure_installed = "all",
ignore_install = { "phpdoc" }, -- list of parser which cause issues or crashes
highlight = { enable = true },
})
end

Error messages

Error executing vim.schedule lua callback: ...codecompanion.nvim/lua/codecompanion/adapters/openai.lua:153: attempt to index a nil value
stack traceback:
...codecompanion.nvim/lua/codecompanion/adapters/openai.lua:153: in function 'inline_output'
...decompanion.nvim/lua/codecompanion/strategies/inline.lua:211: in function 'cb'
...vim/lazy/codecompanion.nvim/lua/codecompanion/client.lua:115: in function ''
vim/_editor.lua: in function <vim/_editor.lua:0>

Health check output

==============================================================================
codecompanion: require("codecompanion.health").check()

codecompanion.nvim report ~

  • Log file: /Users/lijie/.local/state/nvim/codecompanion.log
  • OK plenary.nvim installed
  • OK nvim-treesitter installed
  • OK telescope.nvim installed
  • OK dressing.nvim installed
  • OK edgy.nvim installed
  • OK curl installed
  • OK base64 installed

Log output

Error executing vim.schedule lua callback: ...codecompanion.nvim/lua/codecompanion/adapters/openai.lua:153: attempt to index a nil value
stack traceback:
...codecompanion.nvim/lua/codecompanion/adapters/openai.lua:153: in function 'inline_output'
...decompanion.nvim/lua/codecompanion/strategies/inline.lua:211: in function 'cb'
...vim/lazy/codecompanion.nvim/lua/codecompanion/client.lua:115: in function ''
vim/_editor.lua: in function <vim/_editor.lua:0>

Describe the bug

Error executing vim.schedule lua callback: ...codecompanion.nvim/lua/codecompanion/adapters/openai.lua:153: attempt to index a nil value
stack traceback:
...codecompanion.nvim/lua/codecompanion/adapters/openai.lua:153: in function 'inline_output'
...decompanion.nvim/lua/codecompanion/strategies/inline.lua:211: in function 'cb'
...vim/lazy/codecompanion.nvim/lua/codecompanion/client.lua:115: in function ''
vim/_editor.lua: in function <vim/_editor.lua:0>

Reproduce the bug

No response

Final checks

  • I have made sure this issue exists in the latest version of the plugin
  • I have tested with the minimal.lua config file above and still get the issue

[Bug]: ollama list is called, even if ollama is not used

Your minimal.lua config

local root = vim.fn.fnamemodify("./.repro", ":p")

-- set stdpaths to use .repro
for _, name in ipairs({ "config", "data", "state", "cache" }) do
  vim.env[("XDG_%s_HOME"):format(name:upper())] = root .. "/" .. name
end

-- bootstrap lazy
local lazypath = root .. "/plugins/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
  vim.fn.system({
    "git",
    "clone",
    "--filter=blob:none",
    "--single-branch",
    "https://github.com/folke/lazy.nvim.git",
    lazypath,
  })
end
vim.opt.runtimepath:prepend(lazypath)

-- Your CodeCompanion setup
local plugins = {
  {
    "olimorris/codecompanion.nvim",
    dependencies = {
      { "nvim-treesitter/nvim-treesitter", build = ":TSUpdate"},
      "nvim-lua/plenary.nvim",
      "nvim-telescope/telescope.nvim",
      {
        "stevearc/dressing.nvim",
        opts = {},
      },
    },
    config = function()
      require("codecompanion").setup({
        strategies = { -- Change the adapters as required
          chat = "openai",
          inline = "openai",
        },
      })
    end,
  }
}

require("lazy").setup(plugins, {
  root = root .. "/plugins",
})

-- setup treesitter
local ok, treesitter = pcall(require, "nvim-treesitter.configs")
if ok then
  treesitter.setup({
    ensure_installed = "all",
    ignore_install = { "phpdoc" }, -- list of parser which cause issues or crashes
    highlight = { enable = true },
  })
end

Error messages

Error: could not connect to ollama app, is it running?

Health check output

codecompanion: require("codecompanion.health").check()

codecompanion.nvim report ~

  • Log file: /home/sev/.repro/state/nvim/codecompanion.log
  • OK nvim-treesitter installed
  • OK plenary.nvim installed
  • OK dressing.nvim installed
  • WARNING edgy.nvim not found
  • OK curl installed

Log output

Error: could not connect to ollama app, is it running?

Describe the bug

I would expect, if I'm not using ollama at all, for CodeCompanion to not attempt to call io.popen 'ollama list' on line 4 of lua/codecompanion/adapters/ollama.lua, or at least expect and ignore the Error log message.

Instead, it draws the error text into my window, wherever the cursor is, requiring a Ctrl-L to redraw every time I open nvim.

2024-04-23-165508_463x202_scrot

Reproduce the bug

  1. Install CodeCompanion exactly as recommended, even with the minimal.lua config
  2. Open an existing file

Final checks

  • I have made sure this issue exists in the latest version of the plugin
  • I have tested with the minimal.lua config file above and still get the issue

[Bug]: Inline edit is broken for Anthropic Adapter

Your minimal.lua config

local root = vim.fn.fnamemodify("./.repro", ":p")

-- set stdpaths to use .repro
for _, name in ipairs({ "config", "data", "state", "cache" }) do
	vim.env[("XDG_%s_HOME"):format(name:upper())] = root .. "/" .. name
end

-- bootstrap lazy
local lazypath = root .. "/plugins/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
	vim.fn.system({
		"git",
		"clone",
		"--filter=blob:none",
		"--single-branch",
		"https://github.com/folke/lazy.nvim.git",
		lazypath,
	})
end
vim.opt.runtimepath:prepend(lazypath)

-- Your CodeCompanion setup
local plugins = {
	{
		"olimorris/codecompanion.nvim",
		dependencies = {
			{ "nvim-treesitter/nvim-treesitter", build = ":TSUpdate" },
			"nvim-lua/plenary.nvim",
			"nvim-telescope/telescope.nvim",
			{
				"stevearc/dressing.nvim",
				opts = {},
			},
		},
		config = function()
			local adapters = require("codecompanion.adapters")
			require("codecompanion").setup({
				adapters = {
					anthropic = adapters.use("anthropic", {
						schema = {
							model = {
								default = "claude-3-5-sonnet-20240620",
							},
						},
					}),
				},
				strategies = {
					chat = "anthropic",
					inline = "anthropic",
					tools = "anthropic",
				},
				log_level = "TRACE",
			})
		end,
	},
}

require("lazy").setup(plugins, {
	root = root .. "/plugins",
})

-- setup treesitter
local ok, treesitter = pcall(require, "nvim-treesitter.configs")
if ok then
	treesitter.setup({
		ensure_installed = "all",
		ignore_install = { "phpdoc" }, -- list of parser which cause issues or crashes
		highlight = { enable = true },
	})
end

Error messages

No response

Health check output

codecompanion: require("codecompanion.health").check()

codecompanion.nvim report

  • Log file: /home/user/.repro/state/nvim/codecompanion.log
  • OK plenary.nvim installed
  • OK nvim-treesitter installed
  • OK telescope.nvim installed
  • OK dressing.nvim installed
  • OK curl installed
  • OK base64 installed

Log output

The log is empty.

Describe the bug

When using the Anthropic adapter as in the modified minimal config, visually selecting a code block and typing :CodeCompanion, followed by a prompt, results in no LLM response being inserted into the buffer. Instead, a string like "replace|true" gets inserted at the location of the selection. This string appears to be the value of the placement variable in inline.lua:

local parts = vim.split(placement, "|")

When using the OpenAI adapter, this does not happen, and the LLM response is inserted into the buffer as expected.

Reproduce the bug

  1. Visually select lines of code
  2. Type :CodeCompanion
  3. Write a prompt

Final checks

  • I have made sure this issue exists in the latest version of the plugin
  • I have tested with the minimal.lua config file above and still get the issue
  • I have shared the contents of the log file

[Bug]: ollama adapter not working with new config

Your minimal.lua config

local root = vim.fn.fnamemodify("./.repro", ":p")

-- set stdpaths to use .repro
for _, name in ipairs({ "config", "data", "state", "cache" }) do
  vim.env[("XDG_%s_HOME"):format(name:upper())] = root .. "/" .. name
end

-- bootstrap lazy
local lazypath = root .. "/plugins/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
  vim.fn.system({
    "git",
    "clone",
    "--filter=blob:none",
    "--single-branch",
    "https://github.com/folke/lazy.nvim.git",
    lazypath,
  })
end
vim.opt.runtimepath:prepend(lazypath)

-- install plugins
local plugins = {
  {
    "olimorris/codecompanion.nvim",
    dependencies = {
      { "nvim-treesitter/nvim-treesitter", build = ":TSUpdate"},
      "nvim-lua/plenary.nvim",
      {
        "stevearc/dressing.nvim", -- Optional: Improves the default Neovim UI
        opts = {},
      },
    },
    config = true
  }
}

require("lazy").setup(plugins, {
  root = root .. "/plugins",
})

-- setup treesitter
local ok, treesitter = pcall(require, "nvim-treesitter.configs")
if ok then
  treesitter.setup({
    ensure_installed = "all",
    ignore_install = { "phpdoc" }, -- list of parser which cause issues or crashes
    highlight = { enable = true },
  })
end

Error messages

Error: Error malformed json: Expected value but found T_END at character 1
Error: Error malformed json: Expected value but found invalid token at character 1

Health check output

codecompanion: require("codecompanion.health").check()

codecompanion.nvim report
- Log file: /Users/chazleong/.config/nvim/.repro/state/nvim/codecompanion.log
- OK nvim-treesitter installed
- OK plenary.nvim installed
- OK dressing.nvim installed
- WARNING edgy.nvim not found
- OK curl installed

Log output

<EMPTY>

Describe the bug

Expected Results

Ollama adapter throws no error and CodeCompanion works as usual.

Actual Results

Ollama adapter throws error and CodeCompanion + Ollama is currently broken.

Reproduce the bug

Steps to Reproduce

  1. Use latest version of codecompanion.nvim
  2. Use minimal.lua config above
  3. Run nvim --clean -u minimal.lua
  4. Run :CodeCompanionChat ollama
  5. Observe error

Final checks

  • I have made sure this issue exists in the latest version of the plugin
  • I have tested with the minimal.lua config file above and still get the issue

fix: anthropic inline command and system prompts

Arghhhh...it's because Anthropic want the system message outside of the prompt:

response = client.messages.create(
    model="claude-2.1",
    system="Respond only in Spanish.", # <-- system prompt
    messages=[
        {"role": "user", "content": "Hello, Claude!"} # <-- user prompt
    ]
)

[Bug]: Window settings don't seem to be getting applied?

Your minimal.lua config

local root = vim.fn.fnamemodify("./.repro", ":p")

-- set stdpaths to use .repro
for _, name in ipairs({ "config", "data", "state", "cache" }) do
	vim.env[("XDG_%s_HOME"):format(name:upper())] = root .. "/" .. name
end

-- bootstrap lazy
local lazypath = root .. "/plugins/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
	vim.fn.system({
		"git",
		"clone",
		"--filter=blob:none",
		"--single-branch",
		"https://github.com/folke/lazy.nvim.git",
		lazypath,
	})
end
vim.opt.runtimepath:prepend(lazypath)

-- NOTE this part here
-- these are my defaults, but I want them to be true on the chat buffer
vim.opt.wrap = false
vim.opt.linebreak = false
--

-- install plugins
local plugins = {
	{
		"olimorris/codecompanion.nvim",
		dependencies = {
			{ "nvim-treesitter/nvim-treesitter", build = ":TSUpdate" },
			"nvim-lua/plenary.nvim",
			{
				"stevearc/dressing.nvim", -- Optional: Improves the default Neovim UI
				opts = {},
			},
		},
		opts = {
			adapters = {
				chat = "ollama",
				inline = "ollama",
			},
			display = {
				chat = {
					type = "buffer",
					buf_options = {
						buflisted = true,
					},
					win_options = {
						-- I'd like these settings overridden for the chat buffer
						wrap = true,
						linebreak = true,
					},
				},
			},
		},
	},
}

require("lazy").setup(plugins, {
	root = root .. "/plugins",
})

-- setup treesitter
local ok, treesitter = pcall(require, "nvim-treesitter.configs")
if ok then
	treesitter.setup({
		ensure_installed = "all",
		ignore_install = { "phpdoc" }, -- list of parser which cause issues or crashes
		highlight = { enable = true },
	})
end

Error messages

No response

Health check output

==============================================================================
codecompanion: require("codecompanion.health").check()

codecompanion.nvim report ~
- Log file: $HOME/.local/state/nvim/codecompanion.log
- OK nvim-treesitter installed
- OK plenary.nvim installed
- OK dressing.nvim installed
- WARNING edgy.nvim not found
- OK curl installed

Log output

None

Describe the bug

What I expect to happen

When I open the chat buffer, the window gets vim.opt.wrap = true and vim.opt.linebreak = true

Reproduce the bug

Using the provided minimal config, enter a long string in the chat buffer like

test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test 

Final checks

  • I have made sure this issue exists in the latest version of the plugin
  • I have tested with the minimal.lua config file above and still get the issue

API configuration

Hey just seeing this, looks very cool! It would be cool to be able to use LocalAI, since OpenAI API is quite expensive. LocalAI has a drop-in replacement REST API, so (if things work out the way I hope) it should just be a matter of setting the base URL and all the API endpoint mappings and request/response logic should still work.

https://github.com/mudler/LocalAI

[Bug]: `:CodeCompanion` without an argument puts the prompt text into the current buffer

Your minimal.lua config

local root = vim.fn.fnamemodify("./.repro", ":p")

-- set stdpaths to use .repro
for _, name in ipairs({ "config", "data", "state", "cache" }) do
	vim.env[("XDG_%s_HOME"):format(name:upper())] = root .. "/" .. name
end

-- bootstrap lazy
local lazypath = root .. "/plugins/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
	vim.fn.system({
		"git",
		"clone",
		"--filter=blob:none",
		"--single-branch",
		"https://github.com/folke/lazy.nvim.git",
		lazypath,
	})
end
vim.opt.runtimepath:prepend(lazypath)

-- install plugins
local plugins = {
	{
		"olimorris/codecompanion.nvim",
		dependencies = {
			{ "nvim-treesitter/nvim-treesitter", build = ":TSUpdate" },
			"nvim-lua/plenary.nvim",
			{
				"stevearc/dressing.nvim", -- Optional: Improves the default Neovim UI
				opts = {},
			},
		},
		config = function()
			require("codecompanion").setup({
				adapters = {
					chat = require("codecompanion.adapters").use("ollama"),
					inline = require("codecompanion.adapters").use("ollama"),
				},
			})
		end,
	},
}

require("lazy").setup(plugins, {
	root = root .. "/plugins",
})

-- setup treesitter
local ok, treesitter = pcall(require, "nvim-treesitter.configs")
if ok then
	treesitter.setup({
		ensure_installed = "all",
		ignore_install = { "phpdoc" }, -- list of parser which cause issues or crashes
		highlight = { enable = true },
	})
end

Error messages

No response

Health check output

==============================================================================
codecompanion: require("codecompanion.health").check()

codecompanion.nvim report ~
- Log file: /Users/mat/.local/state/nvim/codecompanion.log
- OK nvim-treesitter installed
- OK plenary.nvim installed
- OK dressing.nvim installed
- WARNING edgy.nvim not found
- OK curl installed

Log output

None

Describe the bug

What I expect to happen

It asks me for a prompt via vim.ui.input()

What actually happens

It inserts the system prompt text into my buffer lol

CleanShot 2024-03-08 at 08 56 43

Reproduce the bug

  1. Run :CodeCompanion without any arguments

Final checks

  • I have made sure this issue exists in the latest version of the plugin
  • I have tested with the minimal.lua config file above and still get the issue

[Bug]: parse yaml setting failed

Your minimal.lua config

local root = vim.fn.fnamemodify("./.repro", ":p")

-- set stdpaths to use .repro
for _, name in ipairs({ "config", "data", "state", "cache" }) do
	vim.env[("XDG_%s_HOME"):format(name:upper())] = root .. "/" .. name
end

-- bootstrap lazy
local lazypath = root .. "/plugins/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
	vim.fn.system({
		"git",
		"clone",
		"--filter=blob:none",
		"--single-branch",
		"https://github.com/folke/lazy.nvim.git",
		lazypath,
	})
end
vim.opt.runtimepath:prepend(lazypath)

-- Your CodeCompanion setup
local plugins = {
	{
		"olimorris/codecompanion.nvim",
		dependencies = {
			"nvim-lua/plenary.nvim",
			"nvim-treesitter/nvim-treesitter",
			"nvim-telescope/telescope.nvim", -- Optional
			{
				"grapp-dev/nui-components.nvim",
				dependencies = {
					"MunifTanjim/nui.nvim",
				},
			},
			{
				"stevearc/dressing.nvim", -- Optional: Improves the default Neovim UI
				opts = {},
			},
			{
				"folke/edgy.nvim",
				event = "VeryLazy",
				init = function()
					vim.opt.laststatus = 3
					vim.opt.splitkeep = "screen"
				end,
				opts = {
					animate = {
						enabled = false,
					},
					right = {
						{ ft = "codecompanion", title = "Code Companion Chat", size = { width = 0.45 } },
					},
				},
			},
		},
		config = function()
			vim.cmd([[cab cc CodeCompanion]])
			vim.cmd([[cab ccb CodeCompanionWithBuffers]])

			require("codecompanion").setup({
				adapters = {
					openai = require("codecompanion.adapters").use("openai", {
						env = {
							api_key = "cmd:gpg --decrypt ~/.openai-api-key.gpg 2>/dev/null",
						},
						url = os.getenv("OPENAI_API_BASE") .. "/chat/completions",
						schema = {
							model = {
								default = "gpt-4o",
								choices = {
									"gpt-4o",
									"gpt-4-turbo-preview",
									"gpt-4",
									"gpt-3.5-turbo",
								},
							},
						},
					}),
					anthropic = require("codecompanion.adapters").use("anthropic", {
						env = {
							api_key = "cmd:gpg --decrypt ~/.openai-api-key.gpg 2>/dev/null",
						},
						url = os.getenv("OPENAI_API_BASE") .. "/messages",
						schema = {
							model = {
								default = "claude-3-5-sonnet",
							},
						},
					}),
				},
				strategies = { -- Change the adapters as required
					chat = {
						adapter = "openai",
					},
					inline = {
						adapter = "openai",
					},
					tool = {
						adapter = "openai",
					},
					agent = {
						adapter = "openai",
						agents = {
							opts = {
								auto_submit_errors = false,
								auto_submit_success = true,
							},
						},
					},
				},
				opts = {
					log_level = "TRACE",
				},
			})
		end,
	},
}

require("lazy").setup(plugins, {
	root = root .. "/plugins",
})

-- setup treesitter
local ok, treesitter = pcall(require, "nvim-treesitter.configs")
if ok then
	treesitter.setup({
		ensure_installed = "all",
		ignore_install = { "phpdoc" }, -- list of parser which cause issues or crashes
		highlight = { enable = true },
	})
end

Error messages

image

Health check output

==============================================================================
codecompanion: require("codecompanion.health").check()

codecompanion.nvim report ~

  • Log file: /Users/lijie/.local/state/nvim/codecompanion.log
  • OK plenary.nvim installed
  • OK nvim-treesitter installed
  • OK telescope.nvim installed
  • OK dressing.nvim installed
  • OK curl installed
  • OK base64 installed

Log output

[TRACE] 2024-07-15 04:13:21
Opening selector
[TRACE] 2024-07-15 04:13:23
Opening selector
[TRACE] 2024-07-15 04:13:24
Context: {
active_buffers = { {
filetype = "lua",
id = 2,
name = "init.lua",
path = "/Users/lijie/dotfiles/.config/nvim/init.lua"
} },
bufnr = 2,
buftype = "",
cursor_pos = { 17, 19 },
end_col = 19,
end_line = 17,
filename = "/Users/lijie/dotfiles/.config/nvim/init.lua",
filetype = "lua",
is_normal = true,
is_visual = false,
lines = {},
mode = "n",
start_col = 19,
start_line = 17,
winnr = 1000
}
[TRACE] 2024-07-15 04:13:24
Strategy: Chat
[ERROR] 2024-07-15 04:13:25
Could not parse the settings in the chat buffer

Describe the bug

As image
image

Reproduce the bug

Actions -> Prompts -> GenerateCommitGitMessage

Final checks

  • I have made sure this issue exists in the latest version of the plugin
  • I have tested with the minimal.lua config file above and still get the issue
  • I have shared the contents of the log file

[Bug]: Ollama schema incorrrectly invalidating valid models

Your minimal.lua config

require("codecompanion").setup({
	adapters = {
		llama3 = require("codecompanion.adapters").use("ollama", {
			schema = {
				model = {
					default = "llama3",
				},
				num_ctx = {
					default = 16384
				},
				num_predict = {
					default = -1
				},
			},
		}),
		codegemma = require("codecompanion.adapters").use("ollama", {
			schema = {
				model = {
					default = "codegemma"
				},
			},
		}),
	},
	strategies = {
		chat = {
			adapter = "llama3",
		},
		inline = {
			adapter = "codegemma",
		},
		agent = {
			adapter = "llama3",
		},
	},
})

Error messages

image

Health check output


==============================================================================
codecompanion: require("codecompanion.health").check()

codecompanion.nvim report ~
- Log file: /Users/jacobpyke/.local/state/nvim/codecompanion.log
- OK plenary.nvim installed
- OK nvim-treesitter installed
- OK telescope.nvim installed
- OK dressing.nvim installed
- OK curl installed
- OK base64 installed

Log output

n/a

Describe the bug

I noticed the get_ollama_choices()

local function get_ollama_choices()
function doesn't correctly return some valid models. When using ollama you can just stipulate llama3 and it will resolve to llama3:latest. Happy to fix it but ran out of time this morning to get it done, so I am leaving this bug report as a slight reminder. I should be able to have it fixed by this afternoon.

Reproduce the bug

No response

Final checks

  • I have made sure this issue exists in the latest version of the plugin
  • I have tested with the minimal.lua config file above and still get the issue
  • I have shared the contents of the log file

Notice of breaking changes

Whilst I'm adopting a fairly rigid approach to maintaining this plugin (as per the README), I will aim to notify users of any breaking changes (and possibly other critical info) via this issue. Users are strongly encouraged to subscribe to this issue to get notified of such changes.

Every breaking change is added as a new comment.

[Bug]: treesitter.lua:124: str: expected string, got nil

Your minimal.lua config

local root = vim.fn.fnamemodify("./.repro", ":p")

-- set stdpaths to use .repro
for _, name in ipairs({ "config", "data", "state", "cache" }) do
  vim.env[("XDG_%s_HOME"):format(name:upper())] = root .. "/" .. name
end

-- bootstrap lazy
local lazypath = root .. "/plugins/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
  vim.fn.system({
    "git",
    "clone",
    "--filter=blob:none",
    "--single-branch",
    "https://github.com/folke/lazy.nvim.git",
    lazypath,
  })
end
vim.opt.runtimepath:prepend(lazypath)

-- Your CodeCompanion setup
local plugins = {
  {
    "olimorris/codecompanion.nvim",
    dependencies = {
      { "nvim-treesitter/nvim-treesitter", build = ":TSUpdate"},
      "nvim-lua/plenary.nvim",
      "nvim-telescope/telescope.nvim",
      {
        "stevearc/dressing.nvim",
        opts = {},
      },
    },
    config = function()
      require("codecompanion").setup({
        strategies = { -- Change the adapters as required
          chat = "openai",
          inline = "openai",
        },
      })
    end,
  }
}

require("lazy").setup(plugins, {
  root = root .. "/plugins",
})

-- setup treesitter
local ok, treesitter = pcall(require, "nvim-treesitter.configs")
if ok then
  treesitter.setup({
    ensure_installed = "all",
    ignore_install = { "phpdoc" }, -- list of parser which cause issues or crashes
    highlight = { enable = true },
  })
end

Error messages

Error detected while processing User Autocommands for "CodeCompanionRequest":
Error executing lua callback: /usr/share/nvim/runtime/lua/vim/treesitter.lua:124: str: expected string, got nil                                                     
stack traceback:                                                                                                                                                    
        [C]: in function 'error'                                                                                                                                    
        vim/shared.lua: in function 'validate'                                                                                                                      
        /usr/share/nvim/runtime/lua/vim/treesitter.lua:124: in function 'get_string_parser'                                                                         
        ...codecompanion.nvim/lua/codecompanion/strategies/chat.lua:246: in function 'run_tools'                                                                    
        ...codecompanion.nvim/lua/codecompanion/strategies/chat.lua:599: in function '_user_on_exit'                                                                
        ...andelwow/.repro/plugins/plenary.nvim/lua/plenary/job.lua:241: in function '_shutdown'                                                                    
        ...andelwow/.repro/plugins/plenary.nvim/lua/plenary/job.lua:221: in function 'shutdown'                                                                     
        .../plugins/codecompanion.nvim/lua/codecompanion/client.lua:31: in function <.../plugins/codecompanion.nvim/lua/codecompanion/client.lua:28>                
        [C]: in function 'nvim_exec_autocmds'                                                                                                                       
        ...codecompanion.nvim/lua/codecompanion/strategies/chat.lua:609: in function 'cb'                                                                           
        .../plugins/codecompanion.nvim/lua/codecompanion/client.lua:115: in function ''                                                                             
        vim/_editor.lua: in function <vim/_editor.lua:0>                                                                                                            

Health check output

codecompanion: require("codecompanion.health").check()

codecompanion.nvim report ~
- Log file: /home/bernie/.local/state/nvim/codecompanion.log
- OK plenary.nvim installed
- OK nvim-treesitter installed
- OK telescope.nvim installed
- OK dressing.nvim installed
- WARNING edgy.nvim not found
- OK curl installed
- OK base64 installed

Log output

[DEBUG] 2024-05-25 18:15:52
Stream Request: { "-sSL", "-D", "/run/user/1000/plenary_curl_b9c14a5b.headers", "--compressed", "-X", "POST", "-H", "Authorization: Bearer REMOVED", "-H", "Content-Type: application/json", "--data-raw", '{"top_p":1,"temperature":1,"presence_penalty":0,"frequency_penalty":0,"messages":[{"role":"user"}],"model":"gpt-4o","stream":true}', "--no-buffer", "--silent", "https://api.openai.com/v1/chat/completions" }
[DEBUG] 2024-05-25 18:15:52
Couldn't parse JSON: {
[DEBUG] 2024-05-25 18:15:52
Couldn't parse JSON:     "error": {
[DEBUG] 2024-05-25 18:15:52
Couldn't parse JSON:         "message": "The model `gpt-4o` does not exist or you do not have access to it.",
[DEBUG] 2024-05-25 18:15:52
Couldn't parse JSON:         "type": "invalid_request_error",
[DEBUG] 2024-05-25 18:15:52
Couldn't parse JSON:         "param": null,
[DEBUG] 2024-05-25 18:15:52
Couldn't parse JSON:         "code": "model_not_found"
[DEBUG] 2024-05-25 18:15:52
Couldn't parse JSON:     }
[DEBUG] 2024-05-25 18:15:52
Couldn't parse JSON: }

Describe the bug

Calling :CodeCompanionChat followed by :w results in the above error.

Tested with nvim built from git head:

NVIM v0.11.0-dev-96+g7994fdba6
Build type: Release
LuaJIT 2.1.1713484068

Also tested with Arch system package:

NVIM v0.10.0
Build type: Release
LuaJIT 2.1.1713773202

Reproduce the bug

  1. /usr/bin/nvim --clean -u minimal.lua
  2. :CodeCompanionChat
  3. :w

Final checks

  • I have made sure this issue exists in the latest version of the plugin
  • I have tested with the minimal.lua config file above and still get the issue

[Bug]: Malformed JSON - Expected value but found T_END

Your minimal.lua config

local root = vim.fn.fnamemodify("./.repro", ":p")

-- set stdpaths to use .repro
for _, name in ipairs({ "config", "data", "state", "cache" }) do
	vim.env[("XDG_%s_HOME"):format(name:upper())] = root .. "/" .. name
end

-- bootstrap lazy
local lazypath = root .. "/plugins/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
	vim.fn.system({
		"git",
		"clone",
		"--filter=blob:none",
		"--single-branch",
		"https://github.com/folke/lazy.nvim.git",
		lazypath,
	})
end
vim.opt.runtimepath:prepend(lazypath)

-- Your CodeCompanion setup
local plugins = {
	{
		"olimorris/codecompanion.nvim",
		dependencies = {
			{ "nvim-treesitter/nvim-treesitter", build = ":TSUpdate" },
			"nvim-lua/plenary.nvim",
			"nvim-telescope/telescope.nvim",
			{
				"stevearc/dressing.nvim",
				opts = {},
			},
		},
		config = function()
			require("codecompanion").setup({
				strategies = { -- Change the adapters as required
					chat = "openai",
					inline = "openai",
				},
			})
		end,
	},
}

require("lazy").setup(plugins, {
	root = root .. "/plugins",
})

-- setup treesitter
local ok, treesitter = pcall(require, "nvim-treesitter.configs")
if ok then
	treesitter.setup({
		ensure_installed = "all",
		ignore_install = { "phpdoc" }, -- list of parser which cause issues or crashes
		highlight = { enable = true },
	})
end

Error messages

Error: Error malformed json: Expected value but found T_END at character 1                                                         
   
Error: Error malformed json: Expected value but found invalid token at character 1
Press ENTER or type command to continue
Error: Error malformed json: Expected the end but found T_COLON at character 12
Press ENTER or type command to continue
Error: Error malformed json: Expected the end but found T_COLON at character 9
Press ENTER or type command to continue
Error: Error malformed json: Expected the end but found T_COLON at character 10
Press ENTER or type command to continue
Error: Error malformed json: Expected the end but found T_COLON at character 9
Press ENTER or type command to continue
Error: Error malformed json: Expected value but found T_END at character 1
Press ENTER or type command to continue
Error: Error malformed json: Expected value but found T_END at character 1

Health check output

codecompanion: require("codecompanion.health").check()

codecompanion.nvim report
- Log file: /Users/adam/.repro/state/nvim/codecompanion.log
- OK nvim-treesitter installed
- OK plenary.nvim installed
- OK dressing.nvim installed
- WARNING edgy.nvim not found
- OK curl installed

Log output

Log file is empty.

Describe the bug

Expect to happen

When I use the :CodeCompanionChat, after typing a prompt and saving the buffer, to get back a prompt.

What happens

I get the malformed JSON error when I save the buffer with a prompt.

Plugin Version

When I look at the plugin code in ~/.repro/plugins/codecompanion.nvim, I'm on this commit 1d081640d4854d619a5746532ffd6073b40bf35e, made on Sat Apr 6 16:30:47.

I have checked that I have the env var for Open AI with:

:lua print(vim.fn.getenv("OPENAI_API_KEY"))                                                                                       

Reproduce the bug

  1. :CodeCompanionChat,
  2. Type a prompt (I use Hello),
  3. Then I get the Malformed JSON error.

Final checks

  • I have made sure this issue exists in the latest version of the plugin
  • I have tested with the minimal.lua config file above and still get the issue

[Bug]: Attempt to call method 'set_params' (a nil value) when using inline

Your minimal.lua config

The default minimal config provided above.

Error messages

Error executing vim.schedule lua callback: ...decompanion.nvim/lua/codecompanion/strategies/inl
ine.lua:205: attempt to call method 'set_params' (a nil value)                                 
stack traceback:                                                                               
        ...decompanion.nvim/lua/codecompanion/strategies/inline.lua:205: in function 'get_inlin
e_output'                                                                                      
        ...decompanion.nvim/lua/codecompanion/strategies/inline.lua:338: in function 'cb'      
        .../sqve/.repro/plugins/dressing.nvim/lua/dressing/util.lua:206: in function <.../sqve/
.repro/plugins/dressing.nvim/lua/dressing/util.lua:202>

Health check output

codecompanion.nvim report ~
- Log file: /home/sqve/.repro/state/nvim/codecompanion.log
- OK plenary.nvim installed
- OK nvim-treesitter installed
- OK telescope.nvim installed
- OK dressing.nvim installed
- WARNING edgy.nvim not found
- OK curl installed
- OK base64 installed

Log output

File is empty

Describe the bug

What I expected to happen

The plugin should generate a unit test for me

What actually happened

An error was produced.

Reproduce the bug

  1. Use default minimal config.
  2. Create new file.
  3. Write test.
  4. Select test and run CodeCompanion.
  5. Write Translate this to a random language in the prompt.

Final checks

  • I have made sure this issue exists in the latest version of the plugin
  • I have tested with the minimal.lua config file above and still get the issue

[Bug]: without dressing / telescope :'<,'>CodeCompanionActions doesn't work

Your minimal.lua config

local root = vim.fn.fnamemodify("./.repro", ":p")

-- set stdpaths to use .repro
for _, name in ipairs({ "config", "data", "state", "cache" }) do
	vim.env[("XDG_%s_HOME"):format(name:upper())] = root .. "/" .. name
end

-- bootstrap lazy
local lazypath = root .. "/plugins/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
	vim.fn.system({
		"git",
		"clone",
		"--filter=blob:none",
		"--single-branch",
		"https://github.com/folke/lazy.nvim.git",
		lazypath,
	})
end
vim.opt.runtimepath:prepend(lazypath)

-- Your CodeCompanion setup
local plugins = {
	{
		"olimorris/codecompanion.nvim",
		dependencies = {
			{ "nvim-treesitter/nvim-treesitter", build = ":TSUpdate" },
			"nvim-lua/plenary.nvim",
			-- "nvim-telescope/telescope.nvim",
			-- {
			--   "stevearc/dressing.nvim",
			--   opts = {},
			-- },
		},
		config = function()
			require("codecompanion").setup({
				strategies = { -- Change the adapters as required
					chat = "openai",
					inline = "openai",
				},
			})
		end,
	},
	{
		"ibhagwan/fzf-lua",
		branch = "main",
		init = function()
			--require("fzf-lua").register_ui_select()
		end,
	},
}

require("lazy").setup(plugins, {
	root = root .. "/plugins",
})

-- setup treesitter
local ok, treesitter = pcall(require, "nvim-treesitter.configs")
if ok then
	treesitter.setup({
		ensure_installed = "all",
		ignore_install = { "phpdoc" }, -- list of parser which cause issues or crashes
		highlight = { enable = true },
	})
end

Error messages

No response

Health check output

no need

Log output

no logs

Describe the bug

The problematic command is :CodeCompanionActions in visual mode or simply :'<,'>CodeCompanionActions.

So, if you don't use any ui lib (dressing) it works perfectly.

But if you use something else, such as the default nvim one, the fzf-lua one and the noice one, it will not work.

  1. default and noice, same behavior
Screenshot 2024-04-11 at 21 13 08

Cannot input any selection

  1. fzf-lua popup opens for a second, then disappear before even selecting (uncomment fzf-lua ui-select to test)

Reproduce the bug

  1. open the nvim with minimal lua
  2. run :'<,'>CodeCompanionActions
  3. cannot select any option, only close popup

Final checks

  • I have made sure this issue exists in the latest version of the plugin
  • I have tested with the minimal.lua config file above and still get the issue

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.