mirror of
https://github.com/NotAShelf/nvf.git
synced 2026-04-27 11:55:22 +00:00
languages/svelte: refactor lsp.servers to use lsp/presets/<name>
This commit is contained in:
parent
60b3715f16
commit
7ce9d912f4
1 changed files with 11 additions and 46 deletions
|
|
@ -8,51 +8,16 @@
|
||||||
inherit (builtins) attrNames;
|
inherit (builtins) attrNames;
|
||||||
inherit (lib.options) mkEnableOption mkOption literalExpression;
|
inherit (lib.options) mkEnableOption mkOption literalExpression;
|
||||||
inherit (lib.modules) mkIf mkMerge;
|
inherit (lib.modules) mkIf mkMerge;
|
||||||
|
inherit (lib) genAttrs;
|
||||||
inherit (lib.meta) getExe;
|
inherit (lib.meta) getExe;
|
||||||
inherit (lib.types) enum coercedTo;
|
inherit (lib.types) enum coercedTo listOf;
|
||||||
inherit (lib.nvim.types) mkGrammarOption diagnostics deprecatedSingleOrListOf;
|
inherit (lib.nvim.types) mkGrammarOption diagnostics deprecatedSingleOrListOf;
|
||||||
inherit (lib.nvim.attrsets) mapListToAttrs;
|
inherit (lib.nvim.attrsets) mapListToAttrs;
|
||||||
inherit (lib.generators) mkLuaInline;
|
|
||||||
|
|
||||||
cfg = config.vim.languages.svelte;
|
cfg = config.vim.languages.svelte;
|
||||||
|
|
||||||
defaultServers = ["svelte"];
|
defaultServers = ["svelte-language-server"];
|
||||||
servers = {
|
servers = ["svelte-language-server"];
|
||||||
svelte = {
|
|
||||||
enable = true;
|
|
||||||
cmd = [(getExe pkgs.svelte-language-server) "--stdio"];
|
|
||||||
filetypes = ["svelte"];
|
|
||||||
root_dir = mkLuaInline ''
|
|
||||||
function(bufnr, on_dir)
|
|
||||||
local root_files = { 'package.json', '.git' }
|
|
||||||
local fname = vim.api.nvim_buf_get_name(bufnr)
|
|
||||||
-- Svelte LSP only supports file:// schema. https://github.com/sveltejs/language-tools/issues/2777
|
|
||||||
if vim.uv.fs_stat(fname) ~= nil then
|
|
||||||
on_dir(vim.fs.dirname(vim.fs.find(root_files, { path = fname, upward = true })[1]))
|
|
||||||
end
|
|
||||||
end
|
|
||||||
'';
|
|
||||||
on_attach = mkLuaInline ''
|
|
||||||
function(client, bufnr)
|
|
||||||
vim.api.nvim_create_autocmd('BufWritePost', {
|
|
||||||
pattern = { '*.js', '*.ts' },
|
|
||||||
group = vim.api.nvim_create_augroup('svelte_js_ts_file_watch', {}),
|
|
||||||
callback = function(ctx)
|
|
||||||
-- internal API to sync changes that have not yet been saved to the file system
|
|
||||||
client:notify('$/onDidChangeTsOrJsFile', { uri = ctx.match })
|
|
||||||
end,
|
|
||||||
})
|
|
||||||
|
|
||||||
vim.api.nvim_buf_create_user_command(bufnr, 'LspMigrateToSvelte5', function()
|
|
||||||
client:exec_cmd({
|
|
||||||
command = 'migrate_to_svelte_5',
|
|
||||||
arguments = { vim.uri_from_bufnr(bufnr) },
|
|
||||||
})
|
|
||||||
end, { desc = 'Migrate Component to Svelte 5 Syntax' })
|
|
||||||
end
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
defaultFormat = ["prettier"];
|
defaultFormat = ["prettier"];
|
||||||
formats = let
|
formats = let
|
||||||
|
|
@ -123,7 +88,7 @@ in {
|
||||||
};
|
};
|
||||||
|
|
||||||
servers = mkOption {
|
servers = mkOption {
|
||||||
type = deprecatedSingleOrListOf "vim.language.svelte.lsp.servers" (enum (attrNames servers));
|
type = listOf (enum servers);
|
||||||
default = defaultServers;
|
default = defaultServers;
|
||||||
description = "Svelte LSP server to use";
|
description = "Svelte LSP server to use";
|
||||||
};
|
};
|
||||||
|
|
@ -167,12 +132,12 @@ in {
|
||||||
})
|
})
|
||||||
|
|
||||||
(mkIf cfg.lsp.enable {
|
(mkIf cfg.lsp.enable {
|
||||||
vim.lsp.servers =
|
vim.lsp = {
|
||||||
mapListToAttrs (n: {
|
presets = genAttrs cfg.lsp.servers (_: {enable = true;});
|
||||||
name = n;
|
servers = genAttrs cfg.lsp.servers (_: {
|
||||||
value = servers.${n};
|
filetypes = ["svelte"];
|
||||||
})
|
});
|
||||||
cfg.lsp.servers;
|
};
|
||||||
})
|
})
|
||||||
|
|
||||||
(mkIf cfg.format.enable {
|
(mkIf cfg.format.enable {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue