summaryrefslogtreecommitdiff
path: root/lib
Commit message (Collapse)AuthorAgeFilesLines
* config: simplify structureconfig-code-formatKyrylo Silin2018-10-287-433/+453
| | | | | | | | | | | * Replace `require_relative` with `require` The project tries to use the `require` form everywhere where possible, which is the common form * `require` from `pry.rb` Spreaded `require` statements where we require internal classes is confusing * Fixed namespace definition for Config classes https://github.com/rubocop-hq/ruby-style-guide#namespace-definition recommends to use explicit nesting
* prompt: refactor to reduce duplicationKyrylo Silin2018-10-281-59/+65
| | | | | | | Since we always need to define two procs that look almost the same, duplication was unavoidable. With help of method wrappers around procs we can reduce it. As a bonus, the class has some YARD annotations now.
* config/default: rename prompt_safe_objects to prompt_safe_contextsKyrylo Silin2018-10-283-4/+4
| | | | | It makes sense to rename it because "objects" we are referring in the context of prompt are actually prompt "contexts".
* Move prompt related code from pry.rb to prompt.rbKyrylo Silin2018-10-287-58/+100
| | | | | It makes a lot more sense to keep these procs under the `Pry::Prompt` namespace than `Pry`, which is already heavily populated by other various things.
* prompt: use explicit nesting for class definitionKyrylo Silin2018-10-281-21/+23
| | | | Per https://github.com/rubocop-hq/ruby-style-guide#namespace-definition
* pry: move INITIAL_PWD to code/code_fileKyrylo Silin2018-10-282-5/+5
| | | | | This constant is not used anywhere else but this file so it makes sense to keep it there.
* repl: fix broken input while using rb-readlineKyrylo Silin2018-10-261-1/+5
| | | | Fixes #1823 (Broken upstream when rb-readline is enabled)
* cli: fix `-f` not suppressing load of `pryrc`Kyrylo Silin2018-10-221-3/+1
| | | | | | | Fixes #1761 (`pry -f` can no longer suppress the loading of .pryrc) If I recall correctly, we split session loading in #1393 because of `Pry.start`. This broke `-f`. I think we can get away with a simple reorder in #parse_options
* indent: tidy up #correct_indentationKyrylo Silin2018-10-221-11/+10
|
* ring: fix #to_a exampleKyrylo Silin2018-10-221-1/+1
|
* repl: correctly calculate overhang for empty linesKyrylo Silin2018-10-221-13/+13
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This improves on https://github.com/pry/pry/pull/1813. I spotted a problem with the way it works: sometimes, if you enter an empty line, the output would span across two lines: ``` [1] pry(main)> [2] pry(main)> [3] pry(main)> ``` This is because overhang is bigger than the current line. I also noticed a bug with method definition, where defining a method leaves an unwanted empty line: ``` [3] pry(main)> def foo | end => :foo ``` To fix this I changed the way we calculate overhang. First and the most important change is that I stopped calculating overhang for emacs mode. This is because it's too risky to introduce this change because it's the default mode and 99% of our users use this, so there's no need to change this behaviour. Another reason is that emacs mode users typically don't use any mode indicators (because emacs has no modes), so it strikes me as a more pragmatic solution. With Vi mode we calculate overhang and still support custom indicators.
* rubocop: fix offences of the Lint/AssignmentInCondition copKyrylo Silin2018-10-219-14/+14
|
* ring: rewrite the class to improve APIKyrylo Silin2018-10-214-99/+64
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Currently, the Ring class is written with help of Hash as backend store. According to the comments, the implementation should behave like a circular buffer, however it doesn't. Upon reaching maximum capacity Ring doesn't replace old elements but keeps writing to new cells, deleting old cells, so that the hash contains `nil` entries. The new implementation is based on Array and seems to be closer to the actual Ring. Older elemens get overwritten with newer ones. This class also includes Enumerable, however none of our APIs take advantage of it, so it seems like an overkill. There was also a problem with with this API because of the above-mentioned nils. For example, if the ring exceeds its maximum size, then callin `Enumerable#first` on it returns `nil`. The new implementation deals with this with removal of Enumerable. The `#[]` syntax is preserved, and now `ring[0]` returns an actual element instead of `nil`. In case users need the Enumerable functionality, they can call `Ring#to_a` to build the array, which supports the wanted methods. As for the speed, the new implementation is: * slower overall because it's thread-safe * faster without mutexes for `#<<` * slower without mutexes for `#[]` Benchmark for old implementation: ``` Warming up -------------------------------------- Ring#<< 223.451k i/100ms Ring#[] 2.837k i/100ms Calculating ------------------------------------- Ring#<< 223.157B (± 3.4%) i/s - 778.097B Ring#[] 82.485M (± 9.4%) i/s - 402.602M in 4.957792s ``` Benchmark for this implementation: ``` Warming up -------------------------------------- Ring#<< 211.587k i/100ms Ring#[] 1.974k i/100ms Calculating ------------------------------------- Ring#<< 211.385B (± 2.8%) i/s - 698.439B Ring#[] 40.292M (±17.0%) i/s - 190.069M in 4.971195s ``` The benchmark: ```rb require './lib/pry' require 'benchmark/ips' Benchmark.ips do |x| empty_ring = Pry::Ring.new(100) populated_ring = Pry::Ring.new(100) 150.times { |i| populated_ring << i } x.report("Ring#<<") do |times| empty_ring << times end x.report("Ring#[]") do |times| populated_ring[0] populated_ring[1] populated_ring[2] populated_ring[-1] populated_ring[-2] populated_ring[-3] populated_ring[1..2] populated_ring[-2..-1] populated_ring[-2..3] populated_ring[0..-1] populated_ring[2..-1] populated_ring[-1..10] populated_ring[-1..0] populated_ring[-1..1] end end ```
* Properly clear after indenting (#1813)W2018-10-201-2/+18
| | | Fixes #1812
* pry_instance: deprecate '#output_array' & '#input_array'Kyrylo Silin2018-10-201-0/+21
| | | | I figured it's better to deprecate them to let plugin authors update their API.
* Rename '{input/output}_array' to '{input/output}_ring'Kyrylo Silin2018-10-207-31/+32
|
* Rename HistoryArray to RingKyrylo Silin2018-10-203-17/+17
| | | | | | | | | | | | `HistoryArray` is a very specific name and it doesn't tell the reader what it *really* means unless you read its code or the docs of the class. On the other hand, `Ring` is a [very well-known term][1], which means exactly what `HistoryArray` does. The alias name for it is circular buffer. I chose `Ring` because it is shorter and used by Golang, so I expect programmers to be familiar with `Ring`. [1]: https://en.wikipedia.org/wiki/Circular_buffer
* rubocop: fix offences of the Style/MultilineTernaryOperator copKyrylo Silin2018-10-205-28/+24
|
* core_extensions: make '__binding__' work with redefined #respond_to?Kyrylo Silin2018-10-171-1/+1
| | | | | | | | | | | | | | | | | | | | | Fixes https://github.com/pry/pry/issues/1596 (Unable to inspect object built from class) Replaces https://github.com/pry/pry/pull/1719 Big thanks to @egwspiti for the repro case and the proposed PR. When a class redefines `respond_to?` or `method_missing` this leads to some problems and confuses Pry. I found another example where Pry misbehaves: ``` [1] pry(main)> cd Class.new { def method_missing(*) end; def respond_to_missing?(*) true end; }.new NoMethodError: private method `eval' called for nil:NilClass from /Users/kyrylo/.gem/ruby/2.4.2/gems/pry-0.11.3/lib/pry/pry_instance.rb:163:in `inject_local' ``` By using `method_defined?` we can work around these bugs since this method doesn't check whether the receiver responds to a certain message but checks whether this method is defined (so we don't redefine it later). Seems like a win-win.
* ommands/ls/formatter,helpers/table: pass local Pry configKyrylo Silin2018-10-162-10/+12
| | | | | | | | | | | | | | | | | Replaces #1713 (Pry local config The following methods take a third required argument, an instance of Pry) This fulfills queries to `_pry_.config` in: * Pry::Helpers.tablify * Pry::Helpers.tablify_to_screen_width * Pry::Helpers.tablify_or_one_line Unlike #1713 this PR doesn't introduce any breaking changes thanks to the default parameter value trick, *except* the `Table#new` signature. Overall, this brings the code in line with how the rest of Pry works.
* rubocop: fix offences of the Lint/StringConversionInInterpolationKyrylo Silin2018-10-163-3/+3
|
* rubocop: fix offences of the Lint/UnneededRequireStatement copKyrylo Silin2018-10-161-2/+0
|
* rubocop: fix offences of the Lint/AmbiguousBlockAssociation coprubocop-lint-ambiguous-block-assosicationKyrylo Silin2018-10-161-3/+4
|
* Fix rubocop empty line after guard clause style violationsArlandis Word2018-10-1437-0/+57
|
* command: fix YARD warning for '#complete'Kyrylo Silin2018-10-141-1/+1
|
* method/disowned: delete unused 'binding' parameterKyrylo Silin2018-10-141-1/+1
| | | | | This was added by 97f1be86b29e41e0a786cf0177d934c4c22e8572 and it feels like a mishap, thus removing.
* commands/watch_expression: add a todo to fix arguments laterKyrylo Silin2018-10-141-0/+2
| | | | | | b031df2f2f5850ee6e9018f33d35f3485a9b0423 added this command but never made use of this variable. The method is being passed an argument but it never uses it. Why? Idk, needs investigation.
* commands/import_set: add a comment to figure out what it does laterKyrylo Silin2018-10-141-0/+1
| | | | | This command is quite obscure: no docs and the parameter it expects is not used in the method. For simplicity, I am leaving the comment to check later.
* commands/amend_line: refactor 'amended_input'Kyrylo Silin2018-10-141-3/+2
| | | | | | The way it's written is still a little bit confusing, however for simplicity of https://github.com/pry/pry/pull/1801 I am leaving this as is and resolving the parameter issue only.
* code: delete unused 'top_module' parameterKyrylo Silin2018-10-141-2/+1
| | | | | | | | This was added by 6fd797d302a63f29d10cf5834bfa25cec7f1ac74. I inspected it closely and I cannot seem to find the reason for this parameter. I don't see it being used anywhere and it doesn't seem to do what it declares. Therefore, I am deleting it.
* rubocop: fix offences of the Lint/UnusedMethodArgument copKyrylo Silin2018-10-1412-12/+12
|
* rubocop: fix offences of the Layout/EmptyLineBetweenDefs copKyrylo Silin2018-10-149-3/+13
|
* rubocop: fix offences of the Style/HashSyntax copKyrylo Silin2018-10-1339-166/+166
|
* rubocop: fix offences of the Layout/EndAlignment copKyrylo Silin2018-10-134-23/+17
|
* rubocop: fix offences of the Layout/ExtraSpacing copKyrylo Silin2018-10-1315-22/+23
|
* helpers/text: delete the 'bright_default' aliasKyrylo Silin2018-10-131-1/+0
| | | | | | | | Replaces https://github.com/pry/pry/pull/1692 (Remove the "default" method from `Pry::Helpers::Text`) This alias serves no real purpose because `bold` is already superior: it's short and understandable.
* Merge pull request #1790 from bambooengineering/handle_null_bytes_in_historyKyrylo Silin2018-10-121-1/+11
|\ | | | | Gracefully handle (ignore) null bytes in history lines
| * Gracefully handle (ignore) null bytes in history linesOwen Stephens2018-10-091-1/+11
| | | | | | | | | | | | | | | | Fixes #1789. Readline is unable to add lines to its history that contain a null byte; we should therefore avoid saving such lines to the history file, and ignore any such lines that are already present in the file.
* | Tweak documentation for pryrcKyrylo Silin2018-10-113-9/+7
| | | | | | | | | | | | | | | | Since `~/.pryrc` was replaced by `$XDG_CONFIG_HOME` and `~/.config/pry/pryrc` in https://github.com/pry/pry/pull/1609, we need to adjust some documentation. `~/.pryrc` becomes simply `pryrc`. I've also edited the wiki with this similar change.
* | Merge pull request #1609 from franklinyu/feat/config-file-pathKyrylo Silin2018-10-101-1/+12
|\ \ | | | | | | Find configuration file in XDG Base Directory
| * | Find configuration file in XDG Base DirectoryFranklin Yu2018-10-091-1/+12
| |/ | | | | | | | | | | Find configuration file in XDG Base Directory only if `PRYRC` is not set, and `~/.pryrc` does not exist, therefore not confusing current users. Note that cache file path is not modified.
* | commands/wtf,pry: add support for Exception#causeAleksandar Kostadinov2018-10-102-0/+22
|/ | | | | Fixes #1449 (support exceptions with cause) Replaces #1525
* Drop support for RubiniusKyrylo Silin2018-10-078-52/+12
| | | | | | | Fixes #1775 (Drop support for Rubinius) I am amazed how many hacks we've had just to support Rubinius. It feels good to be able to remove them and reduce the complexity of the codebase.
* Merge pull request #1771 from DamienRobert/fix_indentKyrylo Silin2018-10-041-1/+1
|\ | | | | repl.rb: guard against negative overhang
| * repl.rb: guard against negative overhangDamien Robert2018-10-031-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | When copy pasting into pry a code like this ~~~ ruby foo do bar #note the tab here done ~~~ then `@indent.indent(val)` replace the tab by two spaces, and so `overhang = original_val.length - indented_val.length` is negative, which yields an Exception in `whitespace = ' ' * overhang`. Guard against this by taking the max with 0.
* | commands/show_source: handle when source is nil but comment exists1452-show-source-fixKyrylo Silin2018-10-042-4/+13
|/ | | | | | | Fixes https://github.com/pry/pry/issues/1452. ($ RuntimeError.exception fails) Alternative to https://github.com/pry/pry/pull/1453.
* Check for existance of cli_options_file before calling realpath()Matthias Winkelmann2018-10-011-1/+3
|
* Add 'Data' as a deprecated constant (#1731)Robert2018-10-011-1/+1
|
* PluginManager#load_cli_options: use the realpath (#1762)Damien Robert2018-10-011-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | * PluginManager#load_cli_options: use the realpath Since ruby 2.5, `require 'foo'` will use the realpath of the file corresponding to foo.rb. However `require '/absolute/path/to/foo.rb'` won't use the realpath. So when $GEM_HOME contains a symlink (ie it is not the realpath), when a pry plugin is loaded, by `activate!`: require gem_name if !active? the real_path of `gem_name` is used. But then in load_cli_options: cli_options_file = File.join(spec.full_gem_path, "lib/#{spec.name}/cli.rb") require cli_options_file if File.exist?(cli_options_file) since the path given is absolute, it will be used directly without realpath. This means that cli.rb may potentially be required twice (once via its realpath if the plugin requires it, the other via its $GEM_HOME path when required by `load_cli_options`), which could raise some errors. Fix this by using the realpath in load_cli_options too. Revision r59984 in ruby 2.5 introduced the use of realpath for load paths, and it was backported to version 2.4 in the minor revision 2.4.4. So only use the realpath ourselves for ruby versions above or equal to 2.4.4.
* Silence output message in Windows when pager doesn't exist.Silver Phoenix2018-09-221-1/+1
| | | | | | | | | | | | | | | | | | | In Windows, if `less` (or another pager) isn't found by `where.exe` it outputs this info to stderr: ``` [1] pry(main)> 1 INFO: Could not find files for the given pattern(s). => 1 ``` The `/Q` flag silences this message: ``` [1] pry(main)> 1 => 1 ``` Tested on Conemu, cmd and PowerShell.