nixos-config/pkgs/bck-nvim/lua/5-lsp.lua

154 lines
3.5 KiB
Lua
Raw Permalink Normal View History

2024-02-23 05:14:23 +00:00
local lspconfig = require('lspconfig')
local capabilities = require('cmp_nvim_lsp').default_capabilities()
2024-03-02 05:39:29 +00:00
local noFormat = function(client, _)
client.server_capabilities.documentFormattingProvider = false
end
2024-02-23 05:14:23 +00:00
----------------------------------------------------------------
lspconfig.lua_ls.setup({
capabilities = capabilities,
settings = {
Lua = {
diagnostics = {
globals = { "vim" }
}
}
}
})
2024-08-01 21:05:38 +00:00
----------------------------------------------------------------
lspconfig.gopls.setup({
capabilities = capabilities,
})
2024-02-23 05:14:23 +00:00
----------------------------------------------------------------
lspconfig.pyright.setup({
capabilities = capabilities,
})
2024-09-16 06:30:11 +00:00
----------------------------------------------------------------
lspconfig.rust_analyzer.setup({
capabilities = capabilities,
})
2024-02-23 05:14:23 +00:00
----------------------------------------------------------------
2024-09-16 04:37:43 +00:00
lspconfig.ts_ls.setup({
2024-02-23 05:14:23 +00:00
capabilities = capabilities,
2024-03-02 05:39:29 +00:00
on_attach = noFormat,
2024-02-23 05:14:23 +00:00
})
----------------------------------------------------------------
lspconfig.html.setup({
capabilities = capabilities,
2024-03-02 05:39:29 +00:00
on_attach = noFormat,
2024-02-23 05:14:23 +00:00
})
----------------------------------------------------------------
lspconfig.cssls.setup({
capabilities = capabilities,
2024-03-02 05:39:29 +00:00
on_attach = noFormat,
2024-02-23 05:14:23 +00:00
})
----------------------------------------------------------------
lspconfig.nil_ls.setup({
capabilities = capabilities,
cmd = { "nil" },
settings = {
['nil'] = {
formatting = {
2024-11-08 03:51:20 +00:00
command = { "nixfmt", "--verify" },
2024-02-23 05:14:23 +00:00
},
},
},
})
2024-03-02 05:28:37 +00:00
----------------------------------------------------------------
lspconfig.jsonls.setup({
capabilities = capabilities,
2024-03-02 05:39:29 +00:00
on_attach = noFormat,
2024-03-02 05:28:37 +00:00
})
2024-02-23 05:14:23 +00:00
----------------------------------------------------------------
lspconfig.yamlls.setup({
capabilities = capabilities,
settings = {
yaml = {
customTags = {
-- https://github.com/aws-cloudformation/cfn-lint-visual-studio-code/blob/3ff0b8cc1bbfc34448c865b54deff8c7d030beba/server/src/cfnSettings.ts
"!And sequence",
"!If sequence",
"!Not sequence",
"!Equals sequence",
"!Or sequence",
"!FindInMap sequence",
"!Base64 scalar",
"!Join sequence",
"!Cidr sequence",
"!Ref scalar",
"!Sub scalar",
"!Sub sequence",
"!GetAtt scalar",
"!GetAtt sequence",
"!GetAZs mapping",
"!GetAZs scalar",
"!ImportValue mapping",
"!ImportValue scalar",
"!Select sequence",
"!Split sequence",
},
},
},
on_attach = function(client, _)
client.server_capabilities.documentFormattingProvider = true
end,
})
----------------------------------------------------------------
----------------------------------------------------------------
----------------------------------------------------------------
local efmprettier = {
{
formatStdin = true,
formatCommand = "prettier --stdin-filepath ${INPUT}",
}
}
lspconfig.efm.setup({
filetypes = {
"css",
"html",
"javascript",
2024-03-02 05:28:37 +00:00
"json",
2024-02-23 05:14:23 +00:00
"typescript",
"python",
},
init_options = {
documentFormatting = true
},
settings = {
languages = {
css = efmprettier,
html = efmprettier,
javascript = efmprettier,
2024-03-02 05:28:37 +00:00
json = efmprettier,
2024-02-23 05:14:23 +00:00
typescript = efmprettier,
python = {
{
formatStdin = true,
formatCommand = "black --quiet -",
},
},
},
},
})
----------------------------------------------------------------
vim.api.nvim_create_autocmd("BufWritePre", {
callback = function(e)
for _, client in pairs(vim.lsp.buf_get_clients(e.buf)) do
if client.supports_method("textDocument/formatting") then
return vim.lsp.buf.format()
end
end
end
})