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 = {}
|
||||
|
||||
---@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 = {
|
||||
globals = {
|
||||
keybinds = {
|
||||
@@ -92,19 +62,14 @@ M.defaults = {
|
||||
}
|
||||
}
|
||||
|
||||
---@type string[]
|
||||
M.user_config = {}
|
||||
|
||||
---@param user_opts table
|
||||
function M.setup(user_opts)
|
||||
M.user_config = vim.tbl_deep_extend("force", {}, M.defaults, user_opts or {})
|
||||
end
|
||||
|
||||
---@param lang string
|
||||
---@return string|table
|
||||
function M.get(lang)
|
||||
return M.user_config[lang] or {}
|
||||
end
|
||||
|
||||
---@return table
|
||||
return M
|
||||
|
||||
@@ -22,20 +22,20 @@ function M.setup(opts)
|
||||
end
|
||||
|
||||
function M.get_project_root()
|
||||
local dir = vim.fn.expand("%:p:h")
|
||||
while dir ~= "/" do
|
||||
if vim.fn.isdirectory(dir .. "/src") == 1 or vim.fn.filereadable(dir .. "/CMakeLists.txt") == 1 then
|
||||
return dir
|
||||
end
|
||||
dir = vim.fn.fnamemodify(dir, ":h")
|
||||
end
|
||||
local result = vim.fs.find({ "src", "CMakeLists.txt" }, {
|
||||
upward = true,
|
||||
stop = vim.loop.os_homedir(),
|
||||
path = vim.fs.dirname(vim.api.nvim_buf_get_name(0)),
|
||||
})
|
||||
return result[1] and vim.fs.dirname(result[1]) or nil
|
||||
end
|
||||
|
||||
local root = M.get_project_root()
|
||||
|
||||
function M.create_new_header_file()
|
||||
vim.ui.input({ prompt = "Enter header file name: " }, function(header_name)
|
||||
if not header_name then return print("Header file creation canceled.") end
|
||||
local root_dir = M.get_project_root()
|
||||
if not root_dir then return print("Error: Project root not found.") end
|
||||
if not root then return print("Error: Project root not found.") end
|
||||
local guard_macro = header_name:upper():gsub("[^A-Z0-9]", "_") .. "_HPP"
|
||||
local content = string.format([[
|
||||
#ifndef %s
|
||||
@@ -48,12 +48,11 @@ void example_function();
|
||||
|
||||
#endif // %s
|
||||
]], 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
|
||||
|
||||
function M.run()
|
||||
local root = M.get_project_root()
|
||||
if not root then return print("Error: Project root not found.") end
|
||||
local build_dir = root .. "/build"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user