From 776f6e866102c0a1c445530405642dbb6e626605 Mon Sep 17 00:00:00 2001 From: elgiano Date: Fri, 25 Oct 2024 11:46:00 +0200 Subject: [PATCH] cmd SCNvimReboot (reboot interpreter) --- doc/SCNvim.txt | 1 + lua/scnvim.lua | 5 +++++ lua/scnvim/commands.lua | 1 + lua/scnvim/sclang.lua | 8 +++++++- test/spec/automated/commands_spec.lua | 1 + 5 files changed, 15 insertions(+), 1 deletion(-) diff --git a/doc/SCNvim.txt b/doc/SCNvim.txt index d8f31292..5b951020 100644 --- a/doc/SCNvim.txt +++ b/doc/SCNvim.txt @@ -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` Open HelpBrowser or window split for `SCNvimStatusLine` Display server status in 'statusline' if configured. diff --git a/lua/scnvim.lua b/lua/scnvim.lua index fc284423..054a513e 100644 --- a/lua/scnvim.lua +++ b/lua/scnvim.lua @@ -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() diff --git a/lua/scnvim/commands.lua b/lua/scnvim/commands.lua index bef749c9..686ea36e 100644 --- a/lua/scnvim/commands.lua +++ b/lua/scnvim/commands.lua @@ -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() diff --git a/lua/scnvim/sclang.lua b/lua/scnvim/sclang.lua index e17d4a1d..18110b37 100644 --- a/lua/scnvim/sclang.lua +++ b/lua/scnvim/sclang.lua @@ -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 @@ -235,15 +235,21 @@ 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 diff --git a/test/spec/automated/commands_spec.lua b/test/spec/automated/commands_spec.lua index 1369a5e4..03007c0b 100644 --- a/test/spec/automated/commands_spec.lua +++ b/test/spec/automated/commands_spec.lua @@ -8,6 +8,7 @@ describe('commands', function() 'SCNvimGenerateAssets', 'SCNvimHelp', 'SCNvimRecompile', + 'SCNvimReboot', 'SCNvimStart', 'SCNvimStatusLine', 'SCNvimStop',