From 8eed75d67f9cbcefb91c4cb5aac0ffd013be25cc Mon Sep 17 00:00:00 2001 From: kylo252 <59826753+kylo252@users.noreply.github.com> Date: Mon, 13 Sep 2021 11:28:15 +0200 Subject: refactor: use more flexible paths (#1381) --- lua/bootstrap.lua | 82 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 lua/bootstrap.lua (limited to 'lua/bootstrap.lua') diff --git a/lua/bootstrap.lua b/lua/bootstrap.lua new file mode 100644 index 00000000..a03440d9 --- /dev/null +++ b/lua/bootstrap.lua @@ -0,0 +1,82 @@ +local M = {} +-- It's not safe to require 'utils' without adjusting the runtimepath +function _G.join_paths(...) + local uv = vim.loop + local path_sep = uv.os_uname().version:match "Windows" and "\\" or "/" + local result = table.concat({ ... }, path_sep) + return result +end + +function _G.get_runtime_dir() + local lvim_runtime_dir = os.getenv "LUNARVIM_RUNTIME_DIR" + if not lvim_runtime_dir then + -- when nvim is used directly + return vim.fn.stdpath "config" + end + return lvim_runtime_dir +end + +function _G.get_config_dir() + local lvim_config_dir = os.getenv "LUNARVIM_CONFIG_DIR" + if not lvim_config_dir then + return vim.fn.stdpath "config" + end + return lvim_config_dir +end + +function _G.get_cache_dir() + local lvim_cache_dir = os.getenv "LUNARVIM_CACHE_DIR" + if not lvim_cache_dir then + return vim.fn.stdpath "cache" + end + return lvim_cache_dir +end + +function M:init() + self.runtime_dir = get_runtime_dir() + self.config_dir = get_config_dir() + self.cache_path = get_cache_dir() + + self.pack_dir = join_paths(self.runtime_dir, "site", "pack") + + if os.getenv "LUNARVIM_RUNTIME_DIR" then + vim.opt.rtp:remove(join_paths(vim.fn.stdpath "data", "site")) + vim.opt.rtp:remove(join_paths(vim.fn.stdpath "data", "site", "after")) + vim.opt.rtp:prepend(join_paths(self.runtime_dir, "site")) + vim.opt.rtp:append(join_paths(self.runtime_dir, "site", "after")) + + vim.opt.rtp:remove(vim.fn.stdpath "config") + vim.opt.rtp:remove(join_paths(vim.fn.stdpath "config", "after")) + vim.opt.rtp:prepend(self.config_dir) + vim.opt.rtp:append(join_paths(self.config_dir, "after")) + -- TODO: we need something like this: vim.opt.packpath = vim.opt.rtp + + vim.cmd [[let &packpath = &runtimepath]] + vim.cmd("set spellfile=" .. join_paths(self.config_dir, "spell", "en.utf-8.add")) + end + + -- FIXME: currently unreliable in unit-tests + if not os.getenv "LVIM_TEST_ENV" then + require("impatient").setup { + path = vim.fn.stdpath "cache" .. "/lvim_cache", + enable_profiling = true, + } + end + + local config = require "config" + config:init { + path = join_paths(self.config_dir, "config.lua"), + } + + require("plugin-loader"):init { + cache_path = self.cache_path, + runtime_dir = self.runtime_dir, + config_dir = self.config_dir, + package_root = join_paths(self.runtime_dir, "site", "pack"), + compile_path = join_paths(self.config_dir, "plugin", "packer_compiled.lua"), + } + + return self +end + +return M -- cgit v1.2.3 From 414777077fc8cd76a83fe3b97c80c149f7dd7d0d Mon Sep 17 00:00:00 2001 From: kylo252 <59826753+kylo252@users.noreply.github.com> Date: Mon, 13 Sep 2021 17:22:27 +0200 Subject: fix: use correct install path for packer (#1540) --- lua/bootstrap.lua | 1 + 1 file changed, 1 insertion(+) (limited to 'lua/bootstrap.lua') diff --git a/lua/bootstrap.lua b/lua/bootstrap.lua index a03440d9..695dacdc 100644 --- a/lua/bootstrap.lua +++ b/lua/bootstrap.lua @@ -72,6 +72,7 @@ function M:init() cache_path = self.cache_path, runtime_dir = self.runtime_dir, config_dir = self.config_dir, + install_path = join_paths(self.runtime_dir, "site", "pack", "packer", "start", "packer.nvim"), package_root = join_paths(self.runtime_dir, "site", "pack"), compile_path = join_paths(self.config_dir, "plugin", "packer_compiled.lua"), } -- cgit v1.2.3 From e22f9a21c179901e6dfcbdb68d035e70eae4d9e8 Mon Sep 17 00:00:00 2001 From: kylo252 <59826753+kylo252@users.noreply.github.com> Date: Thu, 16 Sep 2021 09:58:32 +0200 Subject: fix: more robust reloading (#1556) --- lua/bootstrap.lua | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'lua/bootstrap.lua') diff --git a/lua/bootstrap.lua b/lua/bootstrap.lua index 695dacdc..85d39d2d 100644 --- a/lua/bootstrap.lua +++ b/lua/bootstrap.lua @@ -38,6 +38,8 @@ function M:init() self.cache_path = get_cache_dir() self.pack_dir = join_paths(self.runtime_dir, "site", "pack") + self.packer_install_dir = join_paths(self.runtime_dir, "site", "pack", "packer", "start", "packer.nvim") + self.packer_cache_path = join_paths(self.config_dir, "plugin", "packer_compiled.lua") if os.getenv "LUNARVIM_RUNTIME_DIR" then vim.opt.rtp:remove(join_paths(vim.fn.stdpath "data", "site")) @@ -57,6 +59,7 @@ function M:init() -- FIXME: currently unreliable in unit-tests if not os.getenv "LVIM_TEST_ENV" then + vim.fn.mkdir(vim.fn.stdpath "cache", "p") require("impatient").setup { path = vim.fn.stdpath "cache" .. "/lvim_cache", enable_profiling = true, @@ -69,12 +72,8 @@ function M:init() } require("plugin-loader"):init { - cache_path = self.cache_path, - runtime_dir = self.runtime_dir, - config_dir = self.config_dir, - install_path = join_paths(self.runtime_dir, "site", "pack", "packer", "start", "packer.nvim"), - package_root = join_paths(self.runtime_dir, "site", "pack"), - compile_path = join_paths(self.config_dir, "plugin", "packer_compiled.lua"), + package_root = self.pack_dir, + install_path = self.packer_install_dir, } return self -- cgit v1.2.3 From 254ab2102b5f8f6187321a545998ead4c3abd27a Mon Sep 17 00:00:00 2001 From: chaesngmin Date: Fri, 17 Sep 2021 04:13:52 -0700 Subject: [Feature] Add lunarvim latest release tag to dashboard (#1436) * feat: add lunarvim latest release tag to dashboard * Add a function to center-align text Rename align to align_left Rename shift_left to shift_right * refactor(dashboard): remove unnecessary comment * refactor(dashboard): use `home_dir` variable for `lv_path` * refactor(dashboard): use $LUNARVIM_RUNTIME_DIR for lv_path * feat(bootstrap): add fn that returns lvim version * refactor(dashboard): use version, lunarvim dir with bootstrap fns * build: add global get_version() from bootstrap Co-authored-by: Luc Sinet --- lua/bootstrap.lua | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'lua/bootstrap.lua') diff --git a/lua/bootstrap.lua b/lua/bootstrap.lua index 85d39d2d..5e333d8a 100644 --- a/lua/bootstrap.lua +++ b/lua/bootstrap.lua @@ -32,6 +32,15 @@ function _G.get_cache_dir() return lvim_cache_dir end +function _G.get_version(type) + local lvim_full_ver = vim.fn.system("git -C " .. get_runtime_dir() .. "/lvim describe --tag") + if type == "short" then + return vim.fn.split(lvim_full_ver, "-")[1] + else + return string.sub(lvim_full_ver, 1, #lvim_full_ver - 1) + end +end + function M:init() self.runtime_dir = get_runtime_dir() self.config_dir = get_config_dir() -- cgit v1.2.3 From 390f277b702fe7877f0d5fabbece230528b58cb1 Mon Sep 17 00:00:00 2001 From: chaesngmin Date: Fri, 17 Sep 2021 05:14:31 -0700 Subject: fix(dashboard): hide version when no tag found (#1572) --- lua/bootstrap.lua | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'lua/bootstrap.lua') diff --git a/lua/bootstrap.lua b/lua/bootstrap.lua index 5e333d8a..ff6d9cdf 100644 --- a/lua/bootstrap.lua +++ b/lua/bootstrap.lua @@ -33,7 +33,11 @@ function _G.get_cache_dir() end function _G.get_version(type) - local lvim_full_ver = vim.fn.system("git -C " .. get_runtime_dir() .. "/lvim describe --tag") + local lvim_full_ver = vim.fn.system("git -C " .. get_runtime_dir() .. "/lvim describe --tags") + + if string.match(lvim_full_ver, "%d") == nil then + return nil + end if type == "short" then return vim.fn.split(lvim_full_ver, "-")[1] else -- cgit v1.2.3 From a273c46eee751de4a61360ae0076ed4dac433e5d Mon Sep 17 00:00:00 2001 From: kylo252 <59826753+kylo252@users.noreply.github.com> Date: Fri, 1 Oct 2021 13:27:06 +0200 Subject: feat: add LvimUpdate command (#1634) * feat: add prelimenary LvimUpdate command * feat: use native process management * feat: add a telescope change-log utility * fix: update readme to include the new command --- lua/bootstrap.lua | 96 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 95 insertions(+), 1 deletion(-) (limited to 'lua/bootstrap.lua') diff --git a/lua/bootstrap.lua b/lua/bootstrap.lua index ff6d9cdf..7f8f97ed 100644 --- a/lua/bootstrap.lua +++ b/lua/bootstrap.lua @@ -1,5 +1,7 @@ local M = {} --- It's not safe to require 'utils' without adjusting the runtimepath + +---Join path segments that were passed as input +---@return string function _G.join_paths(...) local uv = vim.loop local path_sep = uv.os_uname().version:match "Windows" and "\\" or "/" @@ -7,6 +9,8 @@ function _G.join_paths(...) return result end +---Get the full path to `$LUNARVIM_RUNTIME_DIR` +---@return string function _G.get_runtime_dir() local lvim_runtime_dir = os.getenv "LUNARVIM_RUNTIME_DIR" if not lvim_runtime_dir then @@ -16,6 +20,8 @@ function _G.get_runtime_dir() return lvim_runtime_dir end +---Get the full path to `$LUNARVIM_CONFIG_DIR` +---@return string function _G.get_config_dir() local lvim_config_dir = os.getenv "LUNARVIM_CONFIG_DIR" if not lvim_config_dir then @@ -24,6 +30,8 @@ function _G.get_config_dir() return lvim_config_dir end +---Get the full path to `$LUNARVIM_CACHE_DIR` +---@return string function _G.get_cache_dir() local lvim_cache_dir = os.getenv "LUNARVIM_CACHE_DIR" if not lvim_cache_dir then @@ -32,7 +40,11 @@ function _G.get_cache_dir() return lvim_cache_dir end +---Get currently installed version of LunarVim +---@param type string can be "short" +---@return string function _G.get_version(type) + type = type or "" local lvim_full_ver = vim.fn.system("git -C " .. get_runtime_dir() .. "/lvim describe --tags") if string.match(lvim_full_ver, "%d") == nil then @@ -45,10 +57,13 @@ function _G.get_version(type) end end +---Initialize the `&runtimepath` variables and prepare for startup +---@return table function M:init() self.runtime_dir = get_runtime_dir() self.config_dir = get_config_dir() self.cache_path = get_cache_dir() + self.repo_dir = join_paths(self.runtime_dir, "lvim") self.pack_dir = join_paths(self.runtime_dir, "site", "pack") self.packer_install_dir = join_paths(self.runtime_dir, "site", "pack", "packer", "start", "packer.nvim") @@ -92,4 +107,83 @@ function M:init() return self end +---Update LunarVim +---pulls the latest changes from github and, resets the startup cache +function M:update() + M:update_repo() + M:reset_cache() + vim.schedule(function() + -- TODO: add a changelog + vim.notify("Update complete", vim.log.levels.INFO) + end) +end + +local function git_cmd(subcmd) + local Job = require "plenary.job" + local Log = require "core.log" + local repo_dir = join_paths(get_runtime_dir(), "lvim") + local args = { "-C", repo_dir } + vim.list_extend(args, subcmd) + + local stderr = {} + local stdout, ret = Job + :new({ + command = "git", + args = args, + cwd = repo_dir, + on_stderr = function(_, data) + table.insert(stderr, data) + end, + }) + :sync() + + if not vim.tbl_isempty(stderr) then + Log:debug(stderr) + end + + if not vim.tbl_isempty(stdout) then + Log:debug(stdout) + end + + return ret +end + +---pulls the latest changes from github +function M:update_repo() + local Log = require "core.log" + local sub_commands = { + fetch = { "fetch" }, + diff = { "diff", "--quiet", "@{upstream}" }, + merge = { "merge", "--ff-only", "--progress" }, + } + Log:info "Checking for updates" + + local ret = git_cmd(sub_commands.fetch) + if ret ~= 0 then + error "Update failed! Check the log for further information" + end + + ret = git_cmd(sub_commands.diff) + + if ret == 0 then + Log:info "LunarVim is already up-to-date" + return + end + + ret = git_cmd(sub_commands.merge) + + if ret ~= 0 then + error "Error: unable to guarantee data integrity while updating your branch" + error "Please pull the changes manually instead." + end +end + +---Reset any startup cache files used by Packer and Impatient +---Tip: Useful for clearing any outdated settings +function M:reset_cache() + _G.__luacache.clear_cache() + _G.__luacache.save_cache() + require("plugin-loader"):cache_reset() +end + return M -- cgit v1.2.3 From d01ba08eaec1640ac2d038893525b3ba0af25813 Mon Sep 17 00:00:00 2001 From: kylo252 <59826753+kylo252@users.noreply.github.com> Date: Sun, 3 Oct 2021 16:13:46 +0200 Subject: refactor: auto-generate language configuration (#1584) Refactor the monolithic `lvim.lang` design into a more modular approach. IMPORTANT: run `:LvimUpdate` in order to generate the new ftplugin template files. --- lua/bootstrap.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'lua/bootstrap.lua') diff --git a/lua/bootstrap.lua b/lua/bootstrap.lua index 7f8f97ed..fb2099ce 100644 --- a/lua/bootstrap.lua +++ b/lua/bootstrap.lua @@ -85,9 +85,10 @@ function M:init() vim.cmd("set spellfile=" .. join_paths(self.config_dir, "spell", "en.utf-8.add")) end + vim.fn.mkdir(vim.fn.stdpath "cache", "p") + -- FIXME: currently unreliable in unit-tests if not os.getenv "LVIM_TEST_ENV" then - vim.fn.mkdir(vim.fn.stdpath "cache", "p") require("impatient").setup { path = vim.fn.stdpath "cache" .. "/lvim_cache", enable_profiling = true, @@ -112,6 +113,7 @@ end function M:update() M:update_repo() M:reset_cache() + require("lsp.templates").generate_templates() vim.schedule(function() -- TODO: add a changelog vim.notify("Update complete", vim.log.levels.INFO) -- cgit v1.2.3 From 1078f43a517d5a0056b1191aca0fa85994a38ecb Mon Sep 17 00:00:00 2001 From: kylo252 <59826753+kylo252@users.noreply.github.com> Date: Sun, 3 Oct 2021 23:02:42 +0200 Subject: fix: add packer-install hook on lvim-update --- lua/bootstrap.lua | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'lua/bootstrap.lua') diff --git a/lua/bootstrap.lua b/lua/bootstrap.lua index fb2099ce..43ce44d5 100644 --- a/lua/bootstrap.lua +++ b/lua/bootstrap.lua @@ -1,5 +1,7 @@ local M = {} +local in_headless = #vim.api.nvim_list_uis() == 0 + ---Join path segments that were passed as input ---@return string function _G.join_paths(...) @@ -114,10 +116,13 @@ function M:update() M:update_repo() M:reset_cache() require("lsp.templates").generate_templates() - vim.schedule(function() - -- TODO: add a changelog - vim.notify("Update complete", vim.log.levels.INFO) - end) + if not in_headless then + vim.schedule(function() + require("packer").install() + -- TODO: add a changelog + vim.notify("Update complete", vim.log.levels.INFO) + end) + end end local function git_cmd(subcmd) -- cgit v1.2.3 From c0e3c8d43ae6ca011e4036329ae31115957d1394 Mon Sep 17 00:00:00 2001 From: kylo252 <59826753+kylo252@users.noreply.github.com> Date: Thu, 7 Oct 2021 17:47:53 +0200 Subject: feat(lsp): handle user configuration in setup() (#1707) --- lua/bootstrap.lua | 49 +++++++++++++++++++++++-------------------------- 1 file changed, 23 insertions(+), 26 deletions(-) (limited to 'lua/bootstrap.lua') diff --git a/lua/bootstrap.lua b/lua/bootstrap.lua index 43ce44d5..866403b7 100644 --- a/lua/bootstrap.lua +++ b/lua/bootstrap.lua @@ -1,6 +1,7 @@ local M = {} -local in_headless = #vim.api.nvim_list_uis() == 0 +package.loaded["utils.hooks"] = nil +local _, hooks = pcall(require, "utils.hooks") ---Join path segments that were passed as input ---@return string @@ -42,12 +43,23 @@ function _G.get_cache_dir() return lvim_cache_dir end +---Get the full path to the currently installed lunarvim repo +---@return string +local function get_install_path() + local lvim_runtime_dir = os.getenv "LUNARVIM_RUNTIME_DIR" + if not lvim_runtime_dir then + -- when nvim is used directly + return vim.fn.stdpath "config" + end + return join_paths(lvim_runtime_dir, "lvim") +end + ---Get currently installed version of LunarVim ---@param type string can be "short" ---@return string function _G.get_version(type) type = type or "" - local lvim_full_ver = vim.fn.system("git -C " .. get_runtime_dir() .. "/lvim describe --tags") + local lvim_full_ver = vim.fn.system("git -C " .. get_install_path() .. " describe --tags") if string.match(lvim_full_ver, "%d") == nil then return nil @@ -65,7 +77,7 @@ function M:init() self.runtime_dir = get_runtime_dir() self.config_dir = get_config_dir() self.cache_path = get_cache_dir() - self.repo_dir = join_paths(self.runtime_dir, "lvim") + self.install_path = get_install_path() self.pack_dir = join_paths(self.runtime_dir, "site", "pack") self.packer_install_dir = join_paths(self.runtime_dir, "site", "pack", "packer", "start", "packer.nvim") @@ -113,23 +125,15 @@ end ---Update LunarVim ---pulls the latest changes from github and, resets the startup cache function M:update() + hooks.run_pre_update() M:update_repo() - M:reset_cache() - require("lsp.templates").generate_templates() - if not in_headless then - vim.schedule(function() - require("packer").install() - -- TODO: add a changelog - vim.notify("Update complete", vim.log.levels.INFO) - end) - end + hooks.run_post_update() end local function git_cmd(subcmd) local Job = require "plenary.job" local Log = require "core.log" - local repo_dir = join_paths(get_runtime_dir(), "lvim") - local args = { "-C", repo_dir } + local args = { "-C", get_install_path() } vim.list_extend(args, subcmd) local stderr = {} @@ -137,7 +141,7 @@ local function git_cmd(subcmd) :new({ command = "git", args = args, - cwd = repo_dir, + cwd = get_install_path(), on_stderr = function(_, data) table.insert(stderr, data) end, @@ -167,7 +171,8 @@ function M:update_repo() local ret = git_cmd(sub_commands.fetch) if ret ~= 0 then - error "Update failed! Check the log for further information" + Log:error "Update failed! Check the log for further information" + return end ret = git_cmd(sub_commands.diff) @@ -180,17 +185,9 @@ function M:update_repo() ret = git_cmd(sub_commands.merge) if ret ~= 0 then - error "Error: unable to guarantee data integrity while updating your branch" - error "Please pull the changes manually instead." + Log:error "Update failed! Please pull the changes manually instead." + return end end ----Reset any startup cache files used by Packer and Impatient ----Tip: Useful for clearing any outdated settings -function M:reset_cache() - _G.__luacache.clear_cache() - _G.__luacache.save_cache() - require("plugin-loader"):cache_reset() -end - return M -- cgit v1.2.3