fix: c/c++ had compile commands linked unnecassarily
This commit is contained in:
@@ -113,7 +113,7 @@ set(CMAKE_C_STANDARD_REQUIRED ON)
|
|||||||
]], project_name, project_name))
|
]], project_name, project_name))
|
||||||
local gitignore = { "build/" }
|
local gitignore = { "build/" }
|
||||||
utils.init_git(full_project_root, gitignore)
|
utils.init_git(full_project_root, gitignore)
|
||||||
vim.fn.system(string.format("cd %s/build && cmake -S .. -B . && cmake --build . && cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON .. && ln -sf compile_commands.json ../compile_commands.json", full_project_root))
|
vim.fn.system(string.format("cd %s/build && cmake -S .. -B . && cmake --build . && cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON ..", full_project_root))
|
||||||
vim.cmd("edit " .. full_project_root .. "/src/main.c")
|
vim.cmd("edit " .. full_project_root .. "/src/main.c")
|
||||||
end
|
end
|
||||||
},
|
},
|
||||||
@@ -127,8 +127,8 @@ set(CMAKE_C_STANDARD_REQUIRED ON)
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
std::cout << "Hello World" << std::endl;
|
std::cout << "Hello World" << std::endl;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
]])
|
]])
|
||||||
utils.write_file({ full_project_root, "CMakeLists.txt" }, string.format([[
|
utils.write_file({ full_project_root, "CMakeLists.txt" }, string.format([[
|
||||||
@@ -147,7 +147,7 @@ set(CMAKE_C_STANDARD_REQUIRED ON)
|
|||||||
|
|
||||||
local gitignore = { "build/" }
|
local gitignore = { "build/" }
|
||||||
utils.init_git(full_project_root, gitignore)
|
utils.init_git(full_project_root, gitignore)
|
||||||
vim.fn.system(string.format("cd %s/build && cmake -S .. -B . && cmake --build . && cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON .. && ln -sf compile_commands.json ../compile_commands.json", full_project_root))
|
vim.fn.system(string.format("cd %s/build && cmake -S .. -B . && cmake --build . && cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON ..", full_project_root))
|
||||||
vim.cmd("edit " .. full_project_root .. "/src/main.cpp")
|
vim.cmd("edit " .. full_project_root .. "/src/main.cpp")
|
||||||
end
|
end
|
||||||
},
|
},
|
||||||
|
|||||||
+71
-74
@@ -2,111 +2,108 @@ local M = {}
|
|||||||
M.opts = {}
|
M.opts = {}
|
||||||
|
|
||||||
function M.setup(opts)
|
function M.setup(opts)
|
||||||
M.opts = vim.tbl_deep_extend("force", {}, require("Polydev.configs").get("terminal"), opts or {})
|
M.opts = vim.tbl_deep_extend("force", {}, require("Polydev.configs").get("terminal"), opts or {})
|
||||||
end
|
end
|
||||||
|
|
||||||
---@return string
|
---@return string
|
||||||
function M.get_project_root()
|
function M.get_project_root()
|
||||||
local plugin_dir = vim.fn.fnamemodify(debug.getinfo(1, "S").source:sub(2), ":h:h:h")
|
local plugin_dir = vim.fn.fnamemodify(debug.getinfo(1, "S").source:sub(2), ":h:h:h")
|
||||||
|
|
||||||
local dir = vim.fn.system(plugin_dir .. "/bash_scripts/walkup.sh"):gsub("%s+$", "")
|
local dir = vim.fn.system(plugin_dir .. "/bash_scripts/walkup.sh"):gsub("%s+$", "")
|
||||||
return dir
|
return dir
|
||||||
end
|
end
|
||||||
|
|
||||||
---@return string
|
---@return string
|
||||||
function M.get_project_name()
|
function M.get_project_name()
|
||||||
return vim.fn.fnamemodify(M.get_project_root(), ":t")
|
return vim.fn.fnamemodify(M.get_project_root(), ":t")
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param path_segments table
|
---@param path_segments table
|
||||||
---@param content string
|
---@param content string
|
||||||
function M.write_file(path_segments, content)
|
function M.write_file(path_segments, content)
|
||||||
local path = table.concat(path_segments, "/")
|
local path = table.concat(path_segments, "/")
|
||||||
local file = assert(io.open(path, "w"), "Error creating file: " .. path)
|
local file = assert(io.open(path, "w"), "Error creating file: " .. path)
|
||||||
file:write(content)
|
file:write(content)
|
||||||
file:close()
|
file:close()
|
||||||
vim.cmd("edit " .. path)
|
vim.cmd("edit " .. path)
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param path string
|
---@param path string
|
||||||
---@param gitignore_lines table
|
---@param gitignore_lines table
|
||||||
function M.init_git(path, gitignore_lines)
|
function M.init_git(path, gitignore_lines)
|
||||||
vim.fn.mkdir(path, "p")
|
vim.fn.mkdir(path, "p")
|
||||||
vim.fn.system({ "git", "-C", path, "init" })
|
vim.fn.system({ "git", "-C", path, "init" })
|
||||||
|
|
||||||
if gitignore_lines and #gitignore_lines > 0 then
|
if gitignore_lines and #gitignore_lines > 0 then
|
||||||
local contents = table.concat(gitignore_lines, "\n")
|
local contents = table.concat(gitignore_lines, "\n")
|
||||||
M.write_file({ path, ".gitignore" }, contents)
|
M.write_file({ path, ".gitignore" }, contents)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param cmd table
|
---@param cmd table
|
||||||
---@return integer, integer?
|
---@return integer, integer?
|
||||||
function M.terminal(cmd)
|
function M.terminal(cmd)
|
||||||
if M.opts.mode == "floating" then
|
if M.opts.mode == "floating" then
|
||||||
local opts = require("Polydev.presets").getPresets(M.opts.win.anchor)
|
local opts = require("Polydev.presets").getPresets(M.opts.win.anchor)
|
||||||
|
|
||||||
local ui = vim.api.nvim_list_uis()[1]
|
local ui = vim.api.nvim_list_uis()[1]
|
||||||
local width
|
local width, height, row, col
|
||||||
local height
|
|
||||||
local row
|
|
||||||
local col
|
|
||||||
|
|
||||||
if opts ~= nil then
|
if opts ~= nil then
|
||||||
width = math.max(1, math.floor(ui.width * 0.9) - opts.left - opts.right)
|
width = math.max(1, math.floor(ui.width * 0.9) - opts.left - opts.right)
|
||||||
height = math.max(1, math.floor(ui.height * 0.9) - opts.top - opts.bottom)
|
height = math.max(1, math.floor(ui.height * 0.9) - opts.top - opts.bottom)
|
||||||
row = math.floor((ui.height - height) / 2) + opts.top
|
row = math.floor((ui.height - height) / 2) + opts.top
|
||||||
col = math.floor((ui.width - width) / 2) + opts.left
|
col = math.floor((ui.width - width) / 2) + opts.left
|
||||||
end
|
end
|
||||||
if opts == nil then
|
if opts == nil then
|
||||||
width = math.max(1, math.floor(ui.width * 0.9))
|
width = math.max(1, math.floor(ui.width * 0.9))
|
||||||
height = math.max(1, math.floor(ui.height * 0.9))
|
height = math.max(1, math.floor(ui.height * 0.9))
|
||||||
row = math.floor((ui.height - height) / 2)
|
row = math.floor((ui.height - height) / 2)
|
||||||
col = math.floor((ui.width - width) / 2)
|
col = math.floor((ui.width - width) / 2)
|
||||||
end
|
end
|
||||||
local buf = vim.api.nvim_create_buf(false, true)
|
local buf = vim.api.nvim_create_buf(false, true)
|
||||||
local win = vim.api.nvim_open_win(buf, true, {
|
local win = vim.api.nvim_open_win(buf, true, {
|
||||||
relative = "editor",
|
relative = "editor",
|
||||||
width = width,
|
width = width,
|
||||||
height = height,
|
height = height,
|
||||||
row = row,
|
row = row,
|
||||||
col = col,
|
col = col,
|
||||||
style = "minimal",
|
style = "minimal",
|
||||||
border = M.opts.border.enabled and M.opts.border.type,
|
border = M.opts.border.enabled and M.opts.border.type,
|
||||||
})
|
})
|
||||||
vim.api.nvim_set_option_value("winhighlight", "Normal:PolydevNormal,FloatBorder:PolydevBorder", { win = win })
|
vim.api.nvim_set_option_value("winhighlight", "Normal:PolydevNormal,FloatBorder:PolydevBorder", { win = win })
|
||||||
vim.fn.jobstart(table.concat(cmd, "/"), { term = true })
|
vim.fn.jobstart(table.concat(cmd, "/"), { term = true })
|
||||||
vim.api.nvim_buf_set_keymap(buf, "n", "<ESC>", "i<C-\\><C-n>:q<CR>", { noremap = true, silent = true })
|
vim.api.nvim_buf_set_keymap(buf, "n", "<ESC>", "i<C-\\><C-n>:q<CR>", { noremap = true, silent = true })
|
||||||
return buf, win
|
return buf, win
|
||||||
end
|
|
||||||
if M.opts.mode == "split" then
|
|
||||||
if M.opts.win.type == "vertical" then
|
|
||||||
if M.opts.win.anchor == "right" then
|
|
||||||
vim.cmd("set splitright")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
if M.opts.win.type == "horizontal" then
|
|
||||||
if M.opts.win.anchor == "bottom" then
|
|
||||||
vim.cmd("set splitbelow")
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
if M.opts.mode == "split" then
|
||||||
|
if M.opts.win.type == "vertical" then
|
||||||
|
if M.opts.win.anchor == "right" then
|
||||||
|
vim.cmd("set splitright")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if M.opts.win.type == "horizontal" then
|
||||||
|
if M.opts.win.anchor == "bottom" then
|
||||||
|
vim.cmd("set splitbelow")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
if M.opts.win.type == "vertical" then
|
if M.opts.win.type == "vertical" then
|
||||||
vim.cmd(M.opts.win.size .. " vsplit")
|
vim.cmd(M.opts.win.size .. " vsplit")
|
||||||
end
|
end
|
||||||
if M.opts.win.type == "horizontal" then
|
if M.opts.win.type == "horizontal" then
|
||||||
vim.cmd(M.opts.win.size .. " split")
|
vim.cmd(M.opts.win.size .. " split")
|
||||||
end
|
end
|
||||||
local buf = vim.api.nvim_create_buf(false, true)
|
local buf = vim.api.nvim_create_buf(false, true)
|
||||||
local win = vim.api.nvim_get_current_win()
|
local win = vim.api.nvim_get_current_win()
|
||||||
|
|
||||||
vim.api.nvim_win_set_buf(0, buf)
|
vim.api.nvim_win_set_buf(0, buf)
|
||||||
|
|
||||||
vim.fn.jobstart(table.concat(cmd, "/"), { term = true })
|
vim.fn.jobstart(table.concat(cmd, "/"), { term = true })
|
||||||
vim.api.nvim_buf_set_keymap(buf, "n", "<ESC>", "i<C-\\><C-n>:q<CR>", { noremap = true, silent = true })
|
vim.api.nvim_buf_set_keymap(buf, "n", "<ESC>", "i<C-\\><C-n>:q<CR>", { noremap = true, silent = true })
|
||||||
return buf, win
|
return buf, win
|
||||||
end
|
end
|
||||||
return 0
|
return 0
|
||||||
end
|
end
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
|||||||
Reference in New Issue
Block a user