Skip to content

Conversation

@rodionlim
Copy link

Constantly getting the following error when starting vectorcode-server on setup due to starting an lsp without an attached buffer. This also causes neovim to send shutdown and exit requests to the lsp server, and as a side effect, sending back a client id of nil.

Failed to start vectorcode-server due some error

Raising a PR to create a temp buffer during setup phase so that vim.lsp.start correctly proceeds and returns with status 0.

@codecov
Copy link

codecov bot commented Jul 1, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.76%. Comparing base (a10ae92) to head (0b26915).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #234   +/-   ##
=======================================
  Coverage   99.76%   99.76%           
=======================================
  Files          24       24           
  Lines        1715     1715           
=======================================
  Hits         1711     1711           
  Misses          4        4           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Davidyz
Copy link
Owner

Davidyz commented Jul 2, 2025

starting an lsp without an attached buffer

Would it help if you just set filetypes to * via vim.lsp.config or just make sure the vectorcode plugin is lazy loaded? I've never run into this error once, so I feel like this is just an issue with the way you configured nvim/vectorcode.

@rodionlim
Copy link
Author

rodionlim commented Jul 2, 2025

I tried lazy loading vectorcode by adding cmd to the configuration but I still get the error. Is this the same way you are configuring it? Feels like it is an unintended behaviour when configuring the lsp server to start during setup phase if you are not lazy loading it.

{
    "Davidyz/VectorCode",
    version = "*",                   
    build = "uv tool upgrade vectorcode", 
    opts = {
      on_setup = { update = false, lsp = true },
      async_backend = "lsp", 
    },
    cmd = "VectorCode",
}

@Davidyz
Copy link
Owner

Davidyz commented Jul 2, 2025

The :Lazy window should show a simple "dependency" that tells you why a plugin is loaded:
image
And the "profile" tab (in the lazy.nvim window) should show you a more detailed call stack.

I suspect that something else is loading vectorcode earlier than necessary. For example, if you're using the lualine component, it might load vectorcode too early (before a buffer has been created). If that's the case, there's nothing I can do from within the plugin. I'm using the following wrapper component in my personal config to avoid vectorcode being triggered by lualine:

local vectorcode_component = {
  function()
    return require("vectorcode.integrations").lualine()[1]()
  end,
  cond = function()
    if package.loaded["vectorcode"] == nil then
      return false
    else
      return require("vectorcode.integrations").lualine().cond()
    end
  end,
}

Also, have you tried setting the before_init callback using vim.lsp.config? If you absolutely have to create a temporary buffer, you can probably do it here. I personally don't want to create a buffer from here because it could trigger some autocommands that lead to unexpected consequences for a lot of people.

@rodionlim
Copy link
Author

rodionlim commented Jul 2, 2025

Ah, thank you for that. You are right, vectorcode was being loaded by codecompanion even though I had cmd specified. Seems like having this configuration (I copied directly from the wiki) causes vectorcode to be loaded before the buffers are created.

---@module "vectorcode"
opts = {
  extensions = {
    vectorcode = {
      ---@type VectorCode.CodeCompanion.ExtensionOpts
      opts = { 
        tool_group = {
          -- this will register a tool group called `@vectorcode_toolbox` that contains all 3 tools
          enabled = true,
          extras = {}, 
          collapse = false, -- whether the individual tools should be shown in the chat
        },
      },
    },
  }
}

@Davidyz
Copy link
Owner

Davidyz commented Jul 2, 2025

Seems like having this configuration (I copied directly from the wiki) causes vectorcode to be loaded before the buffers are created

Is codecompanion not lazy loaded then? From what you've said, it feels like you can fix this issue by lazy loading codecompanion (via the cmd field).

@rodionlim
Copy link
Author

Ah, that works now, my bad. This stems from my poor understanding on how lazy loading works in neovim. Thanks a lot for your help @Davidyz.

@rodionlim rodionlim closed this Jul 2, 2025
@rodionlim rodionlim deleted the fix/on_setup_lsp_throws_error branch July 2, 2025 08:27
@Davidyz
Copy link
Owner

Davidyz commented Jul 2, 2025

In fact, if all you want is to make sure the LSP server is started earlier-ish than the tool call in a codecompanion chat buffer to avoid that waiting, you can try setting the filetypes field in the vim.lsp.config. I believe the chat buffers have codecompanion filetype.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants