Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 3 commits into from
Apr 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 2 additions & 4 deletions lua/lvim/core/log.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
local Log = {}

local logfile = string.format("%s/%s.log", get_cache_dir(), "lvim")

Log.levels = {
TRACE = 1,
DEBUG = 2,
Expand Down Expand Up @@ -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 }),
Expand Down Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions lua/lvim/impatient.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
2 changes: 2 additions & 0 deletions lua/lvim/plugins.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down Expand Up @@ -225,6 +226,7 @@ local core_plugins = {
{
"akinsho/toggleterm.nvim",
event = "BufWinEnter",
branch = "main",
config = function()
require("lvim.core.terminal").setup()
end,
Expand Down
18 changes: 9 additions & 9 deletions snapshots/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"commit": "6655228"
},
"bufferline.nvim": {
"commit": "e62008f"
"commit": "bb3ac30"
},
"cmp-buffer": {
"commit": "d66c4c2"
Expand All @@ -33,7 +33,7 @@
"commit": "e302658"
},
"gitsigns.nvim": {
"commit": "4a68d2a"
"commit": "ac5ba87"
},
"lua-dev.nvim": {
"commit": "a0ee777"
Expand All @@ -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"
Expand All @@ -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"
Expand Down Expand Up @@ -105,7 +105,7 @@
"commit": "b7ae91c"
},
"toggleterm.nvim": {
"commit": "e62008f"
"commit": "1a608cc"
},
"which-key.nvim": {
"commit": "a3c19ec"
Expand Down
20 changes: 16 additions & 4 deletions tests/specs/config_loader_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
57 changes: 29 additions & 28 deletions tests/specs/lsp_spec.lua
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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)
6 changes: 6 additions & 0 deletions tests/specs/plugins_load_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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 }

Expand Down
12 changes: 7 additions & 5 deletions utils/ci/run_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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" "$@"
Expand All @@ -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"