lua.lua 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. -- https://github.com/sumneko/lua-language-server/wiki/Build-and-Run-(Standalone)
  2. local sumneko_root_path = DATA_PATH .. "/lspinstall/lua"
  3. local sumneko_binary = sumneko_root_path .. "/sumneko-lua-language-server"
  4. require("lspconfig").sumneko_lua.setup {
  5. cmd = { sumneko_binary, "-E", sumneko_root_path .. "/main.lua" },
  6. on_attach = require("lsp").common_on_attach,
  7. settings = {
  8. Lua = {
  9. runtime = {
  10. -- Tell the language server which version of Lua you're using (most likely LuaJIT in the case of Neovim)
  11. version = "LuaJIT",
  12. -- Setup your lua path
  13. path = vim.split(package.path, ";"),
  14. },
  15. diagnostics = {
  16. -- Get the language server to recognize the `vim` global
  17. globals = { "vim" },
  18. },
  19. workspace = {
  20. -- Make the server aware of Neovim runtime files
  21. library = {
  22. [vim.fn.expand "$VIMRUNTIME/lua"] = true,
  23. [vim.fn.expand "$VIMRUNTIME/lua/vim/lsp"] = true,
  24. },
  25. maxPreload = 100000,
  26. preloadFileSize = 1000,
  27. },
  28. },
  29. },
  30. }
  31. if O.lang.lua.autoformat then
  32. require("lv-utils").define_augroups {
  33. _lua_autoformat = {
  34. {
  35. "BufWritePre",
  36. "*.lua",
  37. "lua vim.lsp.buf.formatting_sync(nil, 1000)",
  38. },
  39. },
  40. }
  41. end
  42. local lua_arguments = {}
  43. local luaFormat = {
  44. formatCommand = "lua-format -i --no-keep-simple-function-one-line --column-limit=80",
  45. formatStdin = true,
  46. }
  47. local lua_fmt = {
  48. formatCommand = "luafmt --indent-count 2 --line-width 120 --stdin",
  49. formatStdin = true,
  50. }
  51. if O.lang.lua.formatter == "lua-format" then
  52. table.insert(lua_arguments, luaFormat)
  53. elseif O.lang.lua.formatter == "lua-fmt" then
  54. table.insert(lua_arguments, lua_fmt)
  55. end
  56. require("lspconfig").efm.setup {
  57. -- init_options = {initializationOptions},
  58. cmd = { DATA_PATH .. "/lspinstall/efm/efm-langserver" },
  59. init_options = { documentFormatting = true, codeAction = false },
  60. filetypes = { "lua" },
  61. settings = {
  62. rootMarkers = { ".git/" },
  63. languages = {
  64. lua = lua_arguments,
  65. },
  66. },
  67. }