Skip to content

Commit 304ffaa

Browse files
DenzellceWolf
authored andcommitted
chore(presets): add annotations
1 parent 6b2e8b6 commit 304ffaa

6 files changed

Lines changed: 120 additions & 2 deletions

File tree

lua/cmake-tools/build_preset.lua

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
local Path = require("plenary.path")
22
local osys = require("cmake-tools.osys")
33

4+
---@class BuildPreset: CMakeBuildPreset
45
local BuildPreset = {}
56

7+
---@param cwd string
8+
---@param obj CMakeBuildPreset?
9+
---@return BuildPreset
610
function BuildPreset:new(cwd, obj)
711
local instance = setmetatable(obj or {}, { __index = self })
812
instance.__index = self
@@ -16,6 +20,7 @@ function BuildPreset:new(cwd, obj)
1620
return instance
1721
end
1822

23+
---@return string[]|nil
1924
function BuildPreset:get_build_target()
2025
if self.targets == nil then
2126
return nil
@@ -28,13 +33,15 @@ function BuildPreset:get_build_target()
2833
return nil
2934
end
3035

36+
---@return string|nil
3137
function BuildPreset:get_build_type()
3238
if self.configuration == nil then
3339
return nil
3440
end
3541
return self.configuration
3642
end
3743

44+
---@return boolean
3845
function BuildPreset:is_valid()
3946
return self.valid
4047
end

lua/cmake-tools/preset.lua

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ local Path = require("plenary.path")
22
local osys = require("cmake-tools.osys")
33
local utils = require("cmake-tools.utils")
44

5+
---@class ConfigurePreset: CMakeConfigurePreset
56
local Preset = {}
67

78
local function expandMacro(self, str)
@@ -255,6 +256,10 @@ local function parseTree(self, get_preset)
255256
end
256257
end
257258

259+
---@param cwd string
260+
---@param obj CMakeConfigurePreset?
261+
---@param get_preset fun(name: string): CMakeConfigurePreset?
262+
---@return ConfigurePreset
258263
function Preset:new(cwd, obj, get_preset)
259264
local instance = setmetatable(obj or {}, self)
260265
instance.__index = self
@@ -271,10 +276,12 @@ function Preset:new(cwd, obj, get_preset)
271276
return instance
272277
end
273278

279+
---@return string
274280
function Preset:get_build_type()
275281
return self.cacheVariables and self.cacheVariables.CMAKE_BUILD_TYPE or "Debug"
276282
end
277283

284+
---@return string[]|nil
278285
function Preset:get_build_configuration_types()
279286
local generator = self.generator
280287
local multi_configuration_generator = { "Visual Studio", "Xcode", "Ninja Multi-Config" }

lua/cmake-tools/presets.lua

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,14 @@ local function decode(file, visited)
9191
return data
9292
end
9393

94+
---@class Presets
95+
---@field configurePresets ConfigurePreset[]
96+
---@field buildPresets BuildPreset[]
97+
---@field testPresets TestPreset[]
9498
local Presets = {}
9599

100+
---@param cwd string
101+
---@return Presets
96102
function Presets:parse(cwd)
97103
local function merge_presets(lhs, rhs)
98104
local ret = vim.deepcopy(lhs)
@@ -185,14 +191,20 @@ local function get_preset_names(presets, opts)
185191
return options
186192
end
187193

194+
---@param opts table?
195+
---@return string[]
188196
function Presets:get_configure_preset_names(opts)
189197
return get_preset_names(self.configurePresets, opts)
190198
end
191199

200+
---@param opts table?
201+
---@return string[]
192202
function Presets:get_test_preset_names(opts)
193203
return get_preset_names(self.testPresets, opts)
194204
end
195205

206+
---@param opts table
207+
---@return string[]
196208
function Presets:get_build_preset_names(opts)
197209
local presets = get_preset_names(self.buildPresets, opts)
198210
local ret = {}
@@ -231,18 +243,29 @@ local function get_preset(name, tbl, opts)
231243
end
232244
end
233245

246+
---@param name string
247+
---@param opts table?
248+
---@return ConfigurePreset?
234249
function Presets:get_configure_preset(name, opts)
235250
return get_preset(name, self.configurePresets, opts)
236251
end
237252

253+
---@param name string
254+
---@param opts table?
255+
---@return TestPreset?
238256
function Presets:get_test_preset(name, opts)
239257
return get_preset(name, self.testPresets, opts)
240258
end
241259

260+
---@param name string
261+
---@param opts table?
262+
---@return BuildPreset?
242263
function Presets:get_build_preset(name, opts)
243264
return get_preset(name, self.buildPresets, { include_hidden = true, include_disabled = true })
244265
end
245266

267+
---@param cwd string
268+
---@return string?, string?
246269
function Presets.find_preset_files(cwd)
247270
local files = vim.fn.readdir(cwd)
248271
local presetFiles = {}
@@ -263,6 +286,8 @@ function Presets.find_preset_files(cwd)
263286
return unpack(presetFiles)
264287
end
265288

289+
---@param cwd string
290+
---@return boolean
266291
function Presets.exists(cwd)
267292
return Presets.find_preset_files(cwd) ~= nil
268293
end
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
---@meta _
2+
3+
---@class CMakeBuildPreset
4+
---@field name string
5+
---@field hidden boolean?
6+
---@field inherits string|string[]?
7+
---@field condition CMakeCondition?
8+
---@field vendor table?
9+
---@field displayName string?
10+
---@field description string?
11+
---@field environment table<string, string?>?
12+
---@field configurePreset string?
13+
---@field inheritConfigureEnvironment boolean?
14+
---@field jobs integer?
15+
---@field targets string|string[]?
16+
---@field configuration string?
17+
---@field cleanFirst boolean?
18+
---@field resolvePackageReferences ("on"|"off"|"only")?
19+
---@field verbose boolean?
20+
---@field nativeToolOptions string[]?
21+
---@field disabled boolean?
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
---@meta _
2+
3+
---@class CMakeConfigurePresetArchitecture
4+
---@field value string?
5+
---@field strategy ("set"|"external")?
6+
7+
---@class CMakeConfigurePresetToolset
8+
---@field value string?
9+
---@field strategy ("set"|"external")?
10+
11+
---@class CMakeConfigurePresetCacheVariable
12+
---@field type string?
13+
---@field value string|boolean
14+
15+
---@class CMakeConfigurePresetWarnings
16+
---@field dev boolean?
17+
---@field deprecated boolean?
18+
---@field uninitialized boolean?
19+
---@field unusedCli boolean?
20+
---@field systemVars boolean?
21+
22+
---@class CMakeConfigurePresetErrors
23+
---@field dev boolean?
24+
---@field deprecated boolean?
25+
26+
---@class CMakeConfigurePresetDebug
27+
---@field output boolean?
28+
---@field tryCompile boolean?
29+
---@field find boolean?
30+
31+
---@class CMakeConfigurePresetTrace
32+
---@field mode ("on"|"off"|"expand")?
33+
---@field format ("human"|"json-v1")?
34+
---@field source string|string[]?
35+
---@field redirect string?
36+
37+
---@class CMakeConfigurePreset
38+
---@field name string
39+
---@field hidden boolean?
40+
---@field inherits string|string[]?
41+
---@field condition CMakeCondition?
42+
---@field vendor table?
43+
---@field displayName string?
44+
---@field description string?
45+
---@field generator string?
46+
---@field architecture string|CMakeConfigurePresetArchitecture?
47+
---@field toolset string|CMakeConfigurePresetToolset?
48+
---@field toolchainFile string?
49+
---@field graphviz string?
50+
---@field binaryDir string?
51+
---@field binaryDirExpanded string?
52+
---@field installDir string?
53+
---@field cmakeExecutable string?
54+
---@field cacheVariables table<string, string|boolean|CMakeConfigurePresetCacheVariable?>?
55+
---@field environment table<string, string?>?
56+
---@field warnings CMakeConfigurePresetWarnings?
57+
---@field errors CMakeConfigurePresetErrors?
58+
---@field debug CMakeConfigurePresetDebug?
59+
---@field trace CMakeConfigurePresetTrace?
60+
---@field disabled boolean?

lua/types/cmake-preset/test_preset.lua

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@
6060

6161
---@class CMakeTestPreset
6262
---@field name string
63-
---@field valid boolean
6463
---@field hidden boolean?
6564
---@field inherits string|string[]?
6665
---@field condition CMakeCondition?
@@ -76,4 +75,3 @@
7675
---@field filter CMakeTestPresetFilter?
7776
---@field execution CMakeTestPresetExecution?
7877
---@field disabled boolean?
79-
---@field cwd string

0 commit comments

Comments
 (0)