refactor: formate cmake config file

This commit is contained in:
ldoublej 2026-03-08 22:42:50 +08:00
parent 1fa5bfec9c
commit fd65ced8bd

View file

@ -1,154 +1,154 @@
return { return {
"Civitasv/cmake-tools.nvim", "Civitasv/cmake-tools.nvim",
dependencies = { dependencies = {
"akinsho/toggleterm.nvim", "akinsho/toggleterm.nvim",
}, },
opts = {}, opts = {},
config = function() config = function()
local osys = require("cmake-tools.osys") local osys = require("cmake-tools.osys")
require("cmake-tools").setup({ require("cmake-tools").setup({
cmake_command = "cmake", -- this is used to specify cmake command path cmake_command = "cmake", -- this is used to specify cmake command path
ctest_command = "ctest", -- this is used to specify ctest command path ctest_command = "ctest", -- this is used to specify ctest command path
cmake_use_preset = true, cmake_use_preset = true,
cmake_regenerate_on_save = true, -- auto generate when save CMakeLists.txt cmake_regenerate_on_save = true, -- auto generate when save CMakeLists.txt
cmake_generate_options = { "-DCMAKE_EXPORT_COMPILE_COMMANDS=1" }, -- this will be passed when invoke `CMakeGenerate` cmake_generate_options = { "-DCMAKE_EXPORT_COMPILE_COMMANDS=1" }, -- this will be passed when invoke `CMakeGenerate`
cmake_build_options = {}, -- this will be passed when invoke `CMakeBuild` cmake_build_options = {}, -- this will be passed when invoke `CMakeBuild`
-- support macro expansion: -- support macro expansion:
-- ${kit} -- ${kit}
-- ${kitGenerator} -- ${kitGenerator}
-- ${variant:xx} -- ${variant:xx}
cmake_build_directory = function() cmake_build_directory = function()
if osys.iswin32 then if osys.iswin32 then
return "out\\${variant:buildType}" return "out\\${variant:buildType}"
end end
return "out/${variant:buildType}" return "out/${variant:buildType}"
end, -- this is used to specify generate directory for cmake, allows macro expansion, can be a string or a function returning the string, relative to cwd. end, -- this is used to specify generate directory for cmake, allows macro expansion, can be a string or a function returning the string, relative to cwd.
cmake_compile_commands_options = { cmake_compile_commands_options = {
action = "soft_link", -- available options: soft_link, copy, lsp, none action = "soft_link", -- available options: soft_link, copy, lsp, none
-- soft_link: this will automatically make a soft link from compile commands file to target -- soft_link: this will automatically make a soft link from compile commands file to target
-- copy: this will automatically copy compile commands file to target -- copy: this will automatically copy compile commands file to target
-- lsp: this will automatically set compile commands file location using lsp -- lsp: this will automatically set compile commands file location using lsp
-- none: this will make this option ignored -- none: this will make this option ignored
target = vim.loop.cwd(), -- path to directory, this is used only if action == "soft_link" or action == "copy" target = vim.loop.cwd(), -- path to directory, this is used only if action == "soft_link" or action == "copy"
}, },
cmake_kits_path = nil, -- this is used to specify global cmake kits path, see CMakeKits for detailed usage cmake_kits_path = nil, -- this is used to specify global cmake kits path, see CMakeKits for detailed usage
cmake_variants_message = { cmake_variants_message = {
short = { show = true }, -- whether to show short message short = { show = true }, -- whether to show short message
long = { show = true, max_length = 40 }, -- whether to show long message long = { show = true, max_length = 40 }, -- whether to show long message
}, },
cmake_dap_configuration = { -- debug settings for cmake cmake_dap_configuration = { -- debug settings for cmake
name = "cpp", name = "cpp",
type = "codelldb", type = "codelldb",
request = "launch", request = "launch",
stopOnEntry = false, stopOnEntry = false,
runInTerminal = true, runInTerminal = true,
console = "integratedTerminal", console = "integratedTerminal",
}, },
cmake_executor = { -- executor to use cmake_executor = { -- executor to use
name = "toggleterm", -- name of the executor name = "toggleterm", -- name of the executor
opts = {}, -- the options the executor will get, possible values depend on the executor type. See `default_opts` for possible values. opts = {}, -- the options the executor will get, possible values depend on the executor type. See `default_opts` for possible values.
default_opts = { -- a list of default and possible values for executors default_opts = { -- a list of default and possible values for executors
quickfix = { quickfix = {
show = "always", -- "always", "only_on_error" show = "always", -- "always", "only_on_error"
position = "belowright", -- "vertical", "horizontal", "leftabove", "aboveleft", "rightbelow", "belowright", "topleft", "botright", use `:h vertical` for example to see help on them position = "belowright", -- "vertical", "horizontal", "leftabove", "aboveleft", "rightbelow", "belowright", "topleft", "botright", use `:h vertical` for example to see help on them
size = 10, size = 10,
encoding = "utf-8", -- if encoding is not "utf-8", it will be converted to "utf-8" using `vim.fn.iconv` encoding = "utf-8", -- if encoding is not "utf-8", it will be converted to "utf-8" using `vim.fn.iconv`
auto_close_when_success = true, -- typically, you can use it with the "always" option; it will auto-close the quickfix buffer if the execution is successful. auto_close_when_success = true, -- typically, you can use it with the "always" option; it will auto-close the quickfix buffer if the execution is successful.
}, },
toggleterm = { toggleterm = {
direction = "float", -- 'vertical' | 'horizontal' | 'tab' | 'float' direction = "float", -- 'vertical' | 'horizontal' | 'tab' | 'float'
close_on_exit = false, -- whether close the terminal when exit close_on_exit = false, -- whether close the terminal when exit
auto_scroll = true, -- whether auto scroll to the bottom auto_scroll = true, -- whether auto scroll to the bottom
singleton = true, -- single instance, autocloses the opened one, if present singleton = true, -- single instance, autocloses the opened one, if present
}, },
overseer = { overseer = {
new_task_opts = { new_task_opts = {
strategy = { strategy = {
"toggleterm", "toggleterm",
direction = "horizontal", direction = "horizontal",
auto_scroll = true, auto_scroll = true,
quit_on_exit = "success", quit_on_exit = "success",
}, },
}, -- options to pass into the `overseer.new_task` command }, -- options to pass into the `overseer.new_task` command
on_new_task = function(task) on_new_task = function(task)
require("overseer").open({ enter = false, direction = "right" }) require("overseer").open({ enter = false, direction = "right" })
end, -- a function that gets overseer.Task when it is created, before calling `task:start` end, -- a function that gets overseer.Task when it is created, before calling `task:start`
}, },
terminal = { terminal = {
name = "Main Terminal", name = "Main Terminal",
prefix_name = "[CMakeTools]: ", -- This must be included and must be unique, otherwise the terminals will not work. Do not use a simple spacebar " ", or any generic name prefix_name = "[CMakeTools]: ", -- This must be included and must be unique, otherwise the terminals will not work. Do not use a simple spacebar " ", or any generic name
split_direction = "horizontal", -- "horizontal", "vertical" split_direction = "horizontal", -- "horizontal", "vertical"
split_size = 11, split_size = 11,
-- Window handling -- Window handling
single_terminal_per_instance = true, -- Single viewport, multiple windows single_terminal_per_instance = true, -- Single viewport, multiple windows
single_terminal_per_tab = true, -- Single viewport per tab single_terminal_per_tab = true, -- Single viewport per tab
keep_terminal_static_location = true, -- Static location of the viewport if avialable keep_terminal_static_location = true, -- Static location of the viewport if avialable
auto_resize = true, -- Resize the terminal if it already exists auto_resize = true, -- Resize the terminal if it already exists
-- Running Tasks -- Running Tasks
start_insert = false, -- If you want to enter terminal with :startinsert upon using :CMakeRun start_insert = false, -- If you want to enter terminal with :startinsert upon using :CMakeRun
focus = false, -- Focus on terminal when cmake task is launched. focus = false, -- Focus on terminal when cmake task is launched.
do_not_add_newline = false, -- Do not hit enter on the command inserted when using :CMakeRun, allowing a chance to review or modify the command before hitting enter. do_not_add_newline = false, -- Do not hit enter on the command inserted when using :CMakeRun, allowing a chance to review or modify the command before hitting enter.
}, -- terminal executor uses the values in cmake_terminal }, -- terminal executor uses the values in cmake_terminal
}, },
}, },
cmake_runner = { -- runner to use cmake_runner = { -- runner to use
name = "toggleterm", -- name of the runner name = "toggleterm", -- name of the runner
opts = {}, -- the options the runner will get, possible values depend on the runner type. See `default_opts` for possible values. opts = {}, -- the options the runner will get, possible values depend on the runner type. See `default_opts` for possible values.
default_opts = { -- a list of default and possible values for runners default_opts = { -- a list of default and possible values for runners
quickfix = { quickfix = {
show = "always", -- "always", "only_on_error" show = "always", -- "always", "only_on_error"
position = "belowright", -- "bottom", "top" position = "belowright", -- "bottom", "top"
size = 10, size = 10,
encoding = "utf-8", encoding = "utf-8",
auto_close_when_success = true, -- typically, you can use it with the "always" option; it will auto-close the quickfix buffer if the execution is successful. auto_close_when_success = true, -- typically, you can use it with the "always" option; it will auto-close the quickfix buffer if the execution is successful.
}, },
toggleterm = { toggleterm = {
direction = "float", -- 'vertical' | 'horizontal' | 'tab' | 'float' direction = "float", -- 'vertical' | 'horizontal' | 'tab' | 'float'
close_on_exit = false, -- whether close the terminal when exit close_on_exit = false, -- whether close the terminal when exit
auto_scroll = true, -- whether auto scroll to the bottom auto_scroll = true, -- whether auto scroll to the bottom
singleton = true, -- single instance, autocloses the opened one, if present singleton = true, -- single instance, autocloses the opened one, if present
}, },
overseer = { overseer = {
new_task_opts = { new_task_opts = {
strategy = { strategy = {
"toggleterm", "toggleterm",
direction = "horizontal", direction = "horizontal",
autos_croll = true, autos_croll = true,
quit_on_exit = "success", quit_on_exit = "success",
}, },
}, -- options to pass into the `overseer.new_task` command }, -- options to pass into the `overseer.new_task` command
on_new_task = function(task) end, -- a function that gets overseer.Task when it is created, before calling `task:start` on_new_task = function(task) end, -- a function that gets overseer.Task when it is created, before calling `task:start`
}, },
terminal = { terminal = {
name = "Main Terminal", name = "Main Terminal",
prefix_name = "[CMakeTools]: ", -- This must be included and must be unique, otherwise the terminals will not work. Do not use a simple spacebar " ", or any generic name prefix_name = "[CMakeTools]: ", -- This must be included and must be unique, otherwise the terminals will not work. Do not use a simple spacebar " ", or any generic name
split_direction = "horizontal", -- "horizontal", "vertical" split_direction = "horizontal", -- "horizontal", "vertical"
split_size = 11, split_size = 11,
-- Window handling -- Window handling
single_terminal_per_instance = true, -- Single viewport, multiple windows single_terminal_per_instance = true, -- Single viewport, multiple windows
single_terminal_per_tab = true, -- Single viewport per tab single_terminal_per_tab = true, -- Single viewport per tab
keep_terminal_static_location = true, -- Static location of the viewport if avialable keep_terminal_static_location = true, -- Static location of the viewport if avialable
auto_resize = true, -- Resize the terminal if it already exists auto_resize = true, -- Resize the terminal if it already exists
-- Running Tasks -- Running Tasks
start_insert = false, -- If you want to enter terminal with :startinsert upon using :CMakeRun start_insert = false, -- If you want to enter terminal with :startinsert upon using :CMakeRun
focus = false, -- Focus on terminal when cmake task is launched. focus = false, -- Focus on terminal when cmake task is launched.
do_not_add_newline = false, -- Do not hit enter on the command inserted when using :CMakeRun, allowing a chance to review or modify the command before hitting enter. do_not_add_newline = false, -- Do not hit enter on the command inserted when using :CMakeRun, allowing a chance to review or modify the command before hitting enter.
use_shell_alias = false, -- Hide the verbose command wrapper by using a shell alias, showing only the program's output (currently not supported on Windows) use_shell_alias = false, -- Hide the verbose command wrapper by using a shell alias, showing only the program's output (currently not supported on Windows)
}, },
}, },
}, },
cmake_notifications = { cmake_notifications = {
runner = { enabled = true }, runner = { enabled = true },
executor = { enabled = true }, executor = { enabled = true },
spinner = { "", "", "", "", "", "", "", "", "", "" }, -- icons used for progress display spinner = { "", "", "", "", "", "", "", "", "", "" }, -- icons used for progress display
refresh_rate_ms = 100, -- how often to iterate icons refresh_rate_ms = 100, -- how often to iterate icons
}, },
cmake_virtual_text_support = true, -- Show the target related to current file using virtual text (at right corner) cmake_virtual_text_support = true, -- Show the target related to current file using virtual text (at right corner)
cmake_use_scratch_buffer = false, -- A buffer that shows what cmake-tools has done cmake_use_scratch_buffer = false, -- A buffer that shows what cmake-tools has done
}) })
end, end,
} }