Skip to content

Commit 85f7e68

Browse files
committed
fix: type cannot check on nil
1 parent 309470b commit 85f7e68

3 files changed

Lines changed: 14 additions & 5 deletions

File tree

lua/cmake-tools/build_preset.lua

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ function BuildPreset:new(cwd, obj)
1313
end
1414

1515
function BuildPreset:get_build_target()
16+
if self.targets == nil then
17+
return ""
18+
end
1619
if type(self.targets) == "string" then
1720
return self.targets
1821
elseif type(self.targets == "table") then

lua/cmake-tools/init.lua

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,12 +115,18 @@ function cmake.generate(opt, callback)
115115
if presets_exists then
116116
local presets = Presets:parse(config.cwd)
117117

118+
local find_preset = false
118119
-- Refresh build type to use from CMakePresets
119120
if config.configure_preset then
120-
config.build_type = presets:get_configure_preset(config.configure_preset):get_build_type()
121+
local configure_preset =
122+
presets:get_configure_preset(config.configure_preset, { include_hidden = true })
123+
if configure_preset then
124+
find_preset = true
125+
config.build_type = configure_preset:get_build_type()
126+
end
121127
end
122128

123-
if not config.configure_preset then
129+
if (not config.configure_preset) or (find_preset == false) then
124130
-- try to determine the confiure preset based on the build preset
125131
if config.build_preset then
126132
local build_preset = presets:get_build_preset(config.build_preset)
@@ -133,7 +139,7 @@ function cmake.generate(opt, callback)
133139
end
134140
end
135141

136-
if not config.configure_preset then
142+
if (not config.configure_preset) or (find_preset == false) then
137143
-- this will also set value for build type from preset.
138144
-- default to be "Debug"
139145
return cmake.select_configure_preset(function(result)
@@ -147,7 +153,7 @@ function cmake.generate(opt, callback)
147153
return
148154
end
149155

150-
if config.configure_preset then
156+
if config.configure_preset and find_preset then
151157
-- if exsist preset file and set configure preset, then
152158
-- set build directory to the `binaryDir` option of `configurePresets`
153159
local preset = presets:get_configure_preset(config.configure_preset)

lua/cmake-tools/preset.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ local function parseTree(self, get_preset)
255255
end
256256

257257
function Preset:new(cwd, obj, get_preset)
258-
local instance = setmetatable(obj or {}, { __index = self })
258+
local instance = setmetatable(obj or {}, self)
259259
instance.__index = self
260260
instance.environment = instance.environment or {}
261261
instance.cwd = cwd

0 commit comments

Comments
 (0)