File tree Expand file tree Collapse file tree 2 files changed +23
-3
lines changed
Expand file tree Collapse file tree 2 files changed +23
-3
lines changed Original file line number Diff line number Diff line change @@ -296,7 +296,7 @@ M.cancel = Promise.async(function()
296296 end
297297end )
298298
299- function M .opencode_ok ()
299+ M .opencode_ok = Promise . async ( function ()
300300 if vim .fn .executable (' opencode' ) == 0 then
301301 vim .notify (
302302 ' opencode command not found - please install and configure opencode before using this plugin' ,
@@ -306,7 +306,7 @@ function M.opencode_ok()
306306 end
307307
308308 if not state .opencode_cli_version or state .opencode_cli_version == ' ' then
309- local result = vim .system ({ ' opencode' , ' --version' }):wait ()
309+ local result = Promise .system ({ ' opencode' , ' --version' }):await ()
310310 local out = (result and result .stdout or ' ' ):gsub (' %s+$' , ' ' )
311311 state .opencode_cli_version = out :match (' (%d+%%.%d+%%.%d+)' ) or out
312312 end
@@ -328,7 +328,7 @@ function M.opencode_ok()
328328 end
329329
330330 return true
331- end
331+ end )
332332
333333local function on_opencode_server ()
334334 state .current_permission = nil
Original file line number Diff line number Diff line change 2222--- @field wrap fun ( obj : T | Promise<T> ): Promise<T>
2323--- @field spawn fun ( fn : fun (): T | nil ): Promise<T>
2424--- @field async fun ( fn : fun ( ... ): T ?): fun ( ... ): Promise<T>
25+ --- @field system fun ()
2526local Promise = {}
2627Promise .__index = Promise
2728
@@ -336,4 +337,23 @@ function Promise.async(fn)
336337 end
337338end
338339
340+ --- Wrap vim.system in a promise
341+ --- @generic T
342+ --- @param cmd table vim.system cmd options
343+ --- @param opts table | nil vim.system opts
344+ --- @return Promise<T>
345+ function Promise .system (cmd , opts )
346+ local p = Promise .new ()
347+
348+ vim .system (cmd , opts or {}, function (result )
349+ if result .code == 0 then
350+ p :resolve (result )
351+ else
352+ p :reject (result )
353+ end
354+ end )
355+
356+ return p
357+ end
358+
339359return Promise
You can’t perform that action at this time.
0 commit comments