diff options
| author | kylo252 <[email protected]> | 2022-04-12 11:18:17 +0200 | 
|---|---|---|
| committer | GitHub <[email protected]> | 2022-04-12 11:18:17 +0200 | 
| commit | 1569202d39c40d7a44de5eb1b10cf203dd33af41 (patch) | |
| tree | f44862786fe8d39e5f7cd2ec7d0c101b27bc68ba | |
| parent | 3de6a404c92e495baa8688aa76d98c4ea9caa8c7 (diff) | |
fix(impatient): avoid get_options in fast handler (#2451)
| -rw-r--r-- | lua/lvim/core/log.lua | 6 | ||||
| -rw-r--r-- | lua/lvim/impatient.lua | 4 | ||||
| -rw-r--r-- | lua/lvim/plugins.lua | 2 | ||||
| -rw-r--r-- | snapshots/default.json | 18 | ||||
| -rw-r--r-- | tests/specs/config_loader_spec.lua | 20 | ||||
| -rw-r--r-- | tests/specs/lsp_spec.lua | 57 | ||||
| -rw-r--r-- | tests/specs/plugins_load_spec.lua | 6 | ||||
| -rw-r--r-- | utils/ci/run_test.sh | 12 | 
8 files changed, 75 insertions, 50 deletions
| diff --git a/lua/lvim/core/log.lua b/lua/lvim/core/log.lua index d0e74f18..15ccb11c 100644 --- a/lua/lvim/core/log.lua +++ b/lua/lvim/core/log.lua @@ -1,7 +1,5 @@  local Log = {} -local logfile = string.format("%s/%s.log", get_cache_dir(), "lvim") -  Log.levels = {    TRACE = 1,    DEBUG = 2, @@ -39,7 +37,7 @@ function Log:init()              { level = structlog.formatters.FormatColorizer.color_level() }            ),          }), -        structlog.sinks.File(log_level, logfile, { +        structlog.sinks.File(log_level, self:get_path(), {            processors = {              structlog.processors.Namer(),              structlog.processors.StackWriter({ "line", "file" }, { max_parents = 3, stack_level = 2 }), @@ -155,7 +153,7 @@ end  ---Retrieves the path of the logfile  ---@return string path of the logfile  function Log:get_path() -  return logfile +  return string.format("%s/%s.log", get_cache_dir(), "lvim")  end  ---Add a log entry at TRACE level diff --git a/lua/lvim/impatient.lua b/lua/lvim/impatient.lua index 4fdc0026..230e5195 100644 --- a/lua/lvim/impatient.lua +++ b/lua/lvim/impatient.lua @@ -203,6 +203,10 @@ function M.update_reduced_rtp()  end  local function load_package_with_cache_reduced_rtp(name) +  if vim.in_fast_event() then +    -- Can't set/get options in the fast handler +    return load_package_with_cache(name, "fast") +  end    local orig_rtp = get_option "runtimepath"    local orig_ei = get_option "eventignore" diff --git a/lua/lvim/plugins.lua b/lua/lvim/plugins.lua index 29620009..f5b9914c 100644 --- a/lua/lvim/plugins.lua +++ b/lua/lvim/plugins.lua @@ -190,6 +190,7 @@ local core_plugins = {      config = function()        require("lvim.core.bufferline").setup()      end, +    branch = "main",      event = "BufWinEnter",      disable = not lvim.builtin.bufferline.active,    }, @@ -225,6 +226,7 @@ local core_plugins = {    {      "akinsho/toggleterm.nvim",      event = "BufWinEnter", +    branch = "main",      config = function()        require("lvim.core.terminal").setup()      end, diff --git a/snapshots/default.json b/snapshots/default.json index d7a77ca0..22754d39 100644 --- a/snapshots/default.json +++ b/snapshots/default.json @@ -15,7 +15,7 @@      "commit": "6655228"    },    "bufferline.nvim": { -    "commit": "e62008f" +    "commit": "bb3ac30"    },    "cmp-buffer": {      "commit": "d66c4c2" @@ -33,7 +33,7 @@      "commit": "e302658"    },    "gitsigns.nvim": { -    "commit": "4a68d2a" +    "commit": "ac5ba87"    },    "lua-dev.nvim": {      "commit": "a0ee777" @@ -42,13 +42,13 @@      "commit": "c8e5a69"    },    "nlsp-settings.nvim": { -    "commit": "956c8ad" +    "commit": "c4afb0f"    },    "null-ls.nvim": {      "commit": "82be4bf"    },    "nvim-autopairs": { -    "commit": "06535b1" +    "commit": "6fb0479"    },    "nvim-cmp": {      "commit": "3192a0c" @@ -57,19 +57,19 @@      "commit": "10b5781"    },    "nvim-lsp-installer": { -    "commit": "a6c2783" +    "commit": "88f590c"    },    "nvim-lspconfig": {      "commit": "fd7843a"    },    "nvim-notify": { -    "commit": "0d02acf" +    "commit": "9655936"    },    "nvim-tree.lua": { -    "commit": "6e0e70b" +    "commit": "9c272b9"    },    "nvim-treesitter": { -    "commit": "d79b169" +    "commit": "d0fc684"    },    "nvim-ts-context-commentstring": {      "commit": "8834375" @@ -105,7 +105,7 @@      "commit": "b7ae91c"    },    "toggleterm.nvim": { -    "commit": "e62008f" +    "commit": "1a608cc"    },    "which-key.nvim": {      "commit": "a3c19ec" diff --git a/tests/specs/config_loader_spec.lua b/tests/specs/config_loader_spec.lua index 1f2debc7..40eaa350 100644 --- a/tests/specs/config_loader_spec.lua +++ b/tests/specs/config_loader_spec.lua @@ -4,16 +4,28 @@ local config = require "lvim.config"  a.describe("config-loader", function()    local user_config_path = config:get_user_config_path() +  before_each(function() +    vim.cmd [[ +	    let v:errmsg = "" +      let v:errors = [] +    ]] +  end) + +  after_each(function() +    local errmsg = vim.fn.eval "v:errmsg" +    local exception = vim.fn.eval "v:exception" +    local errors = vim.fn.eval "v:errors" +    assert.equal("", errmsg) +    assert.equal("", exception) +    assert.True(vim.tbl_isempty(errors)) +  end) +    a.it("should be able to find user-config", function()      assert.equal(user_config_path, get_config_dir() .. "/config.lua")    end)    a.it("should be able to load user-config without errors", function()      config:load(user_config_path) -    local errmsg = vim.fn.eval "v:errmsg" -    local exception = vim.fn.eval "v:exception" -    assert.equal("", errmsg) -- v:errmsg was not updated. -    assert.equal("", exception)    end)    a.it("should be able to reload user-config without errors", function() diff --git a/tests/specs/lsp_spec.lua b/tests/specs/lsp_spec.lua index 2518b237..7d9a3386 100644 --- a/tests/specs/lsp_spec.lua +++ b/tests/specs/lsp_spec.lua @@ -1,12 +1,26 @@  local a = require "plenary.async_lib.tests"  local utils = require "lvim.utils"  local helpers = require "tests.lvim.helpers" -local temp_dir = vim.loop.os_getenv "TEMP" or "/tmp" -lvim.lsp.templates_dir = join_paths(temp_dir, "lvim", "tests", "artifacts") +local spy = require "luassert.spy"  a.describe("lsp workflow", function() -  local Log = require "lvim.core.log" -  local logfile = Log:get_path() +  before_each(function() +    vim.cmd [[ +     let v:errmsg = "" +      let v:errors = [] +    ]] +  end) + +  after_each(function() +    local errmsg = vim.fn.eval "v:errmsg" +    local exception = vim.fn.eval "v:exception" +    local errors = vim.fn.eval "v:errors" +    assert.equal("", errmsg) +    assert.equal("", exception) +    assert.True(vim.tbl_isempty(errors)) +  end) + +  lvim.lsp.templates_dir = join_paths(get_cache_dir(), "artifacts")    a.it("should be able to delete ftplugin templates", function()      if utils.is_directory(lvim.lsp.templates_dir) then @@ -19,35 +33,13 @@ a.describe("lsp workflow", function()      if utils.is_directory(lvim.lsp.templates_dir) then        assert.equal(vim.fn.delete(lvim.lsp.templates_dir, "rf"), 0)      end -    require("lvim.lsp").setup() - -    -- we need to delay this check until the generation is completed -    vim.schedule(function() -      assert.True(utils.is_directory(lvim.lsp.templates_dir)) -    end) -  end) -  a.it("should not attempt to re-generate ftplugin templates", function() -    lvim.log.level = "debug" - -    local plugins = require "lvim.plugins" -    require("lvim.plugin-loader").load { plugins, lvim.plugins } - -    if utils.is_file(logfile) then -      assert.equal(vim.fn.delete(logfile), 0) -    end - -    assert.True(utils.is_directory(lvim.lsp.templates_dir))      require("lvim.lsp").setup() -    -- we need to delay this check until the log gets populated -    vim.schedule(function() -      assert.False(helpers.log_contains "templates") -    end) +    assert.True(utils.is_directory(lvim.lsp.templates_dir))    end)    a.it("should not include blacklisted servers in the generated templates", function() -    assert.True(utils.is_directory(lvim.lsp.templates_dir))      require("lvim.lsp").setup()      for _, file in ipairs(vim.fn.glob(lvim.lsp.templates_dir .. "/*.lua", 1, 1)) do @@ -59,7 +51,6 @@ a.describe("lsp workflow", function()    end)    a.it("should only include one server per generated template", function() -    assert.True(utils.is_directory(lvim.lsp.templates_dir))      require("lvim.lsp").setup()      for _, file in ipairs(vim.fn.glob(lvim.lsp.templates_dir .. "/*.lua", 1, 1)) do @@ -78,4 +69,14 @@ a.describe("lsp workflow", function()        assert.equal(err_msg, "")      end    end) + +  a.it("should not attempt to re-generate ftplugin templates", function() +    local s = spy.on(require "lvim.lsp.templates", "generate_templates") +    local plugins = require "lvim.plugins" +    require("lvim.plugin-loader").load { plugins, lvim.plugins } + +    require("lvim.lsp").setup() +    assert.spy(s).was_not_called() +    s:revert() +  end)  end) diff --git a/tests/specs/plugins_load_spec.lua b/tests/specs/plugins_load_spec.lua index d32c521d..1f11279e 100644 --- a/tests/specs/plugins_load_spec.lua +++ b/tests/specs/plugins_load_spec.lua @@ -4,6 +4,12 @@ a.describe("plugin-loader", function()    local plugins = require "lvim.plugins"    local loader = require "lvim.plugin-loader" +  pcall(function() +    lvim.log.level = "debug" +    package.loaded["packer.log"] = nil +    package.loaded["lvim.core.log"] = nil +  end) +    a.it("should be able to load default packages without errors", function()      loader.load { plugins, lvim.plugins } diff --git a/utils/ci/run_test.sh b/utils/ci/run_test.sh index 5b7f81ac..b12ceb7e 100644 --- a/utils/ci/run_test.sh +++ b/utils/ci/run_test.sh @@ -6,10 +6,14 @@ export LUNARVIM_RUNTIME_DIR="${LUNARVIM_RUNTIME_DIR:-"$HOME/.local/share/lunarvi  export LVIM_TEST_ENV=true  # we should start with an empty configuration -TEST_BASE_DIR="$(mktemp -d)" +LUNARVIM_CONFIG_DIR="$(mktemp -d)" +LUNARVIM_CACHE_DIR="$(mktemp -d)" -export LUNARVIM_CONFIG_DIR="$TEST_BASE_DIR" -export LUNARVIM_CACHE_DIR="$TEST_BASE_DIR" +export LUNARVIM_CONFIG_DIR LUNARVIM_CACHE_DIR + +echo "cache: $LUNARVIM_CACHE_DIR + +config: $LUNARVIM_CONFIG_DIR"  lvim() {    nvim -u "$LUNARVIM_RUNTIME_DIR/lvim/tests/minimal_init.lua" --cmd "set runtimepath+=$LUNARVIM_RUNTIME_DIR/lvim" "$@" @@ -20,5 +24,3 @@ if [ -n "$1" ]; then  else    lvim --headless -c "PlenaryBustedDirectory tests/specs { minimal_init = './tests/minimal_init.lua' }"  fi - -rm -rf "$TEST_BASE_DIR" | 
