From 4bf705df03f8f8e24b2fe72055f1e413508c3b07 Mon Sep 17 00:00:00 2001 From: Andrew Haynes Date: Fri, 23 Oct 2026 09:30:37 -0400 Subject: [PATCH] CHORE: Bug fixed c and cpp files and fixed their templates. Bug #3 is also done --- lua/vern/actions/c.lua | 4 +- lua/vern/actions/cpp.lua | 9 ++++- lua/vern/actions/python.lua | 2 +- lua/vern/templates/c.lua | 32 ++++++++++------ lua/vern/templates/cpp.lua | 73 ++++++++++++++++++++++--------------- 5 files changed, 76 insertions(+), 44 deletions(-) diff --git a/lua/vern/actions/c.lua b/lua/vern/actions/c.lua index c063abd..1753950 100644 --- a/lua/vern/actions/c.lua +++ b/lua/vern/actions/c.lua @@ -19,9 +19,11 @@ function M.create_project(opts) ---@type VernCConfig local cfg = vim.tbl_deep_extend("force", {}, configs, configs, opts or {}) local root = join(vim.fn.expand(cfg.workspace_root), cfg.c.root, pname) - local build_cmd = "cd " .. root .. " && cmake -S . -B build" local bin = action_utils.create(cfg.c, pname, root) + + local build_cmd = "cd " .. root .. " && cmake -S . -B build" local _ = vim.system({ "sh", "-c", build_cmd }):wait() + utils.init_git(root, "c") vim.cmd.edit(vim.fn.fnameescape(bin)) diff --git a/lua/vern/actions/cpp.lua b/lua/vern/actions/cpp.lua index e743000..e356aef 100644 --- a/lua/vern/actions/cpp.lua +++ b/lua/vern/actions/cpp.lua @@ -20,19 +20,24 @@ function M.create_project(opts) local cfg = vim.tbl_deep_extend("force", {}, configs, configs, opts or {}) local root = join(vim.fn.expand(cfg.workspace_root), cfg.cpp.root, pname) local bin = action_utils.create(cfg.cpp, pname, root) - utils.init_git(root, "c") + + local build_cmd = "cd " .. root .. " && cmake -S . -B build" + local _ = vim.system({ "sh", "-c", build_cmd }):wait() + + utils.init_git(root, "cpp") vim.cmd.edit(vim.fn.fnameescape(bin)) end) end +---@param opts VernCPPConfig function M.create_file(opts) vim.ui.input({ prompt = "Enter type (c/h): " }, function(ft) ft = ft and vim.trim(ft) if not ft or ft == "" then return end - local configs = require("vern.configs.c") + local configs = require("vern.configs.cpp") ---@type VernCPPConfig local cfg = vim.tbl_deep_extend("force", {}, configs, opts or {}) vim.ui.input({ prompt = "Enter file name: " }, function(fname) diff --git a/lua/vern/actions/python.lua b/lua/vern/actions/python.lua index 5eff52c..197960a 100644 --- a/lua/vern/actions/python.lua +++ b/lua/vern/actions/python.lua @@ -64,7 +64,7 @@ function M.run(opts) local exe = join(bin.path, bin.name) or "src/{project_name}/main.py" local exe_path = utils.resolve_path(exe, opts.python.dirs, { project_name = pname }) local full_path = join(vim.fn.expand(root), exe_path) - utils.term({ "python3 " .. full_path }, opts.terminal or {}) + utils.term({ "python3 " .. full_path }, opts.terminal or {}, false) end function M.pip_install() diff --git a/lua/vern/templates/c.lua b/lua/vern/templates/c.lua index cecae62..ff9906a 100644 --- a/lua/vern/templates/c.lua +++ b/lua/vern/templates/c.lua @@ -2,7 +2,7 @@ return { --[[ ===================================================================== TEMPLATE: MAIN (Entrypoint) File: main.c - Target: src/{project_name}/main.py + Target: src/main.c ===================================================================== --]] main = vim.trim([=[ #include @@ -17,9 +17,9 @@ main() ]=]) .. "\n", --[[ ===================================================================== - TEMPLATE: INIT (Package Anchor) - File: __init__.py - Target: src/{project_name}/__init__.py + TEMPLATE: CLANG-FORMAT (Code formatter) + File: .clang-format + Target: .clang-format ===================================================================== --]] format = vim.trim([=[ --- @@ -48,9 +48,9 @@ IncludeBlocks: Preserve ]=]) .. "\n", --[[ ===================================================================== - TEMPLATE: PYPROJECT (Spec / Build Manifest) - File: pyproject.toml - Target: pyproject.toml + TEMPLATE: CMAKELISTS (Spec / Build Manifest) + File: CMakeLists.txt + Target: CMakeLists.txt ===================================================================== --]] CmakeLists = vim.trim([=[ cmake_minimum_required(VERSION 3.16) @@ -67,7 +67,7 @@ set(LIB_SOURCES if(LIB_SOURCES) add_library(__PROJECT_NAME__ STATIC ${LIB_SOURCES}) - target_include_directories(%s + target_include_directories(__PROJECT_NAME__ PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include ) @@ -82,9 +82,9 @@ endif() ]=]) .. "\n", --[[ ===================================================================== - TEMPLATE: MODULE (Standalone File) - File: {name}.py - Target: src/{project_name}/{name}.py + TEMPLATE: HEADER (Standalone File) + File: {name}.h + Target: include/{project_name}/{name}.h ===================================================================== --]] header = vim.trim([=[ #ifndef __PROJECT_NAME___H @@ -95,9 +95,19 @@ endif() #endif /* __PROJECT_NAME___H */ ]=]) .. "\n", + --[[ ===================================================================== + TEMPLATE: SOURCE (Standalone File) + File: {name}.c + Target: src/{name}.c + ===================================================================== --]] source = vim.trim([=[ ]=]) .. "\n", + --[[ ===================================================================== + TEMPLATE: CLANG_TIDY (LINTER) + File: .clang-tidy + Target: .clang-tidy + ===================================================================== --]] linter = vim.trim([=[ Checks: > -*, diff --git a/lua/vern/templates/cpp.lua b/lua/vern/templates/cpp.lua index 27eccb5..a3dd079 100644 --- a/lua/vern/templates/cpp.lua +++ b/lua/vern/templates/cpp.lua @@ -1,25 +1,25 @@ return { --[[ ===================================================================== TEMPLATE: MAIN (Entrypoint) - File: main.c - Target: src/{project_name}/main.py + File: main.cpp + Target: src/main.cpp ===================================================================== --]] main = vim.trim([=[ -#include +#include int main() { - char* str = "Hello World"; - printf("%s\n", str); + std::string str = "Hello World"; + std::cout << str << "\n"; return 0; } ]=]) .. "\n", --[[ ===================================================================== - TEMPLATE: INIT (Package Anchor) - File: __init__.py - Target: src/{project_name}/__init__.py + TEMPLATE: CLANG-FORMAT (Code formatter) + File: .clang-format + Target: .clang-format ===================================================================== --]] format = vim.trim([=[ --- @@ -48,51 +48,66 @@ IncludeBlocks: Preserve ]=]) .. "\n", --[[ ===================================================================== - TEMPLATE: PYPROJECT (Spec / Build Manifest) - File: pyproject.toml - Target: pyproject.toml + TEMPLATE: CMAKELISTS (Spec / Build Manifest) + File: CMakeLists.txt + Target: CMakeLists.txt ===================================================================== --]] CmakeLists = vim.trim([=[ cmake_minimum_required(VERSION 3.16) -project(__PROJECT_NAME__ LANGUAGES C) -set(CMAKE_C_STANDARD 23) -set(CMAKE_C_STANDARD_REQUIRED ON) +project(__PROJECT_NAME__ LANGUAGES CXX) +set(CMAKE_CXX_STANDARD 23) +set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_EXPORT_COMPILE_COMMANDS ON) -add_library(__PROJECT_NAME__ STATIC +set(LIB_SOURCES # Add your other types here as you implement them: - # src/example1.c - # src/example2.c + # src/example1.cpp + # src/example2.cpp ) -target_include_directories(__PROJECT_NAME__ - PUBLIC - ${CMAKE_CURRENT_SOURCE_DIR}/include -) +if(LIB_SOURCES) + add_library(__PROJECT_NAME__ STATIC ${LIB_SOURCES}) + target_include_directories(__PROJECT_NAME__ + PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR}/include + ) +endif() -add_executable(__PROJECT_NAME___bin src/main.c) +add_executable(__PROJECT_NAME___bin src/main.cpp) set_target_properties(__PROJECT_NAME___bin PROPERTIES OUTPUT_NAME "__PROJECT_NAME__") -target_link_libraries(__PROJECT_NAME___bin PRIVATE __PROJECT_NAME__) +if(TARGET __PROJECT_NAME__) + target_link_libraries(__PROJECT_NAME___bin PRIVATE __PROJECT_NAME__) +endif() ]=]) .. "\n", --[[ ===================================================================== - TEMPLATE: MODULE (Standalone File) - File: {name}.py - Target: src/{project_name}/{name}.py + TEMPLATE: HEADER (Standalone File) + File: {name}.hpp + Target: include/{project_name}/{name}.hpp ===================================================================== --]] header = vim.trim([=[ -#ifndef __PROJECT_NAME___H -#define __PROJECT_NAME___H +#ifndef __PROJECT_NAME___HPP +#define __PROJECT_NAME___HPP // Code -#endif /* __PROJECT_NAME___H */ +#endif /* __PROJECT_NAME___HPP */ ]=]) .. "\n", + --[[ ===================================================================== + TEMPLATE: SOURCE (Standalone File) + File: {name}.cpp + Target: src/{name}.cpp + ===================================================================== --]] source = vim.trim([=[ ]=]) .. "\n", + --[[ ===================================================================== + TEMPLATE: CLANG_TIDY (LINTER) + File: .clang-tidy + Target: .clang-tidy + ===================================================================== --]] linter = vim.trim([=[ Checks: > -*,