Skip to content

Commit 5c371ed

Browse files
authored
Prevent add-ons from exiting the server process (#3617)
1 parent 238843e commit 5c371ed

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

lib/ruby_lsp/server.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ def process_message(message)
115115
end
116116
rescue DelegateRequestError
117117
send_message(Error.new(id: message[:id], code: DelegateRequestError::CODE, message: "DELEGATE_REQUEST"))
118-
rescue StandardError, LoadError => e
118+
rescue StandardError, LoadError, SystemExit => e
119119
# If an error occurred in a request, we have to return an error response or else the editor will hang
120120
if message[:id]
121121
# If a document is deleted before we are able to process all of its enqueued requests, we will try to read it

test/server_test.rb

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1605,6 +1605,48 @@ def test_something
16051605
})
16061606
end
16071607

1608+
def test_addons_are_unable_to_exit_the_server_process
1609+
Class.new(RubyLsp::Addon) do
1610+
def activate(global_state, outgoing_queue); end
1611+
1612+
def workspace_did_change_watched_files(changes)
1613+
exit
1614+
end
1615+
1616+
def name
1617+
"Bad add-on"
1618+
end
1619+
1620+
def deactivate; end
1621+
1622+
def version
1623+
"0.1.0"
1624+
end
1625+
end
1626+
1627+
@server.load_addons
1628+
1629+
begin
1630+
@server.global_state.index.index_all(uris: [])
1631+
@server.process_message({
1632+
method: "workspace/didChangeWatchedFiles",
1633+
params: {
1634+
changes: [
1635+
{
1636+
uri: URI::Generic.from_path(path: File.join(Dir.pwd, "lib", "server.rb")).to_s,
1637+
type: RubyLsp::Constant::FileChangeType::CHANGED,
1638+
},
1639+
],
1640+
},
1641+
})
1642+
pass
1643+
rescue SystemExit
1644+
flunk("Add-on was able to exit the server process")
1645+
ensure
1646+
RubyLsp::Addon.unload_addons
1647+
end
1648+
end
1649+
16081650
private
16091651

16101652
def wait_for_indexing

0 commit comments

Comments
 (0)