2022-07-30 07:17:12 +02:00
|
|
|
require("mason").setup({
|
2022-10-11 07:40:50 +02:00
|
|
|
ui = {
|
|
|
|
border = "none",
|
|
|
|
icons = {
|
|
|
|
package_installed = " ",
|
|
|
|
package_pending = " ",
|
|
|
|
package_uninstalled = " ",
|
|
|
|
},
|
|
|
|
},
|
2022-07-30 07:17:12 +02:00
|
|
|
})
|
|
|
|
require("mason-lspconfig").setup({ automatic_installation = true })
|
|
|
|
|
|
|
|
vim.opt.completeopt = "menu,menuone,noselect"
|
|
|
|
|
|
|
|
-- debug mode enabled
|
2022-07-31 20:16:51 +02:00
|
|
|
-- vim.lsp.set_log_level("debug")
|
2022-07-30 07:17:12 +02:00
|
|
|
|
|
|
|
-- Setup nvim-cmp.
|
2022-09-06 23:44:35 +02:00
|
|
|
local present, cmp = pcall(require, "cmp")
|
|
|
|
if not present then
|
2022-10-11 07:40:50 +02:00
|
|
|
return
|
2022-09-06 23:44:35 +02:00
|
|
|
end
|
|
|
|
|
2022-07-30 07:17:12 +02:00
|
|
|
cmp.setup({
|
2022-10-11 07:40:50 +02:00
|
|
|
snippet = {
|
|
|
|
expand = function(args)
|
|
|
|
vim.fn["vsnip#anonymous"](args.body)
|
|
|
|
end,
|
|
|
|
},
|
|
|
|
mapping = cmp.mapping.preset.insert({
|
|
|
|
["<C-Space>"] = cmp.mapping.complete(),
|
|
|
|
["<C-e>"] = cmp.mapping.abort(),
|
|
|
|
["<Tab>"] = cmp.mapping.confirm({ select = true }),
|
|
|
|
}),
|
|
|
|
sources = cmp.config.sources({
|
|
|
|
{ name = "nvim_lsp" },
|
|
|
|
{ name = "vsnip" },
|
|
|
|
}, { { name = "buffer" } }),
|
2022-07-30 07:17:12 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
-- Set configuration for specific filetype.
|
|
|
|
cmp.setup.filetype("gitcommit", {
|
2022-10-11 07:40:50 +02:00
|
|
|
sources = cmp.config.sources({
|
|
|
|
{ name = "cmp_git" },
|
|
|
|
}, { { name = "buffer" } }),
|
2022-07-30 07:17:12 +02:00
|
|
|
})
|
|
|
|
-- search
|
|
|
|
cmp.setup.cmdline("/", {
|
2022-10-11 07:40:50 +02:00
|
|
|
mapping = cmp.mapping.preset.cmdline(),
|
|
|
|
sources = { { name = "buffer" } },
|
2022-07-30 07:17:12 +02:00
|
|
|
})
|
|
|
|
-- Use cmdline & path source for ':'
|
|
|
|
cmp.setup.cmdline(":", {
|
2022-10-11 07:40:50 +02:00
|
|
|
mapping = cmp.mapping.preset.cmdline(),
|
|
|
|
sources = cmp.config.sources(
|
|
|
|
{ {
|
|
|
|
name = "path",
|
|
|
|
option = { trailing_slash = true },
|
|
|
|
} },
|
|
|
|
{ { name = "cmdline" } }
|
|
|
|
),
|
2022-07-30 07:17:12 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
-- Setup lspconfig.
|
2022-10-11 07:40:50 +02:00
|
|
|
local capabilities = require("cmp_nvim_lsp").update_capabilities(
|
|
|
|
vim.lsp.protocol.make_client_capabilities()
|
|
|
|
)
|
2022-07-30 07:17:12 +02:00
|
|
|
|
|
|
|
-- Mappings.
|
|
|
|
-- See `:help vim.diagnostic.*` for documentation on any of the below functions
|
|
|
|
local opts = { noremap = true, silent = true }
|
2022-08-21 20:14:59 +02:00
|
|
|
vim.keymap.set("n", "<space>e", vim.diagnostic.open_float, opts)
|
2022-07-30 07:17:12 +02:00
|
|
|
vim.keymap.set("n", "[d", vim.diagnostic.goto_prev, opts)
|
|
|
|
vim.keymap.set("n", "]d", vim.diagnostic.goto_next, opts)
|
2022-08-21 20:14:59 +02:00
|
|
|
vim.keymap.set("n", "<space>q", vim.diagnostic.setloclist, opts)
|
2022-07-30 07:17:12 +02:00
|
|
|
|
|
|
|
-- Use an on_attach function to only map the following keys
|
|
|
|
-- after the language server attaches to the current buffer
|
|
|
|
---@diagnostic disable-next-line: unused-local
|
|
|
|
local on_attach = function(client, bufnr)
|
2022-10-11 07:40:50 +02:00
|
|
|
-- Enable completion triggered by <c-x><c-o>
|
|
|
|
vim.api.nvim_buf_set_option(bufnr, "omnifunc", "v:lua.vim.lsp.omnifunc")
|
|
|
|
|
|
|
|
-- disable diagnostics on Helm files
|
|
|
|
if vim.bo[bufnr].buftype ~= "" or vim.bo[bufnr].filetype == "helm" then
|
|
|
|
vim.diagnostic.disable()
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Mappings.
|
|
|
|
-- See `:help vim.lsp.*` for documentation on any of the below functions
|
|
|
|
local bufopts = { noremap = true, silent = true, buffer = bufnr }
|
|
|
|
vim.keymap.set("n", "gD", vim.lsp.buf.declaration, bufopts)
|
|
|
|
vim.keymap.set("n", "gd", vim.lsp.buf.definition, bufopts)
|
|
|
|
vim.keymap.set("n", "K", vim.lsp.buf.hover, bufopts)
|
|
|
|
vim.keymap.set("n", "gi", vim.lsp.buf.implementation, bufopts)
|
|
|
|
vim.keymap.set("n", "<C-k>", vim.lsp.buf.signature_help, bufopts)
|
|
|
|
vim.keymap.set("n", "<space>wa", vim.lsp.buf.add_workspace_folder, bufopts)
|
|
|
|
vim.keymap.set("n", "<space>wr", vim.lsp.buf.remove_workspace_folder, bufopts)
|
|
|
|
vim.keymap.set("n", "<space>wl", function()
|
|
|
|
print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
|
|
|
|
end, bufopts)
|
|
|
|
vim.keymap.set("n", "<space>D", vim.lsp.buf.type_definition, bufopts)
|
|
|
|
vim.keymap.set("n", "<space>rn", vim.lsp.buf.rename, bufopts)
|
|
|
|
vim.keymap.set("n", "<space>ca", vim.lsp.buf.code_action, bufopts)
|
|
|
|
vim.keymap.set("n", "gr", vim.lsp.buf.references, bufopts)
|
|
|
|
vim.keymap.set("n", "<space>nf", function() end, bufopts)
|
2022-07-30 07:17:12 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
local common_config = {
|
2022-10-11 07:40:50 +02:00
|
|
|
on_attach = on_attach,
|
|
|
|
capabilities = capabilities,
|
2022-07-30 07:17:12 +02:00
|
|
|
}
|
|
|
|
|
2022-09-06 23:44:35 +02:00
|
|
|
local present, lsp = pcall(require, "lspconfig")
|
|
|
|
if not present then
|
2022-10-11 07:40:50 +02:00
|
|
|
return
|
2022-09-06 23:44:35 +02:00
|
|
|
end
|
|
|
|
|
2022-07-30 07:17:12 +02:00
|
|
|
lsp.sumneko_lua.setup({
|
2022-10-11 07:40:50 +02:00
|
|
|
on_attach = on_attach,
|
|
|
|
capabilities = capabilities,
|
|
|
|
settings = {
|
|
|
|
Lua = {
|
|
|
|
workspace = {
|
|
|
|
-- Make the server aware of Neovim runtime files
|
|
|
|
library = vim.api.nvim_get_runtime_file("", true),
|
|
|
|
checkThirdParty = false,
|
|
|
|
maxPreload = 100000,
|
|
|
|
preloadFileSize = 10000,
|
|
|
|
},
|
|
|
|
diagnostics = {
|
|
|
|
-- Get the language server to recognize the `vim` global
|
|
|
|
globals = { "vim" },
|
|
|
|
},
|
|
|
|
telemetry = {
|
|
|
|
enable = false,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2022-07-30 07:17:12 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
--- the cool kids
|
|
|
|
lsp.bashls.setup(common_config)
|
|
|
|
lsp.gopls.setup(common_config)
|
|
|
|
lsp.pyright.setup(common_config)
|
|
|
|
lsp.rust_analyzer.setup(common_config)
|
|
|
|
|
|
|
|
--- Web Development
|
|
|
|
lsp.cssls.setup(common_config)
|
2022-10-11 07:40:50 +02:00
|
|
|
local emmet_cap = require("cmp_nvim_lsp").update_capabilities(
|
|
|
|
vim.lsp.protocol.make_client_capabilities()
|
|
|
|
)
|
2022-07-30 07:17:12 +02:00
|
|
|
emmet_cap.textDocument.completion.completionItem.snippetSupport = true
|
|
|
|
lsp.emmet_ls.setup({
|
2022-10-11 07:40:50 +02:00
|
|
|
on_attach = on_attach,
|
|
|
|
capabilities = emmet_cap,
|
|
|
|
filetypes = {
|
|
|
|
"javascriptreact",
|
|
|
|
"typescriptreact",
|
|
|
|
"html",
|
|
|
|
"svelte",
|
|
|
|
"css",
|
|
|
|
"less",
|
|
|
|
"sass",
|
|
|
|
"scss",
|
|
|
|
},
|
2022-07-30 07:17:12 +02:00
|
|
|
})
|
|
|
|
-- lsp.html.setup(common_config)
|
|
|
|
lsp.tailwindcss.setup({
|
2022-10-11 07:40:50 +02:00
|
|
|
on_attach = on_attach,
|
|
|
|
capabilities = capabilities,
|
|
|
|
settings = {
|
|
|
|
emmetCompletions = true,
|
|
|
|
},
|
2022-07-30 07:17:12 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
-- soydev
|
|
|
|
lsp.prismals.setup(common_config)
|
|
|
|
lsp.svelte.setup(common_config)
|
|
|
|
-- attach tsserver only when there's a 'package.json' file in the CWD
|
|
|
|
lsp.tsserver.setup({
|
2022-10-11 07:40:50 +02:00
|
|
|
on_attach = on_attach,
|
|
|
|
capabilities = capabilities,
|
|
|
|
root_dir = lsp.util.root_pattern("package.json"),
|
2022-07-30 07:17:12 +02:00
|
|
|
})
|
|
|
|
-- attach deno only when there's a 'deps.ts' file in the CWD
|
|
|
|
lsp.denols.setup({
|
2022-10-11 07:40:50 +02:00
|
|
|
on_attach = on_attach,
|
|
|
|
capabilities = capabilities,
|
|
|
|
root_dir = lsp.util.root_pattern("deps.ts"),
|
|
|
|
single_file_support = false,
|
2022-07-30 07:17:12 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
-- data formats
|
|
|
|
lsp.dockerls.setup(common_config)
|
|
|
|
lsp.graphql.setup({
|
2022-10-11 07:40:50 +02:00
|
|
|
on_attach = on_attach,
|
|
|
|
capabilities = capabilities,
|
|
|
|
root_dir = lsp.util.root_pattern(
|
|
|
|
".graphqlrc*",
|
|
|
|
".graphql.config.*",
|
|
|
|
"graphql.config.*"
|
|
|
|
),
|
|
|
|
settings = {
|
|
|
|
graphql = {
|
|
|
|
schemaPath = "schema.graphql",
|
|
|
|
},
|
|
|
|
},
|
2022-07-30 07:17:12 +02:00
|
|
|
})
|
|
|
|
lsp.jsonls.setup({
|
2022-10-11 07:40:50 +02:00
|
|
|
on_attach = on_attach,
|
|
|
|
capabilities = capabilities,
|
|
|
|
settings = {
|
|
|
|
json = {
|
|
|
|
schemas = require("schemastore").json.schemas(),
|
|
|
|
validate = { enable = true },
|
|
|
|
},
|
|
|
|
},
|
2022-07-30 07:17:12 +02:00
|
|
|
})
|
|
|
|
lsp.yamlls.setup({
|
2022-10-11 07:40:50 +02:00
|
|
|
on_attach = on_attach,
|
|
|
|
capabilities = capabilities,
|
|
|
|
settings = {
|
|
|
|
yaml = {
|
|
|
|
["https://raw.githubusercontent.com/instrumenta/kubernetes-json-schema/master/v1.18.0-standalone-strict/all.json"] = "/*.k8s.yaml",
|
|
|
|
},
|
|
|
|
},
|
2022-07-30 07:17:12 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
--- Documentation
|
|
|
|
lsp.ltex.setup(common_config)
|