diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 056f4f8..063f397 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,10 +1,6 @@ name: Tests -on: - push: - branches: [main] - pull_request: - branches: [main] +on: [push, pull_request] # Cancel any in-progress CI runs for a PR if it is updated concurrency: diff --git a/README.md b/README.md index 7df242f..8771d5c 100644 --- a/README.md +++ b/README.md @@ -222,7 +222,6 @@ require("persisted").setup({ after_source = function() -- Reload the LSP servers vim.lsp.stop_client(vim.lsp.get_active_clients()) - vim.cmd("edit") end }) ``` diff --git a/lua/persisted/init.lua b/lua/persisted/init.lua index e729535..23b7442 100644 --- a/lua/persisted/init.lua +++ b/lua/persisted/init.lua @@ -20,7 +20,6 @@ local function setup_commands() ]]) end - ---Does the current working directory allow for the auto-saving and loading? ---@return boolean local function allow_dir() @@ -106,27 +105,34 @@ function M.load(opt) local session = opt.last and get_last() or get_current() if session and vim.fn.filereadable(session) ~= 0 then - local ok, result = pcall(vim.cmd, "source " .. e(session)) - if not ok then - return utils.echoerr("Error loading the session! ", result) - end - config.options.after_source() + vim.schedule(function() + local ok, result = pcall(vim.cmd, "source " .. e(session)) + if not ok then + return utils.echoerr("Error loading the session! ", result) + end + config.options.after_source() + end) end if config.options.autosave and (allow_dir() and not ignore_dir()) then - M.start() + vim.schedule(function() + M.start() + end) end end ---Start recording a session and write to disk on a specific autocommand ---@return nil function M.start() - vim.cmd(string.format([[ + vim.cmd(string.format( + [[ augroup Persisted autocmd! autocmd %s * lua require("persisted").save() augroup end - ]], config.options.command)) + ]], + config.options.command + )) vim.g.persisting = true end diff --git a/tests/autoload/autoload_allowed_dir_spec.lua b/tests/autoload/autoload_allowed_dir_spec.lua index d61cc92..1cf25dd 100644 --- a/tests/autoload/autoload_allowed_dir_spec.lua +++ b/tests/autoload/autoload_allowed_dir_spec.lua @@ -1,3 +1,6 @@ +local util = require("plenary.async.util") +local async = require("plenary.async.tests") + local e = vim.fn.fnameescape local session_dir = vim.fn.getcwd() .. "/tests/dummy_data/" require("persisted").setup({ @@ -7,15 +10,14 @@ require("persisted").setup({ allowed_dirs = { vim.fn.getcwd() }, }) -describe("Autoloading", function() - +async.describe("Autoloading", function() -- after_each(function() -- vim.fn.system("rm -rf " .. e(session_dir)) -- end) - it("autoloads a file with allowed_dirs config option present", function() - local content = vim.fn.getline(1, '$') + async.it("autoloads a file with allowed_dirs config option present", function() + util.scheduler() + local content = vim.fn.getline(1, "$") assert.equals(content[1], "If you're reading this, I guess auto-loading works") end) - end) diff --git a/tests/autoload/autoload_session_spec.lua b/tests/autoload/autoload_session_spec.lua index 9d4bb8c..3409392 100644 --- a/tests/autoload/autoload_session_spec.lua +++ b/tests/autoload/autoload_session_spec.lua @@ -1,3 +1,6 @@ +local util = require("plenary.async.util") +local async = require("plenary.async.tests") + local e = vim.fn.fnameescape local session_dir = vim.fn.getcwd() .. "/tests/dummy_data/" require("persisted").setup({ @@ -6,9 +9,10 @@ require("persisted").setup({ autosave = true, }) -describe("Autoloading", function() +async.describe("Autoloading", function() - it("autoloads a file", function() + async.it("autoloads a file", function() + util.scheduler() local content = vim.fn.getline(1, '$') assert.equals(content[1], "If you're reading this, I guess auto-loading works") end)