lsp_spec.lua 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. local utils = require "lvim.utils"
  2. local helpers = require "tests.lvim.helpers"
  3. local spy = require "luassert.spy"
  4. describe("lsp workflow", function()
  5. before_each(function()
  6. vim.cmd [[
  7. let v:errmsg = ""
  8. let v:errors = []
  9. ]]
  10. end)
  11. after_each(function()
  12. local errmsg = vim.fn.eval "v:errmsg"
  13. local exception = vim.fn.eval "v:exception"
  14. local errors = vim.fn.eval "v:errors"
  15. assert.equal("", errmsg)
  16. assert.equal("", exception)
  17. assert.True(vim.tbl_isempty(errors))
  18. end)
  19. lvim.lsp.templates_dir = join_paths(get_cache_dir(), "artifacts")
  20. vim.go.loadplugins = true
  21. local plugins = require "lvim.plugins"
  22. require("lvim.plugin-loader").load { plugins, lvim.plugins }
  23. it("should be able to delete ftplugin templates", function()
  24. if utils.is_directory(lvim.lsp.templates_dir) then
  25. assert.equal(vim.fn.delete(lvim.lsp.templates_dir, "rf"), 0)
  26. end
  27. assert.False(utils.is_directory(lvim.lsp.templates_dir))
  28. end)
  29. it("should be able to generate ftplugin templates", function()
  30. if utils.is_directory(lvim.lsp.templates_dir) then
  31. assert.equal(vim.fn.delete(lvim.lsp.templates_dir, "rf"), 0)
  32. end
  33. require("lvim.lsp").setup()
  34. vim.wait(500)
  35. local template_files = vim.fn.glob(lvim.lsp.templates_dir .. "/*.lua", 1, 1)
  36. assert.False(vim.tbl_isempty(template_files))
  37. end)
  38. it("should not include blacklisted servers in the generated templates", function()
  39. require("lvim.lsp").setup()
  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. local _, stdout, _ = helpers.search_file(lvim.lsp.templates_dir, setup_cmd)
  43. assert.True(vim.tbl_isempty(stdout))
  44. end
  45. end)
  46. it("should only include one server per generated template", function()
  47. require("lvim.lsp").setup()
  48. vim.wait(500)
  49. local allowed_dupes = { "tailwindcss" }
  50. local template_files = vim.fn.glob(lvim.lsp.templates_dir .. "/*.lua", 1, 1)
  51. for _, file in ipairs(template_files) do
  52. local content = {}
  53. for entry in io.lines(file) do
  54. local server_name = entry:match [[.*setup%("(.*)"%)]]
  55. if not vim.tbl_contains(allowed_dupes, server_name) then
  56. table.insert(content, server_name)
  57. end
  58. end
  59. local err_msg = ""
  60. if #content > 1 then
  61. err_msg = string.format(
  62. "found more than one server for [%q]: \n{\n %q \n}",
  63. file:match "[^/]*.lua$",
  64. table.concat(content, ", ")
  65. )
  66. end
  67. assert.equal(err_msg, "")
  68. end
  69. end)
  70. it("should not attempt to re-generate ftplugin templates", function()
  71. local s = spy.on(require "lvim.lsp.templates", "generate_templates")
  72. require("lvim.lsp").setup()
  73. assert.spy(s):was_not_called()
  74. s:revert()
  75. end)
  76. end)