summaryrefslogtreecommitdiff
path: root/tests/lsp_spec.lua
blob: 1695bdb460592428dd90dcb42f9d5e1993401b79 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
local a = require "plenary.async_lib.tests"
local utils = require "utils"
lvim.lsp.templates_dir = join_paths(get_runtime_dir(), "lvim", "tests", "artifacts")

a.describe("lsp workflow", function()
  local Log = require "core.log"
  local logfile = Log:get_path()

  a.it("shoud be able to delete ftplugin templates", function()
    if utils.is_directory(lvim.lsp.templates_dir) then
      assert.equal(vim.fn.delete(lvim.lsp.templates_dir, "rf"), 0)
    end
    assert.False(utils.is_directory(lvim.lsp.templates_dir))
  end)

  a.it("shoud be able to generate ftplugin templates", function()
    if utils.is_directory(lvim.lsp.templates_dir) then
      assert.equal(vim.fn.delete(lvim.lsp.templates_dir, "rf"), 0)
    end
    require("lsp").setup()

    -- we need to delay this check until the generation is completed
    vim.schedule(function()
      assert.True(utils.is_directory(lvim.lsp.templates_dir))
    end)
  end)

  a.it("shoud not attempt to re-generate ftplugin templates", function()
    lvim.log.level = "debug"

    local plugins = require "plugins"
    require("plugin-loader"):load { plugins, lvim.plugins }

    if utils.is_file(logfile) then
      assert.equal(vim.fn.delete(logfile), 0)
    end

    assert.True(utils.is_directory(lvim.lsp.templates_dir))
    require("lsp").setup()

    -- we need to delay this check until the log gets populated
    vim.schedule(function()
      assert.False(utils.log_contains "templates")
    end)
  end)

  a.it("shoud retrieve supported filetypes correctly", function()
    local ocaml = {
      name = "ocamlls",
      filetypes = { "ocaml", "reason" },
    }
    local ocaml_fts = require("lsp.utils").get_supported_filetypes(ocaml.name)
    assert.True(vim.deep_equal(ocaml.filetypes, ocaml_fts))

    local tsserver = {
      name = "tsserver",
      filetypes = {
        "javascript",
        "javascriptreact",
        "javascript.jsx",
        "typescript",
        "typescriptreact",
        "typescript.tsx",
      },
    }
    local tsserver_fts = require("lsp.utils").get_supported_filetypes(tsserver.name)
    assert.True(vim.deep_equal(tsserver.filetypes, tsserver_fts))
  end)

  a.it("shoud ignore all javascript servers except tsserver and tailwindcss when generating templates", function()
    local test_server = { name = "denols", filetypes = {} }
    test_server.filetypes = require("lsp.utils").get_supported_filetypes(test_server.name)

    assert.True(vim.tbl_contains(test_server.filetypes, "javascript"))

    local is_ignored = require("lsp.templates").is_ignored(test_server.name)
    assert.True(is_ignored)

    local ts_template = utils.join_paths(lvim.lsp.templates_dir, "typescript.lua")

    assert.True(utils.file_contains(ts_template, "tsserver"))
    assert.True(utils.file_contains(ts_template, "tailwindcss"))
    assert.False(utils.file_contains(ts_template, test_server.name))
  end)

  a.it("shoud not include blacklisted servers in the generated templates", function()
    assert.True(utils.is_directory(lvim.lsp.templates_dir))
    require("lsp").setup()

    local blacklisted = { "jedi_language_server", "pylsp", "sqlls", "sqls", "angularls", "ansiblels" }

    for _, file in ipairs(vim.fn.glob(lvim.lsp.templates_dir .. "/*.lua", 1, 1)) do
      for _, server in ipairs(blacklisted) do
        assert.False(utils.file_contains(file, server))
      end
    end
  end)
end)