rework: check description
docs: removed lines about plenary removal: plenary chore: optmized presets load to default nil as 'max' rework: changed window format of manager and added coloring Future plans: Add custom highlight-groups for Polydev to configure border and background or manager
This commit is contained in:
@@ -12,8 +12,7 @@ Polydev can be installed using any plugin manager of your choice — or even man
|
|||||||
return {
|
return {
|
||||||
"DarthMooMancer/Polydev",
|
"DarthMooMancer/Polydev",
|
||||||
dependencies = {
|
dependencies = {
|
||||||
"MunifTanjim/nui.nvim",
|
"MunifTanjim/nui.nvim"
|
||||||
"nvim-lua/plenary.nvim"
|
|
||||||
},
|
},
|
||||||
opts = {}, -- Setup is later on
|
opts = {}, -- Setup is later on
|
||||||
}
|
}
|
||||||
@@ -27,8 +26,7 @@ return {
|
|||||||
MiniDeps.add({
|
MiniDeps.add({
|
||||||
source = "DarthMooMancer/Polydev"
|
source = "DarthMooMancer/Polydev"
|
||||||
depends = {
|
depends = {
|
||||||
"MunifTanjim/nui.nvim",
|
"MunifTanjim/nui.nvim"
|
||||||
"nvim-lua/plenary.nvim"
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -43,8 +41,7 @@ require("Polydev").setup({})
|
|||||||
use({
|
use({
|
||||||
"DarthMooMancer/Polydev",
|
"DarthMooMancer/Polydev",
|
||||||
requires = {
|
requires = {
|
||||||
"MunifTanjim/nui.nvim",
|
"MunifTanjim/nui.nvim"
|
||||||
"nvim-lua/plenary.nvim"
|
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ function M.setup(opts)
|
|||||||
end
|
end
|
||||||
|
|
||||||
vim.api.nvim_create_user_command("PolydevOpen", function() ui.manager(config.get("globals").project_root) end, {})
|
vim.api.nvim_create_user_command("PolydevOpen", function() ui.manager(config.get("globals").project_root) end, {})
|
||||||
|
-- require("Polydev.styles").setup_highlights()
|
||||||
|
|
||||||
local keys = vim.tbl_deep_extend("force", {}, config.get("globals").keybinds, opts.keybinds or {})
|
local keys = vim.tbl_deep_extend("force", {}, config.get("globals").keybinds, opts.keybinds or {})
|
||||||
for key, _ in pairs(keys) do
|
for key, _ in pairs(keys) do
|
||||||
|
|||||||
@@ -29,14 +29,7 @@ local presets = {
|
|||||||
---@param preset string
|
---@param preset string
|
||||||
---@return table|nil
|
---@return table|nil
|
||||||
function M.getPresets(preset)
|
function M.getPresets(preset)
|
||||||
if presets[preset] ~= nil then
|
return presets[preset]
|
||||||
return presets[preset]
|
|
||||||
elseif presets[preset] == nil then
|
|
||||||
return nil
|
|
||||||
else
|
|
||||||
print("Preset option: " .. preset .. " does not exist")
|
|
||||||
end
|
|
||||||
return {}
|
|
||||||
end
|
end
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
|||||||
@@ -0,0 +1,23 @@
|
|||||||
|
local M = {}
|
||||||
|
|
||||||
|
function M.setup_highlights()
|
||||||
|
-- Only set if not already defined by colorscheme
|
||||||
|
local function define(name, opts)
|
||||||
|
if vim.fn.hlexists(name) == 0 then
|
||||||
|
vim.api.nvim_set_hl(0, name, opts)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
define("PolydevNormal", {
|
||||||
|
fg = vim.api.nvim_get_hl_by_name("NormalFloat", true).foreground,
|
||||||
|
bg = vim.api.nvim_get_hl_by_name("Normal", true).background
|
||||||
|
})
|
||||||
|
|
||||||
|
define("PolydevBorder", {
|
||||||
|
fg = vim.api.nvim_get_hl_by_name("Function", true).foreground,
|
||||||
|
bg = vim.api.nvim_get_hl_by_name("Normal", true).background
|
||||||
|
})
|
||||||
|
define("PolydevTitle", { fg = "#89dceb", bold = true })
|
||||||
|
end
|
||||||
|
|
||||||
|
return M
|
||||||
@@ -2,7 +2,7 @@ local utils = require("Polydev.utils")
|
|||||||
|
|
||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
local function aux_file(guard, file_type, file_name)
|
local function extras(guard, file_type, file_name)
|
||||||
if not file_name then return print("Header file creation canceled") end
|
if not file_name then return print("Header file creation canceled") end
|
||||||
local guard_macro = file_name:upper():gsub("[^A-Z0-9]", "_") .. guard
|
local guard_macro = file_name:upper():gsub("[^A-Z0-9]", "_") .. guard
|
||||||
local content = string.format([[
|
local content = string.format([[
|
||||||
@@ -239,14 +239,14 @@ public class %s {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
M.aux_files = {
|
M.extras = {
|
||||||
run = function (lang, file_name)
|
run = function (lang, file_name)
|
||||||
if lang == "c" then
|
if lang == "c" then
|
||||||
aux_file("_H", ".h", file_name)
|
extras("_H", ".h", file_name)
|
||||||
print("Successful creation of " .. file_name .. ".h")
|
print("Successful creation of " .. file_name .. ".h")
|
||||||
end
|
end
|
||||||
if lang == "cpp" then
|
if lang == "cpp" then
|
||||||
aux_file("_HPP", ".hpp", file_name)
|
extras("_HPP", ".hpp", file_name)
|
||||||
print("Successful creation of " .. file_name .. ".hpp")
|
print("Successful creation of " .. file_name .. ".hpp")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
+65
-46
@@ -39,6 +39,9 @@ local function get_entries(path)
|
|||||||
return result
|
return result
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---@param list table
|
||||||
|
---@param query string
|
||||||
|
---@return table
|
||||||
local function fuzzy_filter(list, query)
|
local function fuzzy_filter(list, query)
|
||||||
local result = {}
|
local result = {}
|
||||||
query = query:lower()
|
query = query:lower()
|
||||||
@@ -51,6 +54,10 @@ local function fuzzy_filter(list, query)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local loaded_languages = {}
|
local loaded_languages = {}
|
||||||
|
|
||||||
|
---@param lang string
|
||||||
|
---@param opts? table
|
||||||
|
---@return boolean
|
||||||
function M.load_language_module(lang, opts)
|
function M.load_language_module(lang, opts)
|
||||||
if loaded_languages[lang] then return true end
|
if loaded_languages[lang] then return true end
|
||||||
|
|
||||||
@@ -67,53 +74,64 @@ function M.manager(project_root)
|
|||||||
local Popup = require("nui.popup")
|
local Popup = require("nui.popup")
|
||||||
local Layout = require("nui.layout")
|
local Layout = require("nui.layout")
|
||||||
local event = require("nui.utils.autocmd").event
|
local event = require("nui.utils.autocmd").event
|
||||||
local Path = require("plenary.path")
|
|
||||||
local display_dir = vim.fn.expand(vim.fn.getcwd())
|
local display_dir = vim.fn.expand(vim.fn.getcwd())
|
||||||
local cwd = display_dir
|
local cwd = display_dir
|
||||||
local entries = get_entries(cwd)
|
local entries = get_entries(cwd)
|
||||||
local current_view = vim.deepcopy(entries)
|
local current_view = vim.deepcopy(entries)
|
||||||
|
|
||||||
|
-- Create a new custom highlight group with Normal background and NormalFloat foreground
|
||||||
|
vim.api.nvim_set_hl(0, "CustomFloatText", {
|
||||||
|
fg = vim.api.nvim_get_hl_by_name("NormalFloat", true).foreground,
|
||||||
|
bg = vim.api.nvim_get_hl_by_name("Normal", true).background,
|
||||||
|
})
|
||||||
|
|
||||||
local popup, search, preview = Popup({
|
local popup, search, preview = Popup({
|
||||||
enter = true,
|
enter = true,
|
||||||
focusable = true,
|
focusable = true,
|
||||||
border = {
|
border = {
|
||||||
style = "rounded", -- "double", "none", "rounded", "shadow", "single" or "solid".
|
style = "rounded", -- "double", "none", "rounded", "shadow", "single" or "solid".
|
||||||
text = { top = " Project Manager ", top_align = "center" },
|
text = { top = " Results ", top_align = "center" },
|
||||||
highlight = "Normal",
|
|
||||||
},
|
},
|
||||||
position = "50%",
|
position = "50%",
|
||||||
buf_options = { modifiable = true, readonly = false },
|
buf_options = { modifiable = true, readonly = false },
|
||||||
|
win_options = {
|
||||||
|
winhighlight = "Normal:CustomFloatText,FloatBorder:Function",
|
||||||
|
}
|
||||||
}), Popup({
|
}), Popup({
|
||||||
enter = false,
|
enter = false,
|
||||||
focusable = true,
|
focusable = true,
|
||||||
border = {
|
border = {
|
||||||
style = "rounded", -- "double", "none", "rounded", "shadow", "single" or "solid".
|
style = "rounded", -- "rounded", "single" or "solid".
|
||||||
text = { top = " Search ", top_align = "center" },
|
text = { top = " Find Files ", top_align = "center" },
|
||||||
highlight = "Normal",
|
|
||||||
},
|
},
|
||||||
buf_options = { modifiable = true, readonly = false },
|
buf_options = { modifiable = true, readonly = false },
|
||||||
|
win_options = {
|
||||||
|
winhighlight = "Normal:CustomFloatText,FloatBorder:Function",
|
||||||
|
}
|
||||||
}), Popup({
|
}), Popup({
|
||||||
enter = false,
|
enter = false,
|
||||||
focusable = false,
|
focusable = false,
|
||||||
border = {
|
border = {
|
||||||
style = "rounded",
|
style = "rounded",
|
||||||
text = { top = " Preview ", top_align = "center" },
|
text = { top = " Grep Preview ", top_align = "center" },
|
||||||
highlight = "Normal",
|
|
||||||
},
|
},
|
||||||
position = "50%",
|
position = "50%",
|
||||||
buf_options = { modifiable = true, readonly = false },
|
buf_options = { modifiable = true, readonly = false },
|
||||||
|
win_options = {
|
||||||
|
winhighlight = "Normal:CustomFloatText,FloatBorder:Function",
|
||||||
|
}
|
||||||
})
|
})
|
||||||
local layout = Layout({
|
local layout = Layout({
|
||||||
position = "50%",
|
position = "55%",
|
||||||
size = { width = "70%", height = "70%" },
|
size = { width = "81%", height = "90%" },
|
||||||
},
|
},
|
||||||
Layout.Box({
|
Layout.Box({
|
||||||
Layout.Box(search, { size = "10%" }),
|
|
||||||
Layout.Box({
|
Layout.Box({
|
||||||
Layout.Box(popup, { size = "50%" }),
|
Layout.Box(search, { size = "10%" }),
|
||||||
Layout.Box(preview, { size = "50%" }),
|
Layout.Box(popup, { size = "93%" }),
|
||||||
}, { dir = "row", size = "90%" }),
|
}, { dir = "col", size = "48%" }),
|
||||||
}, { dir = "col" })
|
Layout.Box(preview, { size = "51.5%" }),
|
||||||
|
}, { dir = "row" })
|
||||||
)
|
)
|
||||||
layout:mount()
|
layout:mount()
|
||||||
|
|
||||||
@@ -180,7 +198,7 @@ function M.manager(project_root)
|
|||||||
table.insert(entries, 1, {
|
table.insert(entries, 1, {
|
||||||
name = "../",
|
name = "../",
|
||||||
type = "directory",
|
type = "directory",
|
||||||
full_path = Path:new(cwd):parent():absolute(),
|
full_path = vim.fn.fnamemodify(cwd, ":h"),
|
||||||
is_up = true
|
is_up = true
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
@@ -234,32 +252,7 @@ function M.manager(project_root)
|
|||||||
-- Mappings
|
-- Mappings
|
||||||
popup:map("n", "q", function() popup:unmount() end)
|
popup:map("n", "q", function() popup:unmount() end)
|
||||||
|
|
||||||
-- Creates a new folder
|
-- Creates new file
|
||||||
popup:map("n", "a", function()
|
|
||||||
vim.ui.input({ prompt = "New folder name:" }, function(input)
|
|
||||||
if input then
|
|
||||||
vim.fn.mkdir(cwd .. "/" .. input, "p")
|
|
||||||
refresh()
|
|
||||||
render()
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
end)
|
|
||||||
|
|
||||||
-- Deletes Folder and confirms deletion
|
|
||||||
popup:map("n", "D", function()
|
|
||||||
local entry = get_selected_entry()
|
|
||||||
if not entry.is_up then
|
|
||||||
vim.ui.input({ prompt = "Deletion of " .. entry.name .. ": (y/N) Defaults to N: " }, function(input)
|
|
||||||
if input == "y" or input == "Y" then
|
|
||||||
vim.fn.delete(entry.full_path, "rf")
|
|
||||||
refresh()
|
|
||||||
render()
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
|
|
||||||
-- Creates a new file in project
|
|
||||||
popup:map("n", "%", function()
|
popup:map("n", "%", function()
|
||||||
vim.ui.input({ prompt = "Enter language for new file: " }, function(lang)
|
vim.ui.input({ prompt = "Enter language for new file: " }, function(lang)
|
||||||
if not lang or lang == "" then return print("File creation canceled") end
|
if not lang or lang == "" then return print("File creation canceled") end
|
||||||
@@ -277,15 +270,16 @@ function M.manager(project_root)
|
|||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
-- Creates extra file
|
||||||
popup:map("n", "x", function()
|
popup:map("n", "x", function()
|
||||||
vim.ui.input({ prompt = "Enter language for new auxilary file: "}, function(lang)
|
vim.ui.input({ prompt = "Enter language for new auxilary file: "}, function(lang)
|
||||||
if not lang or lang == "" then return print("File create canceled") end
|
if not lang or lang == "" then return print("File create canceled") end
|
||||||
if M.load_language_module(lang) and templates.aux_files.run then
|
if M.load_language_module(lang) and templates.extras.run then
|
||||||
popup:unmount()
|
popup:unmount()
|
||||||
vim.schedule(function()
|
vim.schedule(function()
|
||||||
vim.ui.input({ prompt = "Enter file name: "}, function(file_name)
|
vim.ui.input({ prompt = "Enter file name: "}, function(file_name)
|
||||||
if not file_name or file_name == "" then return print("File creation canceled") end
|
if not file_name or file_name == "" then return print("File creation canceled") end
|
||||||
templates.aux_files.run(lang, file_name)
|
templates.extras.run(lang, file_name)
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
else
|
else
|
||||||
@@ -294,7 +288,18 @@ function M.manager(project_root)
|
|||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
-- Creates a new project
|
-- Creates a new folder
|
||||||
|
popup:map("n", "a", function()
|
||||||
|
vim.ui.input({ prompt = "New folder name:" }, function(input)
|
||||||
|
if input then
|
||||||
|
vim.fn.mkdir(cwd .. "/" .. input, "p")
|
||||||
|
refresh()
|
||||||
|
render()
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
end)
|
||||||
|
|
||||||
|
-- Creates new project
|
||||||
popup:map("n", "d", function()
|
popup:map("n", "d", function()
|
||||||
local opts = {}
|
local opts = {}
|
||||||
vim.ui.input({ prompt = "Enter language for project: " }, function(lang)
|
vim.ui.input({ prompt = "Enter language for project: " }, function(lang)
|
||||||
@@ -314,6 +319,20 @@ function M.manager(project_root)
|
|||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
-- Deletes Folder and confirms deletion
|
||||||
|
popup:map("n", "D", function()
|
||||||
|
local entry = get_selected_entry()
|
||||||
|
if not entry.is_up then
|
||||||
|
vim.ui.input({ prompt = "Deletion of " .. entry.name .. ": (y/N) Defaults to N: " }, function(input)
|
||||||
|
if input == "y" or input == "Y" then
|
||||||
|
vim.fn.delete(entry.full_path, "rf")
|
||||||
|
refresh()
|
||||||
|
render()
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
-- Renames Files and Folders
|
-- Renames Files and Folders
|
||||||
popup:map("n", "R", function()
|
popup:map("n", "R", function()
|
||||||
local entry = get_selected_entry()
|
local entry = get_selected_entry()
|
||||||
@@ -347,7 +366,7 @@ function M.manager(project_root)
|
|||||||
end)
|
end)
|
||||||
|
|
||||||
popup:map("n", "<BS>", function()
|
popup:map("n", "<BS>", function()
|
||||||
local parent = Path:new(cwd):parent():absolute()
|
local parent = vim.fn.fnamemodify(cwd, ":h")
|
||||||
if parent ~= cwd then
|
if parent ~= cwd then
|
||||||
cwd = parent
|
cwd = parent
|
||||||
refresh()
|
refresh()
|
||||||
|
|||||||
Reference in New Issue
Block a user