Skip to content

Commit

Permalink
feat: notify if mason has not been set up (#195)
Browse files Browse the repository at this point in the history
Closes #181.
  • Loading branch information
williamboman committed Apr 17, 2023
1 parent e06a620 commit 601c0ad
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 20 deletions.
2 changes: 1 addition & 1 deletion lua/mason-lspconfig/api/command.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
local Optional = require "mason-core.optional"
local _ = require "mason-core.functional"
local a = require "mason-core.async"
local notify = require "mason-core.notify"
local notify = require "mason-lspconfig.notify"

---@async
---@param user_args string[]: The arguments, as provided by the user.
Expand Down
2 changes: 1 addition & 1 deletion lua/mason-lspconfig/ensure_installed.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
local notify = require "mason-core.notify"
local notify = require "mason-lspconfig.notify"
local registry = require "mason-registry"
local settings = require "mason-lspconfig.settings"

Expand Down
9 changes: 8 additions & 1 deletion lua/mason-lspconfig/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ local M = {}

---@param config MasonLspconfigSettings | nil
function M.setup(config)
local ok, mason = pcall(require, "mason")
if not ok or mason.has_setup == false then
require "mason-lspconfig.notify"(
"mason.nvim has not been set up. Make sure to set up 'mason' before 'mason-lspconfig'. :h mason-lspconfig-quickstart",
vim.log.levels.WARN
)
end
local settings = require "mason-lspconfig.settings"

if config then
Expand Down Expand Up @@ -40,7 +47,7 @@ function M.setup_handlers(handlers)
local Optional = require "mason-core.optional"
local server_mapping = require "mason-lspconfig.mappings.server"
local registry = require "mason-registry"
local notify = require "mason-core.notify"
local notify = require "mason-lspconfig.notify"

local default_handler = Optional.of_nilable(handlers[1])

Expand Down
2 changes: 1 addition & 1 deletion lua/mason-lspconfig/install.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
local notify = require "mason-core.notify"
local notify = require "mason-lspconfig.notify"
local server_mapping = require "mason-lspconfig.mappings.server"

local M = {}
Expand Down
8 changes: 8 additions & 0 deletions lua/mason-lspconfig/notify.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
local TITLE = "mason-lspconfig.nvim"

return function(msg, level)
level = level or vim.log.levels.INFO
vim.notify(msg, level, {
title = TITLE,
})
end
2 changes: 1 addition & 1 deletion lua/mason-lspconfig/server_configurations/pylsp/init.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
local _ = require "mason-core.functional"
local a = require "mason-core.async"
local notify = require "mason-core.notify"
local notify = require "mason-lspconfig.notify"
local pip3 = require "mason-core.managers.pip3"
local process = require "mason-core.process"
local spawn = require "mason-core.spawn"
Expand Down
42 changes: 27 additions & 15 deletions tests/mason-lspconfig/setup_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -89,21 +89,27 @@ describe("mason-lspconfig setup", function()
assert.spy(vim.notify).was_called(2)
assert
.spy(vim.notify)
.was_called_with([[[mason-lspconfig.nvim] installing dummylsp]], vim.log.levels.INFO, { title = "mason.nvim" })
assert
.spy(vim.notify)
.was_called_with([[[mason-lspconfig.nvim] installing fail_dummylsp]], vim.log.levels.INFO, { title = "mason.nvim" })
.was_called_with(
[[[mason-lspconfig.nvim] installing dummylsp]],
vim.log.levels.INFO,
{ title = "mason-lspconfig.nvim" }
)
assert.spy(vim.notify).was_called_with(
[[[mason-lspconfig.nvim] installing fail_dummylsp]],
vim.log.levels.INFO,
{ title = "mason-lspconfig.nvim" }
)

assert.wait_for(function()
assert.spy(vim.notify).was_called_with(
[[[mason-lspconfig.nvim] dummylsp was successfully installed]],
vim.log.levels.INFO,
{ title = "mason.nvim" }
{ title = "mason-lspconfig.nvim" }
)
assert.spy(vim.notify).was_called_with(
[[[mason-lspconfig.nvim] failed to install fail_dummylsp. Installation logs are available in :Mason and :MasonLog]],
vim.log.levels.ERROR,
{ title = "mason.nvim" }
{ title = "mason-lspconfig.nvim" }
)
end)
end)
Expand All @@ -129,22 +135,28 @@ describe("mason-lspconfig setup", function()

assert
.spy(vim.notify)
.was_called_with([[[mason-lspconfig.nvim] installing dummylsp]], vim.log.levels.INFO, { title = "mason.nvim" })
assert
.spy(vim.notify)
.was_called_with([[[mason-lspconfig.nvim] installing fail_dummylsp]], vim.log.levels.INFO, { title = "mason.nvim" })
.was_called_with(
[[[mason-lspconfig.nvim] installing dummylsp]],
vim.log.levels.INFO,
{ title = "mason-lspconfig.nvim" }
)
assert.spy(vim.notify).was_called_with(
[[[mason-lspconfig.nvim] installing fail_dummylsp]],
vim.log.levels.INFO,
{ title = "mason-lspconfig.nvim" }
)
assert.wait_for(function()
assert.is_true(dummy.handle:is_closed())
assert.is_true(fail_dummy.handle:is_closed())
assert.spy(vim.notify).was_called_with(
[[[mason-lspconfig.nvim] dummylsp was successfully installed]],
vim.log.levels.INFO,
{ title = "mason.nvim" }
{ title = "mason-lspconfig.nvim" }
)
assert.spy(vim.notify).was_called_with(
[[[mason-lspconfig.nvim] failed to install fail_dummylsp. Installation logs are available in :Mason and :MasonLog]],
vim.log.levels.ERROR,
{ title = "mason.nvim" }
{ title = "mason-lspconfig.nvim" }
)
end)
end)
Expand Down Expand Up @@ -289,7 +301,7 @@ describe("mason-lspconfig setup_handlers", function()
assert.spy(vim.notify).was_called_with(
"mason-lspconfig.setup_handlers: Received handler for unknown lspconfig server name: doesnt_exist_server.",
vim.log.levels.WARN,
{ title = "mason.nvim" }
{ title = "mason-lspconfig.nvim" }
)
end)

Expand All @@ -307,12 +319,12 @@ describe("mason-lspconfig setup_handlers", function()
assert.spy(vim.notify).was_called_with(
[[[mason-lspconfig.nvim] Server "yamllint" is not a valid entry in ensure_installed. Make sure to only provide lspconfig server names.]],
vim.log.levels.WARN,
{ title = "mason.nvim" }
{ title = "mason-lspconfig.nvim" }
)
assert.spy(vim.notify).was_called_with(
[[[mason-lspconfig.nvim] Server "hadolint" is not a valid entry in ensure_installed. Make sure to only provide lspconfig server names.]],
vim.log.levels.WARN,
{ title = "mason.nvim" }
{ title = "mason-lspconfig.nvim" }
)
end)
)
Expand Down

0 comments on commit 601c0ad

Please sign in to comment.