lsp_spec.lua 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. local a = require "plenary.async_lib.tests"
  2. local utils = require "lvim.utils"
  3. local helpers = require "tests.lvim.helpers"
  4. local spy = require "luassert.spy"
  5. a.describe("lsp workflow", function()
  6. before_each(function()
  7. vim.cmd [[
  8. let v:errmsg = ""
  9. let v:errors = []
  10. ]]
  11. end)
  12. after_each(function()
  13. local errmsg = vim.fn.eval "v:errmsg"
  14. local exception = vim.fn.eval "v:exception"
  15. local errors = vim.fn.eval "v:errors"
  16. assert.equal("", errmsg)
  17. assert.equal("", exception)
  18. assert.True(vim.tbl_isempty(errors))
  19. end)
  20. lvim.lsp.templates_dir = join_paths(get_cache_dir(), "artifacts")
  21. vim.go.loadplugins = true
  22. local plugins = require "lvim.plugins"
  23. require("lvim.plugin-loader").load { plugins, lvim.plugins }
  24. a.it("should be able to delete ftplugin templates", function()
  25. if utils.is_directory(lvim.lsp.templates_dir) then
  26. assert.equal(vim.fn.delete(lvim.lsp.templates_dir, "rf"), 0)
  27. end
  28. assert.False(utils.is_directory(lvim.lsp.templates_dir))
  29. end)
  30. a.it("should be able to generate ftplugin templates", function()
  31. if utils.is_directory(lvim.lsp.templates_dir) then
  32. assert.equal(vim.fn.delete(lvim.lsp.templates_dir, "rf"), 0)
  33. end
  34. require("lvim.lsp").setup()
  35. assert.True(#vim.fn.glob(lvim.lsp.templates_dir .. "/*.lua", 1, 1) > 0)
  36. end)
  37. a.it("should not include blacklisted servers in the generated templates", function()
  38. require("lvim.lsp").setup()
  39. for _, file in ipairs(vim.fn.glob(lvim.lsp.templates_dir .. "/*.lua", 1, 1)) do
  40. for _, server_name in ipairs(lvim.lsp.automatic_configuration.skipped_servers) do
  41. local setup_cmd = string.format([[require("lvim.lsp.manager").setup(%q)]], server_name)
  42. assert.False(helpers.file_contains(file, setup_cmd))
  43. end
  44. end
  45. end)
  46. a.it("should only include one server per generated template", function()
  47. require("lvim.lsp").setup()
  48. local allowed_dupes = { "tailwindcss" }
  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. local server_name = entry:match [[.*setup%("(.*)"%)]]
  53. if not vim.tbl_contains(allowed_dupes, server_name) then
  54. table.insert(content, server_name)
  55. end
  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. a.it("should not attempt to re-generate ftplugin templates", function()
  69. local s = spy.on(require "lvim.lsp.templates", "generate_templates")
  70. require("lvim.lsp").setup()
  71. assert.spy(s).was_not_called()
  72. s:revert()
  73. end)
  74. end)