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/utils/init.lua | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'lua/utils/init.lua') diff --git a/lua/utils/init.lua b/lua/utils/init.lua index 8ea842ca..095390b1 100644 --- a/lua/utils/init.lua +++ b/lua/utils/init.lua @@ -90,7 +90,7 @@ function utils.reload_lv_config() config:load() require("keymappings").setup() -- this should be done before loading the plugins - vim.cmd "source ~/.local/share/lunarvim/lvim/lua/plugins.lua" + vim.cmd("source " .. utils.join_paths(get_runtime_dir(), "lvim", "lua", "plugins.lua")) local plugins = require "plugins" local plugin_loader = require("plugin-loader").init() utils.toggle_autoformat() @@ -127,6 +127,12 @@ function utils.is_file(filename) return stat and stat.type == "file" or false end +function utils.join_paths(...) + local path_sep = vim.loop.os_uname().version:match "Windows" and "\\" or "/" + local result = table.concat(vim.tbl_flatten { ... }, path_sep):gsub(path_sep .. "+", path_sep) + return result +end + return utils -- TODO: find a new home for these autocommands -- cgit v1.2.3 From bb130d669b60d0fd4d1a8867387f180d994968c9 Mon Sep 17 00:00:00 2001 From: kylo252 <59826753+kylo252@users.noreply.github.com> Date: Mon, 13 Sep 2021 11:49:53 +0200 Subject: fix: don't re-initalize the plugin-loader --- lua/utils/init.lua | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'lua/utils/init.lua') diff --git a/lua/utils/init.lua b/lua/utils/init.lua index 095390b1..100ab628 100644 --- a/lua/utils/init.lua +++ b/lua/utils/init.lua @@ -92,9 +92,8 @@ function utils.reload_lv_config() require("keymappings").setup() -- this should be done before loading the plugins vim.cmd("source " .. utils.join_paths(get_runtime_dir(), "lvim", "lua", "plugins.lua")) local plugins = require "plugins" - local plugin_loader = require("plugin-loader").init() utils.toggle_autoformat() - plugin_loader:load { plugins, lvim.plugins } + require("plugin-loader"):load { plugins, lvim.plugins } vim.cmd ":PackerCompile" vim.cmd ":PackerInstall" -- vim.cmd ":PackerClean" -- 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/utils/init.lua | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) (limited to 'lua/utils/init.lua') diff --git a/lua/utils/init.lua b/lua/utils/init.lua index 100ab628..5a5e4ba3 100644 --- a/lua/utils/init.lua +++ b/lua/utils/init.lua @@ -93,9 +93,11 @@ function utils.reload_lv_config() vim.cmd("source " .. utils.join_paths(get_runtime_dir(), "lvim", "lua", "plugins.lua")) local plugins = require "plugins" utils.toggle_autoformat() - require("plugin-loader"):load { plugins, lvim.plugins } - vim.cmd ":PackerCompile" + local plugin_loader = require "plugin-loader" + plugin_loader:cache_reset() + plugin_loader:load { plugins, lvim.plugins } vim.cmd ":PackerInstall" + vim.cmd ":PackerCompile" -- vim.cmd ":PackerClean" local null_ls = require "lsp.null-ls" null_ls.setup(vim.bo.filetype, { force_reload = true }) @@ -118,6 +120,18 @@ function utils.gsub_args(args) return args end +--- Returns a table with the default values that are missing. +--- either paramter can be empty. +--@param config (table) table containing entries that take priority over defaults +--@param default_config (table) table contatining default values if found +function utils.apply_defaults(config, default_config) + config = config or {} + default_config = default_config or {} + local new_config = vim.tbl_deep_extend("keep", vim.empty_dict(), config) + new_config = vim.tbl_deep_extend("keep", new_config, default_config) + return new_config +end + --- Checks whether a given path exists and is a file. --@param filename (string) path to check --@returns (bool) @@ -132,6 +146,14 @@ function utils.join_paths(...) return result end +function utils.lvim_cache_reset() + _G.__luacache.clear_cache() + _G.__luacache.save_cache() + require("plugin-loader"):cache_reset() +end + +vim.cmd [[ command! LvimCacheReset lua require('utils').lvim_cache_reset() ]] + return utils -- TODO: find a new home for these autocommands -- 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/utils/init.lua | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) (limited to 'lua/utils/init.lua') diff --git a/lua/utils/init.lua b/lua/utils/init.lua index 5a5e4ba3..7f8e1f77 100644 --- a/lua/utils/init.lua +++ b/lua/utils/init.lua @@ -140,19 +140,7 @@ function utils.is_file(filename) return stat and stat.type == "file" or false end -function utils.join_paths(...) - local path_sep = vim.loop.os_uname().version:match "Windows" and "\\" or "/" - local result = table.concat(vim.tbl_flatten { ... }, path_sep):gsub(path_sep .. "+", path_sep) - return result -end - -function utils.lvim_cache_reset() - _G.__luacache.clear_cache() - _G.__luacache.save_cache() - require("plugin-loader"):cache_reset() -end - -vim.cmd [[ command! LvimCacheReset lua require('utils').lvim_cache_reset() ]] +utils.join_paths = _G.join_paths return utils -- 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/utils/init.lua | 100 ++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 95 insertions(+), 5 deletions(-) (limited to 'lua/utils/init.lua') diff --git a/lua/utils/init.lua b/lua/utils/init.lua index 7f8e1f77..eaac54f4 100644 --- a/lua/utils/init.lua +++ b/lua/utils/init.lua @@ -99,8 +99,7 @@ function utils.reload_lv_config() vim.cmd ":PackerInstall" vim.cmd ":PackerCompile" -- vim.cmd ":PackerClean" - local null_ls = require "lsp.null-ls" - null_ls.setup(vim.bo.filetype, { force_reload = true }) + require("lsp").setup() Log:info "Reloaded configuration" end @@ -133,15 +132,106 @@ function utils.apply_defaults(config, default_config) end --- Checks whether a given path exists and is a file. ---@param filename (string) path to check +--@param path (string) path to check --@returns (bool) -function utils.is_file(filename) - local stat = uv.fs_stat(filename) +function utils.is_file(path) + local stat = uv.fs_stat(path) return stat and stat.type == "file" or false end +--- Checks whether a given path exists and is a directory +--@param path (string) path to check +--@returns (bool) +function utils.is_directory(path) + local stat = uv.fs_stat(path) + return stat and stat.type == "directory" or false +end + +function utils.write_file(path, txt, flag) + uv.fs_open(path, flag, 438, function(open_err, fd) + assert(not open_err, open_err) + uv.fs_write(fd, txt, -1, function(write_err) + assert(not write_err, write_err) + uv.fs_close(fd, function(close_err) + assert(not close_err, close_err) + end) + end) + end) +end + utils.join_paths = _G.join_paths +function utils.write_file(path, txt, flag) + uv.fs_open(path, flag, 438, function(open_err, fd) + assert(not open_err, open_err) + uv.fs_write(fd, txt, -1, function(write_err) + assert(not write_err, write_err) + uv.fs_close(fd, function(close_err) + assert(not close_err, close_err) + end) + end) + end) +end + +function utils.debounce(ms, fn) + local timer = vim.loop.new_timer() + return function(...) + local argv = { ... } + timer:start(ms, 0, function() + timer:stop() + vim.schedule_wrap(fn)(unpack(argv)) + end) + end +end + +function utils.search_file(file, args) + local Job = require "plenary.job" + local stderr = {} + local stdout, ret = Job + :new({ + command = "grep", + args = { args, file }, + cwd = get_cache_dir(), + on_stderr = function(_, data) + table.insert(stderr, data) + end, + }) + :sync() + return stdout, ret, stderr +end + +function utils.file_contains(file, query) + local stdout, ret, stderr = utils.search_file(file, query) + if ret == 0 then + return true + end + if not vim.tbl_isempty(stderr) then + error(vim.inspect(stderr)) + end + if not vim.tbl_isempty(stdout) then + error(vim.inspect(stdout)) + end + return false +end + +function utils.log_contains(query) + local logfile = require("core.log"):get_path() + local stdout, ret, stderr = utils.search_file(logfile, query) + if ret == 0 then + return true + end + if not vim.tbl_isempty(stderr) then + error(vim.inspect(stderr)) + end + if not vim.tbl_isempty(stdout) then + error(vim.inspect(stdout)) + end + if not vim.tbl_isempty(stderr) then + error(vim.inspect(stderr)) + end + return false +end + return utils -- TODO: find a new home for these autocommands -- cgit v1.2.3