nvim-tree.lua/lua/nvim-tree/core.lua
Alexander Courtis 3fc8de198c
chore: migrate to classic (#2991)
* add classic, migrating nodes classes

* add mixins to classic

* typechecked optargs constructors for nodes

* typechecked optargs constructors for watcher and event

* luacheck

* typechecked optargs constructors for GitRunner

* typechecked optargs constructors for Sorter

* typechecked optargs constructors for decorators, WIP

* typechecked optargs constructors for decorators, WIP

* typechecked optargs constructors for decorators

* remove class

* replace enums with named maps

* Renderer and Builder use classic, tidy opts

* LiveFilter uses classic, tidy opts

* Filter uses classic, tidy opts

* add FilterTypes named map

* move toggles into filters

* Marks uses classic, tidy opts

* Sorter uses classic, tidy opts

* Clipboard uses classic, tidy opts

* use supers for node methods

* HighlightDisplay uses classic

* protected :new

* Watcher tidy

* Revert "use supers for node methods"

This reverts commit 9fc7a866ec.

* Watcher tidy

* format

* format

* Filters private methods

* format

* Sorter type safety

* Sorter type safety

* Sorter type safety

* Sorter type safety

* Sorter type safety

* Sorter type safety

* tidy Runner

* tidy hi-test name
2024-11-09 14:14:04 +11:00

68 lines
1.3 KiB
Lua

local events = require("nvim-tree.events")
local notify = require("nvim-tree.notify")
local view = require("nvim-tree.view")
local log = require("nvim-tree.log")
local M = {}
---@type Explorer|nil
local TreeExplorer = nil
local first_init_done = false
---@param foldername string
function M.init(foldername)
local profile = log.profile_start("core init %s", foldername)
if TreeExplorer then
TreeExplorer:destroy()
end
local err, path
if foldername then
path, err = vim.loop.fs_realpath(foldername)
else
path, err = vim.loop.cwd()
end
if path then
TreeExplorer = require("nvim-tree.explorer")({ path = path })
else
notify.error(err)
TreeExplorer = nil
end
if not first_init_done then
events._dispatch_ready()
first_init_done = true
end
log.profile_end(profile)
end
---@return Explorer|nil
function M.get_explorer()
return TreeExplorer
end
function M.reset_explorer()
TreeExplorer = nil
end
---@return string|nil
function M.get_cwd()
return TreeExplorer and TreeExplorer.absolute_path
end
---@return integer
function M.get_nodes_starting_line()
local offset = 1
if view.is_root_folder_visible(M.get_cwd()) then
offset = offset + 1
end
if TreeExplorer and TreeExplorer.live_filter.filter then
return offset + 1
end
return offset
end
return M