-
Notifications
You must be signed in to change notification settings - Fork 120
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Move rdoc require out of repeated execution path #416
Conversation
Sure. I will check it tomorrow and will let you know it. |
Now I checked the PR's code. This PR's intent is to improve the performance, avoid calling the I suppose if we keep the compatibility from the previous code, when the
But if we don't need to call the |
SHOW_DOC_DIALOG will be called repeatedly whenever the corresponding key is pressed, but we only need to require rdoc once. So ideally the require can be put outside of the proc. And because when rdoc is not available the entire proc will be nonfunctional, we can stop registering the SHOW_DOC_DIALOG if we failed to require rdoc.
Yes. Especially in the case when
Actually, the
So my test cases were actually misleading and I've updated them. If we still want to have the
I think we don't need to call |
Ah, ok. That process looks costy.
Oh I see. Thanks for finding the issue.
The Right now it's not easy to test the non-rdoc case. When we create the Ruby RPM package in the Fedora project, we make the separated
OK. Thanks for checking it. |
Yes 🤦♂️
Yeah I'm aware of that. I'll see if having unit-tests like |
OK. That's great for you to work on covering the no-rdoc case. |
@junaruga I've added a case for the |
IRB.conf[:USE_AUTOCOMPLETE] = true | ||
|
||
without_rdoc do | ||
IRB::RelineInputMethod.new |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The assert commands should be in the wethout_rdoc
block shouldn't be?
without_rdoc do
IRB::RelineInputMethod.new
assert Reline.autocompletion
# doesn't register show_doc dialog
assert_equal empty_proc, Reline.dialog_proc(:show_doc).dialog_proc
end
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it doesn't need to be? Because Reline
's state isn't affected by the without_rdoc
block. We just need to make sure the logic that changes Reline
's state is inside the block.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, you are right. Yes, you don't need to move the assertions.
Reline.add_dialog_proc(:show_doc, original_show_doc_proc, Reline::DEFAULT_DIALOG_CONTEXT) | ||
end | ||
|
||
def without_rdoc(&block) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about moving the without_rdoc
method to the common file test/lib/helper.rb
, as the logic: require 'rdoc'
and resure LoadError
is in other parts too?
$ grep -r rdoc lib/
lib/irb/cmd/help.rb: require 'rdoc/ri/driver'
lib/irb/completion.rb: require 'rdoc'
lib/irb/easter-egg.rb: require "rdoc"
lib/irb/input-method.rb: require 'rdoc'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I want to leave it to the next PR (which I'll open after this is merged) because the goal of this one is to move out of the require "rdoc"
. Increasing the coverage is just a good addition. WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I agree with you. It can be the next PR. Without the test_initialization_with_use_autocomplete_but_without_rdoc
test in this PR, it's still better than the current situation.
Thanks for that! That looks great. I like the approach of the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, thank you!
SHOW_DOC_DIALOG
will be called repeatedly whenever the corresponding key is pressed, but we only need to requirerdoc
once. So ideally the require can be put outside of the proc.And because when
rdoc
is not available the entire proc will be nonfunctional, we can stop registering the SHOW_DOC_DIALOG if we failed to requirerdoc
.