config.lua 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. local map = vim.keymap.set
  2. local api = vim.api
  3. local lsp = vim.lsp
  4. local lspconfig = require('lspconfig')
  5. local bufopts = {
  6. noremap = true,
  7. silent = true,
  8. -- buffer=bufnr
  9. }
  10. local capabilities = require('cmp_nvim_lsp').default_capabilities(lsp.protocol.make_client_capabilities())
  11. require("mason").setup({
  12. check_outdated_packages_on_open = true,
  13. registries = {
  14. "github:mason-org/mason-registry",
  15. "lua:mason-registry.index"
  16. },
  17. ui = {
  18. icons = {
  19. package_installed = "✓",
  20. package_pending = "➜",
  21. package_uninstalled = "✗"
  22. }
  23. }
  24. })
  25. require("mason-lspconfig").setup({
  26. ensure_installed = {
  27. 'lua_ls',
  28. 'editorconfig-checker',
  29. }
  30. })
  31. local on_attach = function(client, bufnr)
  32. -- Enable completion triggered by <c-x><c-o>
  33. api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc')
  34. map('n', '<leader>rn', '<cmd> lua vim.lsp.buf.rename()<CR>', bufopts)
  35. map('n', '<leader>qf', '<cmd> lua vim.lsp.buf.code_action()<CR>', bufopts)
  36. require("lsp-format").on_attach(client)
  37. end
  38. require("mason-lspconfig").setup_handlers({
  39. function(server_name)
  40. lspconfig[server_name].setup {
  41. on_attach = on_attach,
  42. capabilities = capabilities,
  43. }
  44. end,
  45. ['lua_ls'] = function()
  46. lspconfig.lua_ls.setup {
  47. on_attach = on_attach,
  48. capabilities = capabilities,
  49. settings = {
  50. Lua = {
  51. runtime = {
  52. -- Tell the language server which version of Lua you're using (most likely LuaJIT in the case of Neovim)
  53. version = 'LuaJIT',
  54. },
  55. diagnostics = {
  56. -- Get the language server to recognize the `vim` global
  57. globals = { 'vim' },
  58. },
  59. workspace = {
  60. -- Make the server aware of Neovim runtime files
  61. library = vim.api.nvim_get_runtime_file("", true),
  62. },
  63. -- Do not send telemetry data containing a randomized but unique identifier
  64. telemetry = {
  65. enable = false,
  66. },
  67. },
  68. },
  69. }
  70. end
  71. })