Skip to content

Commit

Permalink
Fully unload add-ons under a mutex when shutting down (#2970)
Browse files Browse the repository at this point in the history
  • Loading branch information
vinistock authored Dec 16, 2024
1 parent 3f86e25 commit fface59
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
9 changes: 9 additions & 0 deletions lib/ruby_lsp/addon.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,15 @@ def load_addons(global_state, outgoing_queue, include_project_addons: true)
errors
end

# Unloads all add-ons. Only intended to be invoked once when shutting down the Ruby LSP server
sig { void }
def unload_addons
@addons.each(&:deactivate)
@addons.clear
@addon_classes.clear
@file_watcher_addons.clear
end

# Get a reference to another add-on object by name and version. If an add-on exports an API that can be used by
# other add-ons, this is the way to get access to that API.
#
Expand Down
6 changes: 2 additions & 4 deletions lib/ruby_lsp/base_server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,9 @@ def start
"$/cancelRequest"
process_message(message)
when "shutdown"
send_log_message("Shutting down Ruby LSP...")

shutdown

@mutex.synchronize do
send_log_message("Shutting down Ruby LSP...")
shutdown
run_shutdown
@writer.write(Result.new(id: message[:id], response: nil).to_hash)
end
Expand Down
2 changes: 1 addition & 1 deletion lib/ruby_lsp/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1123,7 +1123,7 @@ def workspace_dependencies(message)

sig { override.void }
def shutdown
Addon.addons.each(&:deactivate)
Addon.unload_addons
end

sig { void }
Expand Down

0 comments on commit fface59

Please sign in to comment.