aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWilliam Boman <william@redwill.se>2022-02-21 20:56:16 +0100
committerGitHub <noreply@github.com>2022-02-21 20:56:16 +0100
commit12d97eeabf44c2dd2cf841db218aac449022143d (patch)
tree5c8b996a262761ae2433663351861e505dbceb8d
parentrun autogen_metadata.lua (diff)
downloadmason-12d97eeabf44c2dd2cf841db218aac449022143d.tar
mason-12d97eeabf44c2dd2cf841db218aac449022143d.tar.gz
mason-12d97eeabf44c2dd2cf841db218aac449022143d.tar.bz2
mason-12d97eeabf44c2dd2cf841db218aac449022143d.tar.lz
mason-12d97eeabf44c2dd2cf841db218aac449022143d.tar.xz
mason-12d97eeabf44c2dd2cf841db218aac449022143d.tar.zst
mason-12d97eeabf44c2dd2cf841db218aac449022143d.zip
feat: add async module (#499)
-rw-r--r--.github/workflows/metadata-diff.yml1
-rw-r--r--.github/workflows/run-autogen.yml1
-rw-r--r--lua/nvim-lsp-installer/core/async/init.lua107
-rw-r--r--scripts/autogen_metadata.lua47
-rwxr-xr-xscripts/autogen_metadata.sh3
-rw-r--r--tests/core/async_spec.lua50
-rw-r--r--tests/core/process_spec.lua117
-rw-r--r--tests/luassertx/lua/luassertx.lua15
-rw-r--r--tests/server_spec.lua77
-rw-r--r--tests/ui_spec.lua198
10 files changed, 408 insertions, 208 deletions
diff --git a/.github/workflows/metadata-diff.yml b/.github/workflows/metadata-diff.yml
index 58603822..024c8b61 100644
--- a/.github/workflows/metadata-diff.yml
+++ b/.github/workflows/metadata-diff.yml
@@ -19,7 +19,6 @@ jobs:
run: |
mkdir -p ~/.local/share/nvim/site/pack/packer/start
git clone --depth 1 https://github.com/neovim/nvim-lspconfig ~/.local/share/nvim/site/pack/packer/start/nvim-lspconfig
- git clone --depth 1 https://github.com/nvim-lua/plenary.nvim ~/.local/share/nvim/site/pack/packer/start/plenary.nvim
- name: Run autogen_metadata.sh script
run: ./scripts/autogen_metadata.sh
- name: Ensure there are no diffs
diff --git a/.github/workflows/run-autogen.yml b/.github/workflows/run-autogen.yml
index 1eaffb82..99374c3c 100644
--- a/.github/workflows/run-autogen.yml
+++ b/.github/workflows/run-autogen.yml
@@ -20,7 +20,6 @@ jobs:
run: |
mkdir -p ~/.local/share/nvim/site/pack/packer/start
git clone --depth 1 https://github.com/neovim/nvim-lspconfig ~/.local/share/nvim/site/pack/packer/start/nvim-lspconfig
- git clone --depth 1 https://github.com/nvim-lua/plenary.nvim ~/.local/share/nvim/site/pack/packer/start/plenary.nvim
- name: Run autogen_metadata.sh script
run: ./scripts/autogen_metadata.sh
diff --git a/lua/nvim-lsp-installer/core/async/init.lua b/lua/nvim-lsp-installer/core/async/init.lua
new file mode 100644
index 00000000..a9c1704c
--- /dev/null
+++ b/lua/nvim-lsp-installer/core/async/init.lua
@@ -0,0 +1,107 @@
+local co = coroutine
+
+local exports = {}
+
+local Promise = {}
+Promise.__index = Promise
+
+function Promise.new(resolver)
+ return setmetatable({ resolver = resolver }, Promise)
+end
+
+function Promise:__call(callback)
+ self.resolver(function(...)
+ callback(true, ...)
+ end, function(...)
+ callback(false, ...)
+ end)
+end
+
+local function await(resolver)
+ return co.yield(Promise.new(resolver))
+end
+
+local function table_pack(...)
+ return { n = select("#", ...), ... }
+end
+
+local function promisify(async_fn)
+ return function(...)
+ local args = table_pack(...)
+ return await(function(resolve)
+ args[args.n + 1] = resolve
+ async_fn(unpack(args, 1, args.n + 1))
+ end)
+ end
+end
+
+local function new_execution_context(suspend_fn, callback, ...)
+ local thread = co.create(suspend_fn)
+ local cancelled = false
+ local step
+ step = function(...)
+ if cancelled then
+ return
+ end
+ local ok, promise_or_result = co.resume(thread, ...)
+ if ok then
+ if getmetatable(promise_or_result) == Promise then
+ promise_or_result(step)
+ else
+ callback(true, promise_or_result)
+ thread = nil
+ end
+ else
+ callback(false, promise_or_result)
+ thread = nil
+ end
+ end
+
+ step(...)
+ return function()
+ cancelled = true
+ thread = nil
+ end
+end
+
+exports.scope = function(suspend_fn)
+ return function(...)
+ return new_execution_context(suspend_fn, function() end, ...)
+ end
+end
+
+exports.run_blocking = function(suspend_fn)
+ local resolved, ok, result
+ local cancel_coroutine = new_execution_context(suspend_fn, function(a, b)
+ resolved = true
+ ok = a
+ result = b
+ end)
+
+ if vim.wait(60000, function()
+ return resolved == true
+ end, 50) then
+ if not ok then
+ error(result)
+ end
+ return result
+ else
+ cancel_coroutine()
+ error "async function failed to resolve in time."
+ end
+end
+
+exports.wait = await
+exports.promisify = promisify
+
+exports.sleep = function(ms)
+ await(function(resolve)
+ vim.defer_fn(resolve, ms)
+ end)
+end
+
+exports.scheduler = function()
+ await(vim.schedule)
+end
+
+return exports
diff --git a/scripts/autogen_metadata.lua b/scripts/autogen_metadata.lua
index 8f6217a2..cca9a410 100644
--- a/scripts/autogen_metadata.lua
+++ b/scripts/autogen_metadata.lua
@@ -1,7 +1,7 @@
local uv = vim.loop
-local a = require "plenary.async"
-local curl = require "plenary.curl"
+local a = require "nvim-lsp-installer.core.async"
local Path = require "nvim-lsp-installer.path"
+local fetch = require "nvim-lsp-installer.core.fetch"
local Data = require "nvim-lsp-installer.data"
local coalesce = Data.coalesce
@@ -67,14 +67,14 @@ local function get_supported_filetypes(server)
local default_options = server:get_default_options()
local filetypes = coalesce(
-- nvim-lsp-installer options has precedence
- default_options.filetypes,
+ default_options and default_options.filetypes,
config.default_config.filetypes,
{}
)
return filetypes
end
-local create_filetype_map = a.void(function()
+local function create_filetype_map()
local filetype_map = {}
local available_servers = servers.get_available_servers()
@@ -89,9 +89,9 @@ local create_filetype_map = a.void(function()
end
write_file(Path.concat { generated_dir, "filetype_map.lua" }, "return " .. vim.inspect(filetype_map), "w")
-end)
+end
-local create_autocomplete_map = a.void(function()
+local function create_autocomplete_map()
---@type table<string, Server>
local language_map = {}
@@ -131,9 +131,9 @@ local create_autocomplete_map = a.void(function()
"return " .. vim.inspect(autocomplete_candidates),
"w"
)
-end)
+end
-local create_server_metadata = a.void(function()
+local function create_server_metadata()
local metadata = {}
---@param server Server
@@ -147,21 +147,24 @@ local create_server_metadata = a.void(function()
end
write_file(Path.concat { generated_dir, "metadata.lua" }, "return " .. vim.inspect(metadata), "w")
-end)
+end
-local create_setting_schema_files = a.void(function()
+local function create_setting_schema_files()
local available_servers = servers.get_available_servers()
- local gist_response =
- a.wrap(curl.get, 1) "https://gist.githubusercontent.com/williamboman/a01c3ce1884d4b57cc93422e7eae7702/raw/lsp-packages.json"
- local package_json_mappings = vim.json.decode(gist_response.body)
+ local gist_ok, gist_err, gist_response =
+ a.promisify(fetch) "https://gist.githubusercontent.com/williamboman/a01c3ce1884d4b57cc93422e7eae7702/raw/lsp-packages.json"
+ assert(gist_ok, "Failed to fetch gist.")
+ assert(not gist_err, "Failed to fetch gist.")
+ local package_json_mappings = vim.json.decode(gist_response)
for _, server in pairs(available_servers) do
local package_json_url = package_json_mappings[server.name]
if package_json_url then
print(("Fetching %q..."):format(package_json_url))
- local response = a.wrap(curl.get, 1)(package_json_url)
- assert(response.status == 200, "Failed to fetch package.json for " .. server.name)
- local schema = vim.json.decode(response.body)
+ local ok, err, response = a.promisify(fetch)(package_json_url)
+ assert(ok, "Failed to fetch.")
+ assert(not err, "Failed to fetch package.json for " .. server.name)
+ local schema = vim.json.decode(response)
if schema.contributes and schema.contributes.configuration then
schema = schema.contributes.configuration
end
@@ -177,9 +180,11 @@ local create_setting_schema_files = a.void(function()
end
end
end
-end)
+end
-create_filetype_map()
-create_autocomplete_map()
-create_server_metadata()
-create_setting_schema_files()
+a.run_blocking(function()
+ create_filetype_map()
+ create_autocomplete_map()
+ create_server_metadata()
+ create_setting_schema_files()
+end)
diff --git a/scripts/autogen_metadata.sh b/scripts/autogen_metadata.sh
index 9e2339cf..970a2cb3 100755
--- a/scripts/autogen_metadata.sh
+++ b/scripts/autogen_metadata.sh
@@ -5,9 +5,8 @@ declare -x XDG_DATA_HOME="${XDG_DATA_HOME:-"$HOME/.local/share"}"
declare -x NVIM_PACK_DIR="$XDG_DATA_HOME/nvim/site/pack"
declare -x LSP_CONFIG_DIR="$NVIM_PACK_DIR/packer/start/nvim-lspconfig"
-declare -x PLENARY_DIR="$NVIM_PACK_DIR/packer/start/plenary.nvim"
declare -x LSP_INSTALLER_DIR="$PWD"
nvim -u NONE -E -R --headless \
- --cmd "set rtp+=${PLENARY_DIR},${LSP_CONFIG_DIR},${LSP_INSTALLER_DIR}" \
+ --cmd "set rtp+=${LSP_CONFIG_DIR},${LSP_INSTALLER_DIR}" \
+"luafile scripts/autogen_metadata.lua" +q
diff --git a/tests/core/async_spec.lua b/tests/core/async_spec.lua
new file mode 100644
index 00000000..42c1fe65
--- /dev/null
+++ b/tests/core/async_spec.lua
@@ -0,0 +1,50 @@
+local assert = require "luassert"
+local spy = require "luassert.spy"
+local a = require "nvim-lsp-installer.core.async"
+local process = require "nvim-lsp-installer.process"
+
+local function timestamp()
+ local seconds, microseconds = vim.loop.gettimeofday()
+ return (seconds * 1000) + math.floor(microseconds / 1000)
+end
+
+describe("async", function()
+ it("should run in blocking mode", function()
+ local start = timestamp()
+ a.run_blocking(function()
+ a.sleep(1000)
+ end)
+ local stop = timestamp()
+ local grace_ms = 5
+ assert.is_true((stop - start) >= (1000 - grace_ms))
+ end)
+
+ it(
+ "should wrap callback-style async functions",
+ async_test(function()
+ local stdio = process.in_memory_sink()
+ local ok, success = a.promisify(process.spawn)("env", {
+ args = {},
+ env = { "FOO=BAR", "BAR=BAZ" },
+ stdio_sink = stdio.sink,
+ })
+ assert.is_true(ok)
+ assert.is_true(success)
+ assert.equals("FOO=BAR\nBAR=BAZ\n", table.concat(stdio.buffers.stdout, ""))
+ end)
+ )
+
+ it(
+ "should cancel coroutine",
+ async_test(function()
+ local james_bond = spy.new()
+ local poutine = a.scope(function()
+ a.sleep(100)
+ james_bond()
+ end)()
+ poutine()
+ a.sleep(200)
+ assert.spy(james_bond).was_not.called()
+ end)
+ )
+end)
diff --git a/tests/core/process_spec.lua b/tests/core/process_spec.lua
index 17ff0822..2db42865 100644
--- a/tests/core/process_spec.lua
+++ b/tests/core/process_spec.lua
@@ -63,74 +63,83 @@ end)
describe("process.spawn", function()
-- Unix only
- async.tests.it("should spawn command and feed output to sink", function()
- local stdio = process.in_memory_sink()
- local callback = spy.new()
- process.spawn("env", {
- args = {},
- env = {
- "HELLO=world",
- "MY_ENV=var",
- },
- stdio_sink = stdio.sink,
- }, callback)
+ it(
+ "should spawn command and feed output to sink",
+ async_test(function()
+ local stdio = process.in_memory_sink()
+ local callback = spy.new()
+ process.spawn("env", {
+ args = {},
+ env = {
+ "HELLO=world",
+ "MY_ENV=var",
+ },
+ stdio_sink = stdio.sink,
+ }, callback)
- assert.wait_for(function()
- assert.spy(callback).was_called(1)
- assert.spy(callback).was_called_with(true)
- assert.equal(table.concat(stdio.buffers.stdout, ""), "HELLO=world\nMY_ENV=var\n")
+ assert.wait_for(function()
+ assert.spy(callback).was_called(1)
+ assert.spy(callback).was_called_with(true)
+ assert.equal(table.concat(stdio.buffers.stdout, ""), "HELLO=world\nMY_ENV=var\n")
+ end)
end)
- end)
+ )
end)
describe("process.chain", function()
-- Unix only
- async.tests.it("should chain commands", function()
- local stdio = process.in_memory_sink()
- local callback = spy.new()
+ it(
+ "should chain commands",
+ async_test(function()
+ local stdio = process.in_memory_sink()
+ local callback = spy.new()
- local c = process.chain {
- env = {
- "HELLO=world",
- "MY_ENV=var",
- },
- stdio_sink = stdio.sink,
- }
+ local c = process.chain {
+ env = {
+ "HELLO=world",
+ "MY_ENV=var",
+ },
+ stdio_sink = stdio.sink,
+ }
- c.run("env", {})
- c.run("bash", { "-c", "echo Hello $HELLO" })
- c.spawn(callback)
+ c.run("env", {})
+ c.run("bash", { "-c", "echo Hello $HELLO" })
+ c.spawn(callback)
- assert.wait_for(function()
- assert.spy(callback).was_called(1)
- assert.spy(callback).was_called_with(true)
- assert.equal(table.concat(stdio.buffers.stdout, ""), "HELLO=world\nMY_ENV=var\nHello world\n")
+ assert.wait_for(function()
+ assert.spy(callback).was_called(1)
+ assert.spy(callback).was_called_with(true)
+ assert.equal(table.concat(stdio.buffers.stdout, ""), "HELLO=world\nMY_ENV=var\nHello world\n")
+ end)
end)
- end)
+ )
-- Unix only
- async.tests.it("should abort chain commands should one fail", function()
- local stdio = process.in_memory_sink()
- local callback = spy.new()
+ it(
+ "should abort chain commands should one fail",
+ async_test(function()
+ local stdio = process.in_memory_sink()
+ local callback = spy.new()
- local c = process.chain {
- env = {
- "HELLO=world",
- "MY_ENV=var",
- },
- stdio_sink = stdio.sink,
- }
+ local c = process.chain {
+ env = {
+ "HELLO=world",
+ "MY_ENV=var",
+ },
+ stdio_sink = stdio.sink,
+ }
- c.run("env", {})
- c.run("bash", { "-c", ">&2 echo Uh oh; exit 1" })
- c.run("bash", { "-c", "echo Hello $HELLO" })
- c.spawn(callback)
+ c.run("env", {})
+ c.run("bash", { "-c", ">&2 echo Uh oh; exit 1" })
+ c.run("bash", { "-c", "echo Hello $HELLO" })
+ c.spawn(callback)
- assert.wait_for(function()
- assert.spy(callback).was_called(1)
- assert.spy(callback).was_called_with(false)
- assert.equal(table.concat(stdio.buffers.stdout, ""), "HELLO=world\nMY_ENV=var\n")
- assert.equal(table.concat(stdio.buffers.stderr, ""), "Uh oh\n")
+ assert.wait_for(function()
+ assert.spy(callback).was_called(1)
+ assert.spy(callback).was_called_with(false)
+ assert.equal(table.concat(stdio.buffers.stdout, ""), "HELLO=world\nMY_ENV=var\n")
+ assert.equal(table.concat(stdio.buffers.stderr, ""), "Uh oh\n")
+ end)
end)
- end)
+ )
end)
diff --git a/tests/luassertx/lua/luassertx.lua b/tests/luassertx/lua/luassertx.lua
index 33fa9957..0722a6d7 100644
--- a/tests/luassertx/lua/luassertx.lua
+++ b/tests/luassertx/lua/luassertx.lua
@@ -1,6 +1,17 @@
-local a = require "plenary.async"
+local a = require "nvim-lsp-installer.core.async"
local assert = require "luassert"
+local util = require "luassert.util"
+
+function async_test(suspend_fn)
+ return function()
+ local ok, err = pcall(a.run_blocking, suspend_fn)
+ if not ok then
+ error(err, util.errorlevel())
+ end
+ end
+end
+
local function wait_for(_, arguments)
---@type fun() @Function to execute until it does not error.
local assertions_fn = arguments[1]
@@ -13,7 +24,7 @@ local function wait_for(_, arguments)
repeat
is_ok, err = pcall(assertions_fn)
if not is_ok then
- a.util.sleep(math.min(timeout, 100))
+ a.sleep(math.min(timeout, 100))
end
until is_ok or ((vim.loop.hrtime() - start) / 1e6) > timeout
diff --git a/tests/server_spec.lua b/tests/server_spec.lua
index 53507d27..5204fb69 100644
--- a/tests/server_spec.lua
+++ b/tests/server_spec.lua
@@ -1,44 +1,55 @@
+local spy = require "luassert.spy"
+local match = require "luassert.match"
local lsp_installer = require "nvim-lsp-installer"
local server = require "nvim-lsp-installer.server"
-local spy = require "luassert.spy"
-local a = require "plenary.async"
+local a = require "nvim-lsp-installer.core.async"
+local std = require "nvim-lsp-installer.installers.std"
+local fs = require "nvim-lsp-installer.fs"
+local path = require "nvim-lsp-installer.path"
+local settings = require "nvim-lsp-installer.settings"
describe("server", function()
- a.tests.it("calls registered on_ready handlers upon successful installation", function()
- local on_ready_handler = spy.new()
- local generic_handler = spy.new()
+ it(
+ "calls registered on_ready handlers upon successful installation",
+ async_test(function()
+ local on_ready_handler = spy.new()
+ local generic_handler = spy.new()
- lsp_installer.on_server_ready(generic_handler)
+ lsp_installer.on_server_ready(generic_handler)
- local srv = ServerGenerator {
- name = "on_ready_fixture",
- root_dir = server.get_server_root_path "on_ready_fixture",
- }
- srv:on_ready(on_ready_handler)
- srv:install()
- assert.wait_for(function()
- assert.spy(on_ready_handler).was_called(1)
- assert.spy(generic_handler).was_called(1)
- assert.spy(generic_handler).was_called_with(srv)
+ local srv = ServerGenerator {
+ name = "on_ready_fixture",
+ root_dir = server.get_server_root_path "on_ready_fixture",
+ }
+ srv:on_ready(on_ready_handler)
+ srv:install()
+ assert.wait_for(function()
+ assert.spy(on_ready_handler).was_called(1)
+ assert.spy(generic_handler).was_called(1)
+ assert.spy(generic_handler).was_called_with(srv)
+ end)
+ assert.is_true(srv:is_installed())
end)
- assert.is_true(srv:is_installed())
- end)
+ )
- a.tests.it("doesn't call on_ready handler when server fails installation", function()
- local on_ready_handler = spy.new()
- local generic_handler = spy.new()
+ it(
+ "doesn't call on_ready handler when server fails installation",
+ async_test(function()
+ local on_ready_handler = spy.new()
+ local generic_handler = spy.new()
- lsp_installer.on_server_ready(generic_handler)
+ lsp_installer.on_server_ready(generic_handler)
- local srv = FailingServerGenerator {
- name = "on_ready_fixture_failing",
- root_dir = server.get_server_root_path "on_ready_fixture_failing",
- }
- srv:on_ready(on_ready_handler)
- srv:install()
- a.util.sleep(500)
- assert.spy(on_ready_handler).was_not_called()
- assert.spy(generic_handler).was_not_called()
- assert.is_false(srv:is_installed())
- end)
+ local srv = FailingServerGenerator {
+ name = "on_ready_fixture_failing",
+ root_dir = server.get_server_root_path "on_ready_fixture_failing",
+ }
+ srv:on_ready(on_ready_handler)
+ srv:install()
+ a.sleep(500)
+ assert.spy(on_ready_handler).was_not_called()
+ assert.spy(generic_handler).was_not_called()
+ assert.is_false(srv:is_installed())
+ end)
+ )
end)
diff --git a/tests/ui_spec.lua b/tests/ui_spec.lua
index df771a4d..0c075eef 100644
--- a/tests/ui_spec.lua
+++ b/tests/ui_spec.lua
@@ -2,7 +2,7 @@ local display = require "nvim-lsp-installer.ui.display"
local match = require "luassert.match"
local spy = require "luassert.spy"
local Ui = require "nvim-lsp-installer.ui"
-local a = require "plenary.async"
+local a = require "nvim-lsp-installer.core.async"
describe("ui", function()
it("produces a correct tree", function()
@@ -136,114 +136,124 @@ describe("ui", function()
end)
describe("integration test", function()
- a.tests.it("calls vim APIs as expected during rendering", function()
- local window = display.new_view_only_win "test"
+ it(
+ "calls vim APIs as expected during rendering",
+ async_test(function()
+ local window = display.new_view_only_win "test"
- window.view(function(state)
- return Ui.Node {
- Ui.Keybind("U", "EFFECT", nil, true),
- Ui.Text {
- "Line number 1!",
- state.text,
- },
- Ui.Keybind("R", "R_EFFECT", { state.text }),
- Ui.HlTextNode {
- {
- { "My highlighted text", "MyHighlightGroup" },
+ window.view(function(state)
+ return Ui.Node {
+ Ui.Keybind("U", "EFFECT", nil, true),
+ Ui.Text {
+ "Line number 1!",
+ state.text,
+ },
+ Ui.Keybind("R", "R_EFFECT", { state.text }),
+ Ui.HlTextNode {
+ {
+ { "My highlighted text", "MyHighlightGroup" },
+ },
},
+ }
+ end)
+
+ local mutate_state = window.init { text = "Initial state" }
+
+ window.open {
+ effects = {
+ ["EFFECT"] = function() end,
+ ["R_EFFECT"] = function() end,
+ },
+ highlight_groups = {
+ "hi def MyHighlight gui=bold",
},
}
- end)
- local mutate_state = window.init { text = "Initial state" }
+ local clear_namespace = spy.on(vim.api, "nvim_buf_clear_namespace")
+ local buf_set_option = spy.on(vim.api, "nvim_buf_set_option")
+ local win_set_option = spy.on(vim.api, "nvim_win_set_option")
+ local set_lines = spy.on(vim.api, "nvim_buf_set_lines")
+ local set_extmark = spy.on(vim.api, "nvim_buf_set_extmark")
+ local add_highlight = spy.on(vim.api, "nvim_buf_add_highlight")
+ local set_keymap = spy.on(vim.api, "nvim_buf_set_keymap")
- window.open {
- effects = {
- ["EFFECT"] = function() end,
- ["R_EFFECT"] = function() end,
- },
- highlight_groups = {
- "hi def MyHighlight gui=bold",
- },
- }
+ -- Initial window and buffer creation + initial render
+ a.scheduler()
- local clear_namespace = spy.on(vim.api, "nvim_buf_clear_namespace")
- local buf_set_option = spy.on(vim.api, "nvim_buf_set_option")
- local win_set_option = spy.on(vim.api, "nvim_win_set_option")
- local set_lines = spy.on(vim.api, "nvim_buf_set_lines")
- local set_extmark = spy.on(vim.api, "nvim_buf_set_extmark")
- local add_highlight = spy.on(vim.api, "nvim_buf_add_highlight")
- local set_keymap = spy.on(vim.api, "nvim_buf_set_keymap")
+ assert.spy(win_set_option).was_called(8)
+ assert.spy(win_set_option).was_called_with(match.is_number(), "number", false)
+ assert.spy(win_set_option).was_called_with(match.is_number(), "relativenumber", false)
+ assert.spy(win_set_option).was_called_with(match.is_number(), "wrap", false)
+ assert.spy(win_set_option).was_called_with(match.is_number(), "spell", false)
+ assert.spy(win_set_option).was_called_with(match.is_number(), "foldenable", false)
+ assert.spy(win_set_option).was_called_with(match.is_number(), "signcolumn", "no")
+ assert.spy(win_set_option).was_called_with(match.is_number(), "colorcolumn", "")
+ assert.spy(win_set_option).was_called_with(match.is_number(), "cursorline", true)
- -- Initial window and buffer creation + initial render
- a.util.scheduler()
+ assert.spy(buf_set_option).was_called(9)
+ assert.spy(buf_set_option).was_called_with(match.is_number(), "modifiable", false)
+ assert.spy(buf_set_option).was_called_with(match.is_number(), "swapfile", false)
+ assert.spy(buf_set_option).was_called_with(match.is_number(), "textwidth", 0)
+ assert.spy(buf_set_option).was_called_with(match.is_number(), "buftype", "nofile")
+ assert.spy(buf_set_option).was_called_with(match.is_number(), "bufhidden", "wipe")
+ assert.spy(buf_set_option).was_called_with(match.is_number(), "buflisted", false)
+ assert.spy(buf_set_option).was_called_with(match.is_number(), "filetype", "lsp-installer")
- assert.spy(win_set_option).was_called(8)
- assert.spy(win_set_option).was_called_with(match.is_number(), "number", false)
- assert.spy(win_set_option).was_called_with(match.is_number(), "relativenumber", false)
- assert.spy(win_set_option).was_called_with(match.is_number(), "wrap", false)
- assert.spy(win_set_option).was_called_with(match.is_number(), "spell", false)
- assert.spy(win_set_option).was_called_with(match.is_number(), "foldenable", false)
- assert.spy(win_set_option).was_called_with(match.is_number(), "signcolumn", "no")
- assert.spy(win_set_option).was_called_with(match.is_number(), "colorcolumn", "")
- assert.spy(win_set_option).was_called_with(match.is_number(), "cursorline", true)
+ assert.spy(set_lines).was_called(1)
+ assert.spy(set_lines).was_called_with(
+ match.is_number(),
+ 0,
+ -1,
+ false,
+ { "Line number 1!", "Initial state", "My highlighted text" }
+ )
- assert.spy(buf_set_option).was_called(9)
- assert.spy(buf_set_option).was_called_with(match.is_number(), "modifiable", false)
- assert.spy(buf_set_option).was_called_with(match.is_number(), "swapfile", false)
- assert.spy(buf_set_option).was_called_with(match.is_number(), "textwidth", 0)
- assert.spy(buf_set_option).was_called_with(match.is_number(), "buftype", "nofile")
- assert.spy(buf_set_option).was_called_with(match.is_number(), "bufhidden", "wipe")
- assert.spy(buf_set_option).was_called_with(match.is_number(), "buflisted", false)
- assert.spy(buf_set_option).was_called_with(match.is_number(), "filetype", "lsp-installer")
+ assert.spy(set_extmark).was_called(0)
- assert.spy(set_lines).was_called(1)
- assert.spy(set_lines).was_called_with(
- match.is_number(),
- 0,
- -1,
- false,
- { "Line number 1!", "Initial state", "My highlighted text" }
- )
+ assert.spy(add_highlight).was_called(1)
+ assert.spy(add_highlight).was_called_with(
+ match.is_number(),
+ match.is_number(),
+ "MyHighlightGroup",
+ 2,
+ 0,
+ 19
+ )
- assert.spy(set_extmark).was_called(0)
+ assert.spy(set_keymap).was_called(2)
+ assert.spy(set_keymap).was_called_with(
+ match.is_number(),
+ "n",
+ "U",
+ match.has_match [[<cmd>lua require%('nvim%-lsp%-installer%.ui%.display'%)%.dispatch_effect%(%d, "55"%)<cr>]],
+ { nowait = true, silent = true, noremap = true }
+ )
+ assert.spy(set_keymap).was_called_with(
+ match.is_number(),
+ "n",
+ "R",
+ match.has_match [[<cmd>lua require%('nvim%-lsp%-installer%.ui%.display'%)%.dispatch_effect%(%d, "52"%)<cr>]],
+ { nowait = true, silent = true, noremap = true }
+ )
- assert.spy(add_highlight).was_called(1)
- assert.spy(add_highlight).was_called_with(match.is_number(), match.is_number(), "MyHighlightGroup", 2, 0, 19)
+ assert.spy(clear_namespace).was_called(1)
+ assert.spy(clear_namespace).was_called_with(match.is_number(), match.is_number(), 0, -1)
- assert.spy(set_keymap).was_called(2)
- assert.spy(set_keymap).was_called_with(
- match.is_number(),
- "n",
- "U",
- match.has_match [[<cmd>lua require%('nvim%-lsp%-installer%.ui%.display'%)%.dispatch_effect%(%d, "55"%)<cr>]],
- { nowait = true, silent = true, noremap = true }
- )
- assert.spy(set_keymap).was_called_with(
- match.is_number(),
- "n",
- "R",
- match.has_match [[<cmd>lua require%('nvim%-lsp%-installer%.ui%.display'%)%.dispatch_effect%(%d, "52"%)<cr>]],
- { nowait = true, silent = true, noremap = true }
- )
+ mutate_state(function(state)
+ state.text = "New state"
+ end)
- assert.spy(clear_namespace).was_called(1)
- assert.spy(clear_namespace).was_called_with(match.is_number(), match.is_number(), 0, -1)
+ assert.spy(set_lines).was_called(1)
+ a.scheduler()
+ assert.spy(set_lines).was_called(2)
- mutate_state(function(state)
- state.text = "New state"
+ assert.spy(set_lines).was_called_with(
+ match.is_number(),
+ 0,
+ -1,
+ false,
+ { "Line number 1!", "New state", "My highlighted text" }
+ )
end)
-
- assert.spy(set_lines).was_called(1)
- a.util.scheduler()
- assert.spy(set_lines).was_called(2)
-
- assert.spy(set_lines).was_called_with(
- match.is_number(),
- 0,
- -1,
- false,
- { "Line number 1!", "New state", "My highlighted text" }
- )
- end)
+ )
end)