sumneko_lua.lua 1.6 KB

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