lsp_spec.lua 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. local a = require "plenary.async_lib.tests"
  2. local utils = require "utils"
  3. lvim.lsp.templates_dir = join_paths(get_runtime_dir(), "lvim", "tests", "artifacts")
  4. a.describe("lsp workflow", function()
  5. local Log = require "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("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 "plugins"
  26. require("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("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("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("lsp.utils").get_supported_filetypes(tsserver.name)
  56. assert.True(vim.deep_equal(tsserver.filetypes, tsserver_fts))
  57. end)
  58. a.it("shoud ignore all javascript servers except tsserver and tailwindcss when generating templates", function()
  59. local test_server = { name = "denols", filetypes = {} }
  60. test_server.filetypes = require("lsp.utils").get_supported_filetypes(test_server.name)
  61. assert.True(vim.tbl_contains(test_server.filetypes, "javascript"))
  62. local is_ignored = require("lsp.templates").is_ignored(test_server.name)
  63. assert.True(is_ignored)
  64. local ts_template = utils.join_paths(lvim.lsp.templates_dir, "typescript.lua")
  65. assert.True(utils.file_contains(ts_template, "tsserver"))
  66. assert.False(utils.file_contains(ts_template, test_server.name))
  67. end)
  68. a.it("shoud not include blacklisted servers in the generated templates", function()
  69. assert.True(utils.is_directory(lvim.lsp.templates_dir))
  70. require("lsp").setup()
  71. local blacklisted = { "jedi_language_server", "pylsp", "sqlls", "sqls", "angularls", "ansiblels" }
  72. for _, file in ipairs(vim.fn.glob(lvim.lsp.templates_dir .. "/*.lua", 1, 1)) do
  73. for _, server in ipairs(blacklisted) do
  74. assert.False(utils.file_contains(file, server))
  75. end
  76. end
  77. end)
  78. end)