102 lines
2.4 KiB
Lua
102 lines
2.4 KiB
Lua
---@module "vern-nvim.core.fs"
|
|
local fs = require("vern-nvim.core.fs")
|
|
|
|
---@module "vern-nvim.core.compile"
|
|
local comp = require("vern-nvim.core.compile")
|
|
|
|
local M = {}
|
|
|
|
M.attach = nil
|
|
|
|
---@param root string
|
|
M.create_project = function(root)
|
|
local build_cmd = "cd "
|
|
.. root
|
|
.. " && cmake -S . -B build && cmake --build build"
|
|
local _ = vim.system({ "sh", "-c", build_cmd }):wait()
|
|
end
|
|
|
|
---@type VernCreateFile
|
|
---@param opts VernCPPConfig
|
|
M.create_file = function(opts, continue)
|
|
opts = opts or {}
|
|
local file = vim.tbl_get(opts, "cpp", "templates", "file")
|
|
local items = { "source", "header" }
|
|
vim.ui.select(items, {
|
|
prompt = "Select type:",
|
|
format_item = function(item) return item end,
|
|
}, function(choice, _)
|
|
if choice == items[1] then return continue(file.source) end
|
|
if choice == items[2] then return continue(file.header) end
|
|
continue(nil)
|
|
end)
|
|
end
|
|
|
|
---@param opts? VernCPPConfig Takes a table for the runtime
|
|
M.run = function(opts)
|
|
opts = opts or {}
|
|
|
|
local build_dir = vim.fn.fnameescape(fs.root() .. "/build")
|
|
local build_cmd = string.format("cd %s && cmake --build .", build_dir)
|
|
local run_cmd = string.format("cd %s && ./%s", build_dir, fs.name())
|
|
|
|
comp.compile(opts, build_cmd, run_cmd)
|
|
end
|
|
|
|
---@type VernLanguageConfig
|
|
M.cpp = {
|
|
root = "CPP",
|
|
dirs = {
|
|
src = "src",
|
|
include = "include/{project_name}",
|
|
},
|
|
keybinds = nil,
|
|
templates = {
|
|
project = {
|
|
primary = {
|
|
path = "{dirs.src}",
|
|
name = "main.cpp",
|
|
kind = "main",
|
|
kind_path = "vern-nvim.templates.cpp",
|
|
},
|
|
manifest = {
|
|
path = ".",
|
|
name = "CMakeLists.txt",
|
|
kind = "CmakeLists",
|
|
kind_path = "vern-nvim.templates.cpp",
|
|
},
|
|
style = {
|
|
path = ".",
|
|
name = ".clang-format",
|
|
kind = "format",
|
|
kind_path = "vern-nvim.templates.cpp",
|
|
},
|
|
},
|
|
file = {
|
|
header = {
|
|
path = "{dirs.include}",
|
|
name = "{file_name}.hpp",
|
|
kind = "header",
|
|
kind_path = "vern-nvim.templates.cpp",
|
|
},
|
|
source = {
|
|
path = "{dirs.src}",
|
|
name = "{file_name}.cpp",
|
|
kind = "source",
|
|
kind_path = "vern-nvim.templates.cpp",
|
|
},
|
|
},
|
|
extras = {
|
|
linter = {
|
|
path = ".",
|
|
name = ".clang-tidy",
|
|
kind = "linter",
|
|
kind_path = "vern-nvim.templates.cpp",
|
|
enabled = false,
|
|
},
|
|
},
|
|
},
|
|
}
|
|
|
|
return M
|