diff options
author | Daniil Rozanov <daniilrozzanov@gmail.com> | 2024-04-26 00:50:04 +0300 |
---|---|---|
committer | Daniil Rozanov <daniilrozzanov@gmail.com> | 2024-04-26 00:50:04 +0300 |
commit | 8d05fcaaeb1442c709f148ff934d92900743f051 (patch) | |
tree | a766cc97461968da16baba157acc636388924983 /lua/cmake/actions.lua | |
parent | 2470bad1151fc49941c3821f187c6c232c0cec78 (diff) |
feat: command to edit variants
If there is no cmake-variants.yaml file in current directory, command creates it with default variants
Diffstat (limited to 'lua/cmake/actions.lua')
-rw-r--r-- | lua/cmake/actions.lua | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/lua/cmake/actions.lua b/lua/cmake/actions.lua index ff64f95..3c09d93 100644 --- a/lua/cmake/actions.lua +++ b/lua/cmake/actions.lua @@ -1,6 +1,8 @@ local pr = require("cmake.project") local config = require("cmake.config") local t = require("cmake.terminal") +local utils = require("cmake.utils") +local constants = require("cmake.constants") local Path = require("plenary.path") local M = {} @@ -121,4 +123,21 @@ M.toggle = function() t.cmake_toggle() end +M.edit_variants = function() + utils.file_exists(constants.variants_yaml_filename, function(variants_exists) + if variants_exists then + vim.schedule(function() + vim.cmd(string.format("e %s", constants.variants_yaml_filename)) + end) + else + local default_yaml = require("cmake.lyaml").dump(config.cmake.variants) + utils.write_file(constants.variants_yaml_filename, default_yaml, function() + vim.schedule(function() + vim.cmd(string.format("e %s", constants.variants_yaml_filename)) + end) + end) + end + end) +end + return M |