lua.lua 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. local M = {}
  2. M.config = function()
  3. O.lang.lua = {
  4. diagnostics = {
  5. virtual_text = { spacing = 0, prefix = "" },
  6. signs = true,
  7. underline = true,
  8. },
  9. formatter = {
  10. exe = "stylua",
  11. args = {},
  12. stdin = false,
  13. },
  14. linters = { "luacheck" },
  15. lsp = {
  16. path = DATA_PATH .. "/lspinstall/lua/sumneko-lua-language-server",
  17. },
  18. }
  19. end
  20. M.format = function()
  21. O.formatters.filetype["lua"] = {
  22. function()
  23. return {
  24. exe = O.lang.lua.formatter.exe,
  25. args = O.lang.lua.formatter.args,
  26. stdin = O.lang.lua.formatter.stdin,
  27. tempfile_prefix = ".formatter",
  28. }
  29. end,
  30. }
  31. require("formatter.config").set_defaults {
  32. logging = false,
  33. filetype = O.formatters.filetype,
  34. }
  35. end
  36. M.lint = function()
  37. require("lint").linters_by_ft = {
  38. lua = O.lang.lua.linters,
  39. }
  40. end
  41. M.lsp = function()
  42. if not require("lv-utils").check_lsp_client_active "sumneko_lua" then
  43. -- https://github.com/sumneko/lua-language-server/wiki/Build-and-Run-(Standalone)
  44. local sumneko_main = string.gsub(O.lang.lua.lsp.path, "sumneko-lua-language-server", "main.lua")
  45. require("lspconfig").sumneko_lua.setup {
  46. cmd = { O.lang.lua.lsp.path, "-E", sumneko_main },
  47. on_attach = require("lsp").common_on_attach,
  48. settings = {
  49. Lua = {
  50. runtime = {
  51. -- Tell the language server which version of Lua you're using (most likely LuaJIT in the case of Neovim)
  52. version = "LuaJIT",
  53. -- Setup your lua path
  54. path = vim.split(package.path, ";"),
  55. },
  56. diagnostics = {
  57. -- Get the language server to recognize the `vim` global
  58. globals = { "vim", "O" },
  59. },
  60. workspace = {
  61. -- Make the server aware of Neovim runtime files
  62. library = {
  63. [vim.fn.expand "~/.local/share/lunarvim/lvim/lua"] = true,
  64. [vim.fn.expand "$VIMRUNTIME/lua"] = true,
  65. [vim.fn.expand "$VIMRUNTIME/lua/vim/lsp"] = true,
  66. },
  67. maxPreload = 100000,
  68. preloadFileSize = 1000,
  69. },
  70. },
  71. },
  72. }
  73. end
  74. end
  75. M.dap = function()
  76. -- TODO: implement dap
  77. return "No DAP configured!"
  78. end
  79. return M