From 41830a79b8dde54a0fa3c809c0c92bb3ce627ea9 Mon Sep 17 00:00:00 2001 From: NotAShelf Date: Mon, 6 May 2024 23:41:04 +0300 Subject: [PATCH] languages/clang: set default clang LSP encoding as `utf-16` --- modules/plugins/languages/clang.nix | 39 ++++++++++++++++------------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/modules/plugins/languages/clang.nix b/modules/plugins/languages/clang.nix index 682277d..e357cfd 100644 --- a/modules/plugins/languages/clang.nix +++ b/modules/plugins/languages/clang.nix @@ -26,10 +26,10 @@ ccls = { package = pkgs.ccls; lspConfig = '' - lspconfig.ccls.setup{ - capabilities = capabilities; - on_attach=default_on_attach; - cmd = ${packageToCmd cfg.lsp.package "ccls"}; + lspconfig.ccls.setup { + capabilities = capabilities, + on_attach=default_on_attach, + cmd = ${packageToCmd cfg.lsp.package "ccls"}, ${optionalString (cfg.lsp.opts != null) "init_options = ${cfg.lsp.opts}"} } ''; @@ -40,10 +40,10 @@ local clangd_cap = capabilities -- use same offsetEncoding as null-ls clangd_cap.offsetEncoding = {"utf-16"} - lspconfig.clangd.setup{ - capabilities = clangd_cap; - on_attach=default_on_attach; - cmd = ${packageToCmd cfg.lsp.package "clangd"}; + lspconfig.clangd.setup { + capabilities = clangd_cap, + on_attach=default_on_attach, + cmd = ${packageToCmd cfg.lsp.package "clangd"}, ${optionalString (cfg.lsp.opts != null) "init_options = ${cfg.lsp.opts}"} } ''; @@ -83,12 +83,16 @@ in { enable = mkEnableOption "C/C++ language support"; cHeader = mkOption { - description = '' - C syntax for headers. Can fix treesitter errors, see: - https://www.reddit.com/r/neovim/comments/orfpcd/question_does_the_c_parser_from_nvimtreesitter/ - ''; type = bool; default = false; + description = '' + Enable C syntax for headers. + + ::: {.note} + This can potentially fix Treesitter errors for headers. See [this reddit + post] https://www.reddit.com/r/neovim/comments/orfpcd/question_does_the_c_parser_from_nvimtreesitter/ + ::: + ''; }; treesitter = { @@ -107,16 +111,16 @@ in { }; package = mkOption { - description = "clang LSP server package, or the command to run as a list of strings"; - example = ''[lib.getExe pkgs.jdt-language-server " - data " " ~/.cache/jdtls/workspace "]''; type = either package (listOf str); default = servers.${cfg.lsp.server}.package; + example = ''[lib.getExe pkgs.jdt-language-server " - data " " ~/.cache/jdtls/workspace "]''; + description = "clang LSP server package, or the command to run as a list of strings"; }; opts = mkOption { - description = "Options to pass to clang LSP server"; + default = "--offset-encoding=utf-16"; type = nullOr str; - default = null; + description = "Options to pass to clang LSP server"; }; }; @@ -126,11 +130,13 @@ in { type = bool; default = config.vim.languages.enableDAP; }; + debugger = mkOption { description = "clang debugger to use"; type = enum (attrNames debuggers); default = defaultDebugger; }; + package = mkOption { description = "clang debugger package."; type = package; @@ -151,7 +157,6 @@ in { (mkIf cfg.lsp.enable { vim.lsp.lspconfig.enable = true; - vim.lsp.lspconfig.sources.clang-lsp = servers.${cfg.lsp.server}.lspConfig; })