Advertisement
Guest User

nvim lsp setup

a guest
Sep 24th, 2023
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.86 KB | None | 0 0
  1. -- LSP stuff
  2. local nvim_lsp = require('lspconfig')
  3. local lsp_util = require('lspconfig.util')
  4. local langs = {
  5. hls = {},
  6. rust_analyzer = {
  7. settings = {
  8. ["rust-analyzer"] = {
  9. procMacro = { enable = false }
  10. }
  11. }
  12. },
  13. clangd = {},
  14. texlab = {
  15. settings = {
  16. args = {"-pdf", "--shell-escape"}
  17. }
  18. },
  19. erlangls = {},
  20. eslint = {},
  21. pylsp = {},
  22. solargraph = { root_dir = lsp_util.root_pattern("Gemfile", ".git", ".svn", ".solargraph.yml") },
  23. -- ruby_ls = { root_dir = lsp_util.root_pattern("Gemfile", ".git", ".svn") },
  24. cmake = {},
  25. }
  26.  
  27. local custom_attach = function(client, bufnr_)
  28. bufnr = 0
  29. local function map(mode, key, value)
  30. vim.keymap.set(mode,key,value,{noremap = true, silent = true, buffer = bufnr})
  31. end
  32. local function nmap(key, value) map('n', key, value) end
  33. local function set_option(opt, val)
  34. vim.api.nvim_buf_set_option(bufnr_, opt, val)
  35. end
  36. set_option('omnifunc', 'v:lua.vim.lsp.omnifunc')
  37. nmap('gd', vim.lsp.buf.definition)
  38. nmap('gd', vim.lsp.buf.definition)
  39. nmap('gd', vim.lsp.buf.definition)
  40. nmap('gd', vim.lsp.buf.definition)
  41. nmap('gd', vim.lsp.buf.definition)
  42. nmap('gd', vim.lsp.buf.definition)
  43. nmap('gD', vim.lsp.buf.type_definition)
  44. nmap('gr', vim.lsp.buf.references)
  45. nmap('gR', vim.lsp.buf.rename)
  46. map('v', 'K', vim.lsp.buf.hover)
  47. nmap('K', vim.lsp.buf.hover)
  48. nmap('ga', vim.lsp.buf.code_action)
  49. nmap('=f', vim.lsp.buf.format)
  50. nmap('].', vim.diagnostic.goto_next)
  51. nmap('[.', vim.diagnostic.goto_prev)
  52. nmap('<leader>i', function () vim.diagnostic.open_float(0, { scope = "line", padding="single" }) end)
  53. nmap('<leader>d', vim.lsp.buf.code_action)
  54. nmap('<leader>q', vim.diagnostic.setqflist)
  55. end
  56.  
  57. for lang,opts in pairs(langs) do
  58. nvim_lsp[lang].setup(opts)
  59. nvim_lsp[lang].setup { on_attach = custom_attach }
  60. end
  61.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement