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"
|
|
|
|
|
2022-09-06 23:44:35 +02:00
|
|
|
local present, cmp = pcall(require, "cmp")
|
2022-10-17 17:13:31 +02:00
|
|
|
if not present or not cmp then
|
2022-10-11 07:40:50 +02:00
|
|
|
return
|
2022-09-06 23:44:35 +02:00
|
|
|
end
|
|
|
|
|
2022-10-18 10:02:19 +02:00
|
|
|
local has_words_before = function()
|
2022-10-21 17:01:46 +02:00
|
|
|
local line, col = unpack(vim.api.nvim_win_get_cursor(0))
|
2022-10-18 10:02:19 +02:00
|
|
|
return col ~= 0
|
2022-10-21 17:01:46 +02:00
|
|
|
and vim.api
|
|
|
|
.nvim_buf_get_lines(0, line - 1, line, true)[1]
|
|
|
|
:sub(col, col)
|
|
|
|
:match("%s")
|
2022-10-18 10:02:19 +02:00
|
|
|
== nil
|
|
|
|
end
|
|
|
|
|
|
|
|
local feedkey = function(key, mode)
|
|
|
|
vim.api.nvim_feedkeys(
|
|
|
|
vim.api.nvim_replace_termcodes(key, true, true, true),
|
|
|
|
mode,
|
|
|
|
true
|
|
|
|
)
|
|
|
|
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,
|
|
|
|
},
|
2022-10-17 17:13:31 +02:00
|
|
|
window = {
|
2022-10-21 17:01:46 +02:00
|
|
|
completion = {
|
|
|
|
border = { "╔", "═", "╗", "║", "╝", "═", "╚", "║" },
|
|
|
|
winhighlight = "Normal:CmpPmenu,FloatBorder:CmpBorder,CursorLine:PmenuSel,Search:None",
|
|
|
|
},
|
|
|
|
documentation = {
|
|
|
|
border = { "╔", "═", "╗", "║", "╝", "═", "╚", "║" },
|
|
|
|
winhighlight = "Normal:CmpPmenu,FloatBorder:CmpBorder,CursorLine:PmenuSel,Search:None",
|
|
|
|
},
|
2022-10-17 17:13:31 +02:00
|
|
|
},
|
2022-10-11 07:40:50 +02:00
|
|
|
mapping = cmp.mapping.preset.insert({
|
2022-10-18 10:02:19 +02:00
|
|
|
["<C-b>"] = cmp.mapping.scroll_docs(-4),
|
|
|
|
["<C-f>"] = cmp.mapping.scroll_docs(4),
|
|
|
|
["<C-Space>"] = cmp.mapping.complete(),
|
|
|
|
["<C-e>"] = cmp.mapping.abort(),
|
|
|
|
["<CR>"] = cmp.mapping.confirm({ select = true }),
|
2022-10-17 17:13:31 +02:00
|
|
|
["<Tab>"] = cmp.mapping(function(fallback)
|
|
|
|
if cmp.visible() then
|
2022-10-18 10:02:19 +02:00
|
|
|
cmp.select_next_item()
|
|
|
|
elseif vim.fn["vsnip#available"](1) == 1 then
|
|
|
|
feedkey("<Plug>(vsnip-expand-or-jump)", "")
|
|
|
|
elseif has_words_before() then
|
|
|
|
cmp.complete()
|
2022-10-17 17:13:31 +02:00
|
|
|
else
|
2022-10-18 10:02:19 +02:00
|
|
|
fallback() -- The fallback function sends a already mapped key. In this case, it's probably `<Tab>`.
|
2022-10-17 17:13:31 +02:00
|
|
|
end
|
2022-10-18 10:02:19 +02:00
|
|
|
end, { "i", "s" }),
|
|
|
|
|
|
|
|
["<S-Tab>"] = cmp.mapping(function()
|
|
|
|
if cmp.visible() then
|
|
|
|
cmp.select_prev_item()
|
|
|
|
elseif vim.fn["vsnip#jumpable"](-1) == 1 then
|
|
|
|
feedkey("<Plug>(vsnip-jump-prev)", "")
|
|
|
|
end
|
|
|
|
end, { "i", "s" }),
|
2022-10-11 07:40:50 +02:00
|
|
|
}),
|
|
|
|
sources = cmp.config.sources({
|
|
|
|
{ name = "nvim_lsp" },
|
|
|
|
{ name = "vsnip" },
|
2022-10-17 17:13:31 +02:00
|
|
|
{ name = "vim-dadbod-completion" },
|
|
|
|
}, {
|
|
|
|
{ name = "buffer" },
|
|
|
|
}),
|
2022-10-21 17:01:46 +02:00
|
|
|
formatting = {
|
|
|
|
format = require("lspkind").cmp_format({
|
|
|
|
mode = "symbol_text",
|
|
|
|
maxwidth = 50,
|
|
|
|
ellipsis_char = "...",
|
|
|
|
}),
|
|
|
|
},
|
2022-07-30 07:17:12 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
cmp.setup.filetype("gitcommit", {
|
2022-10-11 07:40:50 +02:00
|
|
|
sources = cmp.config.sources({
|
|
|
|
{ name = "cmp_git" },
|
2022-10-17 17:13:31 +02:00
|
|
|
}, {
|
|
|
|
{ name = "buffer" },
|
|
|
|
}),
|
2022-07-30 07:17:12 +02:00
|
|
|
})
|
2022-10-17 17:13:31 +02:00
|
|
|
|
|
|
|
cmp.setup.cmdline({ "/", "?" }, {
|
2022-10-11 07:40:50 +02:00
|
|
|
mapping = cmp.mapping.preset.cmdline(),
|
2022-10-17 17:13:31 +02:00
|
|
|
sources = {
|
|
|
|
{ name = "buffer" },
|
|
|
|
},
|
2022-07-30 07:17:12 +02:00
|
|
|
})
|
2022-10-17 17:13:31 +02:00
|
|
|
|
2022-07-30 07:17:12 +02:00
|
|
|
cmp.setup.cmdline(":", {
|
2022-10-11 07:40:50 +02:00
|
|
|
mapping = cmp.mapping.preset.cmdline(),
|
2022-10-17 17:13:31 +02:00
|
|
|
sources = cmp.config.sources({
|
2022-10-21 17:01:46 +02:00
|
|
|
{ name = "path", option = { trailing_slash = true } },
|
2022-10-17 17:13:31 +02:00
|
|
|
}, {
|
|
|
|
{ name = "cmdline" },
|
|
|
|
}),
|
2022-07-30 07:17:12 +02:00
|
|
|
})
|
|
|
|
|
2022-10-17 17:13:31 +02:00
|
|
|
local capabilities = require("cmp_nvim_lsp").default_capabilities(
|
2022-10-11 07:40:50 +02:00
|
|
|
vim.lsp.protocol.make_client_capabilities()
|
|
|
|
)
|
2022-07-30 07:17:12 +02:00
|
|
|
---@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")
|
|
|
|
|
|
|
|
-- 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)
|
2022-11-02 16:50:16 +01:00
|
|
|
vim.keymap.set("n", "<leader>wa", vim.lsp.buf.add_workspace_folder, bufopts)
|
|
|
|
vim.keymap.set(
|
|
|
|
"n",
|
|
|
|
"<leader>wr",
|
|
|
|
vim.lsp.buf.remove_workspace_folder,
|
|
|
|
bufopts
|
|
|
|
)
|
|
|
|
vim.keymap.set("n", "<leader>wl", function()
|
2022-10-11 07:40:50 +02:00
|
|
|
print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
|
|
|
|
end, bufopts)
|
2022-11-02 16:50:16 +01:00
|
|
|
vim.keymap.set("n", "<leader>D", vim.lsp.buf.type_definition, bufopts)
|
|
|
|
vim.keymap.set("n", "<leader>rn", vim.lsp.buf.rename, bufopts)
|
|
|
|
vim.keymap.set("n", "<leader>ca", vim.lsp.buf.code_action, bufopts)
|
2022-10-11 07:40:50 +02:00
|
|
|
vim.keymap.set("n", "gr", vim.lsp.buf.references, bufopts)
|
2022-11-02 16:50:16 +01:00
|
|
|
vim.keymap.set("n", "<leader>lr", "<cmd>LspRestart<CR>", bufopts)
|
|
|
|
vim.keymap.set("n", "]d", vim.diagnostic.goto_next, bufopts)
|
|
|
|
vim.keymap.set("n", "[d", vim.diagnostic.goto_prev, bufopts)
|
2022-07-30 07:17:12 +02:00
|
|
|
end
|
2022-10-17 17:13:31 +02:00
|
|
|
local lspconfig = require("lspconfig")
|
2022-07-30 07:17:12 +02:00
|
|
|
|
2022-10-17 17:13:31 +02:00
|
|
|
lspconfig.gopls.setup({
|
2022-10-11 07:40:50 +02:00
|
|
|
capabilities = capabilities,
|
|
|
|
on_attach = on_attach,
|
2022-10-17 17:13:31 +02:00
|
|
|
})
|
|
|
|
|
2022-10-24 04:35:00 +02:00
|
|
|
require("go").setup({
|
|
|
|
disable_defaults = true,
|
|
|
|
lsp_inlay_hints = {
|
|
|
|
enable = true,
|
|
|
|
-- Only show inlay hints for the current line
|
|
|
|
only_current_line = false,
|
|
|
|
-- Event which triggers a refersh of the inlay hints.
|
|
|
|
-- You can make this "CursorMoved" or "CursorMoved,CursorMovedI" but
|
|
|
|
-- not that this may cause higher CPU usage.
|
|
|
|
-- This option is only respected when only_current_line and
|
|
|
|
-- autoSetHints both are true.
|
|
|
|
only_current_line_autocmd = "CursorHold",
|
|
|
|
-- whether to show variable name before type hints with the inlay hints or not
|
|
|
|
-- default: false
|
|
|
|
show_variable_name = true,
|
|
|
|
-- prefix for parameter hints
|
|
|
|
parameter_hints_prefix = " ",
|
|
|
|
show_parameter_hints = true,
|
|
|
|
-- prefix for all the other hints (type, chaining)
|
|
|
|
other_hints_prefix = "=> ",
|
|
|
|
-- whether to align to the lenght of the longest line in the file
|
|
|
|
max_len_align = false,
|
|
|
|
-- padding from the left if max_len_align is true
|
|
|
|
max_len_align_padding = 1,
|
|
|
|
-- whether to align to the extreme right or not
|
|
|
|
right_align = false,
|
|
|
|
-- padding from the right if right_align is true
|
|
|
|
right_align_padding = 6,
|
|
|
|
-- The color of the hints
|
|
|
|
highlight = "Comment",
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
2022-10-17 17:13:31 +02:00
|
|
|
lspconfig.sumneko_lua.setup({
|
2022-10-11 07:40:50 +02:00
|
|
|
capabilities = capabilities,
|
2022-10-17 17:13:31 +02:00
|
|
|
on_attach = on_attach,
|
2022-10-11 07:40:50 +02:00
|
|
|
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 = {
|
2022-10-17 17:13:31 +02:00
|
|
|
globals = { "vim" }, -- Get the server to recognize the `vim` global
|
2022-10-11 07:40:50 +02:00
|
|
|
},
|
|
|
|
telemetry = {
|
|
|
|
enable = false,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2022-07-30 07:17:12 +02:00
|
|
|
})
|
2022-10-17 17:13:31 +02:00
|
|
|
lspconfig["emmet_ls"].setup({
|
|
|
|
capabilities = capabilities,
|
2022-10-11 07:40:50 +02:00
|
|
|
on_attach = on_attach,
|
|
|
|
filetypes = {
|
|
|
|
"javascriptreact",
|
|
|
|
"typescriptreact",
|
|
|
|
"html",
|
|
|
|
"svelte",
|
|
|
|
"css",
|
|
|
|
"less",
|
|
|
|
"sass",
|
|
|
|
"scss",
|
|
|
|
},
|
2022-07-30 07:17:12 +02:00
|
|
|
})
|
|
|
|
-- attach tsserver only when there's a 'package.json' file in the CWD
|
2022-10-17 17:13:31 +02:00
|
|
|
lspconfig.tsserver.setup({
|
2022-10-11 07:40:50 +02:00
|
|
|
capabilities = capabilities,
|
2022-10-17 17:13:31 +02:00
|
|
|
on_attach = on_attach,
|
|
|
|
root_dir = lspconfig.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
|
2022-10-17 17:13:31 +02:00
|
|
|
lspconfig.denols.setup({
|
2022-10-11 07:40:50 +02:00
|
|
|
capabilities = capabilities,
|
2022-10-17 17:13:31 +02:00
|
|
|
on_attach = on_attach,
|
|
|
|
root_dir = lspconfig.util.root_pattern("deps.ts"),
|
2022-10-11 07:40:50 +02:00
|
|
|
single_file_support = false,
|
2022-07-30 07:17:12 +02:00
|
|
|
})
|
2022-10-21 17:01:46 +02:00
|
|
|
lspconfig.ltex.setup({
|
|
|
|
capabilities = capabilities,
|
|
|
|
on_attach = function(client, bufnr)
|
|
|
|
require("ltex_extra").setup({
|
|
|
|
load_langs = { "en-US", "de-AT" },
|
|
|
|
init_check = true,
|
|
|
|
path = vim.fn.stdpath("data") .. "/dictionary",
|
|
|
|
})
|
|
|
|
on_attach(client, bufnr)
|
|
|
|
end,
|
|
|
|
settings = {
|
|
|
|
ltex = {},
|
|
|
|
},
|
|
|
|
})
|
2022-07-30 07:17:12 +02:00
|
|
|
|
2022-11-02 16:50:16 +01:00
|
|
|
lspconfig.yamlls.setup({
|
|
|
|
capabilities = capabilities,
|
|
|
|
on_attach = on_attach,
|
|
|
|
})
|
|
|
|
|
2022-10-17 17:13:31 +02:00
|
|
|
local null = require("null-ls")
|
|
|
|
local augroup = vim.api.nvim_create_augroup("LspFormatting", {})
|
|
|
|
|
|
|
|
null.setup({
|
|
|
|
sources = {
|
|
|
|
null.builtins.formatting.gofmt,
|
|
|
|
null.builtins.formatting.stylua,
|
|
|
|
null.builtins.formatting.stylua,
|
|
|
|
null.builtins.formatting.deno_fmt,
|
2022-10-11 07:40:50 +02:00
|
|
|
},
|
2022-10-17 17:13:31 +02:00
|
|
|
on_attach = function(client, bufnr)
|
|
|
|
if client.supports_method("textDocument/formatting") then
|
|
|
|
vim.api.nvim_clear_autocmds({ group = augroup, buffer = bufnr })
|
|
|
|
vim.api.nvim_create_autocmd("BufWritePre", {
|
|
|
|
group = augroup,
|
|
|
|
buffer = bufnr,
|
|
|
|
callback = function()
|
|
|
|
vim.lsp.buf.format({ bufnr = bufnr })
|
|
|
|
end,
|
|
|
|
})
|
|
|
|
end
|
|
|
|
end,
|
2022-07-30 07:17:12 +02:00
|
|
|
})
|
|
|
|
|
2022-10-17 17:13:31 +02:00
|
|
|
local toggle_formatters = function()
|
|
|
|
null.toggle({ methods = null.methods.FORMATTING })
|
|
|
|
end
|
|
|
|
|
|
|
|
vim.api.nvim_create_user_command("ToggleFormatters", toggle_formatters, {})
|