Skip to content

Commit 0afc8bb

Browse files
committed
Set process group ID in server to terminate after parent
1 parent 56d04dc commit 0afc8bb

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

lib/ruby_lsp/ruby_lsp_rails/runner_client.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,9 @@ def model(name)
6666

6767
sig { void }
6868
def shutdown
69-
send_notification("shutdown")
70-
Thread.pass while @wait_thread.alive?
69+
warn("Ruby LSP Rails shutting down server")
70+
send_message("shutdown")
71+
sleep(0.1) if @wait_thread.alive? # give the server a bit of time to shutdown
7172
[@stdin, @stdout, @stderr].each(&:close)
7273
end
7374

lib/ruby_lsp/ruby_lsp_rails/server.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ def initialize
3838

3939
sig { void }
4040
def start
41+
# Put this process into the same process group as the parent one, so that it gets terminated when the parent
42+
# does
43+
pgid = Process.getpgid(Process.getsid)
44+
Process.setpgid(0, pgid)
45+
4146
initialize_result = { result: { message: "ok" } }.to_json
4247
$stdout.write("Content-Length: #{initialize_result.length}\r\n\r\n#{initialize_result}")
4348

test/ruby_lsp_rails/runner_client_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class RunnerClientTest < ActiveSupport::TestCase
1414
end
1515

1616
teardown do
17-
@client.shutdown
17+
capture_subprocess_io { @client.shutdown }
1818
assert_predicate @client, :stopped?
1919
end
2020

0 commit comments

Comments
 (0)