summaryrefslogtreecommitdiff
path: root/lib/irb/completion.rb
AgeCommit message (Collapse)Author
2025-01-24Migrate irb and reline to the bundled gemsHiroshi SHIBATA
Notes: Merged: https://github.com/ruby/ruby/pull/12624
2024-11-20[ruby/irb] Store method objects in constantsStan Lo
(https://github.com/ruby/irb/pull/1033) It probably won't speed up things significantly, but these are hot paths and we can save a few method calls per completion/input call. https://github.com/ruby/irb/commit/f1e25ec7ae
2024-11-19[ruby/irb] Don't use delegator to install helper methods to maintomoya ishida
object (https://github.com/ruby/irb/pull/1031) IRB used delegator to install command as a method of frozen main object. Command is not a method now. We can drop it. https://github.com/ruby/irb/commit/2f1c593801
2024-07-05[ruby/irb] Return only commands when completing help command'sStan Lo
argument (https://github.com/ruby/irb/pull/973) The command only takes command names as arguments, so we should only return command names as candidates. This will help users find a command faster as completion will be another useful hint too. https://github.com/ruby/irb/commit/7b6557cc24
2024-04-20[ruby/irb] Stop using ExtendCommandBundle internallyStan Lo
(https://github.com/ruby/irb/pull/925) This module was used to extend both commands and helpers when they're not separated. Now that they are, and we have a Command module, we should move command-related logic to the Command module and update related references. This will make the code easier to understand and refactor in the future. https://github.com/ruby/irb/commit/f74ec97236
2024-04-10[ruby/irb] Command implementation not by methodtomoya ishida
(https://github.com/ruby/irb/pull/824) * Command is not a method * Fix command test * Implement non-method command name completion * Add test for ExtendCommandBundle.def_extend_command * Add helper method install test * Remove spaces in command input parse * Remove command arg unquote in help command * Simplify Statement and handle execution in IRB::Irb * Tweak require, const name * Always install CommandBundle module to main object * Remove considering local variable in command or expression check * Remove unused method, tweak * Remove outdated comment for help command arg Co-authored-by: Stan Lo <[email protected]> --------- https://github.com/ruby/irb/commit/8fb776e379 Co-authored-by: Stan Lo <[email protected]>
2024-03-14[ruby/irb] Rescue from exceptions raised by #nameGo
(https://github.com/ruby/irb/pull/899) * Rescue from exceptions raised by #name Irb might terminate if the class overwrites `name` and raise errors. This commit rescue irb from termination. * fix for other unknown patterns https://github.com/ruby/irb/commit/35b87cf893
2024-02-23[ruby/irb] Turn on frozen literal in filesStan Lo
(https://github.com/ruby/irb/pull/881) https://github.com/ruby/irb/commit/83d90550c2
2024-01-03[ruby/irb] Avoid completing empty inputStan Lo
(https://github.com/ruby/irb/pull/832) The candidate list for empty input is all methods + all variables + all constants + all keywords. It's a long list that is not useful. https://github.com/ruby/irb/commit/812dc2df7b
2023-11-29[ruby/irb] Use gem repl_type_completor, remove type_completiontomoya ishida
implementation (https://github.com/ruby/irb/pull/772) https://github.com/ruby/irb/commit/a4868a5373
2023-11-18[ruby/irb] Fix irb crash on `{}.` completiontomoya ishida
(https://github.com/ruby/irb/pull/764) https://github.com/ruby/irb/commit/07e4d540cc
2023-11-08[ruby/irb] Type based completion using Prism and RBStomoya ishida
(https://github.com/ruby/irb/pull/708) * Add completor using prism and rbs * Add TypeCompletion test * Switchable completors: RegexpCompletor and TypeCompletion::Completor * Add completion info to irb_info * Complete reserved words * Fix [*] (*) {**} and prism's change of KeywordParameterNode * Fix require, frozen_string_literal * Drop prism<=0.16.0 support * Add Completor.last_completion_error for debug report * Retrieve `self` and `Module.nesting` in more safe way * Support BasicObject * Handle lvar and ivar get exception correctly * Skip ivar reference test of non-self object in ruby < 3.2 * BaseScope to RootScope, move method objects constant under Methods * Remove unused Splat struct * Drop deeply nested array/hash type calculation from actual object. Now, calculation depth is 1 * Refactor loading rbs in test, change preload_in_thread not to cache Thread object * Use new option added in prism 0.17.1 to parse code with localvars * Add Prism version check and warn when :type completor cannot be enabled * build_type_completor should skip truffleruby (because endless method definition is not supported) https://github.com/ruby/irb/commit/1048c7ed7a
2023-10-14[ruby/irb] Restore IRB::InputCompletor for compatibilitytomoya ishida
(https://github.com/ruby/irb/pull/730) https://github.com/ruby/irb/commit/77265efc5f
2023-10-12[ruby/irb] Fix require path completion disturbing string methodtomoya ishida
completion (https://github.com/ruby/irb/pull/726) https://github.com/ruby/irb/commit/e42dc74ce0
2023-10-11[ruby/irb] Rename current completor to RegexpCompletor andtomoya ishida
refactored for future extension (https://github.com/ruby/irb/pull/707) * Move completion implementation to completion/regexp_completor for future extension * Remove constant CompletionProc and PerfectMatchedProc and add a class method * Move document display logic to InputCompletor. Each completor only need to implement `completion_caididates` and `doc_namespace` * Move display_document logic to RelineInputMethod * Use RegexpCompletor directly. Not through class method of InputCompletor. * RegexpCompletor extends BaseCompletor, move back definition to completion.rb * Move display_document test to input_method test * Stop re-initialize completor on each completion phase * Store completor to ReadlineInputMethod's iver https://github.com/ruby/irb/commit/1e98521483
2023-06-13[ruby/irb] Use symbol.inspect instead of ":"+symbol.id2name to avoidtomoya ishida
completion candidates including newline characters (https://github.com/ruby/irb/pull/539) https://github.com/ruby/irb/commit/aaf0c46645
2023-06-05[ruby/irb] Fixed string escaping omissionsima1zumi
(https://github.com/ruby/irb/pull/599) I received a `RegexpError` when I typed `::Array[`. ::Array[/Users/mi/ghq/github.com/ruby/irb/lib/irb/completion.rb:236:in `retrieve_completion_data': premature end of char-class: /^Array[/ (RegexpError)
2023-04-05[ruby/irb] Drop Ruby 2.6 supportStan Lo
(https://github.com/ruby/irb/pull/555) * Remove all Ruby 2.6 support * Drop Ruby 2.6 specific testing conditions * Only run Ruby 2.7+ on CI * Bump Ruby requirement to 2.7+ https://github.com/ruby/irb/commit/3f714b616c
2023-04-02[ruby/irb] Remove dead code (https://github.com/ruby/irb/pull/554)Stan Lo
* Remove unused ATTR_TTY and ATTR_PLAIN constants They were added in https://github.com/ruby/irb/commit/d7d26b51bf47a52e4e2339e2ad509ace74f0e4c7 But the references were removed in https://github.com/ruby/irb/commit/1c76845cca59635bb0cf386ced721e34b25d7410 Co-authored-by: Alexandre Terrasa <[email protected]> * Remove unused MethodExtender module It was added in https://github.com/ruby/irb/commit/6cc5d718d7045952ef61d504d624f7e70ce828be but it's not used anywhere. Co-authored-by: Alexandre Terrasa <[email protected]> * Remove unused IRB.irb_at_exit It's not used after https://github.com/ruby/irb/commit/aaf4eb4e9830ae71240ca5d2047c5e3ad20a4044 Co-authored-by: Alexandre Terrasa <[email protected]> * Remove unused InputCompletor.ignored_modules It was added in https://github.com/ruby/irb/commit/88311ce3c84251e6f420246cd14efc96e00888be but the reference was removed in https://github.com/ruby/irb/commit/78c74d24254145a39c4d30168dbcd87dbbbc66dc * Remove unused TracerLoadError constant This constant was added in https://github.com/ruby/irb/commit/cb50fa3738121e4d829cb05b4bcb0d5fb43760c5 but never referenced. --------- https://github.com/ruby/irb/commit/7de0234325 Co-authored-by: Alexandre Terrasa <[email protected]>
2023-03-06[ruby/irb] Improve method completion for string and regexp thattomoya ishida
includes word break characters (https://github.com/ruby/irb/pull/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 <[email protected]> * Add comment about regexp's method completion regexp Co-authored-by: Stan Lo <[email protected]> --------- https://github.com/ruby/irb/commit/aa8128c533 Co-authored-by: Stan Lo <[email protected]>
2023-03-04[ruby/irb] Drop chained methods' completion supportStan Lo
(https://github.com/ruby/irb/pull/529) Consider completion for this example: `foo.bar.b` Without type information, it is hard to know the return value of the `bar` method, so the current implementation interates through `ObjectSpace` to get all possible candidates for the second method. In small projects, the performance and accuracy are acceptable. But in bigger projects, the performance is unacceptable and the accuracy is mostly poor. So this commit drops the support for chained methods' completion.
2023-03-03[ruby/irb] Avoid slow symbol completion when completion target is antomoya ishida
empty symbol (https://github.com/ruby/irb/pull/534) https://github.com/ruby/irb/commit/35697f3ef3
2023-01-11[ruby/irb] Removed Release Version and Revisions for old VCS softwareHiroshi SHIBATA
https://github.com/ruby/irb/commit/07fae94862
2022-11-17[ruby/irb] Fix https://github.com/ruby/irb/pull/295: Ignore JavaPatrick Plenefisch
package reference objects in JRuby https://github.com/ruby/irb/commit/84d030182d
2022-11-07[ruby/irb] Don't lazily retrieve gem specs for completionStan Lo
There are a few downsides of the current approach: 1. Because gem specs are lazily retrieved, this computation happens in every irb completion test case, which is not necessary. (In tests we don't cache the result of `retrieve_files_to_require_from_load_path`) 2. Gem::Specification.latest_specs is sensible to the content of LOAD_PATH. And when combined with 1, tests fail "randomly" if they try to mutate LOAD_PATH, even though the test subject it's something else. So by pre-computing and storing the gem paths in a constant, it guarantees that the computation only happens once and it doesn't get affected by test cases. One argument could be made against the change is that, it'll store unnecessary data for users that disable autocompletion. But the counter-arguments are: 1. Since autocompletion is enabled by default, this should not be the case for most users. 2. For users with autocompletion enabled, IRB already caches the result of `retrieve_files_to_require_from_load_path` in memory, which should have a similar size of GEM_SPECS. And we currently haven't received any report about problems caused by such memory consumption. https://github.com/ruby/irb/commit/c671d39020
2022-10-08[ruby/irb] Sort constant completion's candidatesst0012
https://github.com/ruby/irb/commit/ee9b33c817
2022-10-08[ruby/irb] Lazily evaluate candidates localsst0012
https://github.com/ruby/irb/commit/19a2fcbd87
2022-10-05[ruby/irb] Fixed sort of variables in completionImir Kiyamov
https://github.com/ruby/irb/commit/5842888255
2022-10-03[ruby/irb] Change to explicit method call in completion ↵osyo-manga
(https://github.com/ruby/irb/pull/369) Ensure that methods are called even when local variables are defined. see: https://github.com/ruby/irb/issues/368 https://github.com/ruby/irb/commit/c34d54b8bb
2022-09-21[ruby/irb] Handle non-String $LOAD_PATH values more carefullyst0012
In addition to String values, $LOAD_PATH can also take objects that respond_to the `to_path` method, like Pathname objects. So `irb` should be able to handle those objects too. And if $LOAD_PATH contains objects that can't be converted into String, `irb` should simply ignore it. https://github.com/ruby/irb/commit/b2f562176b
2021-10-13[ruby/irb] Ignore parenthesis during completionKaíque Kandy Koga
Rename method https://github.com/ruby/irb/commit/619aecb412
2021-09-24[ruby/irb] Revert "Show original string byte sequence to debug"aycabta
This reverts commit b42fe5937ab2a605a198ffb866db5ccda541568d. https://github.com/ruby/irb/commit/b22094a16f
2021-09-24[ruby/irb] Show original string byte sequence to debugaycabta
https://github.com/ruby/irb/commit/7a97bb0e56
2021-09-23Revert "Show original string byte sequence to debug"aycabta
This reverts commit b42fe5937ab2a605a198ffb866db5ccda541568d.
2021-09-23[ruby/irb] Ignore any encoding errors while symbol completionNobuyoshi Nakada
https://github.com/ruby/irb/commit/daa65cded1
2021-09-23Show original string byte sequence to debugaycabta
2021-09-21[ruby/irb] Sort shortest files in each load pathsNobuyoshi Nakada
There are two directories where csv*/**/*.rb exist, lib/ and test/, and depending on the order of tests, test/ may be placed before lib/. In that case, as "shortest" names were not sorted, csv/helper.rb will be the first candidate for "csv". https://github.com/ruby/irb/commit/2af7c6bf71
2021-09-21[ruby/irb] Check if Gem::Specification is definedNobuyoshi Nakada
https://github.com/ruby/irb/commit/005ade74dd
2021-09-11[ruby/irb] Ignore invalid 3 colons in completionaycabta
https://github.com/ruby/irb/commit/5e29e3e39c
2021-09-08[ruby/irb] Show lib name first because it's the most common use caseaycabta
https://github.com/ruby/irb/commit/74d635758b
2021-09-08[ruby/irb] Define absolute_path? by myself for backward compatibilityaycabta
https://github.com/ruby/irb/commit/d9c0dc043e
2021-09-08[ruby/irb] Use gem paths to complete "require"aycabta
https://github.com/ruby/irb/commit/c870b23455
2021-09-04[ruby/irb] Retrieve completed receiver that is a module or class correctlyaycabta
https://github.com/ruby/irb/commit/b2324727e1
2021-09-02[ruby/irb] Detect the variable class to show docaycabta
https://github.com/ruby/irb/commit/33b9bec954
2021-03-30[ruby/irb] Prevent the completion from crashing if rdoc is missingAleksandar Ivanov
There are cases where ruby is installed without rdoc and e.g. lib/irb/cmd/help.rb also handles the LoadError Here is how to replicate the issue: ``` $ docker run -it alpine:3.13.3 sh / # apk add ruby ruby-irb ruby-io-console / # irb irb(main):001:0> Class[TAB][TAB] ``` And you end up with something like: ``` irb(main):001:0> ClassTraceback (most recent call last): 34: from /usr/bin/irb:23:in `<main>' 33: from /usr/bin/irb:23:in `load' 32: from /usr/lib/ruby/gems/2.7.0/gems/irb-1.2.6/exe/irb:11:in `<top (required)>' 31: from /usr/lib/ruby/2.7.0/irb.rb:400:in `start' 30: from /usr/lib/ruby/2.7.0/irb.rb:471:in `run' 29: from /usr/lib/ruby/2.7.0/irb.rb:471:in `catch' 28: from /usr/lib/ruby/2.7.0/irb.rb:472:in `block in run' 27: from /usr/lib/ruby/2.7.0/irb.rb:537:in `eval_input' 26: from /usr/lib/ruby/2.7.0/irb/ruby-lex.rb:150:in `each_top_level_statement' 25: from /usr/lib/ruby/2.7.0/irb/ruby-lex.rb:150:in `catch' 24: from /usr/lib/ruby/2.7.0/irb/ruby-lex.rb:151:in `block in each_top_level_statement' 23: from /usr/lib/ruby/2.7.0/irb/ruby-lex.rb:151:in `loop' 22: from /usr/lib/ruby/2.7.0/irb/ruby-lex.rb:154:in `block (2 levels) in each_top_level_statement' 21: from /usr/lib/ruby/2.7.0/irb/ruby-lex.rb:182:in `lex' 20: from /usr/lib/ruby/2.7.0/irb.rb:518:in `block in eval_input' 19: from /usr/lib/ruby/2.7.0/irb.rb:704:in `signal_status' 18: from /usr/lib/ruby/2.7.0/irb.rb:519:in `block (2 levels) in eval_input' 17: from /usr/lib/ruby/2.7.0/irb/input-method.rb:294:in `gets' 16: from /usr/lib/ruby/2.7.0/forwardable.rb:235:in `readmultiline' 15: from /usr/lib/ruby/2.7.0/forwardable.rb:235:in `readmultiline' 14: from /usr/lib/ruby/2.7.0/reline.rb:175:in `readmultiline' 13: from /usr/lib/ruby/2.7.0/reline.rb:238:in `inner_readline' 12: from /usr/lib/ruby/2.7.0/reline.rb:238:in `loop' 11: from /usr/lib/ruby/2.7.0/reline.rb:239:in `block in inner_readline' 10: from /usr/lib/ruby/2.7.0/reline.rb:270:in `read_io' 9: from /usr/lib/ruby/2.7.0/reline.rb:270:in `loop' 8: from /usr/lib/ruby/2.7.0/reline.rb:311:in `block in read_io' 7: from /usr/lib/ruby/2.7.0/reline.rb:240:in `block (2 levels) in inner_readline' 6: from /usr/lib/ruby/2.7.0/reline.rb:240:in `each' 5: from /usr/lib/ruby/2.7.0/reline.rb:241:in `block (3 levels) in inner_readline' 4: from /usr/lib/ruby/2.7.0/reline/line_editor.rb:820:in `input_key' 3: from /usr/lib/ruby/2.7.0/reline/line_editor.rb:608:in `complete' 2: from /usr/lib/ruby/2.7.0/irb/completion.rb:269:in `block in <module:InputCompletor>' 1: from /usr/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:92:in `require' /usr/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:92:in `require': cannot load such file -- rdoc (LoadError) ``` https://github.com/ruby/irb/commit/a2d299c2ac
2021-03-25[ruby/irb] Cache completion files to requireaycabta
https://github.com/ruby/irb/commit/612ebcb311
2021-03-24[ruby/irb] Complete require and require_relativeaycabta
https://github.com/ruby/irb/commit/1c61178b4c
2021-01-08[ruby/irb] do not escape a predicate method for doc namespaceNobuhiro IMAI
* Fixes #88 https://github.com/ruby/irb/commit/d431a30af4
2020-11-05Revert "Prefer #send over #__send__ when it is clear there is no possible ↵NARUSE, Yui
conflict" This reverts commit 4dba0c1a8e3cc08664872e637099c4e7d58d24d3. Matz's comment is "send is not deprecated. __send__ is safer". But "Prefer #send over #__send__" is not reasonable.
2020-11-05Prefer #send over #__send__ when it is clear there is no possible conflictBenoit Daloze
* Reverts part of 3198e7abd70bd2af977f2bb6c967e9df8f91adb0. * If the rule is #send should be deprecated, that should be ruled by matz, there is no such rule currently and gems seem to prefer #send overwhelmingly.