1
0
mirror of https://github.com/kmein/niveum synced 2026-03-16 18:21:07 +01:00
Files
niveum/lib/vim/init.lua

146 lines
4.6 KiB
Lua
Raw Normal View History

2023-07-04 21:44:32 +02:00
local cmp = require'cmp'
cmp.setup({
snippet = {
expand = function(args)
require("luasnip").lsp_expand(args.body)
end,
},
2023-07-04 21:44:32 +02:00
mapping = cmp.mapping.preset.insert({
['<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 }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items.
}),
sources = cmp.config.sources({
{ name = 'nvim_lsp' },
{ name = 'luasnip' },
2023-07-04 21:44:32 +02:00
}, {
{ name = 'buffer' },
})
})
-- -- Use buffer source for `/` and `?` (if you enabled `native_menu`, this won't work anymore).
-- cmp.setup.cmdline({ '/', '?' }, {
-- mapping = cmp.mapping.preset.cmdline(),
-- sources = {
-- { name = 'buffer' }
-- }
-- })
2023-07-04 21:44:32 +02:00
-- -- Use cmdline & path source for ':' (if you enabled `native_menu`, this won't work anymore).
-- cmp.setup.cmdline(':', {
-- mapping = cmp.mapping.preset.cmdline(),
-- sources = cmp.config.sources({
-- { name = 'path' }
-- })
-- })
local capabilities = require('cmp_nvim_lsp').default_capabilities(vim.lsp.protocol.make_client_capabilities())
2023-07-04 21:44:32 +02:00
2023-03-06 22:01:58 +01:00
local opts = { noremap=true, silent=true }
vim.keymap.set('n', '<space>e', vim.diagnostic.open_float, opts)
vim.keymap.set('n', '<space>dn', vim.diagnostic.goto_prev, opts)
vim.keymap.set('n', '<space>dp', vim.diagnostic.goto_next, opts)
2023-03-06 22:01:58 +01:00
vim.keymap.set('n', '<space>q', vim.diagnostic.setloclist, opts)
-- Use an on_attach function to only map the following keys
-- after the language server attaches to the current buffer
local on_attach = function(client, bufnr)
-- Enable completion triggered by <c-x><c-o>
-- vim.api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc')
2023-03-06 22:01:58 +01:00
-- 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', 'gt', vim.lsp.buf.type_definition, bufopts)
2023-03-06 22:01:58 +01:00
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>f', vim.lsp.buf.format, bufopts)
2023-03-06 22:01:58 +01:00
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>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>f', function() vim.lsp.buf.format { async = true } end, bufopts)
end
local lsp_flags = {
-- This is the default in Nvim 0.7+
debounce_text_changes = 150,
}
local language_servers = {
clangd = {},
2023-03-06 22:01:58 +01:00
pyright = {}, -- pyright
2023-07-04 21:44:32 +02:00
tsserver = {}, -- typescript-language-server
cssls = {},
2023-07-04 21:44:32 +02:00
elmls = {}, -- elm-language-server
-- denols = {}, -- deno built in
bashls = {}, -- bash-language-server
lua_ls = {
Lua = {
runtime = {
version = 'LuaJIT',
},
diagnostics = {
globals = {'vim'},
},
workspace = {
library = vim.api.nvim_get_runtime_file("", true)
},
telemetry = {
enable = false,
}
},
},
2023-03-06 22:01:58 +01:00
hls = {}, -- haskell-language-server
2023-07-04 21:44:32 +02:00
html = {}, -- vscode-langservers-extracted
jsonls = {}, -- vscode-langservers-extracted
2023-03-06 22:01:58 +01:00
nil_ls = {}, -- github:oxalica/nil
2023-03-06 22:07:57 +01:00
-- rnix = {}, -- rnix-lsp
jqls = {}, -- jq-lsp
2023-03-06 22:01:58 +01:00
rust_analyzer = { ["rust-analyzer"] = {} },
2023-07-04 21:44:32 +02:00
eslint = {},
2023-03-06 22:01:58 +01:00
-- volar? vls?
texlab = {
texlab = {
auxDirectory = ".",
bibtexFormatter = "texlab",
build = {
args = { "-pdf", "-interaction=nonstopmode", "-synctex=1", "%f" },
executable = "latexmk",
forwardSearchAfter = false,
onSave = false
},
chktex = {
onEdit = false,
onOpenAndSave = false
},
diagnosticsDelay = 300,
formatterLineLength = 80,
forwardSearch = {
args = {}
},
latexFormatter = "latexindent",
latexindent = {
modifyLineBreaks = false
}
}
}
}
for server, settings in pairs(language_servers) do
require('lspconfig')[server].setup{
on_attach = on_attach,
flags = lsp_flags,
settings = settings,
2023-07-04 21:44:32 +02:00
capabilities = capabilities
2023-03-06 22:01:58 +01:00
}
end