Skip to content

Commit c670c27

Browse files
committed
languages/clang: fix options; improve option docs
1 parent 355d517 commit c670c27

File tree

1 file changed

+17
-18
lines changed

1 file changed

+17
-18
lines changed

modules/plugins/languages/clang.nix

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@
77
inherit (builtins) attrNames;
88
inherit (lib.modules) mkIf mkMerge;
99
inherit (lib.options) mkEnableOption mkOption;
10-
inherit (lib.types) bool enum package either listOf str nullOr;
10+
inherit (lib.types) bool enum package either listOf str;
1111
inherit (lib.lists) isList;
12-
inherit (lib.strings) optionalString;
1312
inherit (lib.generators) mkLuaInline;
1413
inherit (lib.nvim.lua) expToLua toLuaObject;
1514
inherit (lib.nvim.types) mkGrammarOption;
15+
inherit (lib.nvim.languages) lspOptions;
16+
1617
inherit (lib.nvim.dag) entryAfter;
1718

1819
cfg = config.vim.languages.clang;
@@ -26,14 +27,6 @@
2627
servers = {
2728
ccls = {
2829
package = pkgs.ccls;
29-
lspConfig = ''
30-
lspconfig.ccls.setup{
31-
capabilities = capabilities;
32-
on_attach=default_on_attach;
33-
${optionalString (cfg.lsp.opts != null) "init_options = ${cfg.lsp.opts}"}
34-
}
35-
'';
36-
3730
options = {
3831
capabilities = mkLuaInline "capabilities";
3932
on_attach = mkLuaInline "default_on_attach";
@@ -66,7 +59,6 @@
6659
if isList cfg.lsp.package
6760
then expToLua cfg.lsp.package
6861
else ["${packageToCmd cfg.lsp.package "clangd"}"];
69-
init_options = mkIf (cfg.lsp.opts != null) "${cfg.lsp.opts}";
7062
single_file_support = false; # upstream default
7163
};
7264
};
@@ -82,6 +74,7 @@
8274
command = '${cfg.dap.package}/bin/lldb-dap',
8375
name = 'lldb'
8476
}
77+
8578
dap.configurations.cpp = {
8679
{
8780
name = 'Launch',
@@ -120,10 +113,10 @@ in {
120113
};
121114

122115
lsp = {
123-
enable = mkEnableOption "clang LSP support" // {default = config.vim.languages.enableLSP;};
116+
enable = mkEnableOption "C/C++ LSP support" // {default = config.vim.languages.enableLSP;};
124117

125118
server = mkOption {
126-
description = "The clang LSP server to use";
119+
description = "The C/C++ LSP server to use";
127120
type = enum (attrNames servers);
128121
default = defaultServer;
129122
};
@@ -135,10 +128,15 @@ in {
135128
default = servers.${cfg.lsp.server}.package;
136129
};
137130

138-
opts = mkOption {
139-
description = "Options to pass to clang LSP server";
140-
type = nullOr str;
141-
default = null;
131+
options = mkOption {
132+
type = lspOptions;
133+
default = servers.${cfg.lsp.server}.options;
134+
description = ''
135+
LSP options for C/C++ language support.
136+
137+
This option is freeform, you may add options that are not set by default
138+
and they will be merged into the final table passed to lspconfig.
139+
'';
142140
};
143141
};
144142

@@ -148,11 +146,13 @@ in {
148146
type = bool;
149147
default = config.vim.languages.enableDAP;
150148
};
149+
151150
debugger = mkOption {
152151
description = "clang debugger to use";
153152
type = enum (attrNames debuggers);
154153
default = defaultDebugger;
155154
};
155+
156156
package = mkOption {
157157
description = "clang debugger package.";
158158
type = package;
@@ -173,7 +173,6 @@ in {
173173

174174
(mkIf cfg.lsp.enable {
175175
vim.lsp.lspconfig.enable = true;
176-
177176
vim.lsp.lspconfig.sources.clang-lsp = ''
178177
lspconfig.("${cfg.lsp.server}").setup (${toLuaObject cfg.lsp.options})
179178
'';

0 commit comments

Comments
 (0)