sumneko_lua.lua 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. local default_workspace = {
  2. library = {
  3. vim.fn.expand "$VIMRUNTIME",
  4. get_lvim_base_dir(),
  5. require("lua-dev.config").types(),
  6. },
  7. maxPreload = 5000,
  8. preloadFileSize = 10000,
  9. }
  10. local add_packages_to_workspace = function(packages, config)
  11. -- config.settings.Lua = config.settings.Lua or { workspace = default_workspace }
  12. local runtimedirs = vim.api.nvim__get_runtime({ "lua" }, true, { is_lua = true })
  13. local workspace = config.settings.Lua.workspace
  14. for _, v in pairs(runtimedirs) do
  15. for _, pack in ipairs(packages) do
  16. if v:match(pack) and not vim.tbl_contains(workspace.library, v) then
  17. table.insert(workspace.library, v)
  18. end
  19. end
  20. end
  21. end
  22. local lspconfig = require "lspconfig"
  23. local make_on_new_config = function(on_new_config, _)
  24. return lspconfig.util.add_hook_before(on_new_config, function(new_config, _)
  25. local server_name = new_config.name
  26. if server_name ~= "sumneko_lua" then
  27. return
  28. end
  29. local plugins = { "plenary.nvim", "telescope.nvim", "nvim-treesitter", "LuaSnip" }
  30. add_packages_to_workspace(plugins, new_config)
  31. end)
  32. end
  33. lspconfig.util.default_config = vim.tbl_extend("force", lspconfig.util.default_config, {
  34. on_new_config = make_on_new_config(lspconfig.util.default_config.on_new_config),
  35. })
  36. local opts = {
  37. settings = {
  38. Lua = {
  39. telemetry = { enable = false },
  40. runtime = {
  41. version = "LuaJIT",
  42. special = {
  43. reload = "require",
  44. },
  45. },
  46. diagnostics = {
  47. globals = { "vim", "lvim", "packer_plugins", "reload" },
  48. },
  49. workspace = default_workspace,
  50. },
  51. },
  52. }
  53. return opts