--- Personal lua config files for NeoVim. -- Last Changed: 2019-01-27 -- Author: Federico Igne -- License: This file is placed in the public domain. local map = require 'dyamon.util.map' local lsp = { } --- Collection of settings to be set for any language server function lsp.on_attach_common(client, bufnr, opts) local opts = opts or { } -- Connect omnifunc completion with LSP server vim.api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc') -- Collection of bindings taken from -- https://github.com/neovim/nvim-lspconfig#keybindings-and-completion map.b.nore.n(bufnr, 'gd', 'lua vim.lsp.buf.declaration()', opts) map.b.nore.n(bufnr, 'gD', 'lua vim.lsp.buf.definition()', opts) map.b.nore.n(bufnr, 'K', 'lua vim.lsp.buf.hover()', opts) --map.b.nore.n(bufnr, 'gi', 'lua vim.lsp.buf.implementation()', opts) --map.b.nore.n(bufnr, '', 'lua vim.lsp.buf.signature_help()', opts) --map.b.nore.n(bufnr, 'wa', 'lua vim.lsp.buf.add_workspace_folder()', opts) --map.b.nore.n(bufnr, 'wr', 'lua vim.lsp.buf.remove_workspace_folder()', opts) --map.b.nore.n(bufnr, 'wl', 'lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))', opts) --map.b.nore.n(bufnr, 'D', 'lua vim.lsp.buf.type_definition()', opts) map.b.nore.n(bufnr, 'ln', 'lua vim.lsp.buf.rename()', opts) map.b.nore.n(bufnr, 'la', 'lua vim.lsp.buf.code_action()', opts) map.b.nore.n(bufnr, 'lr', 'Telescope lsp_references', opts) map.b.nore.n(bufnr, '[d', 'lua vim.diagnostic.goto_prev()', opts) map.b.nore.n(bufnr, ']d', 'lua vim.diagnostic.goto_next()', opts) --map.b.nore.n(bufnr, 'q', 'lua vim.lsp.diagnostic.set_loclist()', opts) --map.b.nore.n(bufnr, 'f', 'lua vim.lsp.buf.formatting()', opts) map.b.nore.n(bufnr, 'ld', 'Telescope diagnostics', opts) end function lsp.on_attach_clangd(client, bufnr, opts) local opts = opts or { } lsp.on_attach_common(client, bufnr, opts) map.b.nore.n(bufnr, '##', 'ClangdSwitchSourceHeader', opts) map.b.nore.n(bufnr, '#s', 'split | ClangdSwitchSourceHeader', opts) map.b.nore.n(bufnr, '#v', 'vertical split | ClangdSwitchSourceHeader', opts) map.b.nore.n(bufnr, '#t', 'tab split | ClangdSwitchSourceHeader', opts) map.b.nore.n(bufnr, '#S', 'botright split | ClangdSwitchSourceHeader', opts) map.b.nore.n(bufnr, '#V', 'botright vertical split | ClangdSwitchSourceHeader', opts) end function lsp.on_attach_ltex(client, bufnr, opts) local opts = opts or { } map.b.nore.n(bufnr, '=', 'lua vim.lsp.buf.code_action()', opts) map.b.nore.n(bufnr, '[d', 'lua vim.diagnostic.goto_prev()', opts) map.b.nore.n(bufnr, ']d', 'lua vim.diagnostic.goto_next()', opts) map.b.nore.n(bufnr, 'ld', 'Telescope diagnostics', opts) end return lsp