Skip to content

Commit d827ac8

Browse files
committed
languages: begin converting language modules to new lsp options format
1 parent 208f02f commit d827ac8

File tree

3 files changed

+109
-44
lines changed

3 files changed

+109
-44
lines changed

modules/plugins/languages/asm.nix

Lines changed: 54 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,34 @@
44
lib,
55
...
66
}: let
7+
inherit (builtins) attrNames;
78
inherit (lib.options) mkEnableOption mkOption;
89
inherit (lib.modules) mkIf mkMerge;
9-
inherit (lib.types) package;
10+
inherit (lib.types) enum either listOf package str;
11+
inherit (lib.lists) isList;
12+
inherit (lib.meta) getExe;
13+
inherit (lib.generators) mkLuaInline;
14+
inherit (lib.nvim.lua) expToLua toLuaObject;
15+
inherit (lib.nvim.languages) lspOptions;
1016
inherit (lib.nvim.types) mkGrammarOption;
1117

1218
cfg = config.vim.languages.assembly;
19+
20+
defaultServer = "asm-lsp";
21+
servers = {
22+
asm-lsp = {
23+
package = pkgs.asm-lsp;
24+
options = {
25+
capabilities = mkLuaInline "capabilities";
26+
on_attach = mkLuaInline "attach_keymaps";
27+
filetypes = ["asm" "vasm"];
28+
cmd =
29+
if isList cfg.lsp.package
30+
then expToLua cfg.lsp.package
31+
else ["${getExe cfg.lsp.package}"];
32+
};
33+
};
34+
};
1335
in {
1436
options.vim.languages.assembly = {
1537
enable = mkEnableOption "Assembly support";
@@ -22,28 +44,46 @@ in {
2244
lsp = {
2345
enable = mkEnableOption "Assembly LSP support (asm-lsp)" // {default = config.vim.languages.enableLSP;};
2446

47+
server = mkOption {
48+
description = "Assembly LSP server to use";
49+
type = enum (attrNames servers);
50+
default = defaultServer;
51+
};
52+
2553
package = mkOption {
26-
type = package;
27-
default = pkgs.asm-lsp;
28-
description = "asm-lsp package";
54+
description = "asm-lsp LSP server package, or the command to run as a list of strings";
55+
example = ''[lib.getExe pkgs.asm-lsp "--quiet"]'';
56+
type = either package (listOf str);
57+
default = servers.${cfg.lsp.server}.package;
58+
};
59+
60+
options = mkOption {
61+
type = lspOptions;
62+
default = servers.${cfg.lsp.server}.options;
63+
description = ''
64+
LSP options for Assembly language support.
65+
66+
This option is freeform, you may add options that are not set by default
67+
and they will be merged into the final table passed to lspconfig.
68+
'';
2969
};
3070
};
3171
};
3272
config = mkIf cfg.enable (mkMerge [
3373
(mkIf cfg.treesitter.enable {
34-
vim.treesitter.enable = true;
35-
vim.treesitter.grammars = [cfg.treesitter.package];
74+
vim.treesitter = {
75+
enable = true;
76+
grammars = [cfg.treesitter.package];
77+
};
3678
})
3779

3880
(mkIf cfg.lsp.enable {
39-
vim.lsp.lspconfig.enable = true;
40-
vim.lsp.lspconfig.sources.asm-lsp = ''
41-
lspconfig.asm_lsp.setup {
42-
capabilities = capabilities,
43-
on_attach = default_on_attach,
44-
cmd = {"${cfg.lsp.package}/bin/asm-lsp"},
45-
}
46-
'';
81+
vim.lsp.lspconfig = {
82+
enable = true;
83+
sources.asm-lsp = ''
84+
lspconfig.("asm_lsp").setup (${toLuaObject cfg.lsp.options})
85+
'';
86+
};
4787
})
4888
]);
4989
}

modules/plugins/languages/astro.nix

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@
77
inherit (builtins) attrNames;
88
inherit (lib.options) mkEnableOption mkOption;
99
inherit (lib.modules) mkIf mkMerge;
10+
inherit (lib.types) enum either listOf package str;
1011
inherit (lib.lists) isList;
1112
inherit (lib.meta) getExe;
12-
inherit (lib.types) enum either listOf package str;
13-
inherit (lib.nvim.lua) expToLua;
14-
inherit (lib.nvim.languages) diagnosticsToLua;
13+
inherit (lib.generators) mkLuaInline;
14+
inherit (lib.nvim.lua) expToLua toLuaObject;
15+
inherit (lib.nvim.languages) diagnosticsToLua lspOptions;
1516
inherit (lib.nvim.types) mkGrammarOption diagnostics;
1617

1718
cfg = config.vim.languages.astro;
@@ -20,17 +21,16 @@
2021
servers = {
2122
astro = {
2223
package = pkgs.astro-language-server;
23-
lspConfig = ''
24-
lspconfig.astro.setup {
25-
capabilities = capabilities;
26-
on_attach = attach_keymaps,
27-
cmd = ${
24+
options = {
25+
capabilities = mkLuaInline "capabilities";
26+
on_attach = mkLuaInline "attach_keymaps";
27+
filetypes = ["astro"];
28+
init_options = {typescript = {};};
29+
cmd =
2830
if isList cfg.lsp.package
2931
then expToLua cfg.lsp.package
30-
else ''{"${cfg.lsp.package}/bin/astro-ls", "--stdio"}''
31-
}
32-
}
33-
'';
32+
else ["${getExe cfg.lsp.package}" "--stdio"];
33+
};
3434
};
3535
};
3636

@@ -83,8 +83,7 @@ in {
8383

8484
treesitter = {
8585
enable = mkEnableOption "Astro treesitter" // {default = config.vim.languages.enableTreesitter;};
86-
87-
astroPackage = mkGrammarOption pkgs "astro";
86+
package = mkGrammarOption pkgs "astro";
8887
};
8988

9089
lsp = {
@@ -96,6 +95,17 @@ in {
9695
default = defaultServer;
9796
};
9897

98+
options = mkOption {
99+
type = lspOptions;
100+
default = servers.${cfg.lsp.server}.options;
101+
description = ''
102+
LSP options for Astro language support.
103+
104+
This option is freeform, you may add options that are not set by default
105+
and they will be merged into the final table passed to lspconfig.
106+
'';
107+
};
108+
99109
package = mkOption {
100110
description = "Astro LSP server package, or the command to run as a list of strings";
101111
example = ''[lib.getExe pkgs.astro-language-server "--minify" "--stdio"]'';
@@ -134,12 +144,14 @@ in {
134144
config = mkIf cfg.enable (mkMerge [
135145
(mkIf cfg.treesitter.enable {
136146
vim.treesitter.enable = true;
137-
vim.treesitter.grammars = [cfg.treesitter.astroPackage];
147+
vim.treesitter.grammars = [cfg.treesitter.package];
138148
})
139149

140150
(mkIf cfg.lsp.enable {
141151
vim.lsp.lspconfig.enable = true;
142-
vim.lsp.lspconfig.sources.astro-lsp = servers.${cfg.lsp.server}.lspConfig;
152+
vim.lsp.lspconfig.sources.astro-lsp = ''
153+
lspconfig.("astro").setup (${toLuaObject cfg.lsp.options})
154+
'';
143155
})
144156

145157
(mkIf cfg.format.enable {

modules/plugins/languages/bash.nix

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,29 +7,29 @@
77
inherit (builtins) attrNames;
88
inherit (lib.options) mkOption mkEnableOption literalExpression;
99
inherit (lib.modules) mkIf mkMerge;
10+
inherit (lib.types) enum either listOf package str bool;
1011
inherit (lib.lists) isList;
11-
inherit (lib.types) enum either package listOf str bool;
12-
inherit (lib.nvim.languages) diagnosticsToLua;
13-
inherit (lib.nvim.types) diagnostics mkGrammarOption;
14-
inherit (lib.nvim.lua) expToLua;
12+
inherit (lib.meta) getExe;
13+
inherit (lib.generators) mkLuaInline;
14+
inherit (lib.nvim.lua) expToLua toLuaObject;
15+
inherit (lib.nvim.languages) diagnosticsToLua lspOptions;
16+
inherit (lib.nvim.types) mkGrammarOption diagnostics;
1517

1618
cfg = config.vim.languages.bash;
1719

1820
defaultServer = "bash-ls";
1921
servers = {
2022
bash-ls = {
2123
package = pkgs.bash-language-server;
22-
lspConfig = ''
23-
lspconfig.bashls.setup{
24-
capabilities = capabilities;
25-
on_attach = default_on_attach;
26-
cmd = ${
24+
options = {
25+
capabilities = mkLuaInline "capabilities";
26+
on_attach = mkLuaInline "default_on_attach";
27+
filetypes = ["bash" "sh"];
28+
cmd =
2729
if isList cfg.lsp.package
2830
then expToLua cfg.lsp.package
29-
else ''{"${cfg.lsp.package}/bin/bash-language-server", "start"}''
30-
};
31-
}
32-
'';
31+
else ["${getExe cfg.lsp.package}" "start"];
32+
};
3333
};
3434
};
3535

@@ -87,6 +87,17 @@ in {
8787
type = either package (listOf str);
8888
default = pkgs.bash-language-server;
8989
};
90+
91+
options = mkOption {
92+
type = lspOptions;
93+
default = servers.${cfg.lsp.server}.options;
94+
description = ''
95+
LSP options for Bash language support.
96+
97+
This option is freeform, you may add options that are not set by default
98+
and they will be merged into the final table passed to lspconfig.
99+
'';
100+
};
90101
};
91102

92103
format = {
@@ -126,7 +137,9 @@ in {
126137

127138
(mkIf cfg.lsp.enable {
128139
vim.lsp.lspconfig.enable = true;
129-
vim.lsp.lspconfig.sources.bash-lsp = servers.${cfg.lsp.server}.lspConfig;
140+
vim.lsp.lspconfig.sources.bash-lsp = ''
141+
lspconfig.("bashls").setup (${toLuaObject cfg.lsp.options})
142+
'';
130143
})
131144

132145
(mkIf cfg.format.enable {

0 commit comments

Comments
 (0)