lua.lua 2.1 KB

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