aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWilliam Boman <william@redwill.se>2022-05-19 14:03:57 +0200
committerGitHub <noreply@github.com>2022-05-19 14:03:57 +0200
commit84c07269f66c6d3ba13cab3b8d8d1e58a91f2589 (patch)
tree29f4d72931d0abf7acf1456dd46dcad35a87070b
parentfix(erlangls): follow git tags (#708) (diff)
downloadmason-84c07269f66c6d3ba13cab3b8d8d1e58a91f2589.tar
mason-84c07269f66c6d3ba13cab3b8d8d1e58a91f2589.tar.gz
mason-84c07269f66c6d3ba13cab3b8d8d1e58a91f2589.tar.bz2
mason-84c07269f66c6d3ba13cab3b8d8d1e58a91f2589.tar.lz
mason-84c07269f66c6d3ba13cab3b8d8d1e58a91f2589.tar.xz
mason-84c07269f66c6d3ba13cab3b8d8d1e58a91f2589.tar.zst
mason-84c07269f66c6d3ba13cab3b8d8d1e58a91f2589.zip
feat(lspinfo): check that .setup() has been called to consider cmd executable (#710)
-rw-r--r--ftplugin/lspinfo.lua49
-rw-r--r--lua/nvim-lsp-installer/core/functional/init.lua2
-rw-r--r--lua/nvim-lsp-installer/core/functional/list.lua10
-rw-r--r--lua/nvim-lsp-installer/core/functional/logic.lua7
-rw-r--r--tests/core/functional/list_spec.lua10
-rw-r--r--tests/core/functional/logic_spec.lua5
6 files changed, 65 insertions, 18 deletions
diff --git a/ftplugin/lspinfo.lua b/ftplugin/lspinfo.lua
index 59303347..66680ecd 100644
--- a/ftplugin/lspinfo.lua
+++ b/ftplugin/lspinfo.lua
@@ -1,9 +1,8 @@
local servers = require "nvim-lsp-installer.servers"
-local functional = require "nvim-lsp-installer.core.functional"
+local _ = require "nvim-lsp-installer.core.functional"
+local settings = require "nvim-lsp-installer.settings"
local log = require "nvim-lsp-installer.log"
-local filter, compose = functional.filter, functional.compose
-
---@class LspInfoClient
---@field name string
---@field cmd string[]
@@ -33,6 +32,9 @@ local function is_cmd_executable(client)
-- should not really happen
return false
end
+ if not settings.uses_new_setup then
+ return false
+ end
local options = server:get_default_options()
local path = options.cmd_env and options.cmd_env.PATH
if path then
@@ -90,25 +92,36 @@ local ok, err = pcall(function()
end
---@type LspInfoClient[]
- local executable_clients = compose(
- filter(is_cmd_executable),
- filter(client_has_cmd),
- filter(client_has_cmd_diagnostics),
- filter(is_client_managed)
+ local clients_with_diagnostics = _.compose(
+ _.filter(client_has_cmd),
+ _.filter(client_has_cmd_diagnostics),
+ _.filter(is_client_managed)
)(clients)
- local override_cmd_diagnostics = functional.partial(functional.each, function(client)
- vim.api.nvim_buf_set_lines(
- 0,
- client.cmd_diagnostics.lineno,
- client.cmd_diagnostics.lineno + 1,
- false,
- { " cmd is executable: true (checked by nvim-lsp-installer)" }
- )
- end)
+ local executable_clients = _.filter(is_cmd_executable, clients_with_diagnostics)
+ local unexecutable_clients = _.filter(_.complement(is_cmd_executable), clients_with_diagnostics)
+
+ ---@param diagnostics_lines string
+ ---@param clients LspInfoClient[]
+ local override_cmd_diagnostics = function(diagnostics_lines, clients)
+ local indentation = " "
+ return _.each(function(client)
+ vim.api.nvim_buf_set_lines(
+ 0,
+ client.cmd_diagnostics.lineno,
+ client.cmd_diagnostics.lineno + 1,
+ false,
+ _.map(_.concat(indentation), diagnostics_lines)
+ )
+ end, clients)
+ end
vim.api.nvim_buf_set_option(0, "modifiable", true)
- override_cmd_diagnostics(executable_clients)
+ override_cmd_diagnostics({ "cmd is executable: true (checked by nvim-lsp-installer)" }, executable_clients)
+ override_cmd_diagnostics({
+ "cmd is executable: false (checked by nvim-lsp-installer)",
+ " Make sure you have set up nvim-lsp-installer (:h nvim-lsp-installer-quickstart)",
+ }, unexecutable_clients)
vim.api.nvim_buf_set_option(0, "modifiable", false)
end)
diff --git a/lua/nvim-lsp-installer/core/functional/init.lua b/lua/nvim-lsp-installer/core/functional/init.lua
index 45a09ea6..9337ccef 100644
--- a/lua/nvim-lsp-installer/core/functional/init.lua
+++ b/lua/nvim-lsp-installer/core/functional/init.lua
@@ -28,6 +28,7 @@ _.any = list.any
_.filter = list.filter
_.map = list.map
_.each = list.each
+_.concat = list.concat
-- relation
local relation = require "nvim-lsp-installer.core.functional.relation"
@@ -40,6 +41,7 @@ local logic = require "nvim-lsp-installer.core.functional.logic"
_.all_pass = logic.all_pass
_.if_else = logic.if_else
_.is_not = logic.is_not
+_.complement = logic.complement
_.cond = logic.cond
-- number
diff --git a/lua/nvim-lsp-installer/core/functional/list.lua b/lua/nvim-lsp-installer/core/functional/list.lua
index 666de4d3..11742f1c 100644
--- a/lua/nvim-lsp-installer/core/functional/list.lua
+++ b/lua/nvim-lsp-installer/core/functional/list.lua
@@ -77,4 +77,14 @@ end, 2)
---@return T[] @A shallow copy of the list.
_.list_copy = _.map(fun.identity)
+_.concat = fun.curryN(function(a, b)
+ if type(a) == "table" then
+ assert(type(b) == "table", "concat: expected table")
+ return vim.list_extend(_.list_copy(a), b)
+ elseif type(a) == "string" then
+ assert(type(b) == "string", "concat: expected string")
+ return a .. b
+ end
+end, 2)
+
return _
diff --git a/lua/nvim-lsp-installer/core/functional/logic.lua b/lua/nvim-lsp-installer/core/functional/logic.lua
index 262f04a8..70b349dd 100644
--- a/lua/nvim-lsp-installer/core/functional/logic.lua
+++ b/lua/nvim-lsp-installer/core/functional/logic.lua
@@ -32,6 +32,13 @@ _.is_not = function(value)
return not value
end
+---@generic T
+---@param predicate fun(value: T): boolean
+---@param value T
+_.complement = fun.curryN(function(predicate, value)
+ return not predicate(value)
+end, 2)
+
_.cond = fun.curryN(function(predicate_transformer_pairs, value)
for _, pair in ipairs(predicate_transformer_pairs) do
local predicate, transformer = pair[1], pair[2]
diff --git a/tests/core/functional/list_spec.lua b/tests/core/functional/list_spec.lua
index c553a7d0..7fa644f2 100644
--- a/tests/core/functional/list_spec.lua
+++ b/tests/core/functional/list_spec.lua
@@ -84,4 +84,14 @@ describe("functional: list", function()
assert.spy(iterate_fn).was_called_with("YELLOW", 2)
assert.spy(iterate_fn).was_called_with("RED", 3)
end)
+
+ it("should concat list tables", function()
+ local list = { "monstera", "tulipa", "carnation" }
+ assert.same({ "monstera", "tulipa", "carnation", "rose", "daisy" }, _.concat(list, { "rose", "daisy" }))
+ assert.same({ "monstera", "tulipa", "carnation" }, list) -- does not mutate list
+ end)
+
+ it("should concat strings", function()
+ assert.equals("FooBar", _.concat("Foo", "Bar"))
+ end)
end)
diff --git a/tests/core/functional/logic_spec.lua b/tests/core/functional/logic_spec.lua
index 19ac8bb7..291d8979 100644
--- a/tests/core/functional/logic_spec.lua
+++ b/tests/core/functional/logic_spec.lua
@@ -41,4 +41,9 @@ describe("functional: logic", function()
assert.equals("Hello World!", planetary_object "World!")
assert.equals("to the Moon!", planetary_object "Moon!")
end)
+
+ it("should give complements", function()
+ assert.is_true(_.complement(_.is_nil, "not nil"))
+ assert.is_false(_.complement(_.is_nil, nil))
+ end)
end)