Skip to content

Commit

Permalink
fix fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
dundalek committed Sep 12, 2023
1 parent aad718a commit 01d04e2
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 44 deletions.
9 changes: 2 additions & 7 deletions lua/lazy-lsp/helpers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,8 @@ local function process_config(lang_config, user_config, default_config, nix_pkg,
override.cmd = nix_pkg.cmd
end
local nix_pkgs = type(nix_pkg) == "string" and { nix_pkg } or nix_pkg.pkgs
local config = vim.tbl_extend(
"keep",
user_config or {},
override,
default_config,
lang_config.document_config.default_config
)
local config =
vim.tbl_extend("keep", user_config or {}, override, default_config, lang_config.document_config.default_config)
local original_on_new_config = config.on_new_config

config.on_new_config = function(new_config, root_path)
Expand Down
74 changes: 37 additions & 37 deletions tests/helpers_spec.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
local helpers = require("lazy-lsp.helpers")


local function make_config(config)
config.on_new_config(config, "")
return config
Expand Down Expand Up @@ -34,44 +33,51 @@ describe("lazy-lsp", function()
it("servers config can specify multiple nix packages", function()
assert.same(
{ "nix-shell", "-p", "nix_pkg_a", "nix_pkg_b", "--run", "'ls_original_cmd'" },
make_config(helpers.process_config(lang_config, nil, empty_default_config,
{ pkgs = { "nix_pkg_a", "nix_pkg_b" } })).cmd
make_config(
helpers.process_config(lang_config, nil, empty_default_config, { pkgs = { "nix_pkg_a", "nix_pkg_b" } })
).cmd
)
end)

it("servers config can override cmd", function()
assert.same(
{ "nix-shell", "-p", "nix_pkg_name", "--run", "'ls_server_cmd'" },
make_config(helpers.process_config(
lang_config,
nil,
empty_default_config,
{ cmd = { "ls_server_cmd" }, pkgs = { "nix_pkg_name" } }
)).cmd
make_config(
helpers.process_config(
lang_config,
nil,
empty_default_config,
{ cmd = { "ls_server_cmd" }, pkgs = { "nix_pkg_name" } }
)
).cmd
)
end)

it("servers config can override cmd including arguments", function()
assert.same(
{ "nix-shell", "-p", "nix_pkg_name", "--run", "'ls_server_cmd' '--lsp'" },
make_config(helpers.process_config(
lang_config,
nil,
empty_default_config,
{ cmd = { "ls_server_cmd", "--lsp" }, pkgs = { "nix_pkg_name" } }
)).cmd
make_config(
helpers.process_config(
lang_config,
nil,
empty_default_config,
{ cmd = { "ls_server_cmd", "--lsp" }, pkgs = { "nix_pkg_name" } }
)
).cmd
)
end)

it("user specified cmd takes override priority", function()
assert.same(
{ "nix-shell", "-p", "nix_pkg_name", "--run", "'ls_user_cmd'" },
make_config(helpers.process_config(
lang_config,
{ cmd = { "ls_user_cmd" } },
empty_default_config,
{ cmd = { "ls_server_cmd" }, pkgs = { "nix_pkg_name" } }
)).cmd
make_config(
helpers.process_config(
lang_config,
{ cmd = { "ls_user_cmd" } },
empty_default_config,
{ cmd = { "ls_server_cmd" }, pkgs = { "nix_pkg_name" } }
)
).cmd
)
end)

Expand Down Expand Up @@ -162,10 +168,7 @@ describe("lazy-lsp", function()
}
local config = helpers.process_config(lang_config_with_on_new_config, nil, empty_default_config, "nix_pkg_name")
config.on_new_config(config, "/some/root/path")
assert.same(
{ "nix-shell", "-p", "nix_pkg_name", "--run", "'new_cmd' '--path' '/some/root/path'" },
config.cmd
)
assert.same({ "nix-shell", "-p", "nix_pkg_name", "--run", "'new_cmd' '--path' '/some/root/path'" }, config.cmd)
end)

it("on_new_config from user config takes precedence", function()
Expand All @@ -184,8 +187,12 @@ describe("lazy-lsp", function()
new_config.cmd = { "user_config_cmd", "--path", root_path }
end,
}
local config = helpers.process_config(lang_config_with_on_new_config, user_config_with_on_new_config,
empty_default_config, "nix_pkg_name")
local config = helpers.process_config(
lang_config_with_on_new_config,
user_config_with_on_new_config,
empty_default_config,
"nix_pkg_name"
)
config.on_new_config(config, "/some/root/path")
assert.same(
{ "nix-shell", "-p", "nix_pkg_name", "--run", "'user_config_cmd' '--path' '/some/root/path'" },
Expand All @@ -199,13 +206,9 @@ describe("lazy-lsp", function()
new_config.cmd = helpers.in_shell({ "user_pkg_name" }, new_config.cmd)
end,
}
local config = helpers.process_config(lang_config, user_config, empty_default_config,
"nix_pkg_name")
local config = helpers.process_config(lang_config, user_config, empty_default_config, "nix_pkg_name")
config.on_new_config(config, "")
assert.same(
{ "nix-shell", "-p", "user_pkg_name", "--run", "'ls_original_cmd'" },
config.cmd
)
assert.same({ "nix-shell", "-p", "user_pkg_name", "--run", "'ls_original_cmd'" }, config.cmd)
end)
end)
end)
Expand Down Expand Up @@ -284,10 +287,7 @@ end)
describe("server_configs", function()
it("augments commands with nix-shell", function()
local cfg = helpers.server_configs(fake_lspconfig, fake_servers, {})
assert.same(
{ "nix-shell", "-p", "fakelsp-package", "--run", "'fakelsp-binary'" },
make_config(cfg.fakelsp).cmd
)
assert.same({ "nix-shell", "-p", "fakelsp-package", "--run", "'fakelsp-binary'" }, make_config(cfg.fakelsp).cmd)
assert.same(
{ "nix-shell", "-p", "python39Packages.python-lsp-server", "--run", "'pylsp'" },
make_config(cfg.pylsp).cmd
Expand Down

0 comments on commit 01d04e2

Please sign in to comment.