nixos-configs/common/home/neovim/langs/web.nix

201 lines
6.1 KiB
Nix
Raw Permalink Normal View History

{
config,
lib,
pkgs,
self,
vimplugin-ts-error-translator-src,
...
}: let
inherit (lib) mkIf;
inherit (config.vars) neovimIde;
inherit (import "${self}/lib" {inherit pkgs;}) buildPlugin;
in
mkIf neovimIde {
programs = {
neovim = {
withNodeJs = true;
extraPackages = builtins.attrValues {
inherit
(pkgs)
nodejs_latest
vscode-langservers-extracted
;
2024-05-09 15:36:57 -04:00
inherit
(pkgs.nodePackages)
npm
neovim
;
inherit
(self.packages.${pkgs.system})
some-sass-language-server
;
};
extraLuaConfig =
2024-06-09 22:49:30 -04:00
# lua
''
vim.api.nvim_create_autocmd('FileType', {
pattern = { 'javascript', 'javascriptreact', 'javascript.jsx', 'typescript', 'typescriptreact', 'typescript.tsx', 'css', 'scss' },
command = 'setlocal ts=4 sw=4 sts=0 expandtab',
});
vim.api.nvim_create_autocmd('FileType', {
pattern = 'html',
2024-10-19 01:08:24 -04:00
command = 'setlocal ts=4 sw=4 expandtab',
});
vim.api.nvim_create_autocmd('FileType', {
pattern = 'scss',
command = 'setlocal iskeyword+=@-@',
});
2024-05-09 15:36:57 -04:00
local lsp = require('lspconfig');
local tsserver = require('typescript-tools');
2024-10-19 01:08:24 -04:00
local default_capabilities = require('cmp_nvim_lsp').default_capabilities();
2024-05-09 15:36:57 -04:00
tsserver.setup({
2024-10-19 01:08:24 -04:00
capabilities = default_capabilities,
handlers = {
-- format error code with better error message
['textDocument/publishDiagnostics'] = function(err, result, ctx, config)
require('ts-error-translator').translate_diagnostics(err, result, ctx, config)
vim.lsp.diagnostic.on_publish_diagnostics(err, result, ctx, config)
end,
},
});
lsp.eslint.setup({
2024-10-19 01:08:24 -04:00
capabilities = default_capabilities,
2024-05-09 15:36:57 -04:00
-- auto-save
on_attach = function(client, bufnr)
vim.api.nvim_create_autocmd('BufWritePre', {
buffer = bufnr,
command = 'EslintFixAll',
});
end,
settings = {
validate = 'on',
packageManager = 'npm',
useESLintClass = true,
useFlatConfig = true,
experimental = {
useFlatConfig = true,
},
codeAction = {
disableRuleComment = {
enable = true,
location = 'separateLine'
},
showDocumentation = {
enable = true,
},
},
codeActionOnSave = {
mode = 'all',
rules = {},
},
format = true,
quiet = false,
onIgnoredFiles = 'off',
rulesCustomizations = {},
run = 'onType',
problems = {
shortenToSingleLine = false,
},
nodePath = "",
workingDirectory = {
mode = 'location',
},
options = {
flags = {'unstable_ts_config'},
},
},
});
lsp.cssls.setup({
2024-10-19 01:08:24 -04:00
capabilities = default_capabilities,
2024-05-09 15:36:57 -04:00
settings = {
css = {
validate = false,
},
less = {
validate = false,
},
scss = {
validate = false,
},
},
});
2024-10-19 01:08:24 -04:00
lsp.somesass_ls.setup({
capabilities = default_capabilities,
});
lsp.somesass_ls.manager.config.settings = {
somesass = {
scss = {
completion = {
suggestFromUseOnly = true,
},
},
},
};
2024-10-19 01:08:24 -04:00
local html_caps = default_capabilities;
html_caps.textDocument.completion.completionItem.snippetSupport = true;
lsp.html.setup({
capabilities = html_caps,
settings = {
configurationSection = { "html", "css", "javascript" },
embeddedLanguages = {
css = true,
javascript = true,
},
provideFormatter = true,
tabSize = 4,
insertSpaces = true,
indentEmptyLines = false,
wrapAttributes = 'auto',
wrapAttributesIndentSize = 4,
endWithNewline = true,
},
});
'';
plugins = [
pkgs.vimPlugins.typescript-tools-nvim
2024-05-15 18:55:07 -04:00
(buildPlugin "ts-error-translator" vimplugin-ts-error-translator-src)
{
plugin = pkgs.vimPlugins.package-info-nvim;
type = "lua";
config =
# lua
''
local packageInfo = require('package-info');
packageInfo.setup({
hide_up_to_date = true,
package_manager = 'npm',
});
vim.api.nvim_create_autocmd({ 'BufRead', 'BufNewFile' }, {
pattern = { 'package.json' },
callback = function()
packageInfo.show({ force = true });
end,
});
'';
}
];
};
};
}