Skip to content

Commit 825ae23

Browse files
committed
split start_server into start_server and start_server_unix variants
Pre 2.0 versions of Ruby cannot handle keyword arguments and thus the introduction of a socket_path keyword argument, even if defaulted to nil, will cause errors. Solution: Add `start_server_unix` and `start_control_unix` functions and then share implementation with the original methods by refactoring the implementations into common methods.
1 parent 9f2f7dc commit 825ae23

File tree

2 files changed

+31
-11
lines changed

2 files changed

+31
-11
lines changed

lib/ruby-debug-ide.rb

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -73,17 +73,23 @@ def interrupt_last
7373
end
7474
end
7575

76-
def start_server(host = nil, port = 1234, notify_dispatcher = false, socket_path: nil)
77-
return if started?
78-
start
79-
start_control(host, port, notify_dispatcher, socket_path: socket_path)
76+
def start_server(host = nil, port = 1234, notify_dispatcher = false)
77+
_start_server_common(host, port, nil, notify_dispatcher)
78+
end
79+
80+
def start_server_unix(socket_path, notify_dispatcher = false)
81+
_start_server_common(nil, 0, socket_path, notify_dispatcher)
8082
end
8183

8284
def prepare_debugger(options)
8385
@mutex = Mutex.new
8486
@proceed = ConditionVariable.new
8587

86-
start_server(options.host, options.port, options.notify_dispatcher, socket_path: options.socket_path)
88+
if options.socket_path.nil?
89+
start_server(options.host, options.port, options.notify_dispatcher)
90+
else
91+
start_server_unix(options.socket_path, options.notify_dispatcher)
92+
end
8793

8894
raise "Control thread did not start (#{@control_thread}}" unless @control_thread && @control_thread.alive?
8995

@@ -111,7 +117,23 @@ def run_prog_script
111117
end
112118
end
113119

114-
def start_control(host, port, notify_dispatcher, socket_path: nil)
120+
def start_control(host, port, notify_dispatcher)
121+
_start_control_common(host, port, nil, notify_dispatcher)
122+
end
123+
124+
def start_control_unix(socket_path, notify_dispatcher)
125+
_start_control_common(nil, 0, socket_path, notify_dispatcher)
126+
end
127+
128+
private
129+
130+
def _start_server_common(host, port, socket_path, notify_dispatcher)
131+
return if started?
132+
start
133+
_start_control_common(host, port, socket_path, notify_dispatcher)
134+
end
135+
136+
def _start_control_common(host, port, socket_path, notify_dispatcher)
115137
raise "Debugger is not started" unless started?
116138
return if @control_thread
117139
@control_thread = DebugThread.new do
@@ -130,7 +152,7 @@ def start_control(host, port, notify_dispatcher, socket_path: nil)
130152
raise "Cannot specify host and socket_file at the same time" if host
131153
File.delete(socket_path) if File.exist?(socket_path)
132154
server = UNIXServer.new(socket_path)
133-
print_greeting_msg $stderr, nil, nil, "Fast", socket_path: socket_path if defined? IDE_VERSION
155+
print_greeting_msg $stderr, nil, nil, "Fast", socket_path if defined? IDE_VERSION
134156
end
135157

136158
return unless server
@@ -166,8 +188,6 @@ def start_control(host, port, notify_dispatcher, socket_path: nil)
166188
end
167189
end
168190

169-
private
170-
171191
def notify_dispatcher_if_needed(host, port, need_notify)
172192
return yield port unless need_notify
173193

lib/ruby-debug-ide/greeter.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
module Debugger
1111

1212
class << self
13-
def print_greeting_msg(stream, host, port, debugger_name = "Fast", socket_path: nil)
13+
def print_greeting_msg(stream, host, port, debugger_name = "Fast", socket_path = nil)
1414
base_gem_name = if defined?(JRUBY_VERSION) || RUBY_VERSION < '1.9.0'
1515
'ruby-debug-base'
1616
elsif RUBY_VERSION < '2.0.0'
@@ -39,4 +39,4 @@ def print_greeting_msg(stream, host, port, debugger_name = "Fast", socket_path:
3939
end
4040
end
4141

42-
end
42+
end

0 commit comments

Comments
 (0)