summaryrefslogtreecommitdiff
path: root/.config/nvim/lua/overseer/template/custom/cmake_run.lua
blob: cdb4d5cfc903a2d8d36b1fcbdbec6362480c391a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
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,
    },
}