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

Improve method completion for string and regexp that includes word break characters #523

Merged
merged 4 commits into from
Mar 6, 2023

Conversation

tompng
Copy link
Member

@tompng tompng commented Feb 25, 2023

Description

fixes #314

In these case, irb cannot correctly complete string and regexp methods.

  • "()".
  • "hello world".
  • /hello world/.

This pull request fixes it.

Background

Readline and Reline has a configuration completer_quote_characters and completer_word_break_characters of completion target.
It was able to calculate "()". completion target correctly.

In this pull request(#212), Reline.completer_quote_characters = '' is added, which means reline does not consider quotes in completion target calculation.
Completion target calculated by reline changed from "hello world". to world". and the regexp needed to be updated.

Change

I changed string completion regexp to match anything". I also changed regexp for regexp completion.
Since array completion regexp matches to ]., changing string completion regexp to match ". is acceptable(in my opinion).

test/irb/test_completion.rb Outdated Show resolved Hide resolved
@st0012 st0012 added the bug Something isn't working label Mar 1, 2023
@st0012
Copy link
Member

st0012 commented Mar 5, 2023

Completion target calculated by reline changed from "hello world". to world".

Is it possible to resolve the issue by assigning proper completer_quote_characters? This behaviour doesn't seem intuitive to me.

If it does not match, it will fallback to showing all-methods that searches ObjectSpace. Avoiding it will improve performance a little bit.

This should probably be updated.

@tompng
Copy link
Member Author

tompng commented Mar 5, 2023

Is it possible to resolve the issue by assigning proper completer_quote_characters?

I think it's not possible now. If I add Reline.completer_quote_characters = %('"), closing quote is automatically added and will be impossible to input. I didn't figure it out whether it's a reline's bug or just configuration missing.

movie.mp4

@tompng
Copy link
Member Author

tompng commented Mar 5, 2023

This should probably be updated.

OK 👍 I removed the assert_not_inlcude

Copy link
Member

@st0012 st0012 left a comment

Choose a reason for hiding this comment

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

Hmm it looks like a reline's bug, or completer_quote_characters has very limited use cases if that's intentional.
Can you add comments before the changed regexps to give readers some context?

lib/irb/completion.rb Show resolved Hide resolved
lib/irb/completion.rb Show resolved Hide resolved
tompng and others added 2 commits March 6, 2023 02:20
Co-authored-by: Stan Lo <stan001212@gmail.com>
Co-authored-by: Stan Lo <stan001212@gmail.com>
@st0012 st0012 merged commit aa8128c into ruby:master Mar 6, 2023
matzbot pushed a commit to ruby/ruby that referenced this pull request Mar 6, 2023
includes word break characters
(ruby/irb#523)

* Improve method completion for string and regexp that includes word break characters

* Remove completion-test's assert_not_include because candidates no longer include every possible methods

* Add comment about string's method completion regexp

Co-authored-by: Stan Lo <stan001212@gmail.com>

* Add comment about regexp's method completion regexp

Co-authored-by: Stan Lo <stan001212@gmail.com>

---------

ruby/irb@aa8128c533

Co-authored-by: Stan Lo <stan001212@gmail.com>
@tompng tompng deleted the fix_string_regexp_completion_regexp branch March 6, 2023 05:54
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.

The completion dialog following the parentheses is wrong
2 participants