fix: project root is properly taken by user opts
feat: user can change border of terminal alongside enabling/disabling it
This commit is contained in:
+39
-32
@@ -5,69 +5,76 @@ M.defaults = {
|
|||||||
project_root = "~/Projects",
|
project_root = "~/Projects",
|
||||||
keybinds = {
|
keybinds = {
|
||||||
["<leader>po"] = "PolydevManager",
|
["<leader>po"] = "PolydevManager",
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
terminal = {
|
terminal = {
|
||||||
preset = nil,
|
preset = nil,
|
||||||
border = true,
|
border = {
|
||||||
}
|
enabled = true,
|
||||||
|
type = "rounded",
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
M.defaults.rust = {
|
local function default_languages(project_root)
|
||||||
project_root = M.defaults.globals.project_root .. "/Rust",
|
return {
|
||||||
|
rust = {
|
||||||
|
project_root = project_root .. "/Rust",
|
||||||
keybinds = {
|
keybinds = {
|
||||||
["<leader>pr"] = "RustRun",
|
["<leader>pr"] = "RustRun",
|
||||||
},
|
},
|
||||||
}
|
},
|
||||||
|
java = {
|
||||||
M.defaults.java = {
|
project_root = project_root .. "/Java",
|
||||||
project_root = M.defaults.globals.project_root .. "/Java",
|
|
||||||
keybinds = {
|
keybinds = {
|
||||||
["<leader>pr"] = "JavaRun",
|
["<leader>pr"] = "JavaRun",
|
||||||
},
|
},
|
||||||
}
|
|
||||||
|
|
||||||
M.defaults.python = {
|
|
||||||
project_root = M.defaults.globals.project_root .. "/Python",
|
|
||||||
keybinds = {
|
|
||||||
["<leader>pr"] = "PythonRun",
|
|
||||||
["<leader>pb"] = "PythonPip",
|
|
||||||
},
|
},
|
||||||
}
|
lua = {
|
||||||
|
project_root = project_root .. "/Lua",
|
||||||
M.defaults.lua = {
|
|
||||||
project_root = M.defaults.globals.project_root .. "/Lua",
|
|
||||||
keybinds = {
|
keybinds = {
|
||||||
["<leader>pr"] = "LuaRun",
|
["<leader>pr"] = "LuaRun",
|
||||||
},
|
},
|
||||||
}
|
},
|
||||||
|
c = {
|
||||||
M.defaults.c = {
|
project_root = project_root .. "/C",
|
||||||
project_root = M.defaults.globals.project_root .. "/C",
|
|
||||||
keybinds = {
|
keybinds = {
|
||||||
["<leader>pr"] = "CRun",
|
["<leader>pr"] = "CRun",
|
||||||
},
|
},
|
||||||
build_attributes = "",
|
build_attributes = "",
|
||||||
}
|
},
|
||||||
|
cpp = {
|
||||||
M.defaults.cpp = {
|
project_root = project_root .. "/CPP",
|
||||||
project_root = M.defaults.globals.project_root .. "/CPP",
|
|
||||||
keybinds = {
|
keybinds = {
|
||||||
["<leader>pr"] = "CppRun",
|
["<leader>pr"] = "CppRun",
|
||||||
},
|
},
|
||||||
build_attributes = "",
|
build_attributes = "",
|
||||||
|
},
|
||||||
|
html = {
|
||||||
|
project_root = project_root .. "/Html",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
end
|
||||||
M.defaults.html = {
|
|
||||||
project_root = M.defaults.globals.project_root .. "/Html",
|
|
||||||
}
|
|
||||||
|
|
||||||
M.user_config = {}
|
M.user_config = {}
|
||||||
|
|
||||||
|
---@param user_opts table
|
||||||
function M.setup(user_opts)
|
function M.setup(user_opts)
|
||||||
|
-- First merge global and terminal
|
||||||
M.user_config = vim.tbl_deep_extend("force", {}, M.defaults, user_opts or {})
|
M.user_config = vim.tbl_deep_extend("force", {}, M.defaults, user_opts or {})
|
||||||
|
|
||||||
|
-- Now use the final resolved project_root from user_config
|
||||||
|
local root = M.user_config.globals.project_root
|
||||||
|
local langs = default_languages(root)
|
||||||
|
|
||||||
|
-- Inject languages into the config, respecting user overrides
|
||||||
|
for lang, conf in pairs(langs) do
|
||||||
|
M.user_config[lang] = vim.tbl_deep_extend("force", conf, M.user_config[lang] or {})
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---@param lang string
|
||||||
|
---@return table
|
||||||
function M.get(lang)
|
function M.get(lang)
|
||||||
return M.user_config[lang] or {}
|
return M.user_config[lang] or {}
|
||||||
end
|
end
|
||||||
|
|||||||
+6
-4
@@ -1,5 +1,7 @@
|
|||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
|
---@param path string
|
||||||
|
---@return table
|
||||||
local function get_entries(path)
|
local function get_entries(path)
|
||||||
local result = {}
|
local result = {}
|
||||||
local handle = vim.loop.fs_scandir(path)
|
local handle = vim.loop.fs_scandir(path)
|
||||||
@@ -69,13 +71,13 @@ function M.load_language_module(lang, opts)
|
|||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---@param project_root string
|
||||||
function M.manager(project_root)
|
function M.manager(project_root)
|
||||||
local templates = require("Polydev.templates")
|
local templates = require("Polydev.templates")
|
||||||
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 display_dir = vim.fn.expand(vim.fn.getcwd())
|
local cwd = vim.fn.expand(vim.fn.getcwd())
|
||||||
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)
|
||||||
|
|
||||||
@@ -209,7 +211,7 @@ function M.manager(project_root)
|
|||||||
local hints = {
|
local hints = {
|
||||||
"",
|
"",
|
||||||
"/ → Find a → New Directory % → New File R → Rename",
|
"/ → Find a → New Directory % → New File R → Rename",
|
||||||
"x → New Helper File d → New Project D → Delete q → Quit",
|
"x → New Helper File d → New Project D → Delete",
|
||||||
}
|
}
|
||||||
if not popup.bufnr then return end
|
if not popup.bufnr then return end
|
||||||
vim.api.nvim_buf_set_lines(popup.bufnr, 0, -1, false, {})
|
vim.api.nvim_buf_set_lines(popup.bufnr, 0, -1, false, {})
|
||||||
@@ -250,7 +252,7 @@ function M.manager(project_root)
|
|||||||
popup:map("n", "/", function() vim.schedule(prompt_filter) end)
|
popup:map("n", "/", function() vim.schedule(prompt_filter) end)
|
||||||
|
|
||||||
-- Mappings
|
-- Mappings
|
||||||
popup:map("n", "q", function() popup:unmount() end)
|
popup:map("n", "<ESC>", function() popup:unmount() end)
|
||||||
|
|
||||||
-- Creates new file
|
-- Creates new file
|
||||||
popup:map("n", "%", function()
|
popup:map("n", "%", function()
|
||||||
|
|||||||
@@ -80,7 +80,7 @@ function M.terminal(cmd)
|
|||||||
row = row,
|
row = row,
|
||||||
col = col,
|
col = col,
|
||||||
style = "minimal",
|
style = "minimal",
|
||||||
border = M.opts.border and "rounded" or "none",
|
border = M.opts.border.enabled and M.opts.border.type,
|
||||||
})
|
})
|
||||||
vim.api.nvim_set_option_value("winblend", vim.o.pumblend, { win = win })
|
vim.api.nvim_set_option_value("winblend", vim.o.pumblend, { win = win })
|
||||||
vim.api.nvim_set_option_value("winhighlight", "Normal:Pmenu,FloatBorder:Pmenu", { win = win })
|
vim.api.nvim_set_option_value("winhighlight", "Normal:Pmenu,FloatBorder:Pmenu", { win = win })
|
||||||
|
|||||||
Reference in New Issue
Block a user