mirror of
https://github.com/nvim-treesitter/nvim-treesitter.git
synced 2026-07-13 17:00:09 -04:00
feat: improve logging of failed installs
This commit is contained in:
parent
a8f5641ab3
commit
421e2fb7b2
2 changed files with 109 additions and 136 deletions
|
|
@ -166,16 +166,17 @@ end
|
||||||
--- @param logger Logger
|
--- @param logger Logger
|
||||||
--- @param repo InstallInfo
|
--- @param repo InstallInfo
|
||||||
--- @param compile_location string
|
--- @param compile_location string
|
||||||
|
--- @return string? err
|
||||||
local function do_generate_from_grammar(logger, repo, compile_location)
|
local function do_generate_from_grammar(logger, repo, compile_location)
|
||||||
if repo.generate_requires_npm then
|
if repo.generate_requires_npm then
|
||||||
if not executable('npm') then
|
if not executable('npm') then
|
||||||
logger:error('NPM requires to be installed from grammar.js')
|
return logger:error('NPM requires to be installed from grammar.js')
|
||||||
end
|
end
|
||||||
|
|
||||||
logger:info('Installing NPM dependencies')
|
logger:info('Installing NPM dependencies')
|
||||||
local r = system({ 'npm', 'install' }, { cwd = compile_location })
|
local r = system({ 'npm', 'install' }, { cwd = compile_location })
|
||||||
if r.code > 0 then
|
if r.code > 0 then
|
||||||
logger:error('Error during `npm install`')
|
return logger:error('Error during `npm install`: %s', r.stderr)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -189,7 +190,7 @@ local function do_generate_from_grammar(logger, repo, compile_location)
|
||||||
tostring(vim.treesitter.language_version),
|
tostring(vim.treesitter.language_version),
|
||||||
}, { cwd = compile_location })
|
}, { cwd = compile_location })
|
||||||
if r.code > 0 then
|
if r.code > 0 then
|
||||||
logger:error('Error during "tree-sitter generate"')
|
return logger:error('Error during "tree-sitter generate": %s', r.stderr)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -199,6 +200,7 @@ end
|
||||||
---@param cache_dir string
|
---@param cache_dir string
|
||||||
---@param revision string
|
---@param revision string
|
||||||
---@param project_dir string
|
---@param project_dir string
|
||||||
|
---@return string? err
|
||||||
local function do_download_tar(logger, repo, project_name, cache_dir, revision, project_dir)
|
local function do_download_tar(logger, repo, project_name, cache_dir, revision, project_dir)
|
||||||
local is_github = repo.url:find('github.com', 1, true)
|
local is_github = repo.url:find('github.com', 1, true)
|
||||||
local url = repo.url:gsub('.git$', '')
|
local url = repo.url:gsub('.git$', '')
|
||||||
|
|
@ -228,7 +230,7 @@ local function do_download_tar(logger, repo, project_name, cache_dir, revision,
|
||||||
cwd = cache_dir,
|
cwd = cache_dir,
|
||||||
})
|
})
|
||||||
if r.code > 0 then
|
if r.code > 0 then
|
||||||
logger:error('Error during download, please verify your internet connection: %s', r.stderr)
|
return logger:error('Error during download, please verify your internet connection: %s', r.stderr)
|
||||||
end
|
end
|
||||||
|
|
||||||
logger:debug('Creating temporary directory: ' .. temp_dir)
|
logger:debug('Creating temporary directory: ' .. temp_dir)
|
||||||
|
|
@ -236,7 +238,7 @@ local function do_download_tar(logger, repo, project_name, cache_dir, revision,
|
||||||
local err = uv_mkdir(temp_dir, 493)
|
local err = uv_mkdir(temp_dir, 493)
|
||||||
a.main()
|
a.main()
|
||||||
if err then
|
if err then
|
||||||
logger:error('Could not create %s-tmp: %s', project_name, err)
|
return logger:error('Could not create %s-tmp: %s', project_name, err)
|
||||||
end
|
end
|
||||||
|
|
||||||
logger:info('Extracting ' .. project_name .. '...')
|
logger:info('Extracting ' .. project_name .. '...')
|
||||||
|
|
@ -251,12 +253,12 @@ local function do_download_tar(logger, repo, project_name, cache_dir, revision,
|
||||||
})
|
})
|
||||||
|
|
||||||
if r.code > 0 then
|
if r.code > 0 then
|
||||||
logger:error('Error during tarball extraction: %s', r.stderr)
|
return logger:error('Error during tarball extraction: %s', r.stderr)
|
||||||
end
|
end
|
||||||
|
|
||||||
err = uv_unlink(project_dir .. '.tar.gz')
|
err = uv_unlink(project_dir .. '.tar.gz')
|
||||||
if err then
|
if err then
|
||||||
logger:error('Could not remove tarball: %s', err)
|
return logger:error('Could not remove tarball: %s', err)
|
||||||
end
|
end
|
||||||
a.main()
|
a.main()
|
||||||
|
|
||||||
|
|
@ -264,7 +266,7 @@ local function do_download_tar(logger, repo, project_name, cache_dir, revision,
|
||||||
a.main()
|
a.main()
|
||||||
|
|
||||||
if err then
|
if err then
|
||||||
logger:error('Could not rename temp: %s', err)
|
return logger:error('Could not rename temp: %s', err)
|
||||||
end
|
end
|
||||||
|
|
||||||
util.delete(temp_dir)
|
util.delete(temp_dir)
|
||||||
|
|
@ -276,6 +278,7 @@ end
|
||||||
---@param cache_dir string
|
---@param cache_dir string
|
||||||
---@param revision string
|
---@param revision string
|
||||||
---@param project_dir string
|
---@param project_dir string
|
||||||
|
---@return string? err
|
||||||
local function do_download_git(logger, repo, project_name, cache_dir, revision, project_dir)
|
local function do_download_git(logger, repo, project_name, cache_dir, revision, project_dir)
|
||||||
logger:info('Downloading ' .. project_name .. '...')
|
logger:info('Downloading ' .. project_name .. '...')
|
||||||
|
|
||||||
|
|
@ -290,7 +293,7 @@ local function do_download_git(logger, repo, project_name, cache_dir, revision,
|
||||||
})
|
})
|
||||||
|
|
||||||
if r.code > 0 then
|
if r.code > 0 then
|
||||||
logger:error('Error during download, please verify your internet connection: ' .. r.stderr)
|
return logger:error('Error during download, please verify your internet connection: ', r.stderr)
|
||||||
end
|
end
|
||||||
|
|
||||||
logger:info('Checking out locked revision')
|
logger:info('Checking out locked revision')
|
||||||
|
|
@ -303,7 +306,7 @@ local function do_download_git(logger, repo, project_name, cache_dir, revision,
|
||||||
})
|
})
|
||||||
|
|
||||||
if r.code > 0 then
|
if r.code > 0 then
|
||||||
logger:error('Error while checking out revision: %s', r.stderr)
|
return logger:error('Error while checking out revision: %s', r.stderr)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -411,20 +414,9 @@ end
|
||||||
---@param lang string
|
---@param lang string
|
||||||
---@param cache_dir string
|
---@param cache_dir string
|
||||||
---@param install_dir string
|
---@param install_dir string
|
||||||
---@param force? boolean
|
|
||||||
---@param generate_from_grammar? boolean
|
---@param generate_from_grammar? boolean
|
||||||
local function install_lang(lang, cache_dir, install_dir, force, generate_from_grammar)
|
---@return string? err
|
||||||
if vim.list_contains(config.installed_parsers(), lang) then
|
local function install_lang0(lang, cache_dir, install_dir, generate_from_grammar)
|
||||||
if not force then
|
|
||||||
local yesno =
|
|
||||||
fn.input(lang .. ' parser already available: would you like to reinstall ? y/n: ')
|
|
||||||
print('\n ')
|
|
||||||
if yesno:sub(1, 1) ~= 'y' then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
local logger = log.new('install/' .. lang)
|
local logger = log.new('install/' .. lang)
|
||||||
|
|
||||||
local repo = get_parser_install_info(lang)
|
local repo = get_parser_install_info(lang)
|
||||||
|
|
@ -440,11 +432,11 @@ local function install_lang(lang, cache_dir, install_dir, force, generate_from_g
|
||||||
generate_from_grammar = repo.requires_generate_from_grammar or generate_from_grammar
|
generate_from_grammar = repo.requires_generate_from_grammar or generate_from_grammar
|
||||||
|
|
||||||
if generate_from_grammar and not executable('tree-sitter') then
|
if generate_from_grammar and not executable('tree-sitter') then
|
||||||
logger:error('tree-sitter CLI not found: `tree-sitter` is not executable')
|
return logger:error('tree-sitter CLI not found: `tree-sitter` is not executable')
|
||||||
end
|
end
|
||||||
|
|
||||||
if generate_from_grammar and not executable('node') then
|
if generate_from_grammar and not executable('node') then
|
||||||
logger:error('Node JS not found: `node` is not executable')
|
return logger:error('Node JS not found: `node` is not executable')
|
||||||
end
|
end
|
||||||
|
|
||||||
local revision = get_target_revision(lang)
|
local revision = get_target_revision(lang)
|
||||||
|
|
@ -461,23 +453,26 @@ local function install_lang(lang, cache_dir, install_dir, force, generate_from_g
|
||||||
|
|
||||||
revision = revision or repo.branch or 'master'
|
revision = revision or repo.branch or 'master'
|
||||||
|
|
||||||
if can_download_tar(repo) then
|
local do_download = can_download_tar(repo) and do_download_tar or do_download_git
|
||||||
do_download_tar(logger, repo, project_name, cache_dir, revision, project_dir)
|
local err = do_download(logger, repo, project_name, cache_dir, revision, project_dir)
|
||||||
else
|
if err then
|
||||||
do_download_git(logger, repo, project_name, cache_dir, revision, project_dir)
|
return err
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local compile_location = get_compile_location(repo, cache_dir, project_name, from_local_path)
|
local compile_location = get_compile_location(repo, cache_dir, project_name, from_local_path)
|
||||||
|
|
||||||
if generate_from_grammar then
|
if generate_from_grammar then
|
||||||
do_generate_from_grammar(logger, repo, compile_location)
|
local err = do_generate_from_grammar(logger, repo, compile_location)
|
||||||
|
if err then
|
||||||
|
return err
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
logger:info('Compiling parser')
|
logger:info('Compiling parser')
|
||||||
local r = do_compile(repo, cc, compile_location)
|
local r = do_compile(repo, cc, compile_location)
|
||||||
if r.code > 0 then
|
if r.code > 0 then
|
||||||
logger:error('Error during compilation: %s', r.stderr)
|
return logger:error('Error during compilation: %s', r.stderr)
|
||||||
end
|
end
|
||||||
|
|
||||||
local parser_lib_name = fs.joinpath(install_dir, lang) .. '.so'
|
local parser_lib_name = fs.joinpath(install_dir, lang) .. '.so'
|
||||||
|
|
@ -485,7 +480,7 @@ local function install_lang(lang, cache_dir, install_dir, force, generate_from_g
|
||||||
local err = uv_copyfile(fs.joinpath(compile_location, 'parser.so'), parser_lib_name)
|
local err = uv_copyfile(fs.joinpath(compile_location, 'parser.so'), parser_lib_name)
|
||||||
a.main()
|
a.main()
|
||||||
if err then
|
if err then
|
||||||
logger:error(err)
|
return logger:error(err)
|
||||||
end
|
end
|
||||||
|
|
||||||
local revfile = fs.joinpath(config.get_install_dir('parser-info') or '', lang .. '.revision')
|
local revfile = fs.joinpath(config.get_install_dir('parser-info') or '', lang .. '.revision')
|
||||||
|
|
@ -502,51 +497,55 @@ local function install_lang(lang, cache_dir, install_dir, force, generate_from_g
|
||||||
local err = uv_symlink(queries_src, queries, { dir = true, junction = true })
|
local err = uv_symlink(queries_src, queries, { dir = true, junction = true })
|
||||||
a.main()
|
a.main()
|
||||||
if err then
|
if err then
|
||||||
logger:error(err)
|
return logger:error(err)
|
||||||
end
|
end
|
||||||
logger:info('Language installed')
|
logger:info('Language installed')
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Throttles a function using the first argument as an ID
|
--- @alias InstallStatus
|
||||||
---
|
--- | 'installing'
|
||||||
--- If function is already running then the function will be scheduled to run
|
--- | 'installed'
|
||||||
--- again once the running call has finished.
|
--- | 'failed'
|
||||||
---
|
--- | 'timeout'
|
||||||
--- fn#1 _/‾\__/‾\_/‾\_____________________________
|
|
||||||
--- throttled#1 _/‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾\/‾‾‾‾‾‾‾‾‾‾\____________
|
local install_status = {} --- @type table<string,InstallStatus?>
|
||||||
--
|
|
||||||
--- fn#2 ______/‾\___________/‾\___________________
|
local INSTALL_TIMEOUT = 60000
|
||||||
--- throttled#2 ______/‾‾‾‾‾‾‾‾‾‾\__/‾‾‾‾‾‾‾‾‾‾\__________
|
|
||||||
---
|
---@param lang string
|
||||||
---
|
---@param cache_dir string
|
||||||
--- @generic F: function
|
---@param install_dir string
|
||||||
--- @param f F Function to throttle
|
---@param force? boolean
|
||||||
--- @return F throttled function.
|
---@param generate_from_grammar? boolean
|
||||||
local function throttle_by_id(f)
|
---@return InstallStatus status
|
||||||
local scheduled = {} --- @type table<any,boolean>
|
local function install_lang(lang, cache_dir, install_dir, force, generate_from_grammar)
|
||||||
local running = {} --- @type table<any,boolean>
|
if not force and vim.list_contains(config.installed_parsers(), lang) then
|
||||||
return function(id, ...)
|
local yesno =
|
||||||
if scheduled[id] then
|
fn.input(lang .. ' parser already available: would you like to reinstall ? y/n: ')
|
||||||
-- If f is already scheduled, then drop
|
print('\n ')
|
||||||
return
|
if yesno:sub(1, 1) ~= 'y' then
|
||||||
end
|
install_status[lang] = 'installed'
|
||||||
if not running[id] then
|
return 'installed'
|
||||||
scheduled[id] = true
|
|
||||||
end
|
|
||||||
if running[id] then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
while scheduled[id] do
|
|
||||||
scheduled[id] = nil
|
|
||||||
running[id] = true
|
|
||||||
f(id, ...)
|
|
||||||
running[id] = nil
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
-- Async functions must not be interleaved
|
if install_status[lang] then
|
||||||
local install_lang_throttled = throttle_by_id(install_lang)
|
if install_status[lang] == 'installing' then
|
||||||
|
vim.wait(INSTALL_TIMEOUT, function()
|
||||||
|
return install_status[lang] ~= 'installing'
|
||||||
|
end)
|
||||||
|
install_status[lang] = 'timeout'
|
||||||
|
end
|
||||||
|
else
|
||||||
|
install_status[lang] = 'installing'
|
||||||
|
local err = install_lang0(lang, cache_dir, install_dir, generate_from_grammar)
|
||||||
|
install_status[lang] = err and 'failed' or 'installed'
|
||||||
|
end
|
||||||
|
|
||||||
|
local status = install_status[lang]
|
||||||
|
assert(status and status ~= 'installing')
|
||||||
|
return status
|
||||||
|
end
|
||||||
|
|
||||||
---@class InstallOptions
|
---@class InstallOptions
|
||||||
---@field force? boolean
|
---@field force? boolean
|
||||||
|
|
@ -586,8 +585,10 @@ local function install(languages, options, _callback)
|
||||||
for _, lang in ipairs(languages) do
|
for _, lang in ipairs(languages) do
|
||||||
tasks[#tasks + 1] = a.sync(function()
|
tasks[#tasks + 1] = a.sync(function()
|
||||||
a.main()
|
a.main()
|
||||||
install_lang_throttled(lang, cache_dir, install_dir, force, generate_from_grammar)
|
local status = install_lang(lang, cache_dir, install_dir, force, generate_from_grammar)
|
||||||
done = done + 1
|
if status ~= 'failed' then
|
||||||
|
done = done + 1
|
||||||
|
end
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -621,12 +622,14 @@ M.update = a.sync(function(languages, _options, _callback)
|
||||||
end
|
end
|
||||||
end, 2)
|
end, 2)
|
||||||
|
|
||||||
|
--- @param logger Logger
|
||||||
--- @param lang string
|
--- @param lang string
|
||||||
--- @param parser string
|
--- @param parser string
|
||||||
--- @param queries string
|
--- @param queries string
|
||||||
local function uninstall_lang(lang, parser, queries)
|
--- @return string? err
|
||||||
local logger = log.new('uninstall/' .. lang)
|
local function uninstall_lang(logger, lang, parser, queries)
|
||||||
logger:debug('Uninstalling ' .. lang)
|
logger:debug('Uninstalling ' .. lang)
|
||||||
|
install_status[lang] = nil
|
||||||
|
|
||||||
if vim.fn.filereadable(parser) == 1 then
|
if vim.fn.filereadable(parser) == 1 then
|
||||||
logger:debug('Unlinking ' .. parser)
|
logger:debug('Unlinking ' .. parser)
|
||||||
|
|
@ -634,7 +637,7 @@ local function uninstall_lang(lang, parser, queries)
|
||||||
a.main()
|
a.main()
|
||||||
|
|
||||||
if perr then
|
if perr then
|
||||||
log.error(perr)
|
return logger:error(perr)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -644,7 +647,7 @@ local function uninstall_lang(lang, parser, queries)
|
||||||
a.main()
|
a.main()
|
||||||
|
|
||||||
if qerr then
|
if qerr then
|
||||||
logger:error(qerr)
|
return logger:error(qerr)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -664,14 +667,17 @@ M.uninstall = a.sync(function(languages, _options, _callback)
|
||||||
local tasks = {} --- @type fun()[]
|
local tasks = {} --- @type fun()[]
|
||||||
local done = 0
|
local done = 0
|
||||||
for _, lang in ipairs(languages) do
|
for _, lang in ipairs(languages) do
|
||||||
|
local logger = log.new('uninstall/' .. lang)
|
||||||
if not vim.list_contains(installed, lang) then
|
if not vim.list_contains(installed, lang) then
|
||||||
log.warn('Parser for ' .. lang .. ' is is not managed by nvim-treesitter')
|
log.warn('Parser for ' .. lang .. ' is is not managed by nvim-treesitter')
|
||||||
else
|
else
|
||||||
local parser = fs.joinpath(parser_dir, lang) .. '.so'
|
local parser = fs.joinpath(parser_dir, lang) .. '.so'
|
||||||
local queries = fs.joinpath(query_dir, lang)
|
local queries = fs.joinpath(query_dir, lang)
|
||||||
tasks[#tasks + 1] = a.sync(function()
|
tasks[#tasks + 1] = a.sync(function()
|
||||||
uninstall_lang(lang, parser, queries)
|
local err = uninstall_lang(logger, lang, parser, queries)
|
||||||
done = done + 1
|
if not err then
|
||||||
|
done = done + 1
|
||||||
|
end
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
local api = vim.api
|
local echo = vim.api.nvim_echo
|
||||||
|
|
||||||
-- TODO(lewis6991): write these out to a file
|
-- TODO(lewis6991): write these out to a file
|
||||||
local messages = {} --- @type {[1]: string, [2]: string?, [3]: string}[]
|
local messages = {} --- @type {[1]: string, [2]: string?, [3]: string}[]
|
||||||
|
|
@ -11,69 +11,28 @@ local sev_to_hl = {
|
||||||
error = 'ErrorMsg',
|
error = 'ErrorMsg',
|
||||||
}
|
}
|
||||||
|
|
||||||
---@param ctx string?
|
|
||||||
---@param m string
|
|
||||||
---@param ... any
|
|
||||||
local function trace(ctx, m, ...)
|
|
||||||
messages[#messages + 1] = { 'trace', ctx, string.format(m, ...) }
|
|
||||||
end
|
|
||||||
|
|
||||||
---@param ctx string?
|
|
||||||
---@param m string
|
|
||||||
---@param ... any
|
|
||||||
local function debug(ctx, m, ...)
|
|
||||||
messages[#messages + 1] = { 'debug', ctx, string.format(m, ...) }
|
|
||||||
end
|
|
||||||
|
|
||||||
---@param ctx string?
|
---@param ctx string?
|
||||||
---@return string
|
---@return string
|
||||||
local function mkpfx(ctx)
|
local function mkpfx(ctx)
|
||||||
return ctx and string.format('[nvim-treesitter/%s]', ctx) or '[nvim-treesitter]'
|
return ctx and string.format('[nvim-treesitter/%s]', ctx) or '[nvim-treesitter]'
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param ctx string?
|
---@class TSLogModule
|
||||||
---@param m string
|
---@field trace fun(fmt: string, ...: any)
|
||||||
---@param ... any
|
---@field debug fun(fmt: string, ...: any)
|
||||||
local function info(ctx, m, ...)
|
---@field info fun(fmt: string, ...: any)
|
||||||
local m1 = string.format(m, ...)
|
---@field warn fun(fmt: string, ...: any)
|
||||||
messages[#messages + 1] = { 'info', ctx, m1 }
|
---@field error fun(fmt: string, ...: any)
|
||||||
api.nvim_echo({ { mkpfx(ctx) .. ': ' .. m1, sev_to_hl.info } }, true, {})
|
|
||||||
end
|
|
||||||
|
|
||||||
---@param ctx string?
|
|
||||||
---@param m string
|
|
||||||
---@param ... any
|
|
||||||
local function warn(ctx, m, ...)
|
|
||||||
local m1 = string.format(m, ...)
|
|
||||||
messages[#messages + 1] = { 'warn', ctx, m1 }
|
|
||||||
api.nvim_echo({ { mkpfx(ctx) .. ' warning: ' .. m1, sev_to_hl.warn } }, true, {})
|
|
||||||
end
|
|
||||||
|
|
||||||
---@param ctx string?
|
|
||||||
---@param m string
|
|
||||||
---@param ... any
|
|
||||||
local function lerror(ctx, m, ...)
|
|
||||||
local m1 = string.format(m, ...)
|
|
||||||
messages[#messages + 1] = { 'error', ctx, m1 }
|
|
||||||
error(mkpfx(ctx) .. ' error: ' .. m1)
|
|
||||||
end
|
|
||||||
|
|
||||||
--- @class NTSLogModule
|
|
||||||
--- @field trace fun(fmt: string, ...: any)
|
|
||||||
--- @field debug fun(fmt: string, ...: any)
|
|
||||||
--- @field info fun(fmt: string, ...: any)
|
|
||||||
--- @field warn fun(fmt: string, ...: any)
|
|
||||||
--- @field error fun(fmt: string, ...: any)
|
|
||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
--- @class Logger
|
---@class Logger
|
||||||
--- @field ctx? string
|
---@field ctx? string
|
||||||
local Logger = {}
|
local Logger = {}
|
||||||
|
|
||||||
M.Logger = Logger
|
M.Logger = Logger
|
||||||
|
|
||||||
--- @param ctx? string
|
---@param ctx? string
|
||||||
--- @return Logger
|
---@return Logger
|
||||||
function M.new(ctx)
|
function M.new(ctx)
|
||||||
return setmetatable({ ctx = ctx }, { __index = Logger })
|
return setmetatable({ ctx = ctx }, { __index = Logger })
|
||||||
end
|
end
|
||||||
|
|
@ -81,31 +40,39 @@ end
|
||||||
---@param m string
|
---@param m string
|
||||||
---@param ... any
|
---@param ... any
|
||||||
function Logger:trace(m, ...)
|
function Logger:trace(m, ...)
|
||||||
trace(self.ctx, m, ...)
|
messages[#messages + 1] = { 'trace', self.ctx, m:format(...) }
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param m string
|
---@param m string
|
||||||
---@param ... any
|
---@param ... any
|
||||||
function Logger:debug(m, ...)
|
function Logger:debug(m, ...)
|
||||||
debug(self.ctx, m, ...)
|
messages[#messages + 1] = { 'debug', self.ctx, m:format(...) }
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param m string
|
---@param m string
|
||||||
---@param ... any
|
---@param ... any
|
||||||
function Logger:info(m, ...)
|
function Logger:info(m, ...)
|
||||||
info(self.ctx, m, ...)
|
local m1 = m:format(...)
|
||||||
|
messages[#messages + 1] = { 'info', self.ctx, m1 }
|
||||||
|
echo({ { mkpfx(self.ctx) .. ': ' .. m1, sev_to_hl.info } }, true, {})
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param m string
|
---@param m string
|
||||||
---@param ... any
|
---@param ... any
|
||||||
function Logger:warn(m, ...)
|
function Logger:warn(m, ...)
|
||||||
warn(self.ctx, m, ...)
|
local m1 = m:format(...)
|
||||||
|
messages[#messages + 1] = { 'warn', self.ctx, m1 }
|
||||||
|
echo({ { mkpfx(self.ctx) .. ' warning: ' .. m1, sev_to_hl.warn } }, true, {})
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param m string
|
---@param m string
|
||||||
---@param ... any
|
---@param ... any
|
||||||
|
---@return string
|
||||||
function Logger:error(m, ...)
|
function Logger:error(m, ...)
|
||||||
lerror(self.ctx, m, ...)
|
local m1 = m:format(...)
|
||||||
|
messages[#messages + 1] = { 'error', self.ctx, m1 }
|
||||||
|
echo({ { mkpfx(self.ctx) .. ' error: ' .. m1, sev_to_hl.error } }, true, {})
|
||||||
|
return m1
|
||||||
end
|
end
|
||||||
|
|
||||||
local noctx_logger = M.new()
|
local noctx_logger = M.new()
|
||||||
|
|
@ -126,7 +93,7 @@ function M.show()
|
||||||
local hl = sev_to_hl[sev]
|
local hl = sev_to_hl[sev]
|
||||||
local text = ctx and string.format('%s(%s): %s', sev, ctx, msg)
|
local text = ctx and string.format('%s(%s): %s', sev, ctx, msg)
|
||||||
or string.format('%s: %s', sev, msg)
|
or string.format('%s: %s', sev, msg)
|
||||||
api.nvim_echo({ { text, hl } }, false, {})
|
echo({ { text, hl } }, false, {})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue