class Solargraph::Parser::CommentRipper

Public Class Methods

new(src, filename = '(ripper)', lineno = 0) click to toggle source
Calls superclass method
# File lib/solargraph/parser/comment_ripper.rb, line 6
def initialize src, filename = '(ripper)', lineno = 0
  super
  @buffer = src
  @buffer_lines = @buffer.lines
end

Public Instance Methods

on_comment(*args) click to toggle source
Calls superclass method
# File lib/solargraph/parser/comment_ripper.rb, line 12
def on_comment *args
  result = super
  if @buffer_lines[result[2][0]][0..result[2][1]].strip =~ /^#/
    chomped = result[1].chomp
    if result[2][0] == 0 && chomped.encode('UTF-8', 'binary', invalid: :replace, undef: :replace, replace: '').match(/^#\s*frozen_string_literal:/)
      chomped = '#'
    end
    @comments[result[2][0]] = Snippet.new(Range.from_to(result[2][0], result[2][1], result[2][0], result[2][1] + chomped.length), chomped)
  end
  result
end
on_embdoc(*args) click to toggle source
Calls superclass method
# File lib/solargraph/parser/comment_ripper.rb, line 31
def on_embdoc *args
  result = super
  chomped = result[1].chomp
  @comments[result[2][0]] = Snippet.new(Range.from_to(result[2][0], result[2][1], result[2][0], result[2][1] + chomped.length), chomped)
  result
end
on_embdoc_beg(*args) click to toggle source
Calls superclass method
# File lib/solargraph/parser/comment_ripper.rb, line 24
def on_embdoc_beg *args
  result = super
  chomped = result[1].chomp
  @comments[result[2][0]] = Snippet.new(Range.from_to(result[2][0], result[2][1], result[2][0], result[2][1] + chomped.length), chomped)
  result
end
on_embdoc_end(*args) click to toggle source
Calls superclass method
# File lib/solargraph/parser/comment_ripper.rb, line 38
def on_embdoc_end *args
  result = super
  chomped = result[1].chomp
  @comments[result[2][0]] = Snippet.new(Range.from_to(result[2][0], result[2][1], result[2][0], result[2][1] + chomped.length), chomped)
  result
end
parse() click to toggle source
Calls superclass method
# File lib/solargraph/parser/comment_ripper.rb, line 45
def parse
  @comments = {}
  super
  @comments
end