summaryrefslogtreecommitdiff
path: root/.config/nvim/lua
diff options
context:
space:
mode:
Diffstat (limited to '.config/nvim/lua')
-rw-r--r--.config/nvim/lua/overseer/template/custom/cmake_build.lua24
-rw-r--r--.config/nvim/lua/overseer/template/custom/cmake_run.lua45
-rw-r--r--.config/nvim/lua/overseer/template/custom/cmake_test.lua28
-rw-r--r--.config/nvim/lua/overseer/template/custom/init.lua5
-rw-r--r--.config/nvim/lua/overseer/template/custom/make_c_file.lua (renamed from .config/nvim/lua/overseer/template/custom/make_c.lua)15
5 files changed, 115 insertions, 2 deletions
diff --git a/.config/nvim/lua/overseer/template/custom/cmake_build.lua b/.config/nvim/lua/overseer/template/custom/cmake_build.lua
new file mode 100644
index 0000000..cb321a0
--- /dev/null
+++ b/.config/nvim/lua/overseer/template/custom/cmake_build.lua
@@ -0,0 +1,24 @@
+local overseer = require('overseer')
+local root_pattern = require('lspconfig/util').root_pattern('CMakePresets.json', 'CTestConfig.cmake', 'build', 'cmake')
+return {
+ name = 'Build Cmake Project',
+ builder = function(_)
+ local filename = vim.fn.expand('%:p')
+ local root_dir = root_pattern(filename) or vim.fn.getcwd()
+
+ return {
+ name = 'Cmake',
+ cmd = 'cmake .. && cmake --build .',
+ cwd = root_dir .. '/build',
+ }
+ end,
+ tags = { overseer.TAG.BUILD },
+ priority = 40,
+ condition = {
+ callback = function()
+ local filename = vim.fn.expand('%:p')
+ local root_dir = root_pattern(filename)
+ return root_dir ~= nil
+ end,
+ },
+}
diff --git a/.config/nvim/lua/overseer/template/custom/cmake_run.lua b/.config/nvim/lua/overseer/template/custom/cmake_run.lua
new file mode 100644
index 0000000..cdb4d5c
--- /dev/null
+++ b/.config/nvim/lua/overseer/template/custom/cmake_run.lua
@@ -0,0 +1,45 @@
+local overseer = require('overseer')
+local root_pattern = require('lspconfig/util').root_pattern('CMakePresets.json', 'CTestConfig.cmake', 'build', 'cmake')
+return {
+ name = 'Run Cmake Project',
+ params = {
+ args = {
+ optional = true,
+ type = 'string',
+ },
+ },
+ builder = function(params)
+ local filename = vim.fn.expand('%:p')
+ local root_dir = root_pattern(filename)
+ local exe = vim.g.overseer_cmake_main_exe
+
+ -- Make sure params.args is a string
+ if not params.args or type(params.args) ~= 'string' then
+ params.args = ''
+ end
+
+ return {
+ name = 'Run ' .. exe,
+ cmd = './' .. 'Kalc ' .. params.args,
+ cwd = root_dir .. '/build',
+ }
+ end,
+ tags = { overseer.TAG.RUN },
+ priority = 41,
+ condition = {
+ callback = function()
+ local filename = vim.fn.expand('%:p')
+ local root_dir = root_pattern(filename)
+ if not root_dir then
+ return false, 'Unable to detect root directory of cmake project'
+ end
+
+ if not vim.g.overseer_cmake_main_exe then
+ return false,
+ 'Global "overseer_cmake_main_exe" must be defined. use `vim.g.overseer_cmake_main_exe = "Value"` to define it'
+ end
+
+ return true
+ end,
+ },
+}
diff --git a/.config/nvim/lua/overseer/template/custom/cmake_test.lua b/.config/nvim/lua/overseer/template/custom/cmake_test.lua
new file mode 100644
index 0000000..7591cc9
--- /dev/null
+++ b/.config/nvim/lua/overseer/template/custom/cmake_test.lua
@@ -0,0 +1,28 @@
+local overseer = require('overseer')
+local root_pattern = require('lspconfig/util').root_pattern('CMakePresets.json', 'CTestConfig.cmake', 'build', 'cmake')
+return {
+ name = 'Test Cmake Project',
+ builder = function(_)
+ local filename = vim.fn.expand('%:p')
+ local root_dir = root_pattern(filename)
+
+ return {
+ name = 'Cmake Tests',
+ cmd = 'ctest --output-on-failure',
+ cwd = root_dir .. '/build',
+ }
+ end,
+ tags = { overseer.TAG.TEST },
+ priority = 42,
+ condition = {
+ callback = function()
+ local filename = vim.fn.expand('%:p')
+ local root_dir = root_pattern(filename)
+ if not root_dir then
+ return false, 'Unable to detect root directory of cmake project'
+ end
+
+ return true
+ end,
+ },
+}
diff --git a/.config/nvim/lua/overseer/template/custom/init.lua b/.config/nvim/lua/overseer/template/custom/init.lua
index be9e689..796ee39 100644
--- a/.config/nvim/lua/overseer/template/custom/init.lua
+++ b/.config/nvim/lua/overseer/template/custom/init.lua
@@ -1,3 +1,6 @@
return {
- 'custom.make_c',
+ 'custom.make_c_file',
+ 'custom.cmake_build',
+ 'custom.cmake_run',
+ 'custom.cmake_test',
}
diff --git a/.config/nvim/lua/overseer/template/custom/make_c.lua b/.config/nvim/lua/overseer/template/custom/make_c_file.lua
index 358047f..75f89d0 100644
--- a/.config/nvim/lua/overseer/template/custom/make_c.lua
+++ b/.config/nvim/lua/overseer/template/custom/make_c_file.lua
@@ -13,8 +13,21 @@ return {
}
end,
tags = { overseer.TAG.BUILD },
- priority = 20,
+ priority = 50,
condition = {
filetype = { 'c' },
+ callback = function()
+ -- Disable if already using make/cmake
+ local filename = vim.fn.expand('%:p')
+ local root_dir = require('lspconfig/util').root_pattern(
+ 'Makefile',
+ 'build/Makefile',
+ 'CMakePresets.json',
+ 'CTestConfig.cmake',
+ 'build',
+ 'cmake'
+ )(filename)
+ return root_dir == nil
+ end,
},
}