dotfiles/.config/nvim/lua/plugins/lsp-config.lua

255 lines
7.6 KiB
Lua
Raw Normal View History

2021-04-18 18:51:03 +02:00
local lspconfig = require("lspconfig")
2022-10-17 09:23:07 +02:00
local capabilities = require("cmp_nvim_lsp").default_capabilities()
2022-03-04 12:11:26 +01:00
vim.keymap.set("n", "K", "<Cmd>lua vim.lsp.buf.hover()<CR>")
vim.keymap.set("i", "<C-k>", "<Cmd>lua vim.lsp.buf.signature_help()<CR>")
vim.keymap.set("n", "1gd", "<Cmd>lua vim.lsp.buf.type_definition()<CR>")
2022-10-07 10:29:08 +02:00
vim.keymap.set("n", "gf", "<Cmd>lua vim.lsp.buf.format()<CR>")
vim.keymap.set("n", "rn", "<Cmd>lua vim.lsp.buf.rename()<CR>")
vim.keymap.set("n", "[d", "<Cmd>lua vim.lsp.diagnostic.goto_prev()<CR>")
vim.keymap.set("n", "]d", "<Cmd>lua vim.lsp.diagnostic.goto_next()<CR>")
vim.keymap.set("n", "gwa", "<Cmd>lua vim.lsp.buf.add_workspace_folder()<CR>")
vim.keymap.set("n", "gwr", "<Cmd>lua vim.lsp.buf.add_workspace_folder()<CR>")
vim.keymap.set("n", "gwl", "<Cmd>lua vim.lsp.buf.add_workspace_folder()<CR>")
2022-10-07 10:29:08 +02:00
vim.cmd([[autocmd BufWritePre * lua vim.lsp.buf.format({sync = true})]])
local border = {
{ "🭽", "FloatBorder" },
{ "", "FloatBorder" },
{ "🭾", "FloatBorder" },
{ "", "FloatBorder" },
{ "🭿", "FloatBorder" },
{ "", "FloatBorder" },
{ "🭼", "FloatBorder" },
{ "", "FloatBorder" },
}
vim.lsp.handlers["textDocument/hover"] = vim.lsp.with(vim.lsp.handlers.hover, { border = border })
vim.lsp.handlers["textDocument/signatureHelp"] = vim.lsp.with(vim.lsp.handlers.signature_help, { border = border })
vim.lsp.handlers["textDocument/publishDiagnostics"] = vim.lsp.with(vim.lsp.diagnostic.on_publish_diagnostics, {
2021-04-20 18:10:56 +02:00
update_in_insert = false,
virtual_text = false,
})
local signs = { Error = "🔥", Warn = "⚠️ ", Hint = "💡", Info = "💡" }
for type, icon in pairs(signs) do
local hl = "DiagnosticSign" .. type
vim.fn.sign_define(hl, { text = icon, texthl = hl, numhl = hl })
end
2021-04-18 18:51:03 +02:00
local on_attach = function()
2021-04-20 18:10:56 +02:00
require("folding").on_attach()
require("lsp_signature").on_attach() -- Note: add in lsp client on-attach
2021-04-18 18:51:03 +02:00
end
-- simple setups --
local servers = {
2021-04-20 18:10:56 +02:00
"bashls",
"dockerls",
"gopls",
2021-04-20 18:10:56 +02:00
"jsonls",
-- "sql",
2022-08-25 10:10:44 +02:00
"pyright",
2021-04-20 18:10:56 +02:00
"sumneko_lua",
"terraformls",
2021-04-18 18:51:03 +02:00
"yamlls",
}
for _, lsp in ipairs(servers) do
lspconfig[lsp].setup({ on_attach = on_attach })
2021-04-18 18:51:03 +02:00
end
local efm_prettier = {
2021-04-20 18:10:56 +02:00
formatCommand = "prettier --stdin-filepath ${INPUT}",
formatStdin = true,
2021-04-18 18:51:03 +02:00
}
lspconfig.gopls.setup({
on_attach = on_attach,
settings = {
gopls = {
directoryFilters = {
"-bazel-bin",
"-bazel-out",
"-bazel-testlogs",
"-proto",
},
},
},
})
2021-04-18 18:51:03 +02:00
lspconfig.sumneko_lua.setup({
on_attach = function()
2022-07-23 11:52:42 +02:00
on_attach()
vim.cmd([[autocmd BufWritePre <buffer> lua require'stylua-nvim'.format_file()]])
end,
2021-04-20 18:10:56 +02:00
settings = {
Lua = {
completion = { kewordSnippet = "Disable" },
2021-04-20 18:10:56 +02:00
diagnostics = {
enable = true,
globals = { "renoise", "use", "vim" },
2021-04-20 18:10:56 +02:00
},
runtime = {
version = "LuaJIT",
path = { "?.lua", "?/init.lua", "?/?.lua" },
2021-04-20 18:10:56 +02:00
},
workspace = {
library = vim.api.nvim_get_runtime_file("", true),
maxPreload = 2000,
preloadFileSize = 1000,
checkThirdParty = false,
},
},
},
})
2021-04-18 18:51:03 +02:00
lspconfig.terraformls.setup({})
2021-06-17 11:29:04 +02:00
2021-04-20 18:10:56 +02:00
local yaml_is_k8s = function(bufnr)
local lines = vim.api.nvim_buf_get_lines(bufnr, 0, 50, false) -- Stop after the first 50 lines
for _, l in pairs(lines) do
if string.find(l, "apiVersion") ~= nil then
return true
end
2021-04-20 18:10:56 +02:00
end
return false
end
lspconfig.cssls.setup({
2022-03-04 12:11:26 +01:00
cmd = { "vscode-css-languageserver", "--stdio" },
capabilities = capabilities,
})
2021-07-22 10:32:46 +02:00
lspconfig.cssmodules_ls.setup({})
2022-03-04 12:11:26 +01:00
lspconfig.html.setup({
2021-07-22 10:32:46 +02:00
cmd = { "vscode-html-languageserver", "--stdio" },
filetypes = { "html" },
init_options = {
configurationSection = { "html", "css", "javascript" },
embeddedLanguages = {
css = true,
javascript = true,
},
2021-07-22 10:32:46 +02:00
},
settings = {},
})
2021-07-22 10:32:46 +02:00
lspconfig.yamlls.setup({
2021-04-20 18:10:56 +02:00
settings = {
yaml = {
format = { enable = true, singleQuote = true },
schemaStore = { enable = true, url = "https://json.schemastore.org" },
2021-04-20 18:10:56 +02:00
schemas = {
-- ["https://json.schemastore.org/github-workflow"] = "*.github/workflows/*",
["https://json.schemastore.org/kustomization.json"] = "kustomization.yaml",
-- ["https://json.schemastore.org/ansible-role-2.9.json"] = "*/tasks/*.y*ml",
2021-06-17 11:29:04 +02:00
kubernetes = {
"clusterrolebinding.yaml",
"clusterrole-contour.yaml",
"clusterrole.yaml",
"configmap.yaml",
"cronjob.yaml",
"daemonset.yaml",
"deployment-*.yaml",
"deployment.yaml",
"*-deployment.yaml",
"hpa.yaml",
"ingress.yaml",
"job.yaml",
"namespace.yaml",
"pvc.yaml",
"rbac.yaml",
"rolebinding.yaml",
"role.yaml",
"sa.yaml",
"secret.yaml",
"serviceaccounts.yaml",
"service-account.yaml",
"serviceaccount.yaml",
"service-*.yaml",
"service.yaml",
"*-service.yaml",
"statefulset.yaml",
},
2021-04-20 18:10:56 +02:00
},
validate = true,
},
},
})
2021-07-22 10:32:46 +02:00
2022-11-22 09:56:09 +01:00
require("lspconfig").tsserver.setup({})
2021-07-22 10:32:46 +02:00
-- npm install -g typescript typescript-language-server
2022-11-22 09:56:09 +01:00
-- require("lspconfig").tsserver.setup({
-- on_attach = function(client, bufnr)
-- client.resolved_capabilities.document_formatting = false
-- on_attach(client)
-- require("lsp_signature").on_attach({
-- bind = false, -- This is mandatory, otherwise border config won't get registered.
-- -- If you want to hook lspsaga or other signature handler, pls set to false
-- doc_lines = 2, -- will show two lines of comment/doc(if there are more than two lines in doc, will be truncated);
-- -- set to 0 if you DO NOT want any API comments be shown
-- -- This setting only take effect in insert mode, it does not affect signature help in normal
-- -- mode, 10 by default
-- floating_window = true, -- show hint in a floating window, set to false for virtual text only mode
-- fix_pos = false, -- set to true, the floating window will not auto-close until finish all parameters
-- hint_enable = false, -- virtual hint enable
-- hint_prefix = "🐼 ", -- Panda for parameter
-- hint_scheme = "String",
-- use_lspsaga = true, -- set to true if you want to use lspsaga popup
-- hi_parameter = "Search", -- how your parameter will be highlight
-- max_height = 12, -- max height of signature floating_window, if content is more than max_height, you can scroll down
-- -- to view the hiding contents
-- max_width = 120, -- max_width of signature floating_window, line will be wrapped if exceed max_width
-- handler_opts = {
-- border = "single", -- double, single, shadow, none
-- },
-- extra_trigger_chars = {}, -- Array of extra characters that will trigger signature completion, e.g., {"(", ","}
-- })
-- local ts_utils = require("nvim-lsp-ts-utils")
-- ts_utils.setup({
-- debug = false,
-- disable_commands = false,
-- enable_import_on_completion = false,
-- import_all_timeout = 5000, -- ms
-- -- eslint
-- eslint_enable_code_actions = true,
-- eslint_enable_disable_comments = true,
-- eslint_bin = "eslint_d",
-- eslint_config_fallback = nil,
-- eslint_enable_diagnostics = true,
-- -- formatting
-- enable_formatting = true,
-- formatter = "prettier",
-- formatter_config_fallback = nil,
-- -- parentheses completion
-- complete_parens = false,
-- signature_help_in_parens = false,
-- -- update imports on file move
-- update_imports_on_move = true,
-- require_confirmation_on_move = true,
-- watch_dir = nil,
-- })
-- ts_utils.setup_client(client)
-- vim.api.nvim_buf_set_keymap(bufnr, "n", "<Leader>co", ":TSLspOrganize<CR>", { silent = true })
-- vim.api.nvim_buf_set_keymap(bufnr, "n", "qq", ":TSLspFixCurrent<CR>", { silent = true })
-- vim.api.nvim_buf_set_keymap(bufnr, "n", "<Leader>cR", ":TSLspRenameFile<CR>", { silent = true })
-- vim.api.nvim_buf_set_keymap(bufnr, "n", "<Leader>ci", ":TSLspImportAll<CR>", { silent = true })
-- end,
-- })