From 388196ae5ebd7bdb91a9cea8667d4b38101670b8 Mon Sep 17 00:00:00 2001 From: alemi Date: Tue, 6 Aug 2024 03:10:24 +0200 Subject: [PATCH] feat: show file tree in split --- src/command.lua | 17 ++++++++++++++++- src/workspace.lua | 5 +---- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/command.lua b/src/command.lua index b57116b..551faf1 100644 --- a/src/command.lua +++ b/src/command.lua @@ -1,6 +1,7 @@ local client = require('codemp.client') local buffers = require('codemp.buffer') local workspace = require('codemp.workspace') +local utils = require('codemp.utils') local native = require('codemp.loader').load() @@ -14,6 +15,8 @@ local function filter(needle, haystack) return hints end +local tree_buf = nil; + vim.api.nvim_create_user_command( "MP", function (args) @@ -36,7 +39,19 @@ vim.api.nvim_create_user_command( buffers.sync(client.workspace) elseif args.fargs[1] == "buffers" then if client.workspace == nil then error("connect to a workspace first") end - workspace.buffers(client.workspace) + local tree = workspace.buffers(client.workspace) + if tree_buf == nil then + tree_buf = vim.api.nvim_create_buf(false, true) + vim.api.nvim_buf_set_name(tree_buf, "codemp::" .. client.workspace) + vim.api.nvim_set_option_value('buftype', 'nofile', { buf = tree_buf }) + vim.api.nvim_set_option_value('nomodifiable', true, { buf = tree_buf }) + end + utils.buffer.set_content(tree_buf, "> " .. vim.fn.join(tree, "\n> ")) + vim.api.nvim_open_win(tree_buf, true, { + win = 0, + split = 'left', + width = 20, + }) -- elseif args.fargs[1] == "users" then -- if client.workspace == nil then error("connect to a workspace first") end -- workspace.users(client.workspace) diff --git a/src/workspace.lua b/src/workspace.lua index 0823c69..611ac8a 100644 --- a/src/workspace.lua +++ b/src/workspace.lua @@ -70,10 +70,7 @@ local function list_users(workspace) end local function list_buffers(workspace) - local workspace = native.get_workspace(workspace) - for _, buffer in pairs(workspace.filetree) do - print(" > " .. buffer) - end + return native.get_workspace(workspace).filetree end return {