summaryrefslogtreecommitdiff
path: root/lua
diff options
context:
space:
mode:
Diffstat (limited to 'lua')
-rw-r--r--lua/core/log.lua65
-rw-r--r--lua/core/lualine/styles.lua2
-rw-r--r--lua/keymappings.lua2
-rw-r--r--lua/lsp/init.lua8
-rw-r--r--lua/lsp/null-ls/formatters.lua2
-rw-r--r--lua/lsp/null-ls/linters.lua2
-rw-r--r--lua/plugin-loader.lua9
-rw-r--r--lua/utils/init.lua4
8 files changed, 46 insertions, 48 deletions
diff --git a/lua/core/log.lua b/lua/core/log.lua
index 54620625..1eb786ba 100644
--- a/lua/core/log.lua
+++ b/lua/core/log.lua
@@ -1,60 +1,59 @@
local Log = {}
---- Creates a log handle based on Plenary.log
----@param opts these are passed verbatim to Plenary.log
----@return log handle
-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
-
+--- Adds a log entry using Plenary.log
+---@param msg any
+---@param level string [same as vim.log.log_levels]
function Log:add_entry(msg, level)
- local status_ok, _ = pcall(require, "plenary.log")
- if not status_ok then
- return vim.notify(msg, vim.log.levels[level])
+ assert(type(level) == "string")
+ if self.__handle then
+ -- plenary uses lower-case log levels
+ self.__handle[level:lower()](msg)
+ end
+ local status_ok, plenary = pcall(require, "plenary")
+ 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
- -- plenary uses lower-case log levels
- return self.__handle[level:lower()](msg)
+ -- don't do anything if plenary is not available
end
---- Creates or retrieves a log handle for the default logfile
---- based on Plenary.log
----@return log handle
-function Log:new_default()
- return Log:new { plugin = "lunarvim", level = lvim.log.level }
+---Retrieves the path of the logfile
+---@return string path of the logfile
+function Log:get_path()
+ return string.format("%s/%s.log", vim.fn.stdpath "cache", "lunarvim")
end
+---Add a log entry at TRACE level
+---@param msg any
function Log:trace(msg)
self:add_entry(msg, "TRACE")
end
+---Add a log entry at DEBUG level
+---@param msg any
function Log:debug(msg)
self:add_entry(msg, "DEBUG")
end
+---Add a log entry at INFO level
+---@param msg any
function Log:info(msg)
self:add_entry(msg, "INFO")
end
+---Add a log entry at WARN level
+---@param msg any
function Log:warn(msg)
- self:add_entry(msg, "TRACE")
+ self:add_entry(msg, "WARN")
end
+---Add a log entry at ERROR level
+---@param msg any
function Log:error(msg)
- self:add_entry(msg, "TRACE")
+ self:add_entry(msg, "ERROR")
end
+setmetatable({}, Log)
return Log
diff --git a/lua/core/lualine/styles.lua b/lua/core/lualine/styles.lua
index 53b0691e..84e8123d 100644
--- a/lua/core/lualine/styles.lua
+++ b/lua/core/lualine/styles.lua
@@ -118,7 +118,7 @@ function M.get_style(style)
"options are: ",
string.format('"%s"', table.concat(style_keys, '", "'))
)
- Log:info '"lvim" style is applied.'
+ Log:debug '"lvim" style is applied.'
style = "lvim"
end
diff --git a/lua/keymappings.lua b/lua/keymappings.lua
index fa1af1c4..557e0bde 100644
--- a/lua/keymappings.lua
+++ b/lua/keymappings.lua
@@ -159,7 +159,7 @@ function M.config()
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-Right>"] = lvim.keys.normal_mode["<C-Right>"]
- Log:info "Activated mac keymappings"
+ Log:debug "Activated mac keymappings"
end
end
diff --git a/lua/lsp/init.lua b/lua/lsp/init.lua
index 94fcf550..f3b019aa 100644
--- a/lua/lsp/init.lua
+++ b/lua/lsp/init.lua
@@ -99,21 +99,23 @@ end
function M.common_on_init(client, bufnr)
if lvim.lsp.on_init_callback then
lvim.lsp.on_init_callback(client, bufnr)
- Log:info "Called lsp.on_init_callback"
+ Log:debug "Called lsp.on_init_callback"
return
end
local formatters = lvim.lang[vim.bo.filetype].formatters
if not vim.tbl_isempty(formatters) and formatters[1]["exe"] ~= nil and formatters[1].exe ~= "" then
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
function M.common_on_attach(client, bufnr)
if lvim.lsp.on_attach_callback then
lvim.lsp.on_attach_callback(client, bufnr)
- Log:get_default().info "Called lsp.on_init_callback"
+ Log:debug "Called lsp.on_init_callback"
end
lsp_highlight_document(client)
add_lsp_buffer_keybindings(bufnr)
diff --git a/lua/lsp/null-ls/formatters.lua b/lua/lsp/null-ls/formatters.lua
index 05e0ec62..26be00da 100644
--- a/lua/lsp/null-ls/formatters.lua
+++ b/lua/lsp/null-ls/formatters.lua
@@ -53,7 +53,7 @@ function M.list_configured(formatter_configs)
Log:warn("Not found:", formatter._opts.command)
errors[fmt_config.exe] = {} -- Add data here when necessary
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 }
end
end
diff --git a/lua/lsp/null-ls/linters.lua b/lua/lsp/null-ls/linters.lua
index 70c59974..bc191d7e 100644
--- a/lua/lsp/null-ls/linters.lua
+++ b/lua/lsp/null-ls/linters.lua
@@ -53,7 +53,7 @@ function M.list_configured(linter_configs)
Log:warn("Not found:", linter._opts.command)
errors[lnt_config.exe] = {} -- Add data here when necessary
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 }
end
end
diff --git a/lua/plugin-loader.lua b/lua/plugin-loader.lua
index e238b193..aa1e888d 100644
--- a/lua/plugin-loader.lua
+++ b/lua/plugin-loader.lua
@@ -1,13 +1,10 @@
local plugin_loader = {}
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"
- if fn.empty(fn.glob(install_path)) > 0 then
- execute("!git clone https://github.com/wbthomason/packer.nvim " .. install_path)
- execute "packadd packer.nvim"
+ if vim.fn.empty(vim.fn.glob(install_path)) > 0 then
+ vim.fn.system { "git", "clone", "https://github.com/wbthomason/packer.nvim", install_path }
+ vim.cmd "packadd packer.nvim"
end
local packer_ok, packer = pcall(require, "packer")
diff --git a/lua/utils/init.lua b/lua/utils/init.lua
index 322a961f..8ea842ca 100644
--- a/lua/utils/init.lua
+++ b/lua/utils/init.lua
@@ -70,7 +70,7 @@ function utils.toggle_autoformat()
},
},
}
- Log:info "Format on save active"
+ Log:debug "Format on save active"
end
if not lvim.format_on_save then
@@ -79,7 +79,7 @@ function utils.toggle_autoformat()
:autocmd! autoformat
endif
]]
- Log:info "Format on save off"
+ Log:debug "Format on save off"
end
end