Neovim: Add typescript LSP

This commit is contained in:
GHOSCHT 2024-05-24 13:58:42 +02:00
parent 8c6e4e9ca5
commit f73fbed43a
Signed by: ghoscht
GPG key ID: 2C2C1C62A5388E82
3 changed files with 38 additions and 1 deletions

View file

@ -11,6 +11,7 @@
# LSP
lua-language-server
lua
pkgs.nodePackages.typescript-language-server
# Formatters
stylua # lua
@ -19,6 +20,8 @@
clang-tools_16 # c/c++
rustfmt
yamlfmt
prettierd
vscode-langservers-extracted
# Linters
ruff # python
@ -184,7 +187,7 @@ in {
{
plugin = nvim-autopairs;
config = "require('nvim-autopairs').setup({})";
config = "require('nvim-autopairs').setup()";
type = "lua";
}
@ -207,6 +210,12 @@ in {
config = builtins.readFile ./plugin/vim-tmux-navigator.lua;
type = "lua";
}
{
plugin = nvim-ts-autotag;
config = "require('nvim-ts-autotag').setup({})";
type = "lua";
}
];
extraLuaConfig = ''

View file

@ -43,3 +43,25 @@ require("lspconfig").nixd.setup({
on_attach = on_attach,
capabilities = capabilities,
})
require("lspconfig").tsserver.setup({
on_attach = on_attach,
capabilities = capabilities,
})
require("lspconfig").eslint.setup({
settings = {
packageManager = "yarn",
},
on_attach = function(client, bufnr)
vim.api.nvim_create_autocmd("BufWritePre", {
buffer = bufnr,
command = "EslintFixAll",
})
vim.api.nvim_create_autocmd("BufWritePost", {
callback = function()
vim.lsp.buf.format()
end,
})
end,
})

View file

@ -19,6 +19,12 @@ local opts = {
null_ls.builtins.formatting.rustfmt,
-- YAML
null_ls.builtins.formatting.yamlfmt,
-- Typescript
null_ls.builtins.formatting.prettier.with({
condition = function(utils)
return utils.has_file({ ".prettierrc.js" })
end,
}),
},
on_attach = function(client, bufnr)
if client.supports_method("textDocument/formatting") then