MaskRay / ccls

C/C++/ObjC language server supporting cross references, hierarchies, completion and semantic highlighting
Apache License 2.0
3.72k stars 254 forks source link

Buffer is attached by ccls but lsp operations can not be performed #947

Open hrcHarry opened 12 months ago

hrcHarry commented 12 months ago

Hi

I use Bear (2.3.11) to generate compile_commands.json at the root directory and the lspconfig is set as follows (refering to ccls example on nvim-lspconfig and TJ's video)

local capabilities = require('cmp_nvim_lsp').default_capabilities()
local lspconfig = require'lspconfig'
lspconfig.ccls.setup {
  init_options = {
    compilationDatabaseDirectory = "build";
    index = {
      threads = 0;
    };
    clang = {
      excludeArgs = { "-frounding-math"} ;
    };
  },
  capabilities = capabilities,
  on_attach = function()
                print("LSP ccls is activated!")
                vim.keymap.set('n', 'K', vim.lsp.buf.hover, {desc = "Show description", buffer = 0})
                vim.keymap.set('n', 'gd', vim.lsp.buf.definition, {desc = "Go to definition", buffer = 0})               
              end,
}

Observed behavior

When I open one of the .c file and inspect :LspInfo, it shows 1 client(s) attached to this buffer However, when I tried to use gd to go definition, it doesn't work. Moreover, I notice that the preprocessor that should comment out some block also does not work.

Expected behavior

Lsp operations can be active.

Steps to reproduce

Not sure how to reproduce.

System information

Dose anyone has some idea? Or, is there something I miss? If I lost some information, please let me know and I will edit it. Thanks.