mirror of
https://github.com/NotAShelf/nvf.git
synced 2025-09-06 10:21:31 +00:00
astro module overhaul
This commit is contained in:
parent
0bf6912626
commit
72d129f69a
1 changed files with 43 additions and 26 deletions
|
@ -12,25 +12,46 @@
|
|||
inherit (lib.types) enum either listOf package str;
|
||||
inherit (lib.generators) mkLuaInline;
|
||||
inherit (lib.nvim.lua) expToLua;
|
||||
inherit (lib.nvim.attrsets) mapListToAttrs;
|
||||
inherit (lib.nvim.types) mkGrammarOption diagnostics;
|
||||
|
||||
cfg = config.vim.languages.astro;
|
||||
|
||||
defaultServer = "astro";
|
||||
defaultServers = ["astro"];
|
||||
servers = {
|
||||
astro = {
|
||||
package = pkgs.astro-language-server;
|
||||
lspConfig = ''
|
||||
lspconfig.astro.setup {
|
||||
capabilities = capabilities,
|
||||
on_attach = attach_keymaps,
|
||||
cmd = ${
|
||||
if isList cfg.lsp.package
|
||||
then expToLua cfg.lsp.package
|
||||
else ''{"${cfg.lsp.package}/bin/astro-ls", "--stdio"}''
|
||||
}
|
||||
}
|
||||
'';
|
||||
enable = true;
|
||||
cmd = [(getExe pkgs.astro-language-server) "--stdio"];
|
||||
filetypes = ["astro"];
|
||||
root_markers = ["package.json" "tsconfig.json" "jsconfig.json" ".git"];
|
||||
init_options = {
|
||||
typescript = {};
|
||||
};
|
||||
before_init =
|
||||
mkLuaInline
|
||||
/*
|
||||
lua
|
||||
*/
|
||||
''
|
||||
function(_, config)
|
||||
-- TODO: Make this a shared util function
|
||||
local get_typescript_server_path = function(root_dir)
|
||||
local project_roots = vim.fs.find('node_modules', { path = root_dir, upward = true, limit = math.huge })
|
||||
for _, project_root in ipairs(project_roots) do
|
||||
local typescript_path = project_root .. '/typescript'
|
||||
local stat = vim.loop.fs_stat(typescript_path)
|
||||
if stat and stat.type == 'directory' then
|
||||
return typescript_path .. '/lib'
|
||||
end
|
||||
end
|
||||
return '''
|
||||
end
|
||||
|
||||
if config.init_options and config.init_options.typescript and not config.init_options.typescript.tsdk then
|
||||
config.init_options.typescript.tsdk = get_typescript_server_path(config.root_dir)
|
||||
end
|
||||
end
|
||||
'';
|
||||
};
|
||||
};
|
||||
|
||||
|
@ -82,18 +103,10 @@ in {
|
|||
|
||||
lsp = {
|
||||
enable = mkEnableOption "Astro LSP support" // {default = config.vim.lsp.enable;};
|
||||
|
||||
server = mkOption {
|
||||
type = enum (attrNames servers);
|
||||
default = defaultServer;
|
||||
servers = mkOption {
|
||||
description = "Astro LSP server to use";
|
||||
};
|
||||
|
||||
package = mkOption {
|
||||
type = either package (listOf str);
|
||||
default = servers.${cfg.lsp.server}.package;
|
||||
example = ''[lib.getExe pkgs.astro-language-server "--minify" "--stdio"]'';
|
||||
description = "Astro LSP server package, or the command to run as a list of strings";
|
||||
type = listOf (enum (attrNames servers));
|
||||
default = defaultServers;
|
||||
};
|
||||
};
|
||||
|
||||
|
@ -131,8 +144,12 @@ in {
|
|||
})
|
||||
|
||||
(mkIf cfg.lsp.enable {
|
||||
vim.lsp.lspconfig.enable = true;
|
||||
vim.lsp.lspconfig.sources.astro-lsp = servers.${cfg.lsp.server}.lspConfig;
|
||||
vim.lsp.servers =
|
||||
mapListToAttrs (n: {
|
||||
name = n;
|
||||
value = servers.${n};
|
||||
})
|
||||
cfg.lsp.servers;
|
||||
})
|
||||
|
||||
(mkIf cfg.format.enable {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue