fix(lsp): type-errors, other nits in vim.lsp.log #31235

This commit is contained in:
Maria José Solano 2024-11-16 18:32:09 -08:00 committed by GitHub
parent cdc9baeaf8
commit 38838fb00a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 6 additions and 5 deletions

View File

@ -2149,7 +2149,7 @@ should_log({level}) *vim.lsp.log.should_log()*
• {level} (`integer`) log level
Return: ~
(`bool`) true if would log, false if not
(`boolean`) true if would log, false if not
==============================================================================

View File

@ -32,12 +32,12 @@ local function notify(msg, level)
end
end
local logfilename = vim.fs.joinpath(vim.fn.stdpath('log'), 'lsp.log')
local logfilename = vim.fs.joinpath(vim.fn.stdpath('log') --[[@as string]], '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('log'), 'p')
vim.fn.mkdir(vim.fn.stdpath('log') --[[@as string]], 'p')
--- Returns the log filename.
---@return string log filename
@ -82,6 +82,7 @@ end
for level, levelnr in pairs(log_levels) do
-- Also export the log level on the root object.
---@diagnostic disable-next-line: no-unknown
log[level] = levelnr
-- Add a reverse lookup.
@ -93,7 +94,7 @@ end
--- @return fun(...:any): boolean?
local function create_logger(level, levelnr)
return function(...)
if levelnr < current_log_level then
if not log.should_log(levelnr) then
return false
end
local argc = select('#', ...)
@ -169,7 +170,7 @@ end
--- Checks whether the level is sufficient for logging.
---@param level integer log level
---@return bool : true if would log, false if not
---@return boolean : true if would log, false if not
function log.should_log(level)
return level >= current_log_level
end