mirror of
https://github.com/LunarVim/LunarVim.git
synced 2024-09-20 18:45:08 +02:00
[Refactor]: only allow a single logger (#1405)
This commit is contained in:
parent
14f129cf26
commit
27679f988f
11 changed files with 81 additions and 84 deletions
5
.github/workflows/install.yaml
vendored
5
.github/workflows/install.yaml
vendored
|
@ -38,8 +38,9 @@ jobs:
|
||||||
- name: Install LunarVim
|
- name: Install LunarVim
|
||||||
timeout-minutes: 4
|
timeout-minutes: 4
|
||||||
run: |
|
run: |
|
||||||
mkdir -p "$HOME/.local/share/lunarvim"
|
mkdir -p "$HOME"/.local/share/lunarvim/lvim
|
||||||
mkdir -p "$HOME/.config/lvim"
|
mkdir -p "$HOME"/.config/lvim
|
||||||
|
ln -s "$PWD"/* "$HOME"/.local/share/lunarvim/lvim/.
|
||||||
bash ./utils/installer/install.sh
|
bash ./utils/installer/install.sh
|
||||||
|
|
||||||
- name: Test LunarVim PackerCompile
|
- name: Test LunarVim PackerCompile
|
||||||
|
|
2
init.lua
2
init.lua
|
@ -25,7 +25,7 @@ local plugins = require "plugins"
|
||||||
local plugin_loader = require("plugin-loader").init()
|
local plugin_loader = require("plugin-loader").init()
|
||||||
plugin_loader:load { plugins, lvim.plugins }
|
plugin_loader:load { plugins, lvim.plugins }
|
||||||
|
|
||||||
local Log = require("core.log").new_default()
|
local Log = require "core.log"
|
||||||
Log:info "Starting LunarVim"
|
Log:info "Starting LunarVim"
|
||||||
|
|
||||||
vim.g.colors_name = lvim.colorscheme -- Colorscheme must get called after plugins are loaded or it will break new installs.
|
vim.g.colors_name = lvim.colorscheme -- Colorscheme must get called after plugins are loaded or it will break new installs.
|
||||||
|
|
|
@ -1,60 +1,59 @@
|
||||||
local Log = {}
|
local Log = {}
|
||||||
|
|
||||||
--- Creates a log handle based on Plenary.log
|
--- Adds a log entry using Plenary.log
|
||||||
---@param opts these are passed verbatim to Plenary.log
|
---@param msg any
|
||||||
---@return log handle
|
---@param level string [same as vim.log.log_levels]
|
||||||
function Log:new(opts)
|
|
||||||
local status_ok, handle = pcall(require, "plenary.log")
|
|
||||||
if not status_ok then
|
|
||||||
vim.notify("Plenary.log is not available. Logging to console only", vim.log.levels.DEBUG)
|
|
||||||
end
|
|
||||||
|
|
||||||
self.__handle = handle
|
|
||||||
|
|
||||||
local path = string.format("%s/%s.log", vim.api.nvim_call_function("stdpath", { "cache" }), opts.plugin)
|
|
||||||
|
|
||||||
self.get_path = function()
|
|
||||||
return path
|
|
||||||
end
|
|
||||||
|
|
||||||
setmetatable({}, Log)
|
|
||||||
return self
|
|
||||||
end
|
|
||||||
|
|
||||||
function Log:add_entry(msg, level)
|
function Log:add_entry(msg, level)
|
||||||
local status_ok, _ = pcall(require, "plenary.log")
|
assert(type(level) == "string")
|
||||||
if not status_ok then
|
if self.__handle then
|
||||||
return vim.notify(msg, vim.log.levels[level])
|
-- plenary uses lower-case log levels
|
||||||
|
self.__handle[level:lower()](msg)
|
||||||
end
|
end
|
||||||
-- plenary uses lower-case log levels
|
local status_ok, plenary = pcall(require, "plenary")
|
||||||
return self.__handle[level:lower()](msg)
|
if status_ok then
|
||||||
|
local default_opts = { plugin = "lunarvim", level = lvim.log.level }
|
||||||
|
local handle = plenary.log.new(default_opts)
|
||||||
|
handle[level:lower()](msg)
|
||||||
|
self.__handle = handle
|
||||||
|
end
|
||||||
|
-- don't do anything if plenary is not available
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Creates or retrieves a log handle for the default logfile
|
---Retrieves the path of the logfile
|
||||||
--- based on Plenary.log
|
---@return string path of the logfile
|
||||||
---@return log handle
|
function Log:get_path()
|
||||||
function Log:new_default()
|
return string.format("%s/%s.log", vim.fn.stdpath "cache", "lunarvim")
|
||||||
return Log:new { plugin = "lunarvim", level = lvim.log.level }
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---Add a log entry at TRACE level
|
||||||
|
---@param msg any
|
||||||
function Log:trace(msg)
|
function Log:trace(msg)
|
||||||
self:add_entry(msg, "TRACE")
|
self:add_entry(msg, "TRACE")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---Add a log entry at DEBUG level
|
||||||
|
---@param msg any
|
||||||
function Log:debug(msg)
|
function Log:debug(msg)
|
||||||
self:add_entry(msg, "DEBUG")
|
self:add_entry(msg, "DEBUG")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---Add a log entry at INFO level
|
||||||
|
---@param msg any
|
||||||
function Log:info(msg)
|
function Log:info(msg)
|
||||||
self:add_entry(msg, "INFO")
|
self:add_entry(msg, "INFO")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---Add a log entry at WARN level
|
||||||
|
---@param msg any
|
||||||
function Log:warn(msg)
|
function Log:warn(msg)
|
||||||
self:add_entry(msg, "TRACE")
|
self:add_entry(msg, "WARN")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---Add a log entry at ERROR level
|
||||||
|
---@param msg any
|
||||||
function Log:error(msg)
|
function Log:error(msg)
|
||||||
self:add_entry(msg, "TRACE")
|
self:add_entry(msg, "ERROR")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
setmetatable({}, Log)
|
||||||
return Log
|
return Log
|
||||||
|
|
|
@ -118,7 +118,7 @@ function M.get_style(style)
|
||||||
"options are: ",
|
"options are: ",
|
||||||
string.format('"%s"', table.concat(style_keys, '", "'))
|
string.format('"%s"', table.concat(style_keys, '", "'))
|
||||||
)
|
)
|
||||||
Log:info '"lvim" style is applied.'
|
Log:debug '"lvim" style is applied.'
|
||||||
style = "lvim"
|
style = "lvim"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -159,7 +159,7 @@ function M.config()
|
||||||
lvim.keys.normal_mode["<A-Down>"] = lvim.keys.normal_mode["<C-Down>"]
|
lvim.keys.normal_mode["<A-Down>"] = lvim.keys.normal_mode["<C-Down>"]
|
||||||
lvim.keys.normal_mode["<A-Left>"] = lvim.keys.normal_mode["<C-Left>"]
|
lvim.keys.normal_mode["<A-Left>"] = lvim.keys.normal_mode["<C-Left>"]
|
||||||
lvim.keys.normal_mode["<A-Right>"] = lvim.keys.normal_mode["<C-Right>"]
|
lvim.keys.normal_mode["<A-Right>"] = lvim.keys.normal_mode["<C-Right>"]
|
||||||
Log:info "Activated mac keymappings"
|
Log:debug "Activated mac keymappings"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -99,21 +99,23 @@ end
|
||||||
function M.common_on_init(client, bufnr)
|
function M.common_on_init(client, bufnr)
|
||||||
if lvim.lsp.on_init_callback then
|
if lvim.lsp.on_init_callback then
|
||||||
lvim.lsp.on_init_callback(client, bufnr)
|
lvim.lsp.on_init_callback(client, bufnr)
|
||||||
Log:info "Called lsp.on_init_callback"
|
Log:debug "Called lsp.on_init_callback"
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local formatters = lvim.lang[vim.bo.filetype].formatters
|
local formatters = lvim.lang[vim.bo.filetype].formatters
|
||||||
if not vim.tbl_isempty(formatters) and formatters[1]["exe"] ~= nil and formatters[1].exe ~= "" then
|
if not vim.tbl_isempty(formatters) and formatters[1]["exe"] ~= nil and formatters[1].exe ~= "" then
|
||||||
client.resolved_capabilities.document_formatting = false
|
client.resolved_capabilities.document_formatting = false
|
||||||
Log:info(string.format("Overriding language server [%s] with format provider [%s]", client.name, formatters[1].exe))
|
Log:debug(
|
||||||
|
string.format("Overriding language server [%s] with format provider [%s]", client.name, formatters[1].exe)
|
||||||
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.common_on_attach(client, bufnr)
|
function M.common_on_attach(client, bufnr)
|
||||||
if lvim.lsp.on_attach_callback then
|
if lvim.lsp.on_attach_callback then
|
||||||
lvim.lsp.on_attach_callback(client, bufnr)
|
lvim.lsp.on_attach_callback(client, bufnr)
|
||||||
Log:get_default().info "Called lsp.on_init_callback"
|
Log:debug "Called lsp.on_init_callback"
|
||||||
end
|
end
|
||||||
lsp_highlight_document(client)
|
lsp_highlight_document(client)
|
||||||
add_lsp_buffer_keybindings(bufnr)
|
add_lsp_buffer_keybindings(bufnr)
|
||||||
|
|
|
@ -53,7 +53,7 @@ function M.list_configured(formatter_configs)
|
||||||
Log:warn("Not found:", formatter._opts.command)
|
Log:warn("Not found:", formatter._opts.command)
|
||||||
errors[fmt_config.exe] = {} -- Add data here when necessary
|
errors[fmt_config.exe] = {} -- Add data here when necessary
|
||||||
else
|
else
|
||||||
Log:info("Using formatter:", formatter_cmd)
|
Log:debug("Using formatter:", formatter_cmd)
|
||||||
formatters[fmt_config.exe] = formatter.with { command = formatter_cmd, extra_args = fmt_config.args }
|
formatters[fmt_config.exe] = formatter.with { command = formatter_cmd, extra_args = fmt_config.args }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -53,7 +53,7 @@ function M.list_configured(linter_configs)
|
||||||
Log:warn("Not found:", linter._opts.command)
|
Log:warn("Not found:", linter._opts.command)
|
||||||
errors[lnt_config.exe] = {} -- Add data here when necessary
|
errors[lnt_config.exe] = {} -- Add data here when necessary
|
||||||
else
|
else
|
||||||
Log:info("Using linter:", linter_cmd)
|
Log:debug("Using linter:", linter_cmd)
|
||||||
linters[lnt_config.exe] = linter.with { command = linter_cmd, extra_args = lnt_config.args }
|
linters[lnt_config.exe] = linter.with { command = linter_cmd, extra_args = lnt_config.args }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,13 +1,10 @@
|
||||||
local plugin_loader = {}
|
local plugin_loader = {}
|
||||||
|
|
||||||
function plugin_loader:init()
|
function plugin_loader:init()
|
||||||
local execute = vim.api.nvim_command
|
|
||||||
local fn = vim.fn
|
|
||||||
|
|
||||||
local install_path = "~/.local/share/lunarvim/site/pack/packer/start/packer.nvim"
|
local install_path = "~/.local/share/lunarvim/site/pack/packer/start/packer.nvim"
|
||||||
if fn.empty(fn.glob(install_path)) > 0 then
|
if vim.fn.empty(vim.fn.glob(install_path)) > 0 then
|
||||||
execute("!git clone https://github.com/wbthomason/packer.nvim " .. install_path)
|
vim.fn.system { "git", "clone", "https://github.com/wbthomason/packer.nvim", install_path }
|
||||||
execute "packadd packer.nvim"
|
vim.cmd "packadd packer.nvim"
|
||||||
end
|
end
|
||||||
|
|
||||||
local packer_ok, packer = pcall(require, "packer")
|
local packer_ok, packer = pcall(require, "packer")
|
||||||
|
|
|
@ -70,7 +70,7 @@ function utils.toggle_autoformat()
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
Log:info "Format on save active"
|
Log:debug "Format on save active"
|
||||||
end
|
end
|
||||||
|
|
||||||
if not lvim.format_on_save then
|
if not lvim.format_on_save then
|
||||||
|
@ -79,7 +79,7 @@ function utils.toggle_autoformat()
|
||||||
:autocmd! autoformat
|
:autocmd! autoformat
|
||||||
endif
|
endif
|
||||||
]]
|
]]
|
||||||
Log:info "Format on save off"
|
Log:debug "Format on save off"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -50,33 +50,35 @@ EOF
|
||||||
echo "Detecting platform for managing any additional neovim dependencies"
|
echo "Detecting platform for managing any additional neovim dependencies"
|
||||||
detect_platform
|
detect_platform
|
||||||
|
|
||||||
# skip this in a Github workflow
|
if [ -n "$GITHUB_ACTIONS" ]; then
|
||||||
if [ -z "$GITHUB_ACTIONS" ]; then
|
install_packer
|
||||||
check_system_deps
|
setup_lvim
|
||||||
|
exit 0
|
||||||
__add_separator "80"
|
|
||||||
|
|
||||||
echo "Would you like to check lunarvim's NodeJS dependencies?"
|
|
||||||
read -p "[y]es or [n]o (default: no) : " -r answer
|
|
||||||
[ "$answer" != "${answer#[Yy]}" ] && install_nodejs_deps
|
|
||||||
|
|
||||||
echo "Would you like to check lunarvim's Python dependencies?"
|
|
||||||
read -p "[y]es or [n]o (default: no) : " -r answer
|
|
||||||
[ "$answer" != "${answer#[Yy]}" ] && install_python_deps
|
|
||||||
|
|
||||||
echo "Would you like to check lunarvim's Rust dependencies?"
|
|
||||||
read -p "[y]es or [n]o (default: no) : " -r answer
|
|
||||||
[ "$answer" != "${answer#[Yy]}" ] && install_rust_deps
|
|
||||||
|
|
||||||
__add_separator "80"
|
|
||||||
|
|
||||||
echo "Backing up old LunarVim configuration"
|
|
||||||
backup_old_config
|
|
||||||
|
|
||||||
__add_separator "80"
|
|
||||||
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
check_system_deps
|
||||||
|
|
||||||
|
__add_separator "80"
|
||||||
|
|
||||||
|
echo "Would you like to check lunarvim's NodeJS dependencies?"
|
||||||
|
read -p "[y]es or [n]o (default: no) : " -r answer
|
||||||
|
[ "$answer" != "${answer#[Yy]}" ] && install_nodejs_deps
|
||||||
|
|
||||||
|
echo "Would you like to check lunarvim's Python dependencies?"
|
||||||
|
read -p "[y]es or [n]o (default: no) : " -r answer
|
||||||
|
[ "$answer" != "${answer#[Yy]}" ] && install_python_deps
|
||||||
|
|
||||||
|
echo "Would you like to check lunarvim's Rust dependencies?"
|
||||||
|
read -p "[y]es or [n]o (default: no) : " -r answer
|
||||||
|
[ "$answer" != "${answer#[Yy]}" ] && install_rust_deps
|
||||||
|
|
||||||
|
__add_separator "80"
|
||||||
|
|
||||||
|
echo "Backing up old LunarVim configuration"
|
||||||
|
backup_old_config
|
||||||
|
|
||||||
|
__add_separator "80"
|
||||||
|
|
||||||
case "$@" in
|
case "$@" in
|
||||||
*--overwrite*)
|
*--overwrite*)
|
||||||
echo "!!Warning!! -> Removing all lunarvim related config \
|
echo "!!Warning!! -> Removing all lunarvim related config \
|
||||||
|
@ -219,13 +221,13 @@ function backup_old_config() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function install_packer() {
|
function install_packer() {
|
||||||
git clone --progress --depth 1 https://github.com/wbthomason/packer.nvim \
|
git clone --depth 1 https://github.com/wbthomason/packer.nvim \
|
||||||
"$LUNARVIM_RUNTIME_DIR/site/pack/packer/start/packer.nvim"
|
"$LUNARVIM_RUNTIME_DIR/site/pack/packer/start/packer.nvim"
|
||||||
}
|
}
|
||||||
|
|
||||||
function clone_lvim() {
|
function clone_lvim() {
|
||||||
echo "Cloning LunarVim configuration"
|
echo "Cloning LunarVim configuration"
|
||||||
if ! git clone --progress --branch "$LV_BRANCH" \
|
if ! git clone --branch "$LV_BRANCH" \
|
||||||
--depth 1 "https://github.com/${LV_REMOTE}" "$LUNARVIM_RUNTIME_DIR/lvim"; then
|
--depth 1 "https://github.com/${LV_REMOTE}" "$LUNARVIM_RUNTIME_DIR/lvim"; then
|
||||||
echo "Failed to clone repository. Installation failed."
|
echo "Failed to clone repository. Installation failed."
|
||||||
exit 1
|
exit 1
|
||||||
|
@ -258,12 +260,8 @@ function setup_lvim() {
|
||||||
"$LUNARVIM_CONFIG_DIR/config.lua"
|
"$LUNARVIM_CONFIG_DIR/config.lua"
|
||||||
|
|
||||||
nvim -u "$LUNARVIM_RUNTIME_DIR/lvim/init.lua" --headless \
|
nvim -u "$LUNARVIM_RUNTIME_DIR/lvim/init.lua" --headless \
|
||||||
+'autocmd User PackerComplete sleep 100m | qall' \
|
-c 'autocmd User PackerComplete quitall' \
|
||||||
+PackerInstall
|
-c 'PackerSync'
|
||||||
|
|
||||||
nvim -u "$LUNARVIM_RUNTIME_DIR/lvim/init.lua" --headless \
|
|
||||||
+'autocmd User PackerComplete sleep 100m | qall' \
|
|
||||||
+PackerSync
|
|
||||||
|
|
||||||
echo "Packer setup complete"
|
echo "Packer setup complete"
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue