diff --git a/ycmd.el b/ycmd.el index 020b099..8dcc18c 100644 --- a/ycmd.el +++ b/ycmd.el @@ -610,26 +610,29 @@ control.) The newly started server will have a new HMAC secret." (ycmd--start-keepalive-timer)) +(defun ycmd--shutdown () + "Send a shutdown request to the server." + (ycmd--request "/shutdown" nil :parser 'json-read)) + (defun ycmd-close (&optional time-out-secs) "Shutdown any running ycmd server. -Wait TIME-OUT-SECS seconds after `interrupt-process' call for the -ycmd server to end before killing the process with -`delete-process'. +Wait TIME-OUT-SECS seconds after a shutdown request for the ycmd +server to end before killing the process with `delete-process'. This does nothing if no server is running." (interactive) - (unwind-protect - (when (ycmd-running?) - (condition-case nil - (progn - (interrupt-process ycmd--server-process) - (when time-out-secs - (sit-for time-out-secs) - (delete-process ycmd--server-process))) - (error nil)) - (ycmd--global-teardown))) + (when (ycmd-running?) + (unwind-protect + (progn + (ycmd--shutdown) + (when time-out-secs + (sit-for time-out-secs) + (condition-case nil + (delete-process ycmd--server-process) + (error nil)))) + (ycmd--global-teardown))) (ycmd--kill-timer ycmd--keepalive-timer))