lsp_spec.lua 2.7 KB

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