summaryrefslogtreecommitdiff
path: root/lib/irb/context.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
2025-01-22[ruby/irb] Show a quick preview of inspect result before pagertomoya ishida
launch (https://github.com/ruby/irb/pull/1040) * Quickly show inspect preview even if pretty_print takes too much time * Show a message "Inspecting..." while generating pretty_print content * Update inspecting message Co-authored-by: Stan Lo <[email protected]> * Update rendering test for preparing inspect message * Don't show preview if pretty_print does not take time --------- https://github.com/ruby/irb/commit/03c36586e6 Co-authored-by: Stan Lo <[email protected]> Notes: Merged: https://github.com/ruby/ruby/pull/12612
2025-01-22[ruby/irb] Add copy command (https://github.com/ruby/irb/pull/1044)Prajjwal Singh
Closes https://github.com/ruby/irb/pull/753 https://github.com/ruby/irb/commit/a24ac53d48 Notes: Merged: https://github.com/ruby/ruby/pull/12612
2025-01-12[ruby/irb] Group private methods together in `IRB::Context`Stan Lo
(https://github.com/ruby/irb/pull/1064) This makes them easier to find and matches the convention of the codebase. https://github.com/ruby/irb/commit/ce8fa6857c
2025-01-10[ruby/irb] Gracefully handle incorrect command aliasesStan Lo
(https://github.com/ruby/irb/pull/1059) * Gracefully handle incorrect command aliases Even if the aliased target is a helper method or does not exist, IRB should not crash. This commit warns users in such cases and treat the input as normal expression. * Streamline command parsing and introduce warnings for incorrect command aliases https://github.com/ruby/irb/commit/9fc14eb74b
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-20[ruby/irb] Move main object's safe call logic to ContextStan Lo
(https://github.com/ruby/irb/pull/1034) https://github.com/ruby/irb/commit/9750fa23cc
2024-10-06[ruby/irb] Change default completor from regexp to auto, trytomoya ishida
TypeCompletor and fallback to RegexpCompletor. (https://github.com/ruby/irb/pull/1010) https://github.com/ruby/irb/commit/bb6a99d815
2024-09-20[ruby/irb] Fix debug command in nomultiline modetomoya ishida
(https://github.com/ruby/irb/pull/1006) * Fix debug command in nomultiline mode * context.colorize_code -> context.colorize_input https://github.com/ruby/irb/commit/71f4d6bfb5
2024-09-12[ruby/irb] Remove KEYWORD_ALIASES which handled special alias nametomoya ishida
of irb_break irb_catch and irb_next command (https://github.com/ruby/irb/pull/1004) * Remove KEYWORD_ALIASES which handled special alias name of irb_break irb_catch and irb_next command * Remove unused instance variable user_aliases Co-authored-by: Stan Lo <[email protected]> --------- https://github.com/ruby/irb/commit/f256d7899f Co-authored-by: Stan Lo <[email protected]>
2024-08-27[ruby/irb] Move parse_command method to ContextStan Lo
(https://github.com/ruby/irb/pull/993) Since Context dictates whether a line is a command or an expression, moving the parse_command method to Context makes the relationship more explicit. https://github.com/ruby/irb/commit/9a4487af61
2024-06-18[ruby/irb] Improve how command calls' return value is handledStan Lo
(https://github.com/ruby/irb/pull/972) In #934, we changed command calls to return nil only. This PR improves the behaviour even further by: - Not echoing the `nil` returned by command calls - Not overriding previous return value stored in `_` with the `nil` from commands https://github.com/ruby/irb/commit/c844176842
2024-05-10[ruby/irb] Add a new initialization step to validate IRB.conf'sStan Lo
values (https://github.com/ruby/irb/pull/953) Currently, users can only find out that they have set a wrong value for IRB configs when the value is used, with opaque error messages like "comparison of Integer with true failed (TypeError)". This commit adds a new initialization step to validate the values of some IRB configs, so that users can find out about the wrong values during the initialization of IRB. https://github.com/ruby/irb/commit/af8ef2948b
2024-05-04[ruby/irb] Use flag instead of caller for `debug`'s binding.irbStan Lo
check (https://github.com/ruby/irb/pull/947) https://github.com/ruby/irb/commit/4a4d7a4279
2024-05-02Sync IRB 241e061Stan Lo
2024-04-26[ruby/irb] Suppress command return valuesStan Lo
(https://github.com/ruby/irb/pull/934) Since commands can't be chained with methods, their return values are not intended to be used. But if IRB keeps storing command return values as the last value, and print them, users may rely on such implicit behaviour. So to avoid such confusion, this commit suppresses command's return values. It also updates some commands that currently rely on this implicit behaviour. https://github.com/ruby/irb/commit/fa96bea76f
2024-04-12[ruby/irb] Pass statements to Context#evaluateStan Lo
(https://github.com/ruby/irb/pull/920) This has a few benefits: - We can keep hiding the evaluation logic inside the Context level, which has always been the convention until #824 was merged recently. - Although not an official API, gems like `debug` and `mission_control-jobs` patch `Context#evaluate` to wrap their own logic around it. This implicit contract was broken after #824, and this change restores it. In addition to the refactor, I also converted some context-level evaluation tests into integration tests, which are more robust and easier to maintain. https://github.com/ruby/irb/commit/b32aee4068
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-01[ruby/irb] Restructure workspace managementStan Lo
(https://github.com/ruby/irb/pull/888) * Remove dead irb_level method * Restructure workspace management Currently, workspace is an attribute of IRB::Context in most use cases. But when some workspace commands are used, like `pushws` or `popws`, a workspace will be created and used along side with the original workspace attribute. This complexity is not necessary and will prevent us from expanding multi-workspace support in the future. So this commit introduces a @workspace_stack ivar to IRB::Context so IRB can have a more natural way to manage workspaces. * Fix pushws without args * Always display workspace stack after related commands are used https://github.com/ruby/irb/commit/61560b99b3
2024-02-25[ruby/irb] Refactor IRB::Context#promptingStan Lo
(https://github.com/ruby/irb/pull/889) https://github.com/ruby/irb/commit/7b323ee514
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-02-23[ruby/irb] Unroll extension method generationStan Lo
(https://github.com/ruby/irb/pull/882) * Unroll extension method generation Given we only have 2 remaining extension setter methods, both of which only take 1 argument and don't have any alias, the current method generation logic is overly complicated. This commit simplifies the method generation logic by simply defining the methods directly in the `IRB::Context` class. * Fix use_loader extension https://github.com/ruby/irb/commit/67eba5401b
2024-02-13[ruby/irb] Refactor eval_path and `SourceFinder::Source`Stan Lo
(https://github.com/ruby/irb/pull/870) * Assign `@eval_path` through `irb_path=` method This simplifies the original caching logic for the `eval_path` method and makes it easier to understand. * Refactor SourceFinder::Source https://github.com/ruby/irb/commit/c63e4c4035
2024-02-12[ruby/irb] Powerup show_source by enabling RubyVM.keep_script_linestomoya ishida
(https://github.com/ruby/irb/pull/862) * Powerup show_source by enabling RubyVM.keep_script_lines * Add file_content field to avoid reading file twice while show_source * Change path passed to eval, don't change irb_path. * Encapsulate source coloring logic and binary file check insode class Source * Add edit command testcase when irb_path does not exist * Memoize irb_path existence to reduce file existence check calculating eval_path https://github.com/ruby/irb/commit/239683a937
2024-02-07[ruby/irb] Polish tracer integration and testsStan Lo
(https://github.com/ruby/irb/pull/864) * Remove useless ivar * Simplify tracer test setup * Treat tracer like a normal development dependency * Only require ext/tracer when value is truthy * Make tracer integration skip IRB traces https://github.com/ruby/irb/commit/a97a4129a7
2024-02-06[ruby/irb] Fix usage of tracer gem and add testsNuno Silva
(https://github.com/ruby/irb/pull/857) The new tests are skipped when ruby below 3.1, as it was a default gem on it, and in a version we do not support. This also move definition of `use_tracer` to module Context instead of monkey patch. https://github.com/ruby/irb/commit/08834fbd5f
2024-01-25[ruby/irb] Synatx ==> Syntaxydah
https://github.com/ruby/irb/commit/2ffacaa031
2024-01-06[ruby/irb] Refactor exit commandStan Lo
(https://github.com/ruby/irb/pull/835) * Remove unnecessary code from the exit command's implementation 1. The parameters of `IRB.irb_exit` were never used. But there are some libraries seem to call it with arguments + it's declared on the top-level IRB constant. So I changed the params to anonymous splat instead of removing them. 2. `Context#exit` was completely unnecessary as `IRB.irb_exit` doesn't use the `@irb` instance it passes. And since it's (or should be treated as) a private method, I simply removed it. 3. The `exit` command doesn't use the status argument it receives at all. But to avoid raising errors on usages like `exit 1`, I changed the argument to anonymous splat instead removing it. * Make exit an actual command * Update readme https://github.com/ruby/irb/commit/452b543a65
2023-12-12[ruby/irb] [DOC] RDoc for module IRBBurdette Lamar
(https://github.com/ruby/irb/pull/738) [DOC] RDoc for module IRB https://github.com/ruby/irb/commit/f3a0626298
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-26[ruby/irb] Display aliases in help messageStan Lo
(https://github.com/ruby/irb/pull/788) Similar to Pry, it displays user-defined aliases in the help message with a dedicated section. With the current default aliases, it looks like: ``` ...other sections... Aliases $ Alias for `show_source` @ Alias for `whereami` ``` https://github.com/ruby/irb/commit/2a0eacc891
2023-11-22[ruby/irb] Require prism >= 0.18.0 (MatchWriteNode#targets andtomoya ishida
CaseMatchNode) (https://github.com/ruby/irb/pull/778) https://github.com/ruby/irb/commit/943c14b12e
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-08-29[ruby/irb] Print deprecation message for prompt_n methodsStan Lo
(https://github.com/ruby/irb/pull/691) They were removed in #685, but we should still keep them to avoid breaking changes to tools like Chef. https://github.com/chef/chef/blob/533ff089479763f29045e4e6ddf388b73fc99338/lib/chef/shell.rb#L138 https://github.com/ruby/irb/commit/b585e0c835
2023-08-29[ruby/irb] Remove unused `PROMPT_N`Summer ☀️
(https://github.com/ruby/irb/pull/685) https://github.com/ruby/irb/commit/66e69fa0dc
2023-08-13[ruby/irb] Support seamless integration with ruby/debugStan Lo
(https://github.com/ruby/irb/pull/575) * Support native integration with ruby/debug * Prevent using multi-irb and activating debugger at the same time Multi-irb makes a few assumptions: - IRB will manage all threads that host sub-irb sessions - All IRB sessions will be run on the threads created by IRB itself However, when using the debugger these assumptions are broken: - `debug` will freeze ALL threads when it suspends the session (e.g. when hitting a breakpoint, or performing step-debugging). - Since the irb-debug integration runs IRB as the debugger's interface, it will be run on the debugger's thread, which is not managed by IRB. So we should prevent the 2 features from being used at the same time. To do that, we check if the other feature is already activated when executing the commands that would activate the other feature. https://github.com/ruby/irb/commit/d8fb3246be
2023-08-09[ruby/irb] Fix nested IRB sessions' history savingStan Lo
(https://github.com/ruby/irb/pull/652) 1. Dynamically including `HistorySavingAbility` makes things unnecessarily complicated and should be avoided. 2. Because both `Reline` and `Readline` use a single `HISTORY` constant to store history data. When nesting IRB sessions, only the first IRB session should handle history loading and saving so we can avoid duplicating history. 3. History saving callback should NOT be stored in `IRB.conf` as it's recreated every time `IRB.setup` is called, which would happen when nesting IRB sessions. https://github.com/ruby/irb/commit/0fef0ae160
2023-07-14[ruby/irb] Fix history-saving featureStan Lo
(https://github.com/ruby/irb/pull/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`. https://github.com/ruby/irb/commit/aec7a5b3f5
2023-07-03[ruby/irb] Stop treating history-saving logic as extensionStan Lo
(https://github.com/ruby/irb/pull/613) Since `IRB.conf[:SAVE_HISTORY]` is assigned with 1000 by default, history-saving is a feature enabled by default. So it should not be treated as an extension, which adds unnecessary complexity to the code.
2023-06-30[ruby/irb] Reduce internal operations' exposure to benchmarkingStan Lo
(https://github.com/ruby/irb/pull/618) * Test last value is assigned with measure enabled * Remove unnecessary `result` variable `Context#evaluate` always assigns the result of the evaluation to `_` so we don't need to do it in `Irb#eval_input`. * Move benchmarking logic into `Context#evaluate` Current location of the benchmarking logic is too high up and includes operations like command loading and argument transformation, which should be excluded. So this commit moves it into `Context#evaluate` to reduce the noise. We don't move it further down to `Workspace#evaluate` because `Context` is an argument of the measure block, which is not available in `Workspace`.
2023-06-27[ruby/irb] Remove keyword exception from Context#evaluate becausetomoya ishida
the value is always nil (https://github.com/ruby/irb/pull/617) https://github.com/ruby/irb/commit/62691384f8
2023-06-27[ruby/irb] Move input line mutation out of `Context#evaluate`Stan Lo
(https://github.com/ruby/irb/pull/615) This makes sure `Context#evaluate` really just evaluates the input. It will also make #575's implementation cleaner.
2023-02-18[ruby/irb] Remove unused context argument from Worksapce#evaluateStan Lo
(https://github.com/ruby/irb/pull/488) The context argument was introduced in this change: https://github.com/ruby/irb/commit/6806669d178f90f38b99c144bdfee06bdb93a229#diff-296327851fb7a2c307c2d0693b769f58c01aaf315972f290500d10081ee200a9 perhaps for potential usages. But after that it's never used.
2023-01-11[ruby/irb] Formatting to header stylesHiroshi SHIBATA
https://github.com/ruby/irb/commit/cef125850d
2023-01-11[ruby/irb] Removed Release Version and Revisions for old VCS softwareHiroshi SHIBATA
https://github.com/ruby/irb/commit/07fae94862
2022-11-21[ruby/irb] Add commands to start and use the debuggerTakashi Kokubun
(https://github.com/ruby/irb/pull/449) * Seamlessly integrate a few debug commands * Improve the break command support * Utilize skip_src option if available * Add step and delete commands * Write end-to-end tests for each debugger command * Add documentation * Add backtrace, info, catch commands https://github.com/ruby/irb/commit/976100c1c2
2022-11-15[ruby/irb] Deprecate USE_RELINE and USE_REIDLINEst0012
Based on this commit: https://github.com/ruby/irb/commit/93f87ec65344b44123b0150a5fc07de1fd4c80c4 It appears that the maintainer @aycabta wanted to deprecate any `USE_*LINE` configs in favor of `USE_MULTILINE`. So we should deprecate `USE_RELINE` as well. https://github.com/ruby/irb/commit/478f19f3ae
2022-11-07[ruby/irb] Support non-string input in show_sourceTakashi Kokubun
(https://github.com/ruby/irb/pull/430) * Support non-string input in show_source * Test show_source as a method
2022-11-03[ruby/irb] Allow non-identifier aliases like Pry's @ and $Takashi Kokubun
(https://github.com/ruby/irb/pull/426) * Allow non-identifier aliases * Move the configuration to IRB.conf * Avoid abusing method lookup for symbol aliases * Add more alias tests * A small optimization * Assume non-nil Context * Load IRB.conf earlier https://github.com/ruby/irb/commit/e23db5132e
2022-10-18[ruby/irb] Always use local variables in current context to parse code ↵tomoya ishida
(https://github.com/ruby/irb/pull/397) * Use local_variables for colorize, code_block_open check, nesting_level and assignment_expression check * Check if expression is an assignment BEFORE evaluating it. evaluate might define new localvars and change result of assignment_expression? * Add local_variables dependent code test * pend local variable dependent test on truffleruby code_block_open is not working on truffleruby * Always pass context to RubyLex#lex * Rename local_variable_assign_code generator method name * Add assignment expression truncate test * Add Context#local_variables and make generate_local_variables_assign_code more simple * Update lib/irb/input-method.rb Co-authored-by: Stan Lo <[email protected]> * Add a comment why assignment expression check should be done before evaluate https://github.com/ruby/irb/commit/c8b3877281 Co-authored-by: Stan Lo <[email protected]> Co-authored-by: Takashi Kokubun <[email protected]>