From 966a2b980f5c5843228831de71d5b438baf0315b Mon Sep 17 00:00:00 2001 From: Marc Jakobi Date: Mon, 23 Oct 2023 10:50:07 +0200 Subject: [PATCH] tests(lsp): tweak --- lua/rustaceanvim/compat.lua | 2 ++ spec/lsp_spec.lua | 16 +++++++++++----- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/lua/rustaceanvim/compat.lua b/lua/rustaceanvim/compat.lua index ac00b207..23a2147c 100644 --- a/lua/rustaceanvim/compat.lua +++ b/lua/rustaceanvim/compat.lua @@ -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 diff --git a/spec/lsp_spec.lua b/spec/lsp_spec.lua index 19da39e0..23f68f1e 100644 --- a/spec/lsp_spec.lua +++ b/spec/lsp_spec.lua @@ -1,4 +1,3 @@ -local uv = vim.uv or vim.loop -- load RustAnalyzer command require('rustaceanvim.lsp') @@ -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)