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

144 lines
3.2 KiB
Lua
Raw 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" }
}
}
}
})
----------------------------------------------------------------
lspconfig.pyright.setup({
capabilities = capabilities,
})
----------------------------------------------------------------
lspconfig.tsserver.setup({
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 = {
command = { "nixpkgs-fmt" },
},
},
},
})
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
})