aboutsummaryrefslogtreecommitdiff
path: root/runtime/lua/vim/lsp/log.lua
diff options
context:
space:
mode:
authorChristian Clason <c.clason@uni-graz.at>2022-05-09 11:23:51 +0200
committerChristian Clason <c.clason@uni-graz.at>2022-05-09 16:31:55 +0200
commitaefdc6783cb77f09786542c90901a9e7120bea42 (patch)
treeddce6de8f084ab96270f6111d8e423d0b1533171 /runtime/lua/vim/lsp/log.lua
parent676e9e9334043ce74af74f85f889b0327a443d0b (diff)
downloadrneovim-aefdc6783cb77f09786542c90901a9e7120bea42.tar.gz
rneovim-aefdc6783cb77f09786542c90901a9e7120bea42.tar.bz2
rneovim-aefdc6783cb77f09786542c90901a9e7120bea42.zip
chore: format runtime with stylua
Diffstat (limited to 'runtime/lua/vim/lsp/log.lua')
-rw-r--r--runtime/lua/vim/lsp/log.lua70
1 files changed, 42 insertions, 28 deletions
diff --git a/runtime/lua/vim/lsp/log.lua b/runtime/lua/vim/lsp/log.lua
index fff42fd011..66e82ecfeb 100644
--- a/runtime/lua/vim/lsp/log.lua
+++ b/runtime/lua/vim/lsp/log.lua
@@ -14,21 +14,23 @@ log.levels = vim.deepcopy(vim.log.levels)
-- Default log level is warn.
local current_log_level = log.levels.WARN
-local log_date_format = "%F %H:%M:%S"
-local format_func = function(arg) return vim.inspect(arg, {newline=''}) end
+local log_date_format = '%F %H:%M:%S'
+local format_func = function(arg)
+ return vim.inspect(arg, { newline = '' })
+end
do
- local path_sep = vim.loop.os_uname().version:match("Windows") and "\\" or "/"
+ local path_sep = vim.loop.os_uname().version:match('Windows') and '\\' or '/'
---@private
local function path_join(...)
- return table.concat(vim.tbl_flatten{...}, path_sep)
+ return table.concat(vim.tbl_flatten({ ... }), path_sep)
end
local logfilename = path_join(vim.fn.stdpath('cache'), 'lsp.log')
-- TODO: Ideally the directory should be created in open_logfile(), right
-- before opening the log file, but open_logfile() can be called from libuv
-- callbacks, where using fn.mkdir() is not allowed.
- vim.fn.mkdir(vim.fn.stdpath('cache'), "p")
+ vim.fn.mkdir(vim.fn.stdpath('cache'), 'p')
--- Returns the log filename.
---@returns (string) log filename
@@ -41,28 +43,28 @@ do
--- Opens log file. Returns true if file is open, false on error
local function open_logfile()
-- Try to open file only once
- if logfile then return true end
- if openerr then return false end
+ if logfile then
+ return true
+ end
+ if openerr then
+ return false
+ end
- logfile, openerr = io.open(logfilename, "a+")
+ logfile, openerr = io.open(logfilename, 'a+')
if not logfile then
- local err_msg = string.format("Failed to open LSP client log file: %s", openerr)
+ local err_msg = string.format('Failed to open LSP client log file: %s', openerr)
vim.notify(err_msg, vim.log.levels.ERROR)
return false
end
local log_info = vim.loop.fs_stat(logfilename)
if log_info and log_info.size > 1e9 then
- local warn_msg = string.format(
- "LSP client log is large (%d MB): %s",
- log_info.size / (1000 * 1000),
- logfilename
- )
+ local warn_msg = string.format('LSP client log is large (%d MB): %s', log_info.size / (1000 * 1000), logfilename)
vim.notify(warn_msg)
end
-- Start message for logging
- logfile:write(string.format("[START][%s] LSP logging initiated\n", os.date(log_date_format)))
+ logfile:write(string.format('[START][%s] LSP logging initiated\n', os.date(log_date_format)))
return true
end
@@ -83,24 +85,36 @@ do
-- ```
--
-- This way you can avoid string allocations if the log level isn't high enough.
- if level ~= "OFF" then
+ if level ~= 'OFF' then
log[level:lower()] = function(...)
- local argc = select("#", ...)
- if levelnr < current_log_level then return false end
- if argc == 0 then return true end
- if not open_logfile() then return false end
- local info = debug.getinfo(2, "Sl")
- local header = string.format("[%s][%s] ...%s:%s", level, os.date(log_date_format), string.sub(info.short_src, #info.short_src - 15), info.currentline)
+ local argc = select('#', ...)
+ if levelnr < current_log_level then
+ return false
+ end
+ if argc == 0 then
+ return true
+ end
+ if not open_logfile() then
+ return false
+ end
+ local info = debug.getinfo(2, 'Sl')
+ local header = string.format(
+ '[%s][%s] ...%s:%s',
+ level,
+ os.date(log_date_format),
+ string.sub(info.short_src, #info.short_src - 15),
+ info.currentline
+ )
local parts = { header }
for i = 1, argc do
local arg = select(i, ...)
if arg == nil then
- table.insert(parts, "nil")
+ table.insert(parts, 'nil')
else
table.insert(parts, format_func(arg))
end
end
- logfile:write(table.concat(parts, '\t'), "\n")
+ logfile:write(table.concat(parts, '\t'), '\n')
logfile:flush()
end
end
@@ -115,10 +129,10 @@ vim.tbl_add_reverse_lookup(log.levels)
---@param level (string or number) One of `vim.lsp.log.levels`
function log.set_level(level)
if type(level) == 'string' then
- current_log_level = assert(log.levels[level:upper()], string.format("Invalid log level: %q", level))
+ current_log_level = assert(log.levels[level:upper()], string.format('Invalid log level: %q', level))
else
- assert(type(level) == 'number', "level must be a number or string")
- assert(log.levels[level], string.format("Invalid log level: %d", level))
+ assert(type(level) == 'number', 'level must be a number or string')
+ assert(log.levels[level], string.format('Invalid log level: %d', level))
current_log_level = level
end
end
@@ -132,7 +146,7 @@ end
--- Sets formatting function used to format logs
---@param handle function function to apply to logging arguments, pass vim.inspect for multi-line formatting
function log.set_format_func(handle)
- assert(handle == vim.inspect or type(handle) == 'function', "handle must be a function")
+ assert(handle == vim.inspect or type(handle) == 'function', 'handle must be a function')
format_func = handle
end