fix(impatient): avoid get_options in fast handler (#2451)

This commit is contained in:
kylo252 2022-04-12 11:18:17 +02:00 committed by GitHub
parent 3de6a404c9
commit 1569202d39
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 75 additions and 50 deletions

View file

@ -1,7 +1,5 @@
local Log = {} local Log = {}
local logfile = string.format("%s/%s.log", get_cache_dir(), "lvim")
Log.levels = { Log.levels = {
TRACE = 1, TRACE = 1,
DEBUG = 2, DEBUG = 2,
@ -39,7 +37,7 @@ function Log:init()
{ level = structlog.formatters.FormatColorizer.color_level() } { level = structlog.formatters.FormatColorizer.color_level() }
), ),
}), }),
structlog.sinks.File(log_level, logfile, { structlog.sinks.File(log_level, self:get_path(), {
processors = { processors = {
structlog.processors.Namer(), structlog.processors.Namer(),
structlog.processors.StackWriter({ "line", "file" }, { max_parents = 3, stack_level = 2 }), structlog.processors.StackWriter({ "line", "file" }, { max_parents = 3, stack_level = 2 }),
@ -155,7 +153,7 @@ end
---Retrieves the path of the logfile ---Retrieves the path of the logfile
---@return string path of the logfile ---@return string path of the logfile
function Log:get_path() function Log:get_path()
return logfile return string.format("%s/%s.log", get_cache_dir(), "lvim")
end end
---Add a log entry at TRACE level ---Add a log entry at TRACE level

View file

@ -203,6 +203,10 @@ function M.update_reduced_rtp()
end end
local function load_package_with_cache_reduced_rtp(name) 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_rtp = get_option "runtimepath"
local orig_ei = get_option "eventignore" local orig_ei = get_option "eventignore"

View file

@ -190,6 +190,7 @@ local core_plugins = {
config = function() config = function()
require("lvim.core.bufferline").setup() require("lvim.core.bufferline").setup()
end, end,
branch = "main",
event = "BufWinEnter", event = "BufWinEnter",
disable = not lvim.builtin.bufferline.active, disable = not lvim.builtin.bufferline.active,
}, },
@ -225,6 +226,7 @@ local core_plugins = {
{ {
"akinsho/toggleterm.nvim", "akinsho/toggleterm.nvim",
event = "BufWinEnter", event = "BufWinEnter",
branch = "main",
config = function() config = function()
require("lvim.core.terminal").setup() require("lvim.core.terminal").setup()
end, end,

View file

@ -15,7 +15,7 @@
"commit": "6655228" "commit": "6655228"
}, },
"bufferline.nvim": { "bufferline.nvim": {
"commit": "e62008f" "commit": "bb3ac30"
}, },
"cmp-buffer": { "cmp-buffer": {
"commit": "d66c4c2" "commit": "d66c4c2"
@ -33,7 +33,7 @@
"commit": "e302658" "commit": "e302658"
}, },
"gitsigns.nvim": { "gitsigns.nvim": {
"commit": "4a68d2a" "commit": "ac5ba87"
}, },
"lua-dev.nvim": { "lua-dev.nvim": {
"commit": "a0ee777" "commit": "a0ee777"
@ -42,13 +42,13 @@
"commit": "c8e5a69" "commit": "c8e5a69"
}, },
"nlsp-settings.nvim": { "nlsp-settings.nvim": {
"commit": "956c8ad" "commit": "c4afb0f"
}, },
"null-ls.nvim": { "null-ls.nvim": {
"commit": "82be4bf" "commit": "82be4bf"
}, },
"nvim-autopairs": { "nvim-autopairs": {
"commit": "06535b1" "commit": "6fb0479"
}, },
"nvim-cmp": { "nvim-cmp": {
"commit": "3192a0c" "commit": "3192a0c"
@ -57,19 +57,19 @@
"commit": "10b5781" "commit": "10b5781"
}, },
"nvim-lsp-installer": { "nvim-lsp-installer": {
"commit": "a6c2783" "commit": "88f590c"
}, },
"nvim-lspconfig": { "nvim-lspconfig": {
"commit": "fd7843a" "commit": "fd7843a"
}, },
"nvim-notify": { "nvim-notify": {
"commit": "0d02acf" "commit": "9655936"
}, },
"nvim-tree.lua": { "nvim-tree.lua": {
"commit": "6e0e70b" "commit": "9c272b9"
}, },
"nvim-treesitter": { "nvim-treesitter": {
"commit": "d79b169" "commit": "d0fc684"
}, },
"nvim-ts-context-commentstring": { "nvim-ts-context-commentstring": {
"commit": "8834375" "commit": "8834375"
@ -105,7 +105,7 @@
"commit": "b7ae91c" "commit": "b7ae91c"
}, },
"toggleterm.nvim": { "toggleterm.nvim": {
"commit": "e62008f" "commit": "1a608cc"
}, },
"which-key.nvim": { "which-key.nvim": {
"commit": "a3c19ec" "commit": "a3c19ec"

View file

@ -4,16 +4,28 @@ local config = require "lvim.config"
a.describe("config-loader", function() a.describe("config-loader", function()
local user_config_path = config:get_user_config_path() 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() a.it("should be able to find user-config", function()
assert.equal(user_config_path, get_config_dir() .. "/config.lua") assert.equal(user_config_path, get_config_dir() .. "/config.lua")
end) end)
a.it("should be able to load user-config without errors", function() a.it("should be able to load user-config without errors", function()
config:load(user_config_path) 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) end)
a.it("should be able to reload user-config without errors", function() a.it("should be able to reload user-config without errors", function()

View file

@ -1,12 +1,26 @@
local a = require "plenary.async_lib.tests" local a = require "plenary.async_lib.tests"
local utils = require "lvim.utils" local utils = require "lvim.utils"
local helpers = require "tests.lvim.helpers" local helpers = require "tests.lvim.helpers"
local temp_dir = vim.loop.os_getenv "TEMP" or "/tmp" local spy = require "luassert.spy"
lvim.lsp.templates_dir = join_paths(temp_dir, "lvim", "tests", "artifacts")
a.describe("lsp workflow", function() a.describe("lsp workflow", function()
local Log = require "lvim.core.log" before_each(function()
local logfile = Log:get_path() 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() a.it("should be able to delete ftplugin templates", function()
if utils.is_directory(lvim.lsp.templates_dir) then 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 if utils.is_directory(lvim.lsp.templates_dir) then
assert.equal(vim.fn.delete(lvim.lsp.templates_dir, "rf"), 0) assert.equal(vim.fn.delete(lvim.lsp.templates_dir, "rf"), 0)
end end
require("lvim.lsp").setup() 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)) 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)
end) end)
a.it("should not include blacklisted servers in the generated templates", function() 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() require("lvim.lsp").setup()
for _, file in ipairs(vim.fn.glob(lvim.lsp.templates_dir .. "/*.lua", 1, 1)) do 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) end)
a.it("should only include one server per generated template", function() a.it("should only include one server per generated template", function()
assert.True(utils.is_directory(lvim.lsp.templates_dir))
require("lvim.lsp").setup() require("lvim.lsp").setup()
for _, file in ipairs(vim.fn.glob(lvim.lsp.templates_dir .. "/*.lua", 1, 1)) do 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, "") assert.equal(err_msg, "")
end end
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) end)

View file

@ -4,6 +4,12 @@ a.describe("plugin-loader", function()
local plugins = require "lvim.plugins" local plugins = require "lvim.plugins"
local loader = require "lvim.plugin-loader" 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() a.it("should be able to load default packages without errors", function()
loader.load { plugins, lvim.plugins } loader.load { plugins, lvim.plugins }

View file

@ -6,10 +6,14 @@ export LUNARVIM_RUNTIME_DIR="${LUNARVIM_RUNTIME_DIR:-"$HOME/.local/share/lunarvi
export LVIM_TEST_ENV=true export LVIM_TEST_ENV=true
# we should start with an empty configuration # 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_CONFIG_DIR LUNARVIM_CACHE_DIR
export LUNARVIM_CACHE_DIR="$TEST_BASE_DIR"
echo "cache: $LUNARVIM_CACHE_DIR
config: $LUNARVIM_CONFIG_DIR"
lvim() { lvim() {
nvim -u "$LUNARVIM_RUNTIME_DIR/lvim/tests/minimal_init.lua" --cmd "set runtimepath+=$LUNARVIM_RUNTIME_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 else
lvim --headless -c "PlenaryBustedDirectory tests/specs { minimal_init = './tests/minimal_init.lua' }" lvim --headless -c "PlenaryBustedDirectory tests/specs { minimal_init = './tests/minimal_init.lua' }"
fi fi
rm -rf "$TEST_BASE_DIR"