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
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))
+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 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)
+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_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()
+21 -11
View File
@@ -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 <stdio.h>
@@ -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: >
-*,
+44 -29
View File
@@ -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 <stdio.h>
#include <iostream>
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: >
-*,