@@ -108,6 +108,62 @@ local function get_cmake_opts(path)
108
108
return options
109
109
end
110
110
111
+
112
+ --- Given a Mesonfile, parse all the options,
113
+ --- and return them as a table.
114
+ --- @param path string Path to the meson.build
115
+ --- @return table options A table like :
116
+ --- { { text = "Meson hello", value = "hello", description = "Print Hello, World!", bau = "meson" }, ...}
117
+ local function get_meson_opts (path )
118
+ local options = {}
119
+
120
+ local file = io.open (path , " r" )
121
+
122
+ if file then
123
+ local in_command = false
124
+
125
+ for line in file :lines () do
126
+ -- Parse 'executable' commands
127
+ local target = line :match (" ^%s*([%w_]-)%s*=%s*executable%s*%('%s*([%w_]+)'" )
128
+ or line :match (" ^%s*executable%s*%('%s*([%w_]+)'" )
129
+
130
+ if target then
131
+ in_command = true
132
+ local target_name = line :match (" %('%s*([^']+)'%s*" )
133
+ if target_name then
134
+ table.insert (
135
+ options ,
136
+ { text = " Meson " .. target_name , value = target_name , bau = " meson" }
137
+ )
138
+ end
139
+ elseif in_command then
140
+ in_command = false
141
+ end
142
+
143
+ -- Parse 'custom_target' commands
144
+ local custom_target = line :match (" ^%s*([%w_]-)%s*=%s*custom_target%s*%('%s*([%w_]+)'" )
145
+ or line :match (" ^%s*custom_target%s*%('%s*([%w_]+)'" )
146
+
147
+ if custom_target then
148
+ in_command = true
149
+ local target_name = line :match (" %('([%w_']+)'" )
150
+ if target_name then
151
+ table.insert (
152
+ options ,
153
+ { text = " Meson " .. target_name , value = target_name , bau = " meson" }
154
+ )
155
+ end
156
+ elseif in_command then
157
+ in_command = false
158
+ end
159
+ end
160
+
161
+ file :close ()
162
+ end
163
+
164
+ return options
165
+ end
166
+
111
167
--- Given a build.gradle.kts file, parse all the tasks,
112
168
--- and return them as a table.
113
169
---
@@ -267,6 +323,11 @@ function M.get_bau_opts()
267
323
working_dir .. utils .os_path (" /CMakeLists.txt" )
268
324
))
269
325
326
+ -- meson
327
+ vim .list_extend (options , get_meson_opts (
328
+ working_dir .. utils .os_path (" /meson.build" )
329
+ ))
330
+
270
331
-- gradle
271
332
vim .list_extend (options , get_gradle_opts (
272
333
working_dir .. utils .os_path (" /build.gradle.kts" )
@@ -290,7 +351,8 @@ function M.require_bau(bau)
290
351
local module_file_path = utils .os_path (local_path_dir .. " bau/" .. bau .. " .lua" )
291
352
local success , bau = pcall (dofile , module_file_path )
292
353
293
- if success then return bau
354
+ if success then
355
+ return bau
294
356
else
295
357
-- local error = "Build automation utilities \"" .. bau .. "\" not supported by the compiler."
296
358
-- vim.notify(error, vim.log.levels.INFO, { title = "Build automation utilities unsupported" })
0 commit comments