init.lua 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. local nvim_lsp = require "lspconfig"
  2. local protocol = require "vim.lsp.protocol"
  3. -- Set up lspconfig.
  4. local capabilities = require('cmp_nvim_lsp').update_capabilities(vim.lsp.protocol.make_client_capabilities())
  5. --- the on-attach function that is called for all Language Servers
  6. local on_attach = function(client, bufnr)
  7. vim.keymap.set("n", "K", vim.lsp.buf.hover, {buffer = 0})
  8. vim.keymap.set("n", "gd", vim.lsp.buf.definition, {buffer = 0})
  9. vim.keymap.set("n", "gt", vim.lsp.buf.type_definition, {buffer = 0})
  10. vim.keymap.set("n", "gi", vim.lsp.buf.implementation, {buffer = 0})
  11. vim.keymap.set("n", "<leader>r", vim.lsp.buf.rename, {buffer = 0})
  12. end
  13. require('lspconfig')['pylsp'].setup {
  14. on_attach= on_attach,
  15. capabilities = capabilities
  16. }
  17. require('lspconfig')['nimls'].setup {
  18. on_attach= on_attach,
  19. capabilities = capabilities
  20. }
  21. --- Completion Stuff
  22. vim.opt.completeopt={"menu", "menuone", "noinsert" ,"noselect"}
  23. local cmp = require'cmp'
  24. cmp.setup({
  25. mapping = {
  26. ['<C-b>'] = cmp.mapping.scroll_docs(-4),
  27. ['<C-f>'] = cmp.mapping.scroll_docs(4),
  28. ['<C-Space>'] = cmp.mapping.complete(),
  29. ['<C-e>'] = cmp.mapping.abort(),
  30. ['<CR>'] = cmp.mapping.confirm({ select = true }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items.
  31. },
  32. sources = cmp.config.sources({
  33. { name = 'nvim_lsp' },
  34. })
  35. })