lua.lua 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. O.formatters.filetype["lua"] = {
  2. -- prettier
  3. function()
  4. return {
  5. exe = "stylua",
  6. -- TODO: append to this for args don't overwrite
  7. args = {},
  8. stdin = false,
  9. }
  10. end,
  11. }
  12. require("formatter.config").set_defaults {
  13. logging = false,
  14. filetype = O.formatters.filetype,
  15. }
  16. if not require("lv-utils").check_lsp_client_active "sumneko_lua" then
  17. -- https://github.com/sumneko/lua-language-server/wiki/Build-and-Run-(Standalone)
  18. local sumneko_root_path = DATA_PATH .. "/lspinstall/lua"
  19. local sumneko_binary = sumneko_root_path .. "/sumneko-lua-language-server"
  20. require("lspconfig").sumneko_lua.setup {
  21. cmd = { sumneko_binary, "-E", sumneko_root_path .. "/main.lua" },
  22. on_attach = require("lsp").common_on_attach,
  23. settings = {
  24. Lua = {
  25. runtime = {
  26. -- Tell the language server which version of Lua you're using (most likely LuaJIT in the case of Neovim)
  27. version = "LuaJIT",
  28. -- Setup your lua path
  29. path = vim.split(package.path, ";"),
  30. },
  31. diagnostics = {
  32. -- Get the language server to recognize the `vim` global
  33. globals = { "vim" },
  34. },
  35. workspace = {
  36. -- Make the server aware of Neovim runtime files
  37. library = {
  38. [vim.fn.expand "$VIMRUNTIME/lua"] = true,
  39. [vim.fn.expand "$VIMRUNTIME/lua/vim/lsp"] = true,
  40. },
  41. maxPreload = 100000,
  42. preloadFileSize = 1000,
  43. },
  44. },
  45. },
  46. }
  47. end
  48. if O.lang.lua.autoformat then
  49. require("lv-utils").define_augroups {
  50. _lua_autoformat = {
  51. {
  52. "BufWritePre",
  53. "*.lua",
  54. "lua vim.lsp.buf.formatting_sync(nil, 1000)",
  55. },
  56. },
  57. }
  58. end
  59. vim.cmd "setl ts=2 sw=2"