From 8d05fcaaeb1442c709f148ff934d92900743f051 Mon Sep 17 00:00:00 2001 From: Daniil Rozanov Date: Fri, 26 Apr 2024 00:50:04 +0300 Subject: feat: command to edit variants If there is no cmake-variants.yaml file in current directory, command creates it with default variants --- lua/cmake/actions.lua | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'lua/cmake/actions.lua') 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 -- cgit v1.2.3