lsp.lua 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. local lsp = require("lsp-zero")
  2. lsp.preset("recommended")
  3. lsp.ensure_installed({
  4. 'tsserver',
  5. 'eslint',
  6. 'sumneko_lua',
  7. 'rust_analyzer',
  8. 'pylsp',
  9. 'nimls',
  10. 'bashls',
  11. 'jsonls',
  12. })
  13. local cmp = require('cmp')
  14. local cmp_select = {behavior = cmp.SelectBehavior.Select}
  15. local cmp_mappings = lsp.defaults.cmp_mappings({
  16. ['<C-p>'] = cmp.mapping.select_prev_item(cmp_select),
  17. ['<C-n>'] = cmp.mapping.select_next_item(cmp_select),
  18. ['<C-y>'] = cmp.mapping.confirm({select =true}),
  19. ['<C-Space>'] = cmp.mapping.complete(),
  20. })
  21. lsp.set_preferences({
  22. sign_icons = {}
  23. })
  24. lsp.on_attach(function(client, bufnr)
  25. local opts = {buffer = bufnr, remap = false}
  26. vim.keymap.set("n", "K", function() vim.lsp.buf.hover() end, opts)
  27. vim.keymap.set("n", "gd", function() vim.lsp.buf.definition() end, opts)
  28. vim.keymap.set("n", "gt", function() vim.lsp.buf.type_definition() end, opts)
  29. vim.keymap.set("n", "gi", function() vim.lsp.buf.implementation() end, opts)
  30. vim.keymap.set("n", "<leader>r", function() vim.lsp.buf.rename() end, opts)
  31. end)
  32. lsp.setup()