Skip to content

Commit

Permalink
cmd SCNvimReboot (reboot interpreter)
Browse files Browse the repository at this point in the history
  • Loading branch information
elgiano committed Oct 28, 2024
1 parent de0fbc3 commit d0bfc93
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 1 deletion.
1 change: 1 addition & 0 deletions doc/SCNvim.txt
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ Command Description
`SCNvimStart` Start SuperCollider
`SCNvimStop` Stop SuperCollider
`SCNvimRecompile` Recompile SCClassLibrary
`SCNvimReboot` Reboot sclang interpreter
`SCNvimGenerateAssets` Generate syntax highlightning and snippets
`SCNvimHelp` <subject> Open HelpBrowser or window split for <subject>
`SCNvimStatusLine` Display server status in 'statusline' if configured.
Expand Down
5 changes: 5 additions & 0 deletions lua/scnvim.lua
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,11 @@ function scnvim.recompile()
sclang.recompile()
end

--- Reboot sclang.
function scnvim.reboot()
sclang.reboot()
end

--- Determine if a sclang process is active.
---@return True if sclang is running otherwise false.
function scnvim.is_running()
Expand Down
1 change: 1 addition & 0 deletions lua/scnvim/commands.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ return function()
add_command('SCNvimStart', sclang.start, 'Start the sclang interpreter')
add_command('SCNvimStop', sclang.stop, 'Stop the sclang interpreter')
add_command('SCNvimRecompile', sclang.recompile, 'Recompile the sclang interpreter')
add_command('SCNvimReboot', sclang.reboot, 'Reboot sclang interpreter')
add_command('SCNvimStatusLine', sclang.poll_server_status, 'Display the server status')
add_command('SCNvimGenerateAssets', function()
local on_done = function()
Expand Down
12 changes: 11 additions & 1 deletion lua/scnvim/sclang.lua
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ function M.start()
end

--- Stop the sclang process.
function M.stop()
function M.stop(callback)
if not M.is_running() then
return
end
Expand All @@ -235,15 +235,25 @@ function M.stop()
local ret = M.proc:kill 'sigkill'
if ret == 0 then
timer:close()
if callback then
vim.schedule(callback)
end
M.proc = nil
end
else
-- process exited during timer loop
timer:close()
if callback then
vim.schedule(callback)
end
end
end)
end

function M.reboot()
M.stop(M.start)
end

--- Recompile the class library.
function M.recompile()
if not M.is_running() then
Expand Down
1 change: 1 addition & 0 deletions test/spec/automated/commands_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ describe('commands', function()
'SCNvimGenerateAssets',
'SCNvimHelp',
'SCNvimRecompile',
'SCNvimReboot',
'SCNvimStart',
'SCNvimStatusLine',
'SCNvimStop',
Expand Down

0 comments on commit d0bfc93

Please sign in to comment.