Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions lua/cmake-tools/build_preset.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ function BuildPreset:new(cwd, obj)
instance.environment = instance.environment or {}
instance.cwd = cwd

if instance.valid == nil then
instance.valid = true
end

return instance
end

Expand All @@ -31,4 +35,8 @@ function BuildPreset:get_build_type()
return self.configuration
end

function BuildPreset:is_valid()
return self.valid
end

return BuildPreset
24 changes: 11 additions & 13 deletions lua/cmake-tools/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -856,31 +856,26 @@ function cmake.select_build_preset(callback)
local presets = Presets:parse(config.cwd)
local build_preset_names =
presets:get_build_preset_names({ include_disabled = config:show_disabled_build_presets() })
build_preset_names = vim.list_extend(build_preset_names, { "None" })
local format_preset_name = function(p_name)
if p_name == "None" then
return p_name
end
local p = presets:get_build_preset(p_name)
return p.displayName or p.name
end
vim.ui.select(
build_preset_names,
{ prompt = "Select cmake build presets", format_item = format_preset_name },
vim.schedule_wrap(function(choice)
if not choice or choice == "None" then
if choice == "None" then
config.build_preset = nil
end
if not choice then
callback(Result:new_error(Types.NOT_SELECT_PRESET, "No build preset selected"))
return
end
if config.build_preset ~= choice then
config.build_preset = choice

local build_preset = presets:get_build_preset(choice)
if build_preset then
config:update_build_target()
if build_preset:is_valid() then
config.build_preset = choice

if build_preset then
config:update_build_target()
end
end
end
local associated_configure_preset = presets:get_configure_preset(
Expand All @@ -892,7 +887,10 @@ function cmake.select_build_preset(callback)
or nil
local configure_preset_updated = false

if config.configure_preset ~= associated_configure_preset_name then
if
associated_configure_preset_name
and config.configure_preset ~= associated_configure_preset_name
then
config.configure_preset = associated_configure_preset_name
configure_preset_updated = true
end
Expand Down
2 changes: 2 additions & 0 deletions lua/cmake-tools/presets.lua
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ function Presets:parse(cwd)
build_preset = createBuildPreset(build_preset)
end

table.insert(instance.buildPresets, createBuildPreset({ name = "None", valid = false }))

return instance
end

Expand Down