chore: cleaned up cpp.lua to find polydev file faster and cleaned up
configs file
This commit is contained in:
@@ -1,35 +1,5 @@
|
|||||||
---@type table
|
|
||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
---@class KeybindConfigs
|
|
||||||
---@field [string] string
|
|
||||||
---
|
|
||||||
---@class LanguageConfigs
|
|
||||||
---@field project_root? string
|
|
||||||
---@field keybinds? KeybindConfigs -- ? makes fields optional
|
|
||||||
---@field build_attributes? string
|
|
||||||
|
|
||||||
---@class TerminalConfigs
|
|
||||||
---@field presets string
|
|
||||||
---@field border boolean
|
|
||||||
---@field number boolean
|
|
||||||
---@field relativenumber boolean
|
|
||||||
|
|
||||||
---@class GlobalsConfigs
|
|
||||||
---@field keybinds KeybindConfigs
|
|
||||||
|
|
||||||
---@class Defaults
|
|
||||||
---@field globals GlobalsConfigs
|
|
||||||
---@field html LanguageConfigs
|
|
||||||
---@field rust LanguageConfigs
|
|
||||||
---@field java LanguageConfigs
|
|
||||||
---@field python LanguageConfigs
|
|
||||||
---@field lua LanguageConfigs
|
|
||||||
---@field c LanguageConfigs
|
|
||||||
---@field cpp LanguageConfigs
|
|
||||||
---@field terminal TerminalConfigs
|
|
||||||
|
|
||||||
---@type Defaults
|
|
||||||
M.defaults = {
|
M.defaults = {
|
||||||
globals = {
|
globals = {
|
||||||
keybinds = {
|
keybinds = {
|
||||||
@@ -92,19 +62,14 @@ M.defaults = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
---@type string[]
|
|
||||||
M.user_config = {}
|
M.user_config = {}
|
||||||
|
|
||||||
---@param user_opts table
|
|
||||||
function M.setup(user_opts)
|
function M.setup(user_opts)
|
||||||
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 {})
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param lang string
|
|
||||||
---@return string|table
|
|
||||||
function M.get(lang)
|
function M.get(lang)
|
||||||
return M.user_config[lang] or {}
|
return M.user_config[lang] or {}
|
||||||
end
|
end
|
||||||
|
|
||||||
---@return table
|
|
||||||
return M
|
return M
|
||||||
|
|||||||
@@ -22,20 +22,20 @@ function M.setup(opts)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function M.get_project_root()
|
function M.get_project_root()
|
||||||
local dir = vim.fn.expand("%:p:h")
|
local result = vim.fs.find({ "src", "CMakeLists.txt" }, {
|
||||||
while dir ~= "/" do
|
upward = true,
|
||||||
if vim.fn.isdirectory(dir .. "/src") == 1 or vim.fn.filereadable(dir .. "/CMakeLists.txt") == 1 then
|
stop = vim.loop.os_homedir(),
|
||||||
return dir
|
path = vim.fs.dirname(vim.api.nvim_buf_get_name(0)),
|
||||||
end
|
})
|
||||||
dir = vim.fn.fnamemodify(dir, ":h")
|
return result[1] and vim.fs.dirname(result[1]) or nil
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local root = M.get_project_root()
|
||||||
|
|
||||||
function M.create_new_header_file()
|
function M.create_new_header_file()
|
||||||
vim.ui.input({ prompt = "Enter header file name: " }, function(header_name)
|
vim.ui.input({ prompt = "Enter header file name: " }, function(header_name)
|
||||||
if not header_name then return print("Header file creation canceled.") end
|
if not header_name then return print("Header file creation canceled.") end
|
||||||
local root_dir = M.get_project_root()
|
if not root then return print("Error: Project root not found.") end
|
||||||
if not root_dir then return print("Error: Project root not found.") end
|
|
||||||
local guard_macro = header_name:upper():gsub("[^A-Z0-9]", "_") .. "_HPP"
|
local guard_macro = header_name:upper():gsub("[^A-Z0-9]", "_") .. "_HPP"
|
||||||
local content = string.format([[
|
local content = string.format([[
|
||||||
#ifndef %s
|
#ifndef %s
|
||||||
@@ -48,12 +48,11 @@ void example_function();
|
|||||||
|
|
||||||
#endif // %s
|
#endif // %s
|
||||||
]], guard_macro, guard_macro, guard_macro)
|
]], guard_macro, guard_macro, guard_macro)
|
||||||
utils.write_file(root_dir .. "/include/" .. header_name .. ".hpp", content)
|
utils.write_file(root .. "/include/" .. header_name .. ".hpp", content)
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.run()
|
function M.run()
|
||||||
local root = M.get_project_root()
|
|
||||||
if not root then return print("Error: Project root not found.") end
|
if not root then return print("Error: Project root not found.") end
|
||||||
local build_dir = root .. "/build"
|
local build_dir = root .. "/build"
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user