Something went wrong. Try again.
my experiments with nvim
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990vim.o.winborder = 'rounded'vim.cmd[[set completeopt+=menuone,noselect,popup]]
vim.api.nvim_create_autocmd('LspAttach', { group = vim.api.nvim_create_augroup('my.lsp', {}), callback = function(args) local client = assert(vim.lsp.get_client_by_id(args.data.client_id))
-- goto impl if client:supports_method('textDocument/implementation') then vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, bufopts) end
-- autocomplete if client:supports_method('textDocument/completion') then vim.lsp.completion.enable(true, client.id, args.buf, { autotrigger = true, convert = function(item) return { abbr = item.label:gsub('%b()', '') } end, }) end
-- format on save if not client:supports_method('textDocument/willSaveWaitUntil') and client:supports_method('textDocument/formatting') then vim.api.nvim_create_autocmd('BufWritePre', { group = vim.api.nvim_create_augroup('my.lsp', {clear=false}), buffer = args.buf, callback = function() vim.lsp.buf.format({ bufnr = args.buf, id = client.id, timeout_ms = 1000 }) end, }) end
-- Mappings. local bufopts = { noremap=true, silent=true, buffer=bufnr } vim.keymap.set('n', 'gD', '<C-w>g}', { noremap = true, silent = true }) vim.keymap.set('n', 'gd', vim.lsp.buf.definition, bufopts) vim.keymap.set('n', 'gr', vim.lsp.buf.references, bufopts) vim.keymap.set('n', '<space>r', vim.lsp.buf.rename, bufopts) vim.keymap.set('n', 'K', vim.lsp.buf.hover, bufopts) vim.keymap.set('n', '<C-k>', vim.lsp.buf.signature_help, bufopts)
local opts = { noremap=true, silent=true } vim.keymap.set('n', '<space>d', vim.diagnostic.open_float, opts) vim.keymap.set('n', '[d', function() vim.diagnostic.jump({count=-1, float=true}) end, opts) vim.keymap.set('n', ']d', function() vim.diagnostic.jump({count= 1, float=true}) end, opts) vim.keymap.set('n', '<space>q', vim.diagnostic.setqflist, opts) vim.keymap.set('n', '<space>D', vim.lsp.buf.type_definition, bufopts) vim.keymap.set('n', '<space>a', vim.lsp.buf.code_action, bufopts)
end,})
local function on_list(options) vim.fn.setqflist({}, ' ', options) vim.cmd.cfirst()end
local servers = { "bashls", "gopls", "ts_ls", "hls", "ocamllsp", "rust_analyzer" }for _, lsp in ipairs(servers) do vim.lsp.enable(lsp)end
vim.lsp.config('rust_analyzer', { settings = { ["rust-analyzer"] = { procMacro = { enable = true, }, buildScripts = { rebuildOnSave = true, }, cargo = { allFeatures = false, }, checkOnSave = true, cachePriming = { enable = true, }, }, },})
vim.lsp.config('ocamllsp', { cmd = { 'dune', 'tools', 'exec', 'ocamllsp' },})