lsp_spec.lua 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. local a = require "plenary.async_lib.tests"
  2. local utils = require "lvim.utils"
  3. lvim.lsp.templates_dir = join_paths(get_runtime_dir(), "lvim", "tests", "artifacts")
  4. a.describe("lsp workflow", function()
  5. local Log = require "lvim.core.log"
  6. local logfile = Log:get_path()
  7. a.it("shoud be able to delete ftplugin templates", function()
  8. if utils.is_directory(lvim.lsp.templates_dir) then
  9. assert.equal(vim.fn.delete(lvim.lsp.templates_dir, "rf"), 0)
  10. end
  11. assert.False(utils.is_directory(lvim.lsp.templates_dir))
  12. end)
  13. a.it("shoud be able to generate ftplugin templates", function()
  14. if utils.is_directory(lvim.lsp.templates_dir) then
  15. assert.equal(vim.fn.delete(lvim.lsp.templates_dir, "rf"), 0)
  16. end
  17. require("lvim.lsp").setup()
  18. -- we need to delay this check until the generation is completed
  19. vim.schedule(function()
  20. assert.True(utils.is_directory(lvim.lsp.templates_dir))
  21. end)
  22. end)
  23. a.it("shoud not attempt to re-generate ftplugin templates", function()
  24. lvim.log.level = "debug"
  25. local plugins = require "lvim.plugins"
  26. require("lvim.plugin-loader"):load { plugins, lvim.plugins }
  27. if utils.is_file(logfile) then
  28. assert.equal(vim.fn.delete(logfile), 0)
  29. end
  30. assert.True(utils.is_directory(lvim.lsp.templates_dir))
  31. require("lvim.lsp").setup()
  32. -- we need to delay this check until the log gets populated
  33. vim.schedule(function()
  34. assert.False(utils.log_contains "templates")
  35. end)
  36. end)
  37. a.it("shoud not include blacklisted servers in the generated templates", function()
  38. assert.True(utils.is_directory(lvim.lsp.templates_dir))
  39. require("lvim.lsp").setup()
  40. for _, file in ipairs(vim.fn.glob(lvim.lsp.templates_dir .. "/*.lua", 1, 1)) do
  41. for _, server in ipairs(lvim.lsp.override) do
  42. assert.False(utils.file_contains(file, server))
  43. end
  44. end
  45. end)
  46. a.it("shoud only include one server per generated template", function()
  47. assert.True(utils.is_directory(lvim.lsp.templates_dir))
  48. require("lvim.lsp").setup()
  49. for _, file in ipairs(vim.fn.glob(lvim.lsp.templates_dir .. "/*.lua", 1, 1)) do
  50. local content = {}
  51. for entry in io.lines(file) do
  52. table.insert(content, entry)
  53. end
  54. local err_msg = ""
  55. if #content > 1 then
  56. err_msg = string.format(
  57. "found more than one server for [%q]: \n{\n %q \n}",
  58. file:match "[^/]*.lua$",
  59. table.concat(content, ", ")
  60. )
  61. end
  62. assert.equal(err_msg, "")
  63. end
  64. end)
  65. end)