Skip to content

Commit

Permalink
Fix DAP's completion request with new IRB's completor
Browse files Browse the repository at this point in the history
In IRB 1.8.2, the completor's design and API has been changed and thus
would break DAP server's completion request. This commit fixes the
issue by introducing a `Completor` class that abstracts away the
differences between the old and new completor.
  • Loading branch information
st0012 committed Oct 13, 2023
1 parent 4e70b17 commit 49779e4
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
22 changes: 22 additions & 0 deletions lib/debug/completor.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# frozen_string_literal: true

require "irb/completion"

module DEBUGGER__
class Completor
class << self
# old IRB completion API
if defined?(IRB::InputCompletor)
def retrieve_completion_data(input, binding)
IRB::InputCompletor.retrieve_completion_data(input, bind: binding).compact
end
else
COMPLETOR = IRB::RegexpCompletor.new

def retrieve_completion_data(input, binding)
COMPLETOR.retrieve_completion_data(input, bind: binding, doc_namespace: false).compact
end
end
end
end
end
4 changes: 3 additions & 1 deletion lib/debug/server_dap.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
require 'tmpdir'
require 'fileutils'

require_relative 'completor'

module DEBUGGER__
module UI_DAP
SHOW_PROTOCOL = ENV['DEBUG_DAP_SHOW_PROTOCOL'] == '1' || ENV['RUBY_DEBUG_DAP_SHOW_PROTOCOL'] == '1'
Expand Down Expand Up @@ -980,7 +982,7 @@ def process_dap args
frame = get_frame(fid)

if (b = frame&.binding) && word = text&.split(/[\s\{]/)&.last
words = IRB::InputCompletor::retrieve_completion_data(word, bind: b).compact
words = Completor.retrieve_completion_data(word, b)
end

event! :protocol_result, :completions, req, targets: (words || []).map{|phrase|
Expand Down

0 comments on commit 49779e4

Please sign in to comment.