Skip to content
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

Fix history-saving feature #642

Merged
merged 2 commits into from
Jul 14, 2023
Merged

Fix history-saving feature #642

merged 2 commits into from
Jul 14, 2023

Conversation

st0012
Copy link
Member

@st0012 st0012 commented Jul 14, 2023

The HistorySavingAbility module doesn't do anything if the input method class doesn't define HISTORY.

That's why when #633 breaks history-saving, it went unnoticed.

This patch defines RelineInputMethod::HISTORY to avoid this.

Also, instead of checking the existence of input_method_class::HISTORY, we should make every input method class declare if it supports history saving or not. With this approach, similar issues would be caught by tests in the future.

Since the default value is false, it shouldn't break any custom input method that inherits from IRB::InputMethod.

Closes #641

The HistorySavingAbility module doesn't do anything if the input method
class doesn't define HISTORY.

- https://github.com/ruby/irb/blob/3ac96be660bf052902fb4e532c7a46cf294b71eb/lib/irb/history.rb#L10
- https://github.com/ruby/irb/blob/3ac96be660bf052902fb4e532c7a46cf294b71eb/lib/irb/history.rb#L34

This patch defines RelineInputMethod::HISTORY to avoid this.
Instead of checking the existence of `input_method_class::HISTORY`, we should
make every input method class declare if it supports history saving or not.

Since the default value is `false`, it shouldn't break any custom input method
that inherits from `IRB::InputMethod`.
(IRB.conf[:MAIN_CONTEXT] || self).init_save_history
context = (IRB.conf[:MAIN_CONTEXT] || self)
if context.io.support_history_saving? && !context.io.singleton_class.include?(HistorySavingAbility)
context.io.extend(HistorySavingAbility)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I decided to put these in the same place to make future refactor easier.

@tompng tompng merged commit aec7a5b into master Jul 14, 2023
47 checks passed
@tompng tompng deleted the fix-#641 branch July 14, 2023 15:45
matzbot pushed a commit to ruby/ruby that referenced this pull request Jul 14, 2023
(ruby/irb#642)

* Define RelineInputMethod::HISTORY

The HistorySavingAbility module doesn't do anything if the input method
class doesn't define HISTORY.

- https://github.com/ruby/irb/blob/3ac96be660bf052902fb4e532c7a46cf294b71eb/lib/irb/history.rb#L10
- https://github.com/ruby/irb/blob/3ac96be660bf052902fb4e532c7a46cf294b71eb/lib/irb/history.rb#L34

This patch defines RelineInputMethod::HISTORY to avoid this.

* Improve history-saving's ability check

Instead of checking the existence of `input_method_class::HISTORY`, we should
make every input method class declare if it supports history saving or not.

Since the default value is `false`, it shouldn't break any custom input method
that inherits from `IRB::InputMethod`.

ruby/irb@aec7a5b3f5
@modosc
Copy link

modosc commented Jul 14, 2023

thanks for the quick fix - is this going to get a release today?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Development

Successfully merging this pull request may close these issues.

irb stopped saving history since 1.7.2 on macOS M2 Pro Ventura 13.4.1
3 participants