Skip to content

Commit fd4df34

Browse files
languages/astro: init (#481)
* LSP: Add astro * LSP: Properly add astro * LSP: Properly actually add astro * Flake: Fix mnw * Update flake/develop.nix Co-authored-by: raf <raf@notashelf.dev> * Update configuration.nix Co-authored-by: raf <raf@notashelf.dev> * Update astro.nix * Update rl-0.7.md --------- Co-authored-by: raf <raf@notashelf.dev>
1 parent 88834cc commit fd4df34

File tree

5 files changed

+168
-3
lines changed

5 files changed

+168
-3
lines changed

configuration.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ isMaximal: {
4848

4949
# Assembly is not common, and the asm LSP is a major hit-or-miss
5050
assembly.enable = false;
51+
astro.enable = false;
5152
markdown.enable = isMaximal;
5253
html.enable = isMaximal;
5354
css.enable = isMaximal;

docs/release-notes/rl-0.7.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,3 +383,7 @@ The changes are, in no particular order:
383383
[Nowaaru](https://github.com/Nowaaru):
384384

385385
- Add `precognition-nvim`.
386+
387+
[DamitusThyYeeticus123](https://github.com/DamitusThyYeetus123):
388+
389+
- Add support for [Astro](https://astro.build/) language server.

flake.lock

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

modules/plugins/languages/astro.nix

Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
{
2+
config,
3+
pkgs,
4+
lib,
5+
...
6+
}: let
7+
inherit (builtins) attrNames;
8+
inherit (lib.options) mkEnableOption mkOption;
9+
inherit (lib.modules) mkIf mkMerge;
10+
inherit (lib.lists) isList;
11+
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;
15+
inherit (lib.nvim.types) mkGrammarOption diagnostics;
16+
17+
cfg = config.vim.languages.astro;
18+
19+
defaultServer = "astro";
20+
servers = {
21+
astro = {
22+
package = pkgs.astro-language-server;
23+
lspConfig = ''
24+
lspconfig.astro.setup {
25+
capabilities = capabilities;
26+
on_attach = attach_keymaps,
27+
cmd = ${
28+
if isList cfg.lsp.package
29+
then expToLua cfg.lsp.package
30+
else ''{"${cfg.lsp.package}/bin/astro-ls", "--stdio"}''
31+
}
32+
}
33+
'';
34+
};
35+
};
36+
37+
# TODO: specify packages
38+
defaultFormat = "prettier";
39+
formats = {
40+
prettier = {
41+
package = pkgs.nodePackages.prettier;
42+
nullConfig = ''
43+
table.insert(
44+
ls_sources,
45+
null_ls.builtins.formatting.prettier.with({
46+
command = "${cfg.format.package}/bin/prettier",
47+
})
48+
)
49+
'';
50+
};
51+
52+
biome = {
53+
package = pkgs.biome;
54+
nullConfig = ''
55+
table.insert(
56+
ls_sources,
57+
null_ls.builtins.formatting.biome.with({
58+
command = "${cfg.format.package}/bin/biome",
59+
})
60+
)
61+
'';
62+
};
63+
};
64+
65+
# TODO: specify packages
66+
defaultDiagnosticsProvider = ["eslint_d"];
67+
diagnosticsProviders = {
68+
eslint_d = {
69+
package = pkgs.eslint_d;
70+
nullConfig = pkg: ''
71+
table.insert(
72+
ls_sources,
73+
null_ls.builtins.diagnostics.eslint_d.with({
74+
command = "${getExe pkg}",
75+
})
76+
)
77+
'';
78+
};
79+
};
80+
in {
81+
options.vim.languages.astro = {
82+
enable = mkEnableOption "Astro language support";
83+
84+
treesitter = {
85+
enable = mkEnableOption "Astro treesitter" // {default = config.vim.languages.enableTreesitter;};
86+
87+
astroPackage = mkGrammarOption pkgs "astro";
88+
};
89+
90+
lsp = {
91+
enable = mkEnableOption "Astro LSP support" // {default = config.vim.languages.enableLSP;};
92+
93+
server = mkOption {
94+
description = "Astro LSP server to use";
95+
type = enum (attrNames servers);
96+
default = defaultServer;
97+
};
98+
99+
package = mkOption {
100+
description = "Astro LSP server package, or the command to run as a list of strings";
101+
example = ''[lib.getExe pkgs.astro-language-server "--minify" "--stdio"]'';
102+
type = either package (listOf str);
103+
default = servers.${cfg.lsp.server}.package;
104+
};
105+
};
106+
107+
format = {
108+
enable = mkEnableOption "Astro formatting" // {default = config.vim.languages.enableFormat;};
109+
110+
type = mkOption {
111+
description = "Astro formatter to use";
112+
type = enum (attrNames formats);
113+
default = defaultFormat;
114+
};
115+
116+
package = mkOption {
117+
description = "Astro formatter package";
118+
type = package;
119+
default = formats.${cfg.format.type}.package;
120+
};
121+
};
122+
123+
extraDiagnostics = {
124+
enable = mkEnableOption "extra Astro diagnostics" // {default = config.vim.languages.enableExtraDiagnostics;};
125+
126+
types = diagnostics {
127+
langDesc = "Astro";
128+
inherit diagnosticsProviders;
129+
inherit defaultDiagnosticsProvider;
130+
};
131+
};
132+
};
133+
134+
config = mkIf cfg.enable (mkMerge [
135+
(mkIf cfg.treesitter.enable {
136+
vim.treesitter.enable = true;
137+
vim.treesitter.grammars = [cfg.treesitter.astroPackage];
138+
})
139+
140+
(mkIf cfg.lsp.enable {
141+
vim.lsp.lspconfig.enable = true;
142+
vim.lsp.lspconfig.sources.astro-lsp = servers.${cfg.lsp.server}.lspConfig;
143+
})
144+
145+
(mkIf cfg.format.enable {
146+
vim.lsp.null-ls.enable = true;
147+
vim.lsp.null-ls.sources.astro-format = formats.${cfg.format.type}.nullConfig;
148+
})
149+
150+
(mkIf cfg.extraDiagnostics.enable {
151+
vim.lsp.null-ls.enable = true;
152+
vim.lsp.null-ls.sources = diagnosticsToLua {
153+
lang = "astro";
154+
config = cfg.extraDiagnostics.types;
155+
inherit diagnosticsProviders;
156+
};
157+
})
158+
]);
159+
}

modules/plugins/languages/default.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
in {
44
imports = [
55
./asm.nix
6+
./astro.nix
67
./bash.nix
78
./dart.nix
89
./clang.nix

0 commit comments

Comments
 (0)