1 parent
b1a92f479d
commit
b5f1714ee7
35 files changed
+1815
-2067
No files matched your search
@@ -0,0 +1,275 @@
|
||||
local overseer = require("overseer")
|
||||
local parselib = require("overseer.parselib")
|
||||
|
||||
-- Shared output parser (CMake + GCC/Clang)
|
||||
local function make_combined_parser()
|
||||
local cmake_error_match = parselib.make_lua_match_fn("^CMake Error at (%S+):(%d+)%s*%((.*)%)%s*:%s*(.*)$")
|
||||
local cmake_parse_fn = parselib.make_parse_fn(cmake_error_match, { "filename", "lnum", "type", "text" })
|
||||
local cmake_parser = parselib.make_parser(cmake_parse_fn)
|
||||
|
||||
local gcc_parser = parselib.parser_from_errorformat(
|
||||
"%f:%l:%c: %t%n %m," .. "%f:%l:%c: %t%*[^:]: %m," .. "%f:%l: %t%n %m," .. "%f:%l: %t%*[^:]: %m"
|
||||
)
|
||||
|
||||
return parselib.combine_parsers({ cmake_parser, gcc_parser })
|
||||
end
|
||||
|
||||
-- Core builder used by every variant
|
||||
local function build_task(params)
|
||||
local cwd = vim.fn.fnamemodify(params.cwd or vim.fn.getcwd(), ":p")
|
||||
local src = vim.fn.fnamemodify(params.src_dir, ":p")
|
||||
local build = vim.fn.fnamemodify(params.build_dir, ":p")
|
||||
|
||||
local exts = {}
|
||||
for ext in params.extensions:gmatch("[^,]+") do
|
||||
local clean_ext = vim.trim(ext):gsub("^%.+", "")
|
||||
table.insert(exts, clean_ext)
|
||||
end
|
||||
if #exts == 0 then
|
||||
exts = { "cppm", "ixx", "cpp" }
|
||||
end
|
||||
|
||||
local ext_pipe = table.concat(exts, "|")
|
||||
local ext_comma = table.concat(exts, ",")
|
||||
|
||||
local script = string.format(
|
||||
[[
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
cd "%s"
|
||||
SRC_DIR="%s"
|
||||
BUILD_DIR="%s"
|
||||
CMAKE="%s"
|
||||
CMAKE_ARGS="%s"
|
||||
BUILD_ARGS="%s"
|
||||
|
||||
echo "[overseer] CWD: $(pwd)"
|
||||
echo "[overseer] SRC_DIR: $SRC_DIR"
|
||||
echo "[overseer] BUILD_DIR: $BUILD_DIR"
|
||||
echo "[overseer] Extensions: {%s}"
|
||||
|
||||
if [ ! -d "$SRC_DIR" ]; then
|
||||
echo "[overseer] ERROR: Source directory does not exist: $SRC_DIR"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
mkdir -p "$BUILD_DIR"
|
||||
|
||||
rebuild() {
|
||||
echo "[overseer] >>> Change detected. Reconfiguring..."
|
||||
set -x
|
||||
$CMAKE -S . -B "$BUILD_DIR" $CMAKE_ARGS
|
||||
$CMAKE --build "$BUILD_DIR" $BUILD_ARGS
|
||||
set +x
|
||||
echo "[overseer] >>> Build complete. Watching..."
|
||||
}
|
||||
|
||||
echo "[overseer] >>> Initial CMake configuration..."
|
||||
rebuild
|
||||
|
||||
echo "[overseer] >>> Watching $SRC_DIR recursively for .{%s} files..."
|
||||
while true; do
|
||||
if command -v inotifywait >/dev/null 2>&1; then
|
||||
inotifywait -r -e create,modify,move,delete --include ".*\.(%s)$" -q "$SRC_DIR" 2>/dev/null || true
|
||||
rebuild
|
||||
elif command -v fswatch >/dev/null 2>&1; then
|
||||
fswatch -r -e ".*" -i "\.(%s)$" --event Created --event Updated --event Removed "$SRC_DIR" | head -n 1 >/dev/null
|
||||
rebuild
|
||||
else
|
||||
echo "[overseer] ERROR: Install inotifywait (Linux) or fswatch (macOS)"
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
]],
|
||||
cwd,
|
||||
src,
|
||||
build,
|
||||
params.cmake,
|
||||
params.cmake_args,
|
||||
params.build_args,
|
||||
ext_comma,
|
||||
ext_comma,
|
||||
ext_pipe,
|
||||
ext_pipe
|
||||
)
|
||||
|
||||
return {
|
||||
cmd = { "bash", "-c", script },
|
||||
cwd = cwd,
|
||||
name = string.format("CMake Watcher [%s]", params.src_dir),
|
||||
components = {
|
||||
"default",
|
||||
{ "on_output_parse", parser = make_combined_parser() },
|
||||
{ "on_output_quickfix", open = false, close = true },
|
||||
"on_result_diagnostics",
|
||||
},
|
||||
}
|
||||
end
|
||||
|
||||
-- Parameter schema for the [Custom] variant
|
||||
local custom_params = {
|
||||
src_dir = {
|
||||
desc = "Source directory to watch recursively",
|
||||
type = "string",
|
||||
default = "src",
|
||||
order = 1,
|
||||
},
|
||||
build_dir = {
|
||||
desc = "CMake build directory",
|
||||
type = "string",
|
||||
default = "build",
|
||||
order = 2,
|
||||
},
|
||||
cmake = {
|
||||
desc = "CMake executable",
|
||||
type = "string",
|
||||
default = "cmake",
|
||||
order = 3,
|
||||
},
|
||||
cmake_args = {
|
||||
desc = "CMake config args (space-separated)",
|
||||
type = "string",
|
||||
order = 4,
|
||||
},
|
||||
build_args = {
|
||||
desc = "CMake build args (space-separated)",
|
||||
type = "string",
|
||||
default = "-j32",
|
||||
order = 5,
|
||||
},
|
||||
extensions = {
|
||||
desc = "Extensions to watch (comma-separated)",
|
||||
type = "string",
|
||||
default = "cppm,ixx,cpp",
|
||||
order = 6,
|
||||
},
|
||||
cwd = {
|
||||
desc = "Working directory",
|
||||
type = "string",
|
||||
default = vim.fn.getcwd(),
|
||||
order = 7,
|
||||
},
|
||||
}
|
||||
|
||||
---@type overseer.TemplateFileProvider
|
||||
return {
|
||||
generator = function(search)
|
||||
local cwd = vim.fn.getcwd()
|
||||
|
||||
-- Add/remove presets here as needed
|
||||
local presets = {
|
||||
{
|
||||
name = "cmake watcher [debug]",
|
||||
desc = "watch src/ with debug configuration",
|
||||
params = {
|
||||
src_dir = "src",
|
||||
build_dir = "build",
|
||||
cmake = "cmake",
|
||||
cmake_args = "-DCMAKE_BUILD_TYPE=Debug -G Ninja -DCMAKE_EXPORT_COMPILE_COMMANDS=ON",
|
||||
build_args = "-j32",
|
||||
extensions = "cppm,ixx,cpp",
|
||||
cwd = cwd,
|
||||
},
|
||||
},
|
||||
{
|
||||
name = "cmake watcher [release]",
|
||||
desc = "watch src/ with release configuration",
|
||||
params = {
|
||||
src_dir = "src",
|
||||
build_dir = "build",
|
||||
cmake = "cmake",
|
||||
cmake_args = "-DCMAKE_BUILD_TYPE=Release -G Ninja -DCMAKE_EXPORT_COMPILE_COMMANDS=ON",
|
||||
build_args = "-j32",
|
||||
extensions = "cppm,ixx,cpp",
|
||||
cwd = cwd,
|
||||
},
|
||||
},
|
||||
{
|
||||
name = "cmake watcher [relwithdebinfo]",
|
||||
desc = "watch src/ with relwithdebinfo configuration",
|
||||
params = {
|
||||
src_dir = "src",
|
||||
build_dir = "build",
|
||||
cmake = "cmake",
|
||||
cmake_args = "-DCMAKE_BUILD_TYPE=RelWithDebInfo -G Ninja -DCMAKE_EXPORT_COMPILE_COMMANDS=ON",
|
||||
build_args = "-j32",
|
||||
extensions = "cppm,ixx,cpp",
|
||||
cwd = cwd,
|
||||
},
|
||||
},
|
||||
{
|
||||
name = "cmake watcher [debug, qt]",
|
||||
desc = "watch src/ with debug configuration",
|
||||
params = {
|
||||
src_dir = "src",
|
||||
build_dir = "build",
|
||||
cmake = "cmake",
|
||||
cmake_args = '-G Ninja -DCMAKE_CXX_COMPILER=/usr/bin/clang++ --install-prefix "$PWD/release" -DQT_DEPLOY_USE_PATCHELF=ON -DVLW_ENABLE_DEV=ON -DCMAKE_BUILD_TYPE=Debug -DCMAKE_EXPORT_COMPILE_COMMANDS=ON',
|
||||
build_args = "-j32",
|
||||
extensions = "cppm,ixx,cpp",
|
||||
cwd = cwd,
|
||||
},
|
||||
},
|
||||
{
|
||||
name = "cmake watcher [release,qt]",
|
||||
desc = "watch src/ with release configuration",
|
||||
params = {
|
||||
src_dir = "src",
|
||||
build_dir = "build",
|
||||
cmake = "cmake",
|
||||
cmake_args = '-G Ninja -DCMAKE_CXX_COMPILER=/usr/bin/clang++ --install-prefix "$PWD/release" -DQT_DEPLOY_USE_PATCHELF=ON -DVLW_ENABLE_DEV=ON -DCMAKE_BUILD_TYPE=Release -DCMAKE_EXPORT_COMPILE_COMMANDS=ON',
|
||||
build_args = "-j32",
|
||||
extensions = "cppm,ixx,cpp",
|
||||
cwd = cwd,
|
||||
},
|
||||
},
|
||||
{
|
||||
name = "cmake watcher [relwithdebinfo,qt]",
|
||||
desc = "watch src/ with relwithdebinfo configuration",
|
||||
params = {
|
||||
src_dir = "src",
|
||||
build_dir = "build",
|
||||
cmake = "cmake",
|
||||
cmake_args = '-G Ninja -DCMAKE_CXX_COMPILER=/usr/bin/clang++ --install-prefix "$PWD/release" -DQT_DEPLOY_USE_PATCHELF=ON -DVLW_ENABLE_DEV=ON -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_EXPORT_COMPILE_COMMANDS=ON',
|
||||
build_args = "-j32",
|
||||
extensions = "cppm,ixx,cpp",
|
||||
cwd = cwd,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
local templates = {}
|
||||
|
||||
-- Presets: hardcoded args, no prompt
|
||||
for _, preset in ipairs(presets) do
|
||||
table.insert(templates, {
|
||||
name = preset.name,
|
||||
desc = preset.desc,
|
||||
builder = function()
|
||||
return build_task(preset.params)
|
||||
end,
|
||||
tags = { overseer.TAG.BUILD },
|
||||
})
|
||||
end
|
||||
|
||||
-- Custom: overseer will prompt for params before running
|
||||
table.insert(templates, {
|
||||
name = "CMake Watcher [Custom]",
|
||||
desc = "Watch with fully customizable parameters",
|
||||
builder = function(params)
|
||||
return build_task(params)
|
||||
end,
|
||||
params = custom_params,
|
||||
tags = { overseer.TAG.BUILD },
|
||||
})
|
||||
|
||||
return templates
|
||||
end,
|
||||
|
||||
condition = {
|
||||
callback = function(search)
|
||||
return vim.fn.filereadable(vim.fs.joinpath(search.dir, "CMakeLists.txt")) == 1
|
||||
end,
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,260 @@
|
||||
local overseer = require("overseer")
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
-- Core builder
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
local function build_task(params)
|
||||
local executable = vim.fn.fnamemodify(params.executable, ":p")
|
||||
local watch_dir = vim.fn.fnamemodify(executable, ":h")
|
||||
local basename = vim.fn.fnamemodify(executable, ":t")
|
||||
|
||||
if vim.fn.filereadable(executable) == 0 then
|
||||
vim.notify("Executable not found: " .. executable, vim.log.levels.ERROR)
|
||||
return nil
|
||||
end
|
||||
|
||||
if vim.fn.executable(executable) ~= 1 then
|
||||
vim.notify("File is not executable: " .. executable, vim.log.levels.ERROR)
|
||||
return nil
|
||||
end
|
||||
|
||||
local script = string.format(
|
||||
[[
|
||||
#!/bin/bash
|
||||
set -euo pipefail
|
||||
set -m
|
||||
|
||||
EXECUTABLE="%s"
|
||||
WATCH_DIR="%s"
|
||||
BASENAME="%s"
|
||||
|
||||
echo "[overseer] Executable: $EXECUTABLE"
|
||||
echo "[overseer] Watch dir: $WATCH_DIR"
|
||||
echo "[overseer] Basename: $BASENAME"
|
||||
|
||||
cleanup() {
|
||||
if [ -n "${PID:-}" ] && kill -0 "$PID" 2>/dev/null; then
|
||||
echo "[overseer] Stopping process group $PID..."
|
||||
kill -TERM -"$PID" 2>/dev/null || true
|
||||
for i in {1..20}; do
|
||||
kill -0 "$PID" 2>/dev/null || break
|
||||
sleep 0.1
|
||||
done
|
||||
if kill -0 "$PID" 2>/dev/null; then
|
||||
kill -KILL -"$PID" 2>/dev/null || true
|
||||
fi
|
||||
wait "$PID" 2>/dev/null || true
|
||||
fi
|
||||
PID=""
|
||||
}
|
||||
trap cleanup EXIT
|
||||
|
||||
run() {
|
||||
echo "[overseer] >>> Starting $BASENAME..."
|
||||
"$EXECUTABLE" &
|
||||
PID=$!
|
||||
}
|
||||
|
||||
run
|
||||
|
||||
exec 3< <(inotifywait -m -e close_write,moved_to --format '%%f' "$WATCH_DIR")
|
||||
INOTIFY_PID=$!
|
||||
|
||||
trap 'kill $INOTIFY_PID 2>/dev/null || true; wait $INOTIFY_PID 2>/dev/null || true; cleanup' EXIT
|
||||
|
||||
while read -r file <&3; do
|
||||
if [ "$file" = "$BASENAME" ]; then
|
||||
sleep 0.1
|
||||
cleanup
|
||||
run
|
||||
fi
|
||||
done
|
||||
|
||||
kill $INOTIFY_PID 2>/dev/null || true
|
||||
wait $INOTIFY_PID 2>/dev/null || true
|
||||
echo "[overseer] Watch ended"
|
||||
]],
|
||||
executable,
|
||||
watch_dir,
|
||||
basename
|
||||
)
|
||||
|
||||
return {
|
||||
cmd = { "bash", "-c", script },
|
||||
cwd = watch_dir,
|
||||
name = string.format("Run & Watch [%s]", basename),
|
||||
components = {
|
||||
"default",
|
||||
{ "on_output_quickfix", open = false, close = true },
|
||||
},
|
||||
}
|
||||
end
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
-- Scan for executables
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
local function scan_executables(root)
|
||||
local candidates = {}
|
||||
local seen = {}
|
||||
|
||||
local function try_add(path)
|
||||
if not seen[path] and vim.fn.filereadable(path) == 1 and vim.fn.executable(path) == 1 then
|
||||
seen[path] = true
|
||||
table.insert(candidates, path)
|
||||
end
|
||||
end
|
||||
|
||||
-- Root directory (non-recursive)
|
||||
local handle = vim.uv.fs_scandir(root)
|
||||
if handle then
|
||||
while true do
|
||||
local name, typ = vim.uv.fs_scandir_next(handle)
|
||||
if not name then
|
||||
break
|
||||
end
|
||||
if typ == "file" then
|
||||
try_add(root .. "/" .. name)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- Common build directories (depth 1)
|
||||
for _, sub in ipairs({
|
||||
"build",
|
||||
"bin",
|
||||
"target/debug",
|
||||
"target/release",
|
||||
"cmake-build-debug",
|
||||
"cmake-build-release",
|
||||
"out",
|
||||
"dist",
|
||||
}) do
|
||||
local dir = root .. "/" .. sub
|
||||
if vim.fn.isdirectory(dir) == 1 then
|
||||
local h = vim.uv.fs_scandir(dir)
|
||||
if h then
|
||||
while true do
|
||||
local name, typ = vim.uv.fs_scandir_next(h)
|
||||
if not name then
|
||||
break
|
||||
end
|
||||
if typ == "file" then
|
||||
try_add(dir .. "/" .. name)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- Newest first
|
||||
table.sort(candidates, function(a, b)
|
||||
local sa = vim.uv.fs_stat(a)
|
||||
local sb = vim.uv.fs_stat(b)
|
||||
if not sa or not sb then
|
||||
return false
|
||||
end
|
||||
return sa.mtime.sec > sb.mtime.sec
|
||||
end)
|
||||
|
||||
while #candidates > 8 do
|
||||
table.remove(candidates)
|
||||
end
|
||||
|
||||
return candidates
|
||||
end
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
-- Template provider
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
local provider = {
|
||||
generator = function(search)
|
||||
local templates = {}
|
||||
local cwd = search.dir or vim.fn.getcwd()
|
||||
|
||||
for _, exe in ipairs(scan_executables(cwd)) do
|
||||
local name = vim.fn.fnamemodify(exe, ":t")
|
||||
table.insert(templates, {
|
||||
name = string.format("Run & Watch [%s]", name),
|
||||
desc = string.format("Run %s and restart when the binary changes", exe),
|
||||
builder = function()
|
||||
return build_task({ executable = exe })
|
||||
end,
|
||||
tags = { overseer.TAG.RUN },
|
||||
})
|
||||
end
|
||||
|
||||
table.insert(templates, {
|
||||
name = "Run & Watch [Custom]",
|
||||
desc = "Provide the path to an executable to run and watch",
|
||||
builder = function(params)
|
||||
return build_task(params)
|
||||
end,
|
||||
params = {
|
||||
executable = {
|
||||
desc = "Path to executable",
|
||||
type = "string",
|
||||
order = 1,
|
||||
validate = function(v)
|
||||
if v == "" or v == nil then
|
||||
return false, "Executable path is required"
|
||||
end
|
||||
local p = vim.fn.fnamemodify(v, ":p")
|
||||
if vim.fn.filereadable(p) == 0 then
|
||||
return false, "File does not exist"
|
||||
end
|
||||
if vim.fn.executable(p) ~= 1 then
|
||||
return false, "File is not executable"
|
||||
end
|
||||
return true
|
||||
end,
|
||||
},
|
||||
},
|
||||
tags = { overseer.TAG.RUN },
|
||||
})
|
||||
|
||||
return templates
|
||||
end,
|
||||
}
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
-- Telescope integration
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
provider.pick_executable_and_run = function()
|
||||
local has_telescope, telescope = pcall(require, "telescope.builtin")
|
||||
if not has_telescope then
|
||||
vim.notify("Telescope.nvim is required", vim.log.levels.ERROR)
|
||||
return
|
||||
end
|
||||
|
||||
telescope.find_files({
|
||||
prompt_title = "Select executable to run & watch",
|
||||
find_command = { "find", ".", "-maxdepth", "3", "-type", "f", "-executable" },
|
||||
attach_mappings = function(prompt_bufnr, _)
|
||||
local actions = require("telescope.actions")
|
||||
local action_state = require("telescope.actions.state")
|
||||
|
||||
actions.select_default:replace(function()
|
||||
actions.close(prompt_bufnr)
|
||||
local selection = action_state.get_selected_entry()
|
||||
if not selection then
|
||||
return
|
||||
end
|
||||
local path = vim.fn.fnamemodify(selection.path or selection.value, ":p")
|
||||
|
||||
local task_defn = build_task({ executable = path })
|
||||
if not task_defn then
|
||||
return
|
||||
end
|
||||
local task = overseer.new_task(task_defn)
|
||||
task:start()
|
||||
end)
|
||||
return true
|
||||
end,
|
||||
})
|
||||
end
|
||||
|
||||
return provider
|
||||
Reference in new issue
Block a user