summaryrefslogtreecommitdiff
path: root/lib
Commit message (Collapse)AuthorAgeFilesLines
* rubocop: enable the Style/FrozenStringLiteralComment copKyrylo Silin2019-05-08134-0/+268
| | | | This will greatly ease Pry support on Ruby 3.0 (when it's out).
* control_d_handler: don't mutate eval_string within the handlerKyrylo Silin2019-05-043-4/+32
| | | | | | | | | | | | | | | | | This is a preparational step for #1824 (Enabling `# frozen_string_literal: true` in `~/.pryc` crashes most operations) Alternative to https://github.com/pry/pry/pull/2030 (config: delete the `control_d_handler` option) We had to jump a few hoops to change how the handler works. The problem is that mutation is the default expected behaviour. Therefore, we had to change its API. There's no need to pass `eval_string` because `pry_instance` already has it as an attribute. `config.control_d_handler` is a proxy proc, to preserve backwards compatibility with users of old signature (one known user is Pry Byebug). The handler will emit a warning if the old signature is used.
* warning: print file and line of the calling frameKyrylo Silin2019-05-041-2/+2
| | | | | | We want to print the calling frame, so we can point out who exactly triggered it. The current behaviour is less useful (we print the line that called the warning).
* Merge pull request #2031 from pry/warning-moduleKyrylo Silin2019-05-044-14/+34
|\ | | | | Add Pry::Warning
| * Add Pry::WarningKyrylo Silin2019-05-044-14/+34
| | | | | | | | | | | | Quite often, when we deprecate APIs, we want to print a warning. Such a warning would be hard to track without a file and line location. We are trying to be a good citizen and print warnings like Ruby does it.
* | pry_instance: fix Style/AccessModifierDeclarations cop offencesKyrylo Silin2019-05-041-107/+105
|/
* config: add `rc_file` that allows specifying `pryrc` fileKyrylo Silin2019-05-032-15/+22
| | | | | | Keeping this in a constant makes it really hard to test. Moving it to the config and making it configurable seems to be sensible. Now we have a new option and a lot of tests.
* commands/show_info: fix formatting error for C method headerKyrylo Silin2019-05-022-2/+2
| | | | | | | | | | | | | Fixes #2006 (show-source formatting bug in From) In order to test this I had to build Pry from master locally and install it. When I ran `String#initialize` I saw an error that `has_pry_doc` is undefined on the Config class. This makes sense. This option is defined in the pry-doc plugin. As a workaround, I had to change the check to `defined?`. However, in the future, we should make Pry plugin-agnostic - strictly no plugin checks in the code.
* history: cache @history.count to improve performanceKyrylo Silin2019-05-021-6/+8
| | | | | | | | | | | | Fixes #2007 (Performance slowdown on entering lines) By default, when we call `@history.count`, we actually call `Readline::HISTORY.count`. It turns out this is a very expensive call (probably `O(n)`). My history file has over 50k lines and calling `count` makes the problem noticeable by spamming `Enter` as demostrated in the GIF in the issue. We fix this issue by caching history line count and incrementing/resetting when needed.
* Refactor ConfigKyrylo Silin2019-05-0215-546/+359
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Fixes #1843 (Rework the Pry config) There are a few breaking changes. They are mostly minor, so I decided not to indroduce deprecations because it will considerable slow things down. Key changes: * `Pry.lazy` was replaced with `Pry::Configuration::LazyValue` The config accepts three values now `LazyValue`, `MemoizedValue` and simply `Value`. The main difference is that: - `Value` is any value, including procs (so that an option returns a raw proc) - `LazyValue` is a proc that is call on every invocation of an option - `MemoizedValue` is a value that is called only once (and then the option always returns the return value of the ) * `Pry.config.history` was a meta-option that held suboptions. However, the new config doesn't permit that (unless you know what you do) Instead, we introduce a few options. For example: - `Pry.config.history.histignore` becomes `Pry.config.history_ignorelist` - `Pry.config.history.file` becomes `Pry.config.history_file` - and so on This was done so we can simplify configuration merging. Inlining option makes configuration implementation simpler, without losing much. The rule is that you want to keep your options under your prefix (if you are a plugin). Therefore, say, `Pry.config.pry_rescue.*` should be `Pry.config.pry_rescue_*` if you need merging. The rest should behave in a similar fashion (and I rely heavily on our test suite to claim so).
* Reduce the influence of Pry::ConfigKyrylo Silin2019-04-304-4/+7
| | | | | | | This is one of preliminary steps for #1843 (Rework the Pry config). In this commit we replace calls to `Pry::Config` where possible, therefore we reduce coupling between the config and other components.
* pry_instance: factor out command state to be globalcommand-global-stateKyrylo Silin2019-04-295-5/+37
| | | | | | | | | | | | | | | | | This change is aimed to simplify #1843 (Rework the Pry config). Current command state implementation gets in the way. We would like to simplify the Config class. The current implementation penetrates Pry codebase everywhere, and during my rework of the config I discovered that `watch` uses global command state. It means the state should survive `Pry.new` calls. With my (unpublished yet) implementation, the `watch` command fails to do so. I realised that we can refactor command state implementation to be global. It makes sense to me and also helps with the Config refactoring. With help of a dedicated class we can easily manage the command state (resetting).
* commands/watch_expression: use command state instead of configKyrylo Silin2019-04-281-1/+1
| | | | | | It seems like this command defines options on the config as the user uses Pry. This is wrong. We have command state API for this purpose. Configuration should be done before Pry is initialized.
* config: factor out control_d_handler to ControlDHandlerKyrylo Silin2019-04-153-21/+27
|
* config: factor out 'system' to SystemCommandHandlerKyrylo Silin2019-04-153-8/+17
|
* config: factor out exception_handler hook to a separate classexception-handler-refactoringKyrylo Silin2019-04-153-22/+43
|
* config: factor out color printer proc to ColorPrinterKyrylo Silin2019-04-144-10/+10
|
* config: factor out default hook definition to Pry::HooksKyrylo Silin2019-04-142-8/+11
|
* Move history file detection to Pry::HistoryKyrylo Silin2019-04-103-16/+20
| | | | | This makes `Pry::Config` a bit cleaner and history code is better off in `Pry::History`, since it's probably the most expected location.
* Move `default_editor_for_platform` to Pry::EditorKyrylo Silin2019-04-104-12/+12
| | | | | The name strongly suggests that this method belongs to `Pry::Editor` and it makes no sense to have it on `Pry` class.
* spec/command: refactor to cover more, and more clearlyKyrylo Silin2019-04-091-12/+11
|
* command: rename #correct_arg_arity to #normalize_method_argsKyrylo Silin2019-04-083-11/+13
| | | | We also refactor it to use `case` instead of `if`.
* block_command: delete backwards compatibility codeKyrylo Silin2019-04-081-3/+0
| | | | | | This has been "backwards compatible" for 8 years or so, so it's time to drop it to reduce complexity of the codebase. I am not even sure what this is about and it's likely not relevant.
* command: reorder methodsKyrylo Silin2019-04-081-54/+52
| | | | | This order makes more sense to me because it follows traditional scheme: class methods first, instance methods next.
* command: move BlockCommand to a separate fileKyrylo Silin2019-04-083-22/+24
|
* command: move ClassCommand to a separate fileKyrylo Silin2019-04-083-191/+193
|
* command: delete #hooksKyrylo Silin2019-04-081-7/+1
| | | | This was deprecated 4 years ago, so I guess it's time to remove it.
* command_set: refactor specsKyrylo Silin2019-04-041-24/+21
| | | | | | | In this change we: * Used modern RSpec API * Deleted unused methods
* command_set: delete #disabled_commandsKyrylo Silin2019-03-311-11/+0
| | | | | | | | | * the name of the method is not a verb, which is confusing * commands have aliases * we can deprecate commands at the place where they are defined. We would've avoided this case with `edit-method` where the command was deprecated for years but never removed. This is because it was deprecated using `#disabled_commands` at an unexpected location.
* Delete commands/disabled_commandsKyrylo Silin2019-03-314-5/+2
| | | | These comands were 'disabled' 6 years ago, it's about damn time to delete them.
* helpers/command_helpers: add tests, refactor variable namesKyrylo Silin2019-03-303-66/+40
| | | | | | | | | | | | | | | | | First of all, we move the spec file from `spec` to `spec/helpers`. This is where it is supposed to be. Next, we add tests for all the methods that the module defines. During this process I had to change `module_function` to `extend self`. Rubocop doesn't like it for some unknown to me reason, so I had to disable the rule. There's no harm in doing so. Finally, I refactored some methods (low-hanging fruits only) and discovered that the `command_error` method is not necessary at all. All in all, this module is a lot better now but I feel like it shouldn't exist at all, since almost all methods are very specific to certain Pry commands. It's hardly a general purpose module for Pry plugins.
* color_printer: cosmetic refactoringKyrylo Silin2019-03-301-40/+32
| | | | | | | | | Changes: * method extractions * indentation fixes * brackets for methods * clearer variable names
* color_printer: inline OBJ_COLOR so it's testableKyrylo Silin2019-03-301-10/+3
|
* color_printer: require EnglishKyrylo Silin2019-03-281-0/+1
| | | | This is needed for $DEFAULT_OUTPUT to work. Otherwise it's equal to `nil`.
* color_printer: move class documentation above the class definitionKyrylo Silin2019-03-281-1/+1
|
* Stop requiring coderay in files that don't use itKyrylo Silin2019-03-288-13/+0
|
* Factor out all CodeRay code to Pry::SyntaxHighlighterKyrylo Silin2019-03-289-11/+38
| | | | | | | | This moves all the code related syntax highlighting and tokenization to a wrapper class of CodeRay. Benefits: * we reduce duplication (no need to call `scan(code, :ruby).term` everywhere) * swapping CodeRay becomes easier because it's isolated in one class
* rubocop: "fix" the Lint/ShadowedException copKyrylo Silin2019-03-241-1/+1
|
* rubocop: fix the Lint/Void copKyrylo Silin2019-03-241-1/+0
|
* rubocop: fix the Naming/AccessorMethodName copKyrylo Silin2019-03-242-4/+4
|
* rubocop: fix the Naming/BinaryOperatorParameterName copKyrylo Silin2019-03-241-6/+4
|
* rubocop: fix the Naming/ConstantName copKyrylo Silin2019-03-241-2/+2
|
* rubocop: fix the Naming/UncommunicativeMethodParamName copKyrylo Silin2019-03-2411-63/+58
|
* rubocop: fix Naming/HeredocDelimiterNaming copKyrylo Silin2019-03-244-8/+8
|
* rubocop: fix Naming/MemoizedInstanceVariableName offencesKyrylo Silin2019-03-241-1/+1
|
* rubocop: "fix" offences of the Security/Eval copKyrylo Silin2019-03-243-9/+16
|
* rubocop: fix offences of the Style/CaseEquality copKyrylo Silin2019-03-2421-32/+37
|
* rubocop: fix offences of the Style/AccessModifierDeclarations copKyrylo Silin2019-03-235-42/+41
|
* rubocop: fix offences of the Style/AsciiComments copKyrylo Silin2019-03-232-2/+2
|
* rubocop: fix offences of the Style/ClassVars copKyrylo Silin2019-03-231-0/+2
|