refactor(#2826): remove consistency checks, enabling new path for view get_winid and get_bufnr

This commit is contained in:
Alexander Courtis 2025-07-28 12:09:46 +10:00
parent ec5d41f182
commit e6a03854a6
17 changed files with 61 additions and 337 deletions

View File

@ -639,7 +639,6 @@ Following is the default configuration. See |nvim-tree-opts| for details. >lua
},
},
experimental = {
multi_instance = false,
},
log = {
enable = false,

View File

@ -74,7 +74,7 @@ end
function M.tab_enter()
local explorer = core.get_explorer()
if explorer and explorer.view:is_visible({ any_tabpage = true }, "nvim-tree.tab_enter") then
if explorer and explorer.view:is_visible({ any_tabpage = true }) then
local bufname = vim.api.nvim_buf_get_name(0)
local ft
@ -97,7 +97,7 @@ end
function M.open_on_directory()
local explorer = core.get_explorer()
local should_proceed = _config.hijack_directories.auto_open or explorer and explorer.view:is_visible(nil, "nvim-tree.open_on_directory")
local should_proceed = _config.hijack_directories.auto_open or explorer and explorer.view:is_visible()
if not should_proceed then
return
end
@ -486,7 +486,6 @@ local DEFAULT_OPTS = { -- BEGIN_DEFAULT_OPTS
},
},
experimental = {
multi_instance = false,
},
log = {
enable = false,
@ -727,7 +726,6 @@ function M.setup(conf)
require("nvim-tree.buffers").setup(opts)
require("nvim-tree.help").setup(opts)
require("nvim-tree.watcher").setup(opts)
require("nvim-tree.multi-instance-debug").setup(opts)
setup_autocommands(opts)

View File

@ -13,7 +13,7 @@ local running = {}
---@param path string relative or absolute
function M.fn(path)
local explorer = core.get_explorer()
if not explorer or not explorer.view:is_visible(nil, "finders/find-file.fn1") then
if not explorer or not explorer.view:is_visible() then
return
end
@ -83,7 +83,7 @@ function M.fn(path)
end)
:iterate()
if found and explorer.view:is_visible(nil, "finders/find-file.fn2") then
if found and explorer.view:is_visible() then
explorer.renderer:draw()
explorer.view:set_cursor({ line, 0 })
end

View File

@ -23,7 +23,7 @@ local function usable_win_ids()
local explorer = core.get_explorer()
local tabpage = vim.api.nvim_get_current_tabpage()
local win_ids = vim.api.nvim_tabpage_list_wins(tabpage)
local tree_winid = explorer and explorer.view:get_winid(tabpage, "open-file.usable_win_ids")
local tree_winid = explorer and explorer.view:get_winid(tabpage)
return vim.tbl_filter(function(id)
local bufid = vim.api.nvim_win_get_buf(id)
@ -196,7 +196,7 @@ local function open_file_in_tab(filename)
if M.quit_on_open then
local explorer = core.get_explorer()
if explorer then
explorer.view:close(nil, "open-file.open_file_in_tab")
explorer.view:close()
end
end
if M.relative_path then
@ -209,7 +209,7 @@ local function drop(filename)
if M.quit_on_open then
local explorer = core.get_explorer()
if explorer then
explorer.view:close(nil, "open-file.drop")
explorer.view:close()
end
end
if M.relative_path then
@ -222,7 +222,7 @@ local function tab_drop(filename)
if M.quit_on_open then
local explorer = core.get_explorer()
if explorer then
explorer.view:close(nil, "open-file.tab_drop")
explorer.view:close()
end
end
if M.relative_path then
@ -453,7 +453,7 @@ function M.fn(mode, filename)
end
if M.quit_on_open and explorer then
explorer.view:close(nil, "open-file.fn")
explorer.view:close()
end
end

View File

@ -85,7 +85,7 @@ M.force_dirchange = add_profiling_to(function(foldername, should_open_view)
if should_change_dir() then
cd(M.options.global, foldername)
end
core.init(foldername, "change-dir")
core.init(foldername)
end
if should_open_view then

View File

@ -41,7 +41,7 @@ function M.fn(opts)
end
local explorer = core.get_explorer()
if explorer and explorer.view:is_visible(nil, "tree/find-file.fn") then
if explorer and explorer.view:is_visible() then
-- focus
if opts.focus then
lib.set_target_win()

View File

@ -25,7 +25,7 @@ function M.fn(opts)
local explorer = core.get_explorer()
if explorer and explorer.view:is_visible(nil, "open.fn") then
if explorer and explorer.view:is_visible() then
-- focus
lib.set_target_win()
explorer.view:focus()

View File

@ -42,9 +42,9 @@ function M.fn(opts, no_focus, cwd, bang)
opts.path = nil
end
if explorer and explorer.view:is_visible(nil, "toggle.fn") then
if explorer and explorer.view:is_visible() then
-- close
explorer.view:close(nil, "toggle.fn")
explorer.view:close()
else
-- open
lib.open({

View File

@ -247,7 +247,7 @@ local function edit(mode, node, edit_opts)
local mode_unsupported_quit_on_open = mode == "drop" or mode == "tab_drop" or mode == "edit_in_place"
if not mode_unsupported_quit_on_open and edit_opts.quit_on_open then
if explorer then
explorer.view:close(cur_tabpage, "api.edit " .. mode)
explorer.view:close(cur_tabpage)
end
end

View File

@ -9,12 +9,9 @@ local TreeExplorer = nil
local first_init_done = false
---@param foldername string
---@param callsite string
function M.init(foldername, callsite)
function M.init(foldername)
local profile = log.profile_start("core init %s", foldername)
log.line("dev", "core.init(%s, %s)", foldername, callsite)
if TreeExplorer then
TreeExplorer:destroy()
end

View File

@ -185,7 +185,7 @@ function M.update_coc()
local bufnr
if explorer then
bufnr = explorer.view:get_bufnr("diagnostics.update_coc")
bufnr = explorer.view:get_bufnr()
end
local should_draw = bufnr and vim.api.nvim_buf_is_valid(bufnr) and vim.api.nvim_buf_is_loaded(bufnr)

View File

@ -105,12 +105,9 @@ function Explorer:create_autocmds()
vim.api.nvim_create_autocmd("WinLeave", {
group = self.augroup_id,
pattern = "NvimTree_*",
callback = function(data)
if self.opts.experimental.multi_instance then
log.line("dev", "WinLeave %s", vim.inspect(data, { newline = "" }))
end
callback = function()
if utils.is_nvim_tree_buf(0) then
self.view:close(nil, "WinLeave")
self.view:close()
end
end,
})
@ -172,10 +169,7 @@ function Explorer:create_autocmds()
vim.api.nvim_create_autocmd("BufWipeout", {
group = self.augroup_id,
pattern = "NvimTree_*",
callback = function(data)
if self.opts.experimental.multi_instance then
log.line("dev", "BufWipeout %s", vim.inspect(data, { newline = "" }))
end
callback = function()
if not utils.is_nvim_tree_buf(0) then
return
end
@ -532,7 +526,7 @@ function Explorer:reload_explorer()
local projects = git.reload_all_projects()
self:refresh_nodes(projects)
if self.view:is_visible(nil, "Explorer:reload_explorer") then
if self.view:is_visible() then
self.renderer:draw()
end
event_running = false
@ -554,7 +548,7 @@ end
---nil on no explorer or invalid view win
---@return integer[]|nil
function Explorer:get_cursor_position()
local winnr = self.view:get_winid(nil, "Explorer:get_cursor_position")
local winnr = self.view:get_winid()
if not winnr or not vim.api.nvim_win_is_valid(winnr) then
return
end

View File

@ -161,7 +161,7 @@ local move_tbl = {
---@private
function View:set_window_options_and_buffer()
pcall(vim.api.nvim_command, "buffer " .. self:get_bufnr("View:set_window_options_and_buffer"))
pcall(vim.api.nvim_command, "buffer " .. self:get_bufnr())
if vim.fn.has("nvim-0.10") == 1 then
local eventignore = vim.api.nvim_get_option_value("eventignore", {})
@ -244,24 +244,18 @@ end
---@param tabid integer
function View:save_state(tabid)
tabid = tabid or vim.api.nvim_get_current_tabpage()
self.cursors_by_tabid[tabid] = vim.api.nvim_win_get_cursor(self:get_winid(tabid, "View:save_tab_state") or 0)
self.cursors_by_tabid[tabid] = vim.api.nvim_win_get_cursor(self:get_winid(tabid) or 0)
end
---@private
---@param tabid integer
function View:close_internal(tabid)
--- BEGIN multi-instance FF
if self.explorer.opts.experimental.multi_instance then
log.line("dev", "View:close_internal(t%s)", tabid)
end
--- END multi-instance FF
if not self:is_visible({ tabpage = tabid }, "View:close_internal") then
if not self:is_visible({ tabpage = tabid }) then
return
end
self:save_state(tabid)
switch_buf_if_last_buf()
local tree_win = self:get_winid(tabid, "View:close_internal")
local tree_win = self:get_winid(tabid)
local current_win = vim.api.nvim_get_current_win()
for _, win in pairs(vim.api.nvim_tabpage_list_wins(tabid)) do
if vim.api.nvim_win_get_config(win).relative == "" then
@ -270,12 +264,6 @@ function View:close_internal(tabid)
vim.api.nvim_set_current_win(vim.fn.win_getid(prev_win))
end
if vim.api.nvim_win_is_valid(tree_win or 0) then
--- BEGIN multi-instance FF
if self.explorer.opts.experimental.multi_instance then
log.line("dev", "View:close_internal(t%s) w%s", tabid, tree_win)
end
--- END multi-instance FF
---
local success, error = pcall(vim.api.nvim_win_close, tree_win or 0, true)
if not success then
notify.debug("Failed to close window: " .. error)
@ -288,38 +276,18 @@ function View:close_internal(tabid)
end
function View:close_this_tab_only()
--- BEGIN multi-instance FF
if self.explorer.opts.experimental.multi_instance then
log.line("dev", "View:close_this_tab_only()")
end
--- END multi-instance FF
self:close_internal(vim.api.nvim_get_current_tabpage())
end
-- TODO this is broken at 1.13.0 - current tab does not close when tab.sync.close is set
function View:close_all_tabs()
log.line("dev", "View:close_all_tabs() globals.WINID_BY_TABID=%s", vim.inspect(globals.WINID_BY_TABID))
for tabid, _ in pairs(globals.WINID_BY_TABID) do
--- BEGIN multi-instance FF
if self.explorer.opts.experimental.multi_instance then
log.line("dev", "View:close_all_tabs()")
end
--- END multi-instance FF
self:close_internal(tabid)
end
end
---@param tabid integer|nil
---@param callsite string
function View:close(tabid, callsite)
--- BEGIN multi-instance FF
if self.explorer.opts.experimental.multi_instance then
log.line("dev", "View:close(t%s, %s)", tabid, callsite)
end
--- END multi-instance FF
function View:close(tabid)
if self.explorer.opts.tab.sync.close then
self:close_all_tabs()
elseif tabid then
@ -331,7 +299,7 @@ end
---@param options table|nil
function View:open(options)
if self:is_visible(nil, "View:open") then
if self:is_visible() then
return
end
@ -354,12 +322,12 @@ end
---@private
function View:grow()
local starts_at = self:is_root_folder_visible(require("nvim-tree.core").get_cwd()) and 1 or 0
local lines = vim.api.nvim_buf_get_lines(self:get_bufnr("View:grow1"), starts_at, -1, false)
local lines = vim.api.nvim_buf_get_lines(self:get_bufnr(), starts_at, -1, false)
-- number of columns of right-padding to indicate end of path
local padding = self:get_size(self.padding)
-- account for sign/number columns etc.
local wininfo = vim.fn.getwininfo(self:get_winid(nil, "View:grow"))
local wininfo = vim.fn.getwininfo(self:get_winid())
if type(wininfo) == "table" and type(wininfo[1]) == "table" then
padding = padding + wininfo[1].textoff
end
@ -378,7 +346,7 @@ function View:grow()
for line_nr, l in pairs(lines) do
local count = vim.fn.strchars(l)
-- also add space for right-aligned icons
local extmarks = vim.api.nvim_buf_get_extmarks(self:get_bufnr("View:grow2"), ns_id, { line_nr, 0 }, { line_nr, -1 }, { details = true })
local extmarks = vim.api.nvim_buf_get_extmarks(self:get_bufnr(), ns_id, { line_nr, 0 }, { line_nr, -1 }, { details = true })
count = count + utils.extmarks_length(extmarks)
if resizing_width < count then
resizing_width = count
@ -423,11 +391,11 @@ function View:resize(size)
self.width = size
end
if not self:is_visible(nil, "View:resize") then
if not self:is_visible() then
return
end
local winid = self:get_winid(nil, "View:resize") or 0
local winid = self:get_winid() or 0
local new_size = self:get_width()
@ -481,17 +449,6 @@ end
function View:abandon_current_window()
local tab = vim.api.nvim_get_current_tabpage()
--- BEGIN multi-instance FF
if self.explorer.opts.experimental.multi_instance then
log.line("dev", "View:abandon_current_window() t%d w%s b%s member b%s %s",
tab,
globals.WINID_BY_TABID[tab],
globals.BUFNR_BY_TABID[tab],
self.bufnr_by_tabid[tab],
(globals.BUFNR_BY_TABID[tab] == self.bufnr_by_tabid[tab]) and "" or "MISMATCH")
end
--- END multi-instance FF
-- reset both bufnr registries
globals.BUFNR_BY_TABID[tab] = nil
self.bufnr_by_tabid[tab] = nil
@ -507,91 +464,45 @@ function View:abandon_all_windows()
end
---@param opts table|nil
---@param callsite string
---@return boolean
function View:is_visible(opts, callsite)
local msg
--- BEGIN multi-instance FF
if self.explorer.opts.experimental.multi_instance then
msg = string.format("View:is_visible(%s, %-20.20s)", vim.inspect(opts, { newline = "" }), callsite)
end
--- END multi-instance FF
function View:is_visible(opts)
if opts and opts.tabpage then
--- BEGIN multi-instance FF
if self.explorer.opts.experimental.multi_instance then
local winid = self:winid(opts.tabpage)
local winid_by_tabid = opts.tabpage and globals.WINID_BY_TABID[opts.tabpage] or nil
msg = string.format("%s globals.WINID_BY_TABID[%s]=w%s view.winid(%s)=w%s",
msg,
opts.tabpage, winid_by_tabid,
opts.tabpage, winid
)
if winid ~= winid_by_tabid then
msg = string.format("%s MISMATCH", msg)
notify.error(msg)
end
log.line("dev", "%s", msg)
return winid and vim.api.nvim_win_is_valid(winid) or false
--- END multi-instance FF
else
local winid = globals.WINID_BY_TABID[opts.tabpage]
return winid and vim.api.nvim_win_is_valid(winid)
end
local winid = self:winid(opts.tabpage)
return winid and vim.api.nvim_win_is_valid(winid) or false
end
if opts and opts.any_tabpage then
for tabid, winid_by_tabid in pairs(globals.WINID_BY_TABID) do
--- BEGIN multi-instance FF
if self.explorer.opts.experimental.multi_instance then
local winid = self:winid(tabid)
msg = string.format("%s globals.WINID_BY_TABID[%s]=w%s view.winid(%s)=w%s",
msg,
tabid, winid_by_tabid,
tabid, winid
)
if winid ~= winid_by_tabid then
msg = string.format("%s MISMATCH", msg)
notify.error(msg)
end
log.line("dev", "%s", msg)
for tabid, _ in pairs(globals.WINID_BY_TABID) do
local winid = self:winid(tabid)
if winid and vim.api.nvim_win_is_valid(winid) then
return true
end
--- END multi-instance FF
else
if winid_by_tabid and vim.api.nvim_win_is_valid(winid_by_tabid) then
return true
end
if winid and vim.api.nvim_win_is_valid(winid) then
return true
end
end
return false
end
local winid = self:get_winid(nil, "View:is_visible")
local winid = self:get_winid()
return winid ~= nil and vim.api.nvim_win_is_valid(winid or 0)
end
---@param opts table|nil
function View:set_cursor(opts)
if self:is_visible(nil, "View:set_cursor") then
pcall(vim.api.nvim_win_set_cursor, self:get_winid(nil, "View:set_cursor"), opts)
if self:is_visible() then
pcall(vim.api.nvim_win_set_cursor, self:get_winid(), opts)
end
end
---@param winid number|nil
---@param open_if_closed boolean|nil
function View:focus(winid, open_if_closed)
local wid = winid or self:get_winid(nil, "View:focus1")
local wid = winid or self:get_winid(nil)
if vim.api.nvim_win_get_tabpage(wid or 0) ~= vim.api.nvim_win_get_tabpage(0) then
self:close(nil, "View:focus")
self:close()
self:open()
wid = self:get_winid(nil, "View:focus2")
elseif open_if_closed and not self:is_visible(nil, "View:focus") then
wid = self:get_winid(nil)
elseif open_if_closed and not self:is_visible() then
self:open()
end
@ -608,8 +519,8 @@ function View:api_winid(opts)
if tabpage == 0 then
tabpage = vim.api.nvim_get_current_tabpage()
end
if self:is_visible({ tabpage = tabpage }, "View:api_winid") then
return self:get_winid(tabpage, "View:winid")
if self:is_visible({ tabpage = tabpage }) then
return self:get_winid(tabpage)
else
return nil
end
@ -637,85 +548,23 @@ end
--- Returns the window number for nvim-tree within the tabpage specified
---@param tabid number|nil (optional) the number of the chosen tabpage. Defaults to current tabpage.
---@param callsite string
---@return number|nil
function View:get_winid(tabid, callsite)
local tabid_param = tabid
function View:get_winid(tabid)
tabid = tabid or vim.api.nvim_get_current_tabpage()
local global_winid = nil
--- BEGIN multi-instance FF
if self.explorer.opts.experimental.multi_instance then
local msg_fault = ""
if not globals.WINID_BY_TABID[tabid] then
msg_fault = "no WINID_BY_TABID"
elseif not vim.api.nvim_win_is_valid(globals.WINID_BY_TABID[tabid]) then
msg_fault = string.format("invalid globals.WINID_BY_TABID[tabid] %d", globals.WINID_BY_TABID[tabid])
else
global_winid = globals.WINID_BY_TABID[tabid]
end
local winid = self:winid(tabid)
if winid ~= global_winid then
msg_fault = "MISMATCH"
end
local msg = string.format("View:get_winid(%3s, %-20.20s) globals.WINID_BY_TABID[%s]=w%s view.winid(%s)=w%s %s",
tabid_param,
callsite,
tabid, global_winid,
tabid, winid,
msg_fault
)
log.line("dev", "%s", msg)
if winid ~= global_winid then
notify.error(msg)
end
return winid
end
--- END multi-instance FF
-- legacy codepath
if global_winid and vim.api.nvim_win_is_valid(global_winid) then
return global_winid
end
return self:winid(tabid)
end
--- Returns the current nvim tree bufnr
---@param callsite string
---@return number
function View:get_bufnr(callsite)
function View:get_bufnr()
local tab = vim.api.nvim_get_current_tabpage()
--- BEGIN multi-instance FF
if self.explorer.opts.experimental.multi_instance then
local msg = string.format("View:get_bufnr(%-20.20s) globals.BUFNR_BY_TABID[%s]=b%s view.bufnr_by_tab[%s]=b%s %s",
callsite,
tab, globals.BUFNR_BY_TABID[tab],
tab, self.bufnr_by_tabid[tab],
(globals.BUFNR_BY_TABID[tab] == self.bufnr_by_tabid[tab]) and "" or "MISMATCH"
)
if globals.BUFNR_BY_TABID[tab] ~= self.bufnr_by_tabid[tab] then
notify.error(msg)
end
log.line("dev", msg)
return self.bufnr_by_tabid[tab]
end
--- END multi-instance FF
return globals.BUFNR_BY_TABID[tab]
return self.bufnr_by_tabid[tab]
end
function View:prevent_buffer_override()
local view_winid = self:get_winid(nil, "View:prevent_buffer_override")
local view_bufnr = self:get_bufnr("View:prevent_buffer_override")
local view_winid = self:get_winid()
local view_bufnr = self:get_bufnr()
-- need to schedule to let the new buffer populate the window
-- because this event needs to be run on bufWipeout.
@ -769,7 +618,7 @@ end
-- used on ColorScheme event
function View:reset_winhl()
local winid = self:get_winid(nil, "View:reset_winhl")
local winid = self:get_winid()
if winid and vim.api.nvim_win_is_valid(winid) then
vim.wo[winid].winhl = appearance.WIN_HL
end

View File

@ -4,7 +4,6 @@ local M = {
-- from View
WINID_BY_TABID = {},
BUFNR_BY_TABID = {},
CURSORS = {},
}
return M

View File

@ -15,7 +15,7 @@ function M.set_target_win()
local id = vim.api.nvim_get_current_win()
if explorer and id == explorer.view:get_winid(nil, "lib.set_target_win") then
if explorer and id == explorer.view:get_winid() then
M.target_winid = 0
return
end
@ -102,14 +102,14 @@ function M.open(opts)
M.set_target_win()
if not core.get_explorer() or opts.path then
if opts.path then
core.init(opts.path, "lib.open - opts.path")
core.init(opts.path)
else
local cwd, err = vim.loop.cwd()
if not cwd then
notify.error(string.format("current working directory unavailable: %s", err))
return
end
core.init(cwd, "lib.open - cwd")
core.init(cwd)
end
end

View File

@ -1,112 +0,0 @@
local globals = require("nvim-tree.globals")
local M = {}
--- Debugging only.
--- Tabs show WINID_BY_TABID winid and BUFNR_BY_TABID bufnr for the tab.
--- Orphans for inexistent tab_ids are shown at the right.
--- lib.target_winid is always shown at the right next to a close button.
--- Enable with:
--- vim.opt.tabline = "%!v:lua.require('nvim-tree.explorer.view').tab_line()"
--- vim.opt.showtabline = 2
---@return string
function M.tab_line()
local tabids = vim.api.nvim_list_tabpages()
local tabid_cur = vim.api.nvim_get_current_tabpage()
local bufnr_by_tabid = vim.deepcopy(globals.BUFNR_BY_TABID)
local winid_by_tabid = vim.deepcopy(globals.WINID_BY_TABID)
local tl = "%#TabLine#"
for i, tabid in ipairs(tabids) do
-- click to select
tl = tl .. "%" .. i .. "T"
-- style
if tabid == tabid_cur then
tl = tl .. "%#StatusLine#|"
else
tl = tl .. "|%#TabLine#"
end
-- tab_id itself
tl = tl .. " t" .. tabid
-- winid, if present
local tp = globals.WINID_BY_TABID[tabid]
if tp then
tl = tl .. " w" .. (tp or "nil")
else
tl = tl .. " "
end
-- bufnr, if present
local bpt = globals.BUFNR_BY_TABID[tabid]
if bpt then
tl = tl .. " b" .. bpt
else
tl = tl .. " "
end
tl = tl .. " "
-- remove actively mapped
bufnr_by_tabid[tabid] = nil
winid_by_tabid[tabid] = nil
end
-- close last and reset
tl = tl .. "|%#CursorLine#%T"
-- collect orphans
local orphans = {}
for tab_id, bufnr in pairs(bufnr_by_tabid) do
orphans[tab_id] = orphans[tab_id] or {}
orphans[tab_id].bufnr = bufnr
end
for tab_id, tp in pairs(winid_by_tabid) do
orphans[tab_id] = orphans[tab_id] or {}
orphans[tab_id].winid = tp
end
-- right-align
tl = tl .. "%=%#TabLine#"
-- print orphans
for tab_id, orphan in pairs(orphans) do
-- inexistent tab
tl = tl .. "%#error#| t" .. tab_id
-- maybe winid
if orphan.winid then
tl = tl .. " w" .. (orphan.winid or "nil")
else
tl = tl .. " "
end
-- maybe bufnr
if orphan.bufnr then
tl = tl .. " b" .. orphan.bufnr
else
tl = tl .. " "
end
tl = tl .. " "
end
-- target win id and close button
tl = tl .. "|%#TabLine# twi" .. (require("nvim-tree.lib").target_winid or "?") .. " %999X| X |"
return tl
end
function M.setup(opts)
if not opts.experimental.multi_instance then
return
end
vim.opt.tabline = "%!v:lua.require('nvim-tree.multi-instance-debug').tab_line()"
vim.opt.showtabline = 2
end
return M

View File

@ -101,11 +101,11 @@ function Renderer:render_hl(bufnr, hl_range_args)
end
function Renderer:draw()
local bufnr = self.explorer.view:get_bufnr("Renderer:draw")
local bufnr = self.explorer.view:get_bufnr()
if not bufnr or not vim.api.nvim_buf_is_loaded(bufnr) then
return
end
local winid = self.explorer.view:get_winid(nil, "Renderer:draw")
local winid = self.explorer.view:get_winid()
local profile = log.profile_start("draw")