File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11module SyntaxSuggest
2- # A visitor that walks the AST and pulls out information
3- # that is too dificult to discern by just looking at tokens
2+ # Walks the Prism AST to extract structural info that cannot be reliably determined from tokens
3+ # alone.
4+ #
5+ # Such as the location of lines that must be logically joined so the search algorithm will
6+ # treat them as one. Example:
7+ #
8+ # source = <<~RUBY
9+ # User # 1
10+ # .where(name: "Earlopain") # 2
11+ # .first # 3
12+ # RUBY
13+ # ast, _tokens = Prism.parse_lex(source).value
14+ # visitor = Visitor.new
15+ # visitor.visit(ast)
16+ # visitor.consecutive_lines_hash # => [1, 2]
17+ #
18+ # This output means that line 1 and line 2 needs to be joined with it's next line.
19+ #
20+ # And determing the location of "endless" method defintition. For example:
21+ #
22+ # source = <<~RUBY
23+ # def square(x) = x * x # 1
24+ # RUBY
25+ #
26+ # ast, _tokens = Prism.parse_lex(source).value
27+ # visitor = Visitor.new
28+ # visitor.endless_def_keyword_locs.first.start_line # => 1
429 class Visitor < Prism ::Visitor
530 attr_reader :endless_def_keyword_locs
631
You can’t perform that action at this time.
0 commit comments