irongit

My nvim configuration

hygo-nvim/lsp/ccls.lua
53 lines1.9 KBLua
1---@brief
2---
3--- https://github.com/MaskRay/ccls/wiki
4---
5--- ccls relies on a [JSON compilation database](https://clang.llvm.org/docs/JSONCompilationDatabase.html) specified
6--- as compile_commands.json or, for simpler projects, a .ccls.
7--- For details on how to automatically generate one using CMake look [here](https://cmake.org/cmake/help/latest/variable/CMAKE_EXPORT_COMPILE_COMMANDS.html). Alternatively, you can use [Bear](https://github.com/rizsotto/Bear).
8---
9--- Customization options are passed to ccls at initialization time via init_options, a list of available options can be found [here](https://github.com/MaskRay/ccls/wiki/Customization#initialization-options). For example:
10---
11--- ```lua
12--- vim.lsp.config("ccls", {
13--- init_options = {
14--- compilationDatabaseDirectory = "build";
15--- index = {
16--- threads = 0;
17--- };
18--- clang = {
19--- excludeArgs = { "-frounding-math"} ;
20--- };
21--- }
22--- })
23--- ```
24
25local function switch_source_header(client, bufnr)
26 local method_name = "textDocument/switchSourceHeader"
27 local params = vim.lsp.util.make_text_document_params(bufnr)
28 client:request(method_name, params, function(err, result)
29 if err then
30 error(tostring(err))
31 end
32 if not result then
33 vim.notify("corresponding file cannot be determined")
34 return
35 end
36 vim.cmd.edit(vim.uri_to_fname(result))
37 end, bufnr)
38end
39
40---@type vim.lsp.Config
41return {
42 cmd = { "ccls" },
43 filetypes = { "c", "cpp", "objc", "objcpp", "cuda" },
44 root_markers = { "compile_commands.json", ".ccls", ".git" },
45 offset_encoding = "utf-32",
46 -- ccls does not support sending a null root directory
47 workspace_required = true,
48 on_attach = function(client, bufnr)
49 vim.api.nvim_buf_create_user_command(bufnr, "LspCclsSwitchSourceHeader", function()
50 switch_source_header(client, bufnr)
51 end, { desc = "Switch between source/header" })
52 end,
53}