lsp_spec.lua 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. local a = require "plenary.async_lib.tests"
  2. local utils = require "lvim.utils"
  3. local helpers = require "tests.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 in ipairs(lvim.lsp.override) do
  44. assert.False(helpers.file_contains(file, server))
  45. end
  46. end
  47. end)
  48. a.it("should only include one server per generated template", function()
  49. assert.True(utils.is_directory(lvim.lsp.templates_dir))
  50. require("lvim.lsp").setup()
  51. for _, file in ipairs(vim.fn.glob(lvim.lsp.templates_dir .. "/*.lua", 1, 1)) do
  52. local content = {}
  53. for entry in io.lines(file) do
  54. table.insert(content, entry)
  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. end)