lua.lua 2.1 KB

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