lsp_spec.lua 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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 _, server_name in ipairs(lvim.lsp.automatic_configuration.skipped_servers) do
  40. local setup_cmd = string.format([[require("lvim.lsp.manager").setup(%q)]], server_name)
  41. local _, stdout, _ = helpers.search_file(lvim.lsp.templates_dir, setup_cmd)
  42. assert.True(vim.tbl_isempty(stdout))
  43. end
  44. end)
  45. a.it("should only include one server per generated template", function()
  46. require("lvim.lsp").setup()
  47. local allowed_dupes = { "tailwindcss" }
  48. for _, file in ipairs(vim.fn.glob(lvim.lsp.templates_dir .. "/*.lua", 1, 1)) do
  49. local content = {}
  50. for entry in io.lines(file) do
  51. local server_name = entry:match [[.*setup%("(.*)"%)]]
  52. if not vim.tbl_contains(allowed_dupes, server_name) then
  53. table.insert(content, server_name)
  54. end
  55. end
  56. local err_msg = ""
  57. if #content > 1 then
  58. err_msg = string.format(
  59. "found more than one server for [%q]: \n{\n %q \n}",
  60. file:match "[^/]*.lua$",
  61. table.concat(content, ", ")
  62. )
  63. end
  64. assert.equal(err_msg, "")
  65. end
  66. end)
  67. a.it("should not attempt to re-generate ftplugin templates", function()
  68. local s = spy.on(require "lvim.lsp.templates", "generate_templates")
  69. require("lvim.lsp").setup()
  70. assert.spy(s):was_not_called()
  71. s:revert()
  72. end)
  73. end)