mirror of
https://github.com/hexedtech/codemp-nvim.git
synced 2024-11-22 15:34:53 +01:00
feat(neotree): better tree structure
This commit is contained in:
parent
0eeedead59
commit
89b75430e0
1 changed files with 23 additions and 31 deletions
|
@ -66,6 +66,17 @@ local function new_workspace(name, owned, expanded)
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function new_root(name)
|
||||||
|
return {
|
||||||
|
id = "codemp-tree-" .. name,
|
||||||
|
name = name,
|
||||||
|
type = "root",
|
||||||
|
extra = {},
|
||||||
|
children = {}
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
---@return Item
|
||||||
local function spacer()
|
local function spacer()
|
||||||
return {
|
return {
|
||||||
id = "codemp-ws-spacer-" .. vim.fn.rand() % 1024,
|
id = "codemp-ws-spacer-" .. vim.fn.rand() % 1024,
|
||||||
|
@ -75,52 +86,33 @@ local function spacer()
|
||||||
end
|
end
|
||||||
|
|
||||||
M.update_state = function(state)
|
M.update_state = function(state)
|
||||||
---@type Item
|
---@type Item[]
|
||||||
local root
|
local root = {}
|
||||||
|
|
||||||
if codemp.workspace ~= nil then
|
if codemp.workspace ~= nil then
|
||||||
root = {
|
root = {
|
||||||
id = "codemp",
|
new_root(codemp.client.username .. "@" .. codemp.workspace.name),
|
||||||
name = codemp.client.username .. "@" .. codemp.workspace.name,
|
spacer(),
|
||||||
type = "root",
|
new_root("users"),
|
||||||
extra = {},
|
spacer(),
|
||||||
children = {}
|
|
||||||
}
|
}
|
||||||
table.insert(root.children, spacer())
|
table.insert(root.children, spacer())
|
||||||
for i, path in ipairs(codemp.workspace:filetree()) do
|
for i, path in ipairs(codemp.workspace:filetree()) do
|
||||||
table.insert(root.children, new_item(codemp.workspace.name, path))
|
table.insert(root[1].children, new_item(codemp.workspace.name, path))
|
||||||
end
|
end
|
||||||
table.insert(root.children, spacer())
|
|
||||||
for user, buffer in pairs(buf_manager.users) do
|
for user, buffer in pairs(buf_manager.users) do
|
||||||
table.insert(root.children, new_user(codemp.workspace.name, user))
|
table.insert(root[3].children, new_user(codemp.workspace.name, user))
|
||||||
end
|
end
|
||||||
elseif codemp.client ~= nil then
|
elseif codemp.client ~= nil then
|
||||||
root = {
|
root = { new_root(codemp.client.username .. "@codemp") }
|
||||||
id = "codemp",
|
|
||||||
name = codemp.client.username .. "@codemp",
|
|
||||||
type = "root",
|
|
||||||
extra = {},
|
|
||||||
children = {}
|
|
||||||
}
|
|
||||||
for _, ws in ipairs(codemp.available) do
|
for _, ws in ipairs(codemp.available) do
|
||||||
local workspace = new_workspace(ws.name, ws.owned)
|
table.insert(root.children, new_workspace(ws.name, ws.owned))
|
||||||
|
|
||||||
if codemp.workspace ~= nil and codemp.workspace.name == ws.name then
|
|
||||||
end
|
|
||||||
|
|
||||||
table.insert(root.children, workspace)
|
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
root = {
|
root = { new_root("codemp") }
|
||||||
id = "codemp",
|
|
||||||
name = "codemp",
|
|
||||||
type = "root",
|
|
||||||
extra = {},
|
|
||||||
children = {}
|
|
||||||
}
|
|
||||||
end
|
end
|
||||||
|
|
||||||
renderer.show_nodes({ root }, state)
|
renderer.show_nodes(root, state)
|
||||||
|
|
||||||
if codemp.workspace ~= nil then
|
if codemp.workspace ~= nil then
|
||||||
for _, node in ipairs(state.tree:get_nodes()) do
|
for _, node in ipairs(state.tree:get_nodes()) do
|
||||||
|
|
Loading…
Reference in a new issue