CHORE: Bug fixed c and cpp files and fixed their templates. Bug #3 is

also done
This commit is contained in:
2026-10-23 09:30:37 -04:00
parent 1c4a61ce7f
commit 4bf705df03
5 changed files with 76 additions and 44 deletions
+3 -1
View File
@@ -19,9 +19,11 @@ function M.create_project(opts)
---@type VernCConfig ---@type VernCConfig
local cfg = vim.tbl_deep_extend("force", {}, configs, configs, opts or {}) 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 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 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() local _ = vim.system({ "sh", "-c", build_cmd }):wait()
utils.init_git(root, "c") utils.init_git(root, "c")
vim.cmd.edit(vim.fn.fnameescape(bin)) vim.cmd.edit(vim.fn.fnameescape(bin))
+7 -2
View File
@@ -20,19 +20,24 @@ function M.create_project(opts)
local cfg = vim.tbl_deep_extend("force", {}, configs, configs, opts or {}) 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 root = join(vim.fn.expand(cfg.workspace_root), cfg.cpp.root, pname)
local bin = action_utils.create(cfg.cpp, pname, root) 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)) vim.cmd.edit(vim.fn.fnameescape(bin))
end) end)
end end
---@param opts VernCPPConfig
function M.create_file(opts) function M.create_file(opts)
vim.ui.input({ prompt = "Enter type (c/h): " }, function(ft) vim.ui.input({ prompt = "Enter type (c/h): " }, function(ft)
ft = ft and vim.trim(ft) ft = ft and vim.trim(ft)
if not ft or ft == "" then if not ft or ft == "" then
return return
end end
local configs = require("vern.configs.c") local configs = require("vern.configs.cpp")
---@type VernCPPConfig ---@type VernCPPConfig
local cfg = vim.tbl_deep_extend("force", {}, configs, opts or {}) local cfg = vim.tbl_deep_extend("force", {}, configs, opts or {})
vim.ui.input({ prompt = "Enter file name: " }, function(fname) vim.ui.input({ prompt = "Enter file name: " }, function(fname)
+1 -1
View File
@@ -64,7 +64,7 @@ function M.run(opts)
local exe = join(bin.path, bin.name) or "src/{project_name}/main.py" 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 exe_path = utils.resolve_path(exe, opts.python.dirs, { project_name = pname })
local full_path = join(vim.fn.expand(root), exe_path) 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 end
function M.pip_install() function M.pip_install()
+21 -11
View File
@@ -2,7 +2,7 @@ return {
--[[ ===================================================================== --[[ =====================================================================
TEMPLATE: MAIN (Entrypoint) TEMPLATE: MAIN (Entrypoint)
File: main.c File: main.c
Target: src/{project_name}/main.py Target: src/main.c
===================================================================== --]] ===================================================================== --]]
main = vim.trim([=[ main = vim.trim([=[
#include <stdio.h> #include <stdio.h>
@@ -17,9 +17,9 @@ main()
]=]) .. "\n", ]=]) .. "\n",
--[[ ===================================================================== --[[ =====================================================================
TEMPLATE: INIT (Package Anchor) TEMPLATE: CLANG-FORMAT (Code formatter)
File: __init__.py File: .clang-format
Target: src/{project_name}/__init__.py Target: .clang-format
===================================================================== --]] ===================================================================== --]]
format = vim.trim([=[ format = vim.trim([=[
--- ---
@@ -48,9 +48,9 @@ IncludeBlocks: Preserve
]=]) .. "\n", ]=]) .. "\n",
--[[ ===================================================================== --[[ =====================================================================
TEMPLATE: PYPROJECT (Spec / Build Manifest) TEMPLATE: CMAKELISTS (Spec / Build Manifest)
File: pyproject.toml File: CMakeLists.txt
Target: pyproject.toml Target: CMakeLists.txt
===================================================================== --]] ===================================================================== --]]
CmakeLists = vim.trim([=[ CmakeLists = vim.trim([=[
cmake_minimum_required(VERSION 3.16) cmake_minimum_required(VERSION 3.16)
@@ -67,7 +67,7 @@ set(LIB_SOURCES
if(LIB_SOURCES) if(LIB_SOURCES)
add_library(__PROJECT_NAME__ STATIC ${LIB_SOURCES}) add_library(__PROJECT_NAME__ STATIC ${LIB_SOURCES})
target_include_directories(%s target_include_directories(__PROJECT_NAME__
PUBLIC PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/include ${CMAKE_CURRENT_SOURCE_DIR}/include
) )
@@ -82,9 +82,9 @@ endif()
]=]) .. "\n", ]=]) .. "\n",
--[[ ===================================================================== --[[ =====================================================================
TEMPLATE: MODULE (Standalone File) TEMPLATE: HEADER (Standalone File)
File: {name}.py File: {name}.h
Target: src/{project_name}/{name}.py Target: include/{project_name}/{name}.h
===================================================================== --]] ===================================================================== --]]
header = vim.trim([=[ header = vim.trim([=[
#ifndef __PROJECT_NAME___H #ifndef __PROJECT_NAME___H
@@ -95,9 +95,19 @@ endif()
#endif /* __PROJECT_NAME___H */ #endif /* __PROJECT_NAME___H */
]=]) .. "\n", ]=]) .. "\n",
--[[ =====================================================================
TEMPLATE: SOURCE (Standalone File)
File: {name}.c
Target: src/{name}.c
===================================================================== --]]
source = vim.trim([=[ source = vim.trim([=[
]=]) .. "\n", ]=]) .. "\n",
--[[ =====================================================================
TEMPLATE: CLANG_TIDY (LINTER)
File: .clang-tidy
Target: .clang-tidy
===================================================================== --]]
linter = vim.trim([=[ linter = vim.trim([=[
Checks: > Checks: >
-*, -*,
+39 -24
View File
@@ -1,25 +1,25 @@
return { return {
--[[ ===================================================================== --[[ =====================================================================
TEMPLATE: MAIN (Entrypoint) TEMPLATE: MAIN (Entrypoint)
File: main.c File: main.cpp
Target: src/{project_name}/main.py Target: src/main.cpp
===================================================================== --]] ===================================================================== --]]
main = vim.trim([=[ main = vim.trim([=[
#include <stdio.h> #include <iostream>
int int
main() main()
{ {
char* str = "Hello World"; std::string str = "Hello World";
printf("%s\n", str); std::cout << str << "\n";
return 0; return 0;
} }
]=]) .. "\n", ]=]) .. "\n",
--[[ ===================================================================== --[[ =====================================================================
TEMPLATE: INIT (Package Anchor) TEMPLATE: CLANG-FORMAT (Code formatter)
File: __init__.py File: .clang-format
Target: src/{project_name}/__init__.py Target: .clang-format
===================================================================== --]] ===================================================================== --]]
format = vim.trim([=[ format = vim.trim([=[
--- ---
@@ -48,51 +48,66 @@ IncludeBlocks: Preserve
]=]) .. "\n", ]=]) .. "\n",
--[[ ===================================================================== --[[ =====================================================================
TEMPLATE: PYPROJECT (Spec / Build Manifest) TEMPLATE: CMAKELISTS (Spec / Build Manifest)
File: pyproject.toml File: CMakeLists.txt
Target: pyproject.toml Target: CMakeLists.txt
===================================================================== --]] ===================================================================== --]]
CmakeLists = vim.trim([=[ CmakeLists = vim.trim([=[
cmake_minimum_required(VERSION 3.16) cmake_minimum_required(VERSION 3.16)
project(__PROJECT_NAME__ LANGUAGES C) project(__PROJECT_NAME__ LANGUAGES CXX)
set(CMAKE_C_STANDARD 23) set(CMAKE_CXX_STANDARD 23)
set(CMAKE_C_STANDARD_REQUIRED ON) set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON) set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
add_library(__PROJECT_NAME__ STATIC set(LIB_SOURCES
# Add your other types here as you implement them: # Add your other types here as you implement them:
# src/example1.c # src/example1.cpp
# src/example2.c # src/example2.cpp
) )
if(LIB_SOURCES)
add_library(__PROJECT_NAME__ STATIC ${LIB_SOURCES})
target_include_directories(__PROJECT_NAME__ target_include_directories(__PROJECT_NAME__
PUBLIC PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/include ${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__") set_target_properties(__PROJECT_NAME___bin PROPERTIES OUTPUT_NAME "__PROJECT_NAME__")
if(TARGET __PROJECT_NAME__)
target_link_libraries(__PROJECT_NAME___bin PRIVATE __PROJECT_NAME__) target_link_libraries(__PROJECT_NAME___bin PRIVATE __PROJECT_NAME__)
endif()
]=]) .. "\n", ]=]) .. "\n",
--[[ ===================================================================== --[[ =====================================================================
TEMPLATE: MODULE (Standalone File) TEMPLATE: HEADER (Standalone File)
File: {name}.py File: {name}.hpp
Target: src/{project_name}/{name}.py Target: include/{project_name}/{name}.hpp
===================================================================== --]] ===================================================================== --]]
header = vim.trim([=[ header = vim.trim([=[
#ifndef __PROJECT_NAME___H #ifndef __PROJECT_NAME___HPP
#define __PROJECT_NAME___H #define __PROJECT_NAME___HPP
// Code // Code
#endif /* __PROJECT_NAME___H */ #endif /* __PROJECT_NAME___HPP */
]=]) .. "\n", ]=]) .. "\n",
--[[ =====================================================================
TEMPLATE: SOURCE (Standalone File)
File: {name}.cpp
Target: src/{name}.cpp
===================================================================== --]]
source = vim.trim([=[ source = vim.trim([=[
]=]) .. "\n", ]=]) .. "\n",
--[[ =====================================================================
TEMPLATE: CLANG_TIDY (LINTER)
File: .clang-tidy
Target: .clang-tidy
===================================================================== --]]
linter = vim.trim([=[ linter = vim.trim([=[
Checks: > Checks: >
-*, -*,