Skip to content

Commit

Permalink
tests(lsp): tweak
Browse files Browse the repository at this point in the history
  • Loading branch information
mrcjkb committed Oct 23, 2023
1 parent d3a10a1 commit 966a2b9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
2 changes: 2 additions & 0 deletions lua/rustaceanvim/compat.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@ end

M.get_clients = vim.lsp.get_clients or vim.lsp.get_active_clients

M.uv = vim.uv or vim.loop

return M
16 changes: 11 additions & 5 deletions spec/lsp_spec.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
local uv = vim.uv or vim.loop
-- load RustAnalyzer command
require('rustaceanvim.lsp')

Expand All @@ -7,18 +6,25 @@ describe('LSP client API', function()
local RustaceanConfig = require('rustaceanvim.config.internal')
local Types = require('rustaceanvim.types.internal')
local ra_bin = Types.evaluate(RustaceanConfig.server.cmd)[1]
if vim.fn.executable(ra_bin) ~= 0 then
if vim.fn.executable(ra_bin) == 1 then
it('Can spin up rust-analyzer.', function()
local lsp_start = stub(vim.lsp, 'start')
local notify_once = stub(vim, 'notify_once')
local notify = stub(vim, 'notify')
vim.cmd.e('test.rs')
local bufnr = vim.api.nvim_create_buf(true, false)
vim.api.nvim_buf_set_name(bufnr, 'test.rs')
vim.bo[bufnr].filetype = 'rust'
vim.api.nvim_set_current_buf(bufnr)
vim.cmd.RustAnalyzer('start')
-- TODO: Use something less flaky, e.g. a timeout
uv.sleep(5000)
assert.stub(lsp_start).was_called()
assert.stub(notify_once).was_not_called()
assert.stub(notify).was_not_called()
-- TODO: Use something less flaky, e.g. a timeout
-- local compat = require('rustaceanvim.compat')
-- compat.uv.sleep(5000)
-- local ra = require('rustaceanvim.rust_analyzer')
-- FIXME:
-- assert.equals(1, #ra.get_active_rustaceanvim_clients(bufnr))
end)
end
end)

0 comments on commit 966a2b9

Please sign in to comment.