diff options
| author | John Drouhard <john@jmdtech.org> | 2021-01-08 16:11:34 -0600 |
|---|---|---|
| committer | John Drouhard <john@jmdtech.org> | 2021-01-08 16:12:36 -0600 |
| commit | 53ef07e5158e3f347db1be9ea5090466434b37b7 (patch) | |
| tree | 296a0b80c73af46602ba6b52dd5478c76fa5c635 /lua | |
| parent | Merge pull request #560 from mjlbach/readme_tweaks (diff) | |
| download | nvim-lspconfig-53ef07e5158e3f347db1be9ea5090466434b37b7.tar nvim-lspconfig-53ef07e5158e3f347db1be9ea5090466434b37b7.tar.gz nvim-lspconfig-53ef07e5158e3f347db1be9ea5090466434b37b7.tar.bz2 nvim-lspconfig-53ef07e5158e3f347db1be9ea5090466434b37b7.tar.lz nvim-lspconfig-53ef07e5158e3f347db1be9ea5090466434b37b7.tar.xz nvim-lspconfig-53ef07e5158e3f347db1be9ea5090466434b37b7.tar.zst nvim-lspconfig-53ef07e5158e3f347db1be9ea5090466434b37b7.zip | |
clangd: fix capabilities by extending protocol defaults with utf-8 offset encoding
Also removes the utf8_config helper function which was only used by
clangd and is a clangd-specific protocol extension.
Diffstat (limited to 'lua')
| -rw-r--r-- | lua/lspconfig/clangd.lua | 25 | ||||
| -rw-r--r-- | lua/lspconfig/util.lua | 10 |
2 files changed, 17 insertions, 18 deletions
diff --git a/lua/lspconfig/clangd.lua b/lua/lspconfig/clangd.lua index d165edbb..8a79f649 100644 --- a/lua/lspconfig/clangd.lua +++ b/lua/lspconfig/clangd.lua @@ -13,8 +13,18 @@ local function switch_source_header(bufnr) end local root_pattern = util.root_pattern("compile_commands.json", "compile_flags.txt", ".git") + +local default_capabilities = vim.tbl_deep_extend('force', vim.lsp.protocol.make_client_capabilities(), { + textDocument = { + completion = { + editsNearCursor = true + } + }, + offsetEncoding = {"utf-8", "utf-16"} +}); + configs.clangd = { - default_config = util.utf8_config { + default_config = { cmd = {"clangd", "--background-index"}; filetypes = {"c", "cpp", "objc", "objcpp"}; root_dir = function(fname) @@ -22,13 +32,12 @@ configs.clangd = { or util.path.join(vim.loop.cwd(), fname) return root_pattern(filename) or util.path.dirname(filename) end; - capabilities = { - textDocument = { - completion = { - editsNearCursor = true - } - } - }, + on_init = function(client, result) + if result.offsetEncoding then + client.offset_encoding = result.offsetEncoding + end + end; + capabilities = default_capabilities; }; commands = { ClangdSwitchSourceHeader = { diff --git a/lua/lspconfig/util.lua b/lua/lspconfig/util.lua index d218b25d..5b45ff51 100644 --- a/lua/lspconfig/util.lua +++ b/lua/lspconfig/util.lua @@ -326,16 +326,6 @@ function M.find_package_json_ancestor(startpath) end) end -function M.utf8_config(config) - config.capabilities = config.capabilities or lsp.protocol.make_client_capabilities() - config.capabilities.offsetEncoding = {"utf-8", "utf-16"} - function config.on_init(client, result) - if result.offsetEncoding then - client.offset_encoding = result.offsetEncoding - end - end - return config -end return M -- vim:et ts=2 sw=2 |
