[前][次][番号順一覧][スレッド一覧]

ruby-changes:58935

From: aycabta <ko1@a...>
Date: Thu, 28 Nov 2019 15:24:01 +0900 (JST)
Subject: [ruby-changes:58935] 7d75e94ea9 (master): Fix regexp to complete complex literal

https://git.ruby-lang.org/ruby.git/commit/?id=7d75e94ea9

From 7d75e94ea967a47e1ca1083f6d1090eaac7ca58e Mon Sep 17 00:00:00 2001
From: aycabta <aycabta@g...>
Date: Thu, 28 Nov 2019 15:15:41 +0900
Subject: Fix regexp to complete complex literal

IRB completion logic always needed exponential notation for complex literal
such as 3e6i but it's bug. I fixed to support complex literal without
exponential notation such as 3i.

diff --git a/lib/irb/completion.rb b/lib/irb/completion.rb
index 232929e..3536e8e 100644
--- a/lib/irb/completion.rb
+++ b/lib/irb/completion.rb
@@ -42,9 +42,7 @@ module IRB https://github.com/ruby/ruby/blob/trunk/lib/irb/completion.rb#L42
       retrieve_completion_data(input).compact.map{ |i| i.encode(Encoding.default_external) }
     }
 
-    def self.retrieve_completion_data(input, doc_namespace = false)
-      bind = IRB.conf[:MAIN_CONTEXT].workspace.binding
-
+    def self.retrieve_completion_data(input, bind: IRB.conf[:MAIN_CONTEXT].workspace.binding, doc_namespace: false)
       case input
       when /^((["'`]).*\2)\.([^.]*)$/
         # String
@@ -145,7 +143,7 @@ module IRB https://github.com/ruby/ruby/blob/trunk/lib/irb/completion.rb#L143
           select_message(receiver, message, candidates, sep)
         end
 
-      when /^(?<num>-?(0[dbo])?[0-9_]+(\.[0-9_]+)?([eE][+-]?[0-9]+i?|r)?)(?<sep>\.|::)(?<mes>[^.]*)$/
+      when /^(?<num>-?(0[dbo])?[0-9_]+(\.[0-9_]+)?(([eE][+-]?[0-9]+)?i?|r)?)(?<sep>\.|::)(?<mes>[^.]*)$/
         # Numeric
         receiver = $~[:num]
         sep = $~[:sep]
@@ -277,7 +275,7 @@ module IRB https://github.com/ruby/ruby/blob/trunk/lib/irb/completion.rb#L275
         end
         return
       end
-      namespace = retrieve_completion_data(matched, true)
+      namespace = retrieve_completion_data(matched, doc_namespace: true)
       return unless matched
       if namespace.is_a?(Array)
         out = RDoc::Markup::Document.new
diff --git a/test/irb/test_completion.rb b/test/irb/test_completion.rb
index 204b321..7cfcbba 100644
--- a/test/irb/test_completion.rb
+++ b/test/irb/test_completion.rb
@@ -19,5 +19,10 @@ module TestIRB https://github.com/ruby/ruby/blob/trunk/test/irb/test_completion.rb#L19
         skip "cannot load irb/completion"
       end
     end
+
+    def test_complete_numeric
+      assert_include(IRB::InputCompletor.retrieve_completion_data("1r.positi", bind: binding), "1r.positive?")
+      assert_empty(IRB::InputCompletor.retrieve_completion_data("1i.positi", bind: binding))
+    end
   end
 end
-- 
cgit v0.10.2


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]