lsp_spec.lua 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. local a = require "plenary.async_lib.tests"
  2. local utils = require "lvim.utils"
  3. lvim.lsp.templates_dir = join_paths(get_runtime_dir(), "lvim", "tests", "artifacts")
  4. a.describe("lsp workflow", function()
  5. local Log = require "lvim.core.log"
  6. local logfile = Log:get_path()
  7. a.it("shoud be able to delete ftplugin templates", function()
  8. if utils.is_directory(lvim.lsp.templates_dir) then
  9. assert.equal(vim.fn.delete(lvim.lsp.templates_dir, "rf"), 0)
  10. end
  11. assert.False(utils.is_directory(lvim.lsp.templates_dir))
  12. end)
  13. a.it("shoud be able to generate ftplugin templates", function()
  14. if utils.is_directory(lvim.lsp.templates_dir) then
  15. assert.equal(vim.fn.delete(lvim.lsp.templates_dir, "rf"), 0)
  16. end
  17. require("lvim.lsp").setup()
  18. -- we need to delay this check until the generation is completed
  19. vim.schedule(function()
  20. assert.True(utils.is_directory(lvim.lsp.templates_dir))
  21. end)
  22. end)
  23. a.it("shoud not attempt to re-generate ftplugin templates", function()
  24. lvim.log.level = "debug"
  25. local plugins = require "lvim.plugins"
  26. require("lvim.plugin-loader"):load { plugins, lvim.plugins }
  27. if utils.is_file(logfile) then
  28. assert.equal(vim.fn.delete(logfile), 0)
  29. end
  30. assert.True(utils.is_directory(lvim.lsp.templates_dir))
  31. require("lvim.lsp").setup()
  32. -- we need to delay this check until the log gets populated
  33. vim.schedule(function()
  34. assert.False(utils.log_contains "templates")
  35. end)
  36. end)
  37. a.it("shoud retrieve supported filetypes correctly", function()
  38. local ocaml = {
  39. name = "ocamlls",
  40. filetypes = { "ocaml", "reason" },
  41. }
  42. local ocaml_fts = require("lvim.lsp.utils").get_supported_filetypes(ocaml.name)
  43. assert.True(vim.deep_equal(ocaml.filetypes, ocaml_fts))
  44. local tsserver = {
  45. name = "tsserver",
  46. filetypes = {
  47. "javascript",
  48. "javascriptreact",
  49. "javascript.jsx",
  50. "typescript",
  51. "typescriptreact",
  52. "typescript.tsx",
  53. },
  54. }
  55. local tsserver_fts = require("lvim.lsp.utils").get_supported_filetypes(tsserver.name)
  56. assert.True(vim.deep_equal(tsserver.filetypes, tsserver_fts))
  57. end)
  58. a.it("shoud not include blacklisted servers in the generated templates", function()
  59. assert.True(utils.is_directory(lvim.lsp.templates_dir))
  60. require("lvim.lsp").setup()
  61. for _, file in ipairs(vim.fn.glob(lvim.lsp.templates_dir .. "/*.lua", 1, 1)) do
  62. for _, server in ipairs(lvim.lsp.override) do
  63. assert.False(utils.file_contains(file, server))
  64. end
  65. end
  66. end)
  67. end)