Skip to content

Commit

Permalink
Merge pull request #2291 from andrehjr/fix-highlight-calling-clear-me…
Browse files Browse the repository at this point in the history
…thod

Fix 'calling clear method' when defined in pry context.
  • Loading branch information
andrehjr committed Oct 28, 2023
2 parents aa6282f + 5a4aa4e commit d5a1f1c
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 6 deletions.
4 changes: 1 addition & 3 deletions lib/pry/indent.rb
Expand Up @@ -281,9 +281,7 @@ def in_string?
# @param [String] string The Ruby to lex
# @return [Array] An Array of pairs of [token_value, token_type]
def tokenize(string)
tokens = SyntaxHighlighter.tokenize(string)
tokens = tokens.tokens.each_slice(2) if tokens.respond_to?(:tokens) # Coderay 1.0.0
tokens.to_a
SyntaxHighlighter.tokenize(string).each_slice(2).to_a
end

# Update the internal state about what kind of strings are open.
Expand Down
3 changes: 1 addition & 2 deletions lib/pry/method.rb
Expand Up @@ -564,8 +564,7 @@ def super_using_ancestors(ancestors, times = 1)
def method_name_from_first_line(first_ln)
return nil if first_ln.strip !~ /^def /

tokens = SyntaxHighlighter.tokenize(first_ln)
tokens = tokens.tokens.each_slice(2) if tokens.respond_to?(:tokens)
tokens = SyntaxHighlighter.tokenize(first_ln).each_slice(2)
tokens.each_cons(2) do |t1, t2|
if t2.last == :method || t2.last == :ident && t1 == [".", :operator]
return t2.first
Expand Down
2 changes: 1 addition & 1 deletion lib/pry/syntax_highlighter.rb
Expand Up @@ -11,7 +11,7 @@ def self.highlight(code, language = :ruby)
end

def self.tokenize(code, language = :ruby)
CodeRay.scan(code, language)
CodeRay::Scanners[language].new(code).tokens
end

def self.keyword_token_color
Expand Down

0 comments on commit d5a1f1c

Please sign in to comment.