feat(nvim): setup overseer for C with cmake
This commit is contained in:
24
.config/nvim/lua/overseer/template/custom/cmake_build.lua
Normal file
24
.config/nvim/lua/overseer/template/custom/cmake_build.lua
Normal file
@@ -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,
|
||||
},
|
||||
}
|
||||
45
.config/nvim/lua/overseer/template/custom/cmake_run.lua
Normal file
45
.config/nvim/lua/overseer/template/custom/cmake_run.lua
Normal file
@@ -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,
|
||||
},
|
||||
}
|
||||
28
.config/nvim/lua/overseer/template/custom/cmake_test.lua
Normal file
28
.config/nvim/lua/overseer/template/custom/cmake_test.lua
Normal file
@@ -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,
|
||||
},
|
||||
}
|
||||
@@ -1,3 +1,6 @@
|
||||
return {
|
||||
'custom.make_c',
|
||||
'custom.make_c_file',
|
||||
'custom.cmake_build',
|
||||
'custom.cmake_run',
|
||||
'custom.cmake_test',
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
},
|
||||
}
|
||||
Reference in New Issue
Block a user