Skip to content

Possible issue when switching build type in cross-compilation #381

@laraSalconiDenis

Description

@laraSalconiDenis

Bug description

I am not sure if it's my usage or if it's a real bug.

When I was switching from Debug to my custom build type name Test do run unit test I notice that I had multiple error with file not found.
I was able to build using CMakeBuild and the compile_commands.json is correctly symlink to the root.
If I close my nvim and then reopen the root project and look at my unit test everything was fixed.

I made this function to attempt to embed the selection and the fix for the lsp:

    vim.keymap.set("n", "<leader>ct", function()
      local cwd = vim.fn.getcwd()
      local cc_path

      -- prefer vim.fs.joinpath if available (Neovim 0.9+)
      if vim.fs and vim.fs.joinpath then
        cc_path = vim.fs.joinpath(cwd, "compile_commands.json")
      else
        cc_path = cwd .. "/compile_commands.json"
      end

      -- stop existing clangd clients
      for _, client in pairs(vim.lsp.get_clients()) do
        if client.name == "clangd" then
          client:stop()  -- equivalent, uses the client object
        end
      end

      if vim.fn.filereadable(cc_path) == 1 then
        local ok = vim.fn.delete(cc_path)
        if ok == 0 then
--          vim.notify("Removed: " .. cc_path, vim.log.levels.INFO)
        else
          vim.notify("Failed to remove: " .. cc_path, vim.log.levels.ERROR)
          return
        end
      else
        vim.notify("No compile_commands.json in cwd: " .. cwd, vim.log.levels.WARN)
      end

        cmaketool.select_build_type()
        vim.defer_fn(function ()
           vim.lsp.enable('clangd')
        end,30*1000)

    end, { desc = "Select cmake build type" })

Steps to reproduce

Minimal configuration

cmake.lua in my .config/nvim:

return {
  'Civitasv/cmake-tools.nvim',
  dependencies = {
    "nvim-lua/plenary.nvim",
  },
  config = function ()
    local osys = require("cmake-tools.osys")
    local cmaketool = require("cmake-tools")
    cmaketool.setup {
      ctest_show_labels = true,
      cmake_use_preset = false,
      cmake_build_directory = function()
        if osys.iswin32 then
          return "build\\${variant:buildType}"
        end
        return "build/${variant:buildType}"
      end, -- this is used to specify generate directory for cmake, allows macro expansion, can be a string
      cmake_compile_commands_options = {
        action = "soft_link", -- available options: soft_link, copy, lsp, none
                              -- soft_link: this will automatically make a soft link from compile commands file to target
                              -- copy:      this will automatically copy compile commands file to target
                              -- lsp:       this will automatically set compile commands file location using lsp
                              -- none:      this will make this option ignored
        target = vim.loop.cwd, -- path or function returning path to directory, this is used only if action == "soft_link" or action == "copy"
      },
    }
  1. I guess get a project that cross compile ( im not sure if it happend on a native code ).
  2. run my command <leader>ct or just call :CMakeSelectBuildType

Expected behavior

I expect that I dont have to stop and restart manualy my lsp everytime I switch build type.

Screenshots

Environment

  • OS: debian
  • Desktop environment: inside a distrobox docker so not applicable?
  • Plugins commit hash: e100f40

Contents in the *cmake-tools* buffer
I dont know how to get that?

If you need anything to help finding why the lsp doesn't work automatically let me know.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions