Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Can not use inline in C++ buffer #531

Closed
3 tasks done
mars90226 opened this issue Dec 13, 2024 · 2 comments
Closed
3 tasks done

[Bug]: Can not use inline in C++ buffer #531

mars90226 opened this issue Dec 13, 2024 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@mars90226
Copy link

Your minimal.lua config

---@diagnostic disable: missing-fields

--NOTE: Set config path to enable the copilot adapter to work.
--It will search the follwoing paths for the for copilot token:
--  - "$CODECOMPANION_TOKEN_PATH/github-copilot/hosts.json"
--  - "$CODECOMPANION_TOKEN_PATH/github-copilot/apps.json"
vim.env["CODECOMPANION_TOKEN_PATH"] = vim.fn.expand("~/.config")

vim.env.LAZY_STDPATH = ".repro"
load(vim.fn.system("curl -s https://raw.githubusercontent.com/folke/lazy.nvim/main/bootstrap.lua"))()

-- Your CodeCompanion setup
local plugins = {
  {
    "olimorris/codecompanion.nvim",
    dependencies = {
      { "nvim-treesitter/nvim-treesitter", build = ":TSUpdate" },
      { "nvim-lua/plenary.nvim" },
      -- Test with blink.cmp
      {
        "saghen/blink.cmp",
        lazy = false,
        version = "*",
        opts = {
          keymap = {
            preset = "enter",
            ["<S-Tab>"] = { "select_prev", "fallback" },
            ["<Tab>"] = { "select_next", "fallback" },
          },
          sources = {
            completion = {
              enabled_providers = { "lsp", "path", "buffer", "codecompanion" },
            },
            providers = {
              codecompanion = {
                name = "CodeCompanion",
                module = "codecompanion.providers.completion.blink",
                enabled = true,
              },
            },
          },
        },
      },
      -- Test with nvim-cmp
      -- { "hrsh7th/nvim-cmp" },
    },
    opts = {
      --Refer to: https://github.com/olimorris/codecompanion.nvim/blob/main/lua/codecompanion/config.lua
      strategies = {
        --NOTE: Change the adapter as required
        chat = { adapter = "copilot" },
        inline = { adapter = "copilot" },
      },
      opts = {
        log_level = "DEBUG",
      },
    },
  },
}

require("lazy.minit").repro({ spec = plugins })

-- Setup Tree-sitter
local ts_status, treesitter = pcall(require, "nvim-treesitter.configs")
if ts_status then
  treesitter.setup({
    ensure_installed = { "lua", "markdown", "markdown_inline", "yaml" },
    highlight = { enable = true },
  })
end

-- Setup nvim-cmp
-- local cmp_status, cmp = pcall(require, "cmp")
-- if cmp_status then
--   cmp.setup({
--     mapping = cmp.mapping.preset.insert({
--       ["<C-b>"] = cmp.mapping.scroll_docs(-4),
--       ["<C-f>"] = cmp.mapping.scroll_docs(4),
--       ["<C-Space>"] = cmp.mapping.complete(),
--       ["<C-e>"] = cmp.mapping.abort(),
--       ["<CR>"] = cmp.mapping.confirm({ select = true }),
--       -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items.
--     }),
--   })
-- end

Error messages

Error executing vim.schedule lua callback: ...panion.nvim/lua/codecompanion/providers/diff/default.lua:68: E474: Invalid argument
stack traceback:
        [C]: in function 'nvim_set_option_value'
        ...panion.nvim/lua/codecompanion/providers/diff/default.lua:68: in function 'new'
        ...decompanion.nvim/lua/codecompanion/strategies/inline.lua:550: in function 'start_diff'
        ...decompanion.nvim/lua/codecompanion/strategies/inline.lua:321: in function 'done'
        .../nvim/lazy/codecompanion.nvim/lua/codecompanion/http.lua:109: in function <.../nvim/lazy/codecompanion.nvim/lua/codecompanion/http.lua:97>
Press ENTER or type command to continue

Log output

[DEBUG] 2024-12-13 20:17:14
Inline instance created with ID 7942063
[DEBUG] 2024-12-13 20:17:14
Prompt to classify: { {
    content = "<question>write hello world</question>",
    role = "user"
  } }
[INFO] 2024-12-13 20:17:14
Inline classification request started
[DEBUG] 2024-12-13 20:17:14
Authorizing GitHub Copilot token
[DEBUG] 2024-12-13 20:17:14
Reusing GitHub Copilot token
[INFO] 2024-12-13 20:17:14
Request body file: /tmp/nvim.root/WU3dx8/0.json
[DEBUG] 2024-12-13 20:17:14
Request:
{ "-sSL", "-D", "/tmp/plenary_curl_69104fb2.headers", "--compressed", "-X", "POST", "-H", "Content-Type: application/json", "-H", "Copilot-Integration-Id: vscode-chat", "-H", "Editor-Version: Neovim/0.11.0", "-d", "@/tmp/nvim.root/WU3dx8/0.json", "--no-buffer", "--silent", "https://api.githubcopilot.com/chat/completions" }
[INFO] 2024-12-13 20:17:15
Placement: "<add>"
[DEBUG] 2024-12-13 20:17:15
Determined position for output: {
  bufnr = 1,
  col = 0,
  line = 2
}
[INFO] 2024-12-13 20:17:15
Inline request started

Health check output

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

- Neovim version: 0.11.0
- Log file: /root/.repro//state/nvim/codecompanion.log

Plugins: ~
- OK plenary.nvim installed
- OK nvim-treesitter installed

Tree-sitter parsers: ~
- OK markdown parser installed
- OK yaml parser installed

Libraries: ~
- OK curl installed

Describe the bug

In C++ buffer, :CodeCompanion inline strategy failed.

I think it's because it try to use context filetype to set diff buffer's filetype. But the C++ context filetype is "C++", not "cpp". This cause vim.api.nvim_set_option_value() failed.

Reproduce the bug

  1. nvim --clean -u minimal.lua.
  2. :edit hello.cpp.
  3. :CodeCompanion write hello world

Final checks

  • I have made sure this issue exists in the latest version of the plugin
  • I have tested with the minimal.lua file from above and have shared this
  • I have shared the contents of the log file
@mars90226 mars90226 added the bug Something isn't working label Dec 13, 2024
@olimorris
Copy link
Owner

Thanks for raising this! Fixed in the latest release.

@mars90226
Copy link
Author

mars90226 commented Dec 13, 2024

Thank you for the quick fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants