lsp_spec.lua 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. -- trigger loading event manually for mason
  24. vim.api.nvim_exec_autocmds("User", { pattern = "FileOpened" })
  25. it("should be able to delete ftplugin templates", function()
  26. if utils.is_directory(lvim.lsp.templates_dir) then
  27. assert.equal(vim.fn.delete(lvim.lsp.templates_dir, "rf"), 0)
  28. end
  29. assert.False(utils.is_directory(lvim.lsp.templates_dir))
  30. end)
  31. it("should be able to generate ftplugin templates", function()
  32. if utils.is_directory(lvim.lsp.templates_dir) then
  33. assert.equal(vim.fn.delete(lvim.lsp.templates_dir, "rf"), 0)
  34. end
  35. require("lvim.lsp").setup()
  36. vim.wait(500)
  37. local template_files = vim.fn.glob(lvim.lsp.templates_dir .. "/*.lua", 1, 1)
  38. assert.False(vim.tbl_isempty(template_files))
  39. end)
  40. it("should not include blacklisted servers in the generated templates", function()
  41. require("lvim.lsp").setup()
  42. for _, server_name in ipairs(lvim.lsp.automatic_configuration.skipped_servers) do
  43. local setup_cmd = string.format([[require("lvim.lsp.manager").setup(%q)]], server_name)
  44. local _, stdout, _ = helpers.search_file(lvim.lsp.templates_dir, setup_cmd)
  45. assert.True(vim.tbl_isempty(stdout))
  46. end
  47. end)
  48. it("should only include one server per generated template", function()
  49. require("lvim.lsp").setup()
  50. vim.wait(500)
  51. local allowed_dupes = { "tailwindcss" }
  52. local template_files = vim.fn.glob(lvim.lsp.templates_dir .. "/*.lua", 1, 1)
  53. for _, file in ipairs(template_files) do
  54. local content = {}
  55. for entry in io.lines(file) do
  56. local server_name = entry:match [[.*setup%("(.*)"%)]]
  57. if not vim.tbl_contains(allowed_dupes, server_name) then
  58. table.insert(content, server_name)
  59. end
  60. end
  61. local err_msg = ""
  62. if #content > 1 then
  63. err_msg = string.format(
  64. "found more than one server for [%q]: \n{\n %q \n}",
  65. file:match "[^/]*.lua$",
  66. table.concat(content, ", ")
  67. )
  68. end
  69. assert.equal(err_msg, "")
  70. end
  71. end)
  72. it("should not attempt to re-generate ftplugin templates", function()
  73. local s = spy.on(require "lvim.lsp.templates", "generate_templates")
  74. require("lvim.lsp").setup()
  75. assert.spy(s):was_not_called()
  76. s:revert()
  77. end)
  78. end)