aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorWilliam Boman <william@redwill.se>2022-07-22 03:15:43 +0200
committerGitHub <noreply@github.com>2022-07-22 03:15:43 +0200
commit11c0af44e69a165df41e5fe6681b47f4204d3623 (patch)
tree28bc4c9c6e7295996924d6b2ce8e620b2a963fa2 /tests
parentfeat: add markdownlint linter (#107) (diff)
downloadmason-11c0af44e69a165df41e5fe6681b47f4204d3623.tar
mason-11c0af44e69a165df41e5fe6681b47f4204d3623.tar.gz
mason-11c0af44e69a165df41e5fe6681b47f4204d3623.tar.bz2
mason-11c0af44e69a165df41e5fe6681b47f4204d3623.tar.lz
mason-11c0af44e69a165df41e5fe6681b47f4204d3623.tar.xz
mason-11c0af44e69a165df41e5fe6681b47f4204d3623.tar.zst
mason-11c0af44e69a165df41e5fe6681b47f4204d3623.zip
refactor!: extract mason-lspconfig to separate plugin (#109)
The rationale behind this is to make boundaries clearer as mason.nvim has no direct relation with lspconfig per se. Also, hopefully, by having it as a separate package like this would encourage more people to write similar extensions (think mason-dap and mason-null-ls). Ideally such extensions wouldn't be required at all, but there are definitely gaps to fill as of today. From now on you'll need to add `williamboman/mason-lspconfig.nvim` as a plugin if you want to use the `mason-lspconfig` extension: ```lua use { { "williamboman/mason.nvim", branch = "alpha" }, "williamboman/mason-lspconfig.nvim", "neovim/nvim-lspconfig", } ``` ```lua Plug "williamboman/mason.nvim", { 'branch': 'alpha' } Plug "williamboman/mason-lspconfig.nvim" Plug "neovim/nvim-lspconfig" ```
Diffstat (limited to 'tests')
-rw-r--r--tests/mason-lspconfig/api/command_spec.lua71
-rw-r--r--tests/mason-lspconfig/setup_spec.lua93
-rw-r--r--tests/minimal_debug_init.lua61
3 files changed, 0 insertions, 225 deletions
diff --git a/tests/mason-lspconfig/api/command_spec.lua b/tests/mason-lspconfig/api/command_spec.lua
deleted file mode 100644
index 0551c777..00000000
--- a/tests/mason-lspconfig/api/command_spec.lua
+++ /dev/null
@@ -1,71 +0,0 @@
-local spy = require "luassert.spy"
-local stub = require "luassert.stub"
-local match = require "luassert.match"
-
-local server_mappings = require "mason-lspconfig.mappings.server"
-local filetype_mappings = require "mason-lspconfig.mappings.filetype"
-local api = require "mason-lspconfig.api.command"
-local registry = require "mason-registry"
-local Pkg = require "mason-core.package"
-
-describe(":LspInstall", function()
- server_mappings.lspconfig_to_package["dummylsp"] = "dummy"
- server_mappings.package_to_lspconfig["dummy"] = "dummylsp"
- filetype_mappings.dummylang = { "dummylsp" }
-
- it("should install the provided servers", function()
- local dummy = registry.get_package "dummy"
- spy.on(Pkg, "install")
- api.LspInstall { "dummylsp@1.0.0" }
- assert.spy(Pkg.install).was_called(1)
- assert.spy(Pkg.install).was_called_with(match.ref(dummy), {
- version = "1.0.0",
- })
- end)
-
- it(
- "should prompt user for server to install based on filetype",
- async_test(function()
- local dummy = registry.get_package "dummy"
- spy.on(Pkg, "install")
- stub(vim.ui, "select")
- vim.ui.select.invokes(function(items, opts, callback)
- callback "dummylsp"
- end)
- vim.cmd [[new | setf dummylang]]
- api.LspInstall {}
- assert.spy(Pkg.install).was_called(1)
- assert.spy(Pkg.install).was_called_with(match.ref(dummy), {
- version = nil,
- })
- assert.spy(vim.ui.select).was_called(1)
- assert.spy(vim.ui.select).was_called_with({ "dummylsp" }, match.is_table(), match.is_function())
- end)
- )
-
- it(
- "should not prompt user for server to install if no filetype match exists",
- async_test(function()
- spy.on(Pkg, "install")
- stub(vim.ui, "select")
- vim.cmd [[new | setf nolsplang]]
- api.LspInstall {}
- assert.spy(Pkg.install).was_called(0)
- assert.spy(vim.ui.select).was_called(0)
- end)
- )
-end)
-
-describe(":LspUninstall", function()
- server_mappings.lspconfig_to_package["dummylsp"] = "dummy"
- server_mappings.package_to_lspconfig["dummy"] = "dummylsp"
- filetype_mappings.dummylang = { "dummylsp" }
-
- it("should uninstall the provided servers", function()
- local dummy = registry.get_package "dummy"
- spy.on(Pkg, "uninstall")
- api.LspUninstall { "dummylsp" }
- assert.spy(Pkg.uninstall).was_called(1)
- assert.spy(Pkg.uninstall).was_called_with(match.ref(dummy))
- end)
-end)
diff --git a/tests/mason-lspconfig/setup_spec.lua b/tests/mason-lspconfig/setup_spec.lua
deleted file mode 100644
index 64067b1c..00000000
--- a/tests/mason-lspconfig/setup_spec.lua
+++ /dev/null
@@ -1,93 +0,0 @@
-local match = require "luassert.match"
-local stub = require "luassert.stub"
-local spy = require "luassert.spy"
-
-local Pkg = require "mason-core.package"
-local mason_lspconfig = require "mason-lspconfig"
-local server_mappings = require "mason-lspconfig.mappings.server"
-local registry = require "mason-registry"
-local filetype_mappings = require "mason-lspconfig.mappings.filetype"
-
-describe("mason-lspconfig setup", function()
- server_mappings.lspconfig_to_package["dummylsp"] = "dummy"
- server_mappings.package_to_lspconfig["dummy"] = "dummylsp"
- filetype_mappings.dummylang = { "dummylsp" }
-
- it("should set up user commands", function()
- mason_lspconfig.setup()
- local user_commands = vim.api.nvim_get_commands {}
-
- assert.is_true(match.tbl_containing {
- bang = false,
- bar = false,
- nargs = "*",
- complete = "custom",
- definition = "Install one or more LSP servers.",
- }(user_commands["LspInstall"]))
-
- assert.is_true(match.tbl_containing {
- bang = false,
- bar = false,
- definition = "Uninstall one or more LSP servers.",
- nargs = "+",
- complete = "custom",
- }(user_commands["LspUninstall"]))
- end)
-
- it("should install servers listed in ensure_installed", function()
- local dummy = registry.get_package "dummy"
- spy.on(Pkg, "install")
- stub(Pkg, "is_installed")
- Pkg.is_installed.returns(false)
- mason_lspconfig.setup { ensure_installed = { "dummylsp@1.0.0" } }
- assert.spy(Pkg.install).was_called(1)
- assert.spy(Pkg.install).was_called_with(match.ref(dummy), {
- version = "1.0.0",
- })
- end)
-end)
-
-describe("mason-lspconfig setup_handlers", function()
- server_mappings.lspconfig_to_package["dummylsp"] = "dummy"
- server_mappings.package_to_lspconfig["dummy"] = "dummylsp"
- filetype_mappings.dummylang = { "dummylsp" }
-
- it("should call default handler", function()
- stub(registry, "get_installed_package_names")
- registry.get_installed_package_names.returns { "dummy" }
- local default_handler = spy.new()
-
- mason_lspconfig.setup_handlers { default_handler }
-
- assert.spy(default_handler).was_called(1)
- assert.spy(default_handler).was_called_with "dummylsp"
- end)
-
- it("should call dedicated handler", function()
- stub(registry, "get_installed_package_names")
- registry.get_installed_package_names.returns { "dummy" }
- local dedicated_handler = spy.new()
- local default_handler = spy.new()
-
- mason_lspconfig.setup_handlers {
- default_handler,
- ["dummylsp"] = dedicated_handler,
- }
-
- assert.spy(default_handler).was_called(0)
- assert.spy(dedicated_handler).was_called(1)
- assert.spy(dedicated_handler).was_called_with "dummylsp"
- end)
-
- it("should print warning if registering handler for non-existent server name", function()
- spy.on(vim, "notify")
- mason_lspconfig.setup_handlers {
- doesnt_exist_server = spy.new(),
- }
- assert.spy(vim.notify).was_called(1)
- assert.spy(vim.notify).was_called_with(
- "[mason.nvim] mason-lspconfig.setup_handlers: Received handler for unknown lspconfig server name: doesnt_exist_server.",
- vim.log.levels.WARN
- )
- end)
-end)
diff --git a/tests/minimal_debug_init.lua b/tests/minimal_debug_init.lua
deleted file mode 100644
index 82a8b0d2..00000000
--- a/tests/minimal_debug_init.lua
+++ /dev/null
@@ -1,61 +0,0 @@
-local on_windows = vim.loop.os_uname().version:match "Windows"
-
-local function join_paths(...)
- local path_sep = on_windows and "\\" or "/"
- local result = table.concat({ ... }, path_sep)
- return result
-end
-
-vim.opt.runtimepath = vim.env.VIMRUNTIME
-vim.opt.completeopt = "menu"
-
-local temp_dir = vim.loop.os_getenv "TEMP" or "/tmp"
-
-vim.opt.packpath = join_paths(temp_dir, "mason-debug", "site")
-
-local package_root = join_paths(temp_dir, "mason-debug", "site", "pack")
-local install_path = join_paths(package_root, "packer", "start", "packer.nvim")
-local compile_path = join_paths(install_path, "plugin", "packer_compiled.lua")
-
-local function load_plugins()
- require("packer").startup {
- {
- "wbthomason/packer.nvim",
- "neovim/nvim-lspconfig",
- "williamboman/mason.nvim",
- },
- config = {
- package_root = package_root,
- compile_path = compile_path,
- },
- }
-end
-
-function _G.load_config()
- local lspconfig = require "lspconfig"
-
- local function on_attach(client, bufnr)
- vim.api.nvim_buf_set_option(bufnr, "omnifunc", "v:lua.vim.lsp.omnifunc")
- end
-
- require("mason").setup {
- log = vim.log.levels.DEBUG,
- }
-
- -- ==================================================
- -- ========= SETUP RELEVANT SERVER(S) HERE! =========
- -- ==================================================
- --
- -- lspconfig.sumneko_lua.setup { on_attach = on_attach }
-end
-
-if vim.fn.isdirectory(install_path) == 0 then
- vim.fn.system { "git", "clone", "https://github.com/wbthomason/packer.nvim", install_path }
- load_plugins()
- require("packer").sync()
- vim.cmd [[autocmd User PackerComplete ++once lua load_config()]]
-else
- load_plugins()
- require("packer").sync()
- _G.load_config()
-end