aboutsummaryrefslogtreecommitdiffstats
path: root/lua/lspconfig/clangd.lua
diff options
context:
space:
mode:
authorMichael Lingelbach <m.j.lbach@gmail.com>2021-07-03 14:45:08 -0700
committerMichael Lingelbach <m.j.lbach@gmail.com>2021-07-03 15:49:27 -0700
commitec11b85df73cce4edb2925cb7f1d0e8db3a07b1c (patch)
tree77d533dc9606ca7e9b30d1a96baebf3de325d2a8 /lua/lspconfig/clangd.lua
parent[docgen] Update CONFIG.md (diff)
downloadnvim-lspconfig-ec11b85df73cce4edb2925cb7f1d0e8db3a07b1c.tar
nvim-lspconfig-ec11b85df73cce4edb2925cb7f1d0e8db3a07b1c.tar.gz
nvim-lspconfig-ec11b85df73cce4edb2925cb7f1d0e8db3a07b1c.tar.bz2
nvim-lspconfig-ec11b85df73cce4edb2925cb7f1d0e8db3a07b1c.tar.lz
nvim-lspconfig-ec11b85df73cce4edb2925cb7f1d0e8db3a07b1c.tar.xz
nvim-lspconfig-ec11b85df73cce4edb2925cb7f1d0e8db3a07b1c.tar.zst
nvim-lspconfig-ec11b85df73cce4edb2925cb7f1d0e8db3a07b1c.zip
ci: lint and format with stylua
Diffstat (limited to 'lua/lspconfig/clangd.lua')
-rw-r--r--lua/lspconfig/clangd.lua72
1 files changed, 39 insertions, 33 deletions
diff --git a/lua/lspconfig/clangd.lua b/lua/lspconfig/clangd.lua
index 4d769e13..c5f756bc 100644
--- a/lua/lspconfig/clangd.lua
+++ b/lua/lspconfig/clangd.lua
@@ -1,54 +1,60 @@
-local configs = require 'lspconfig/configs'
-local util = require 'lspconfig/util'
+local configs = require "lspconfig/configs"
+local util = require "lspconfig/util"
-- https://clangd.llvm.org/extensions.html#switch-between-sourceheader
local function switch_source_header(bufnr)
bufnr = util.validate_bufnr(bufnr)
local params = { uri = vim.uri_from_bufnr(bufnr) }
- vim.lsp.buf_request(bufnr, 'textDocument/switchSourceHeader', params, function(err, _, result)
- if err then error(tostring(err)) end
- if not result then print ("Corresponding file cannot be determined") return end
- vim.api.nvim_command('edit '..vim.uri_to_fname(result))
+ vim.lsp.buf_request(bufnr, "textDocument/switchSourceHeader", params, function(err, _, result)
+ if err then
+ error(tostring(err))
+ end
+ if not result then
+ print "Corresponding file cannot be determined"
+ return
+ end
+ vim.api.nvim_command("edit " .. vim.uri_to_fname(result))
end)
end
local root_pattern = util.root_pattern("compile_commands.json", "compile_flags.txt", ".git")
local default_capabilities = vim.tbl_deep_extend(
- 'force',
- util.default_config.capabilities or vim.lsp.protocol.make_client_capabilities(), {
- textDocument = {
- completion = {
- editsNearCursor = true
- }
- },
- offsetEncoding = {"utf-8", "utf-16"}
-});
+ "force",
+ util.default_config.capabilities or vim.lsp.protocol.make_client_capabilities(),
+ {
+ textDocument = {
+ completion = {
+ editsNearCursor = true,
+ },
+ },
+ offsetEncoding = { "utf-8", "utf-16" },
+ }
+)
configs.clangd = {
default_config = {
- cmd = {"clangd", "--background-index"};
- filetypes = {"c", "cpp", "objc", "objcpp"};
+ cmd = { "clangd", "--background-index" },
+ filetypes = { "c", "cpp", "objc", "objcpp" },
root_dir = function(fname)
- local filename = util.path.is_absolute(fname) and fname
- or util.path.join(vim.loop.cwd(), fname)
+ local filename = util.path.is_absolute(fname) and fname or util.path.join(vim.loop.cwd(), fname)
return root_pattern(filename) or util.path.dirname(filename)
- end;
+ end,
on_init = function(client, result)
if result.offsetEncoding then
client.offset_encoding = result.offsetEncoding
end
- end;
- capabilities = default_capabilities;
- };
+ end,
+ capabilities = default_capabilities,
+ },
commands = {
ClangdSwitchSourceHeader = {
function()
switch_source_header(0)
- end;
- description = "Switch between source/header";
- };
- };
+ end,
+ description = "Switch between source/header",
+ },
+ },
docs = {
description = [[
https://clangd.llvm.org/installation.html
@@ -58,13 +64,13 @@ https://clangd.llvm.org/installation.html
clangd relies on a [JSON compilation database](https://clang.llvm.org/docs/JSONCompilationDatabase.html) specified
as compile_commands.json or, for simpler projects, a compile_flags.txt.
For details on how to automatically generate one using CMake look [here](https://cmake.org/cmake/help/latest/variable/CMAKE_EXPORT_COMPILE_COMMANDS.html).
-]];
+]],
default_config = {
- root_dir = [[root_pattern("compile_commands.json", "compile_flags.txt", ".git") or dirname]];
- on_init = [[function to handle changing offsetEncoding]];
- capabilities = [[default capabilities, with offsetEncoding utf-8]];
- };
- };
+ root_dir = [[root_pattern("compile_commands.json", "compile_flags.txt", ".git") or dirname]],
+ on_init = [[function to handle changing offsetEncoding]],
+ capabilities = [[default capabilities, with offsetEncoding utf-8]],
+ },
+ },
}
configs.clangd.switch_source_header = switch_source_header