Class: RubyLsp::Requests::ShowSyntaxTree

Inherits:
BaseRequest
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/ruby_lsp/requests/show_syntax_tree.rb

Overview

![Show syntax tree demo](../../show_syntax_tree.gif)

Show syntax tree is a custom [LSP request](microsoft.github.io/language-server-protocol/specification#requestMessage) that displays the AST for the current document or for the current selection in a new tab.

# Example

“‘ruby # Executing the Ruby LSP: Show syntax tree command will display the AST for the document 1 + 1 # (program (statements ((binary (int “1”) + (int “1”))))) “`

Instance Method Summary collapse

Methods inherited from BaseRequest

#visit_all

Methods included from RubyLsp::Requests::Support::Common

#create_code_lens, #markdown_from_index_entries, #range_from_location, #range_from_node, #visible?

Constructor Details

#initialize(document, range) ⇒ ShowSyntaxTree

Returns a new instance of ShowSyntaxTree.



24
25
26
27
28
# File 'lib/ruby_lsp/requests/show_syntax_tree.rb', line 24

def initialize(document, range)
  super(document)

  @range = range
end

Instance Method Details

#runObject



31
32
33
34
35
36
37
# File 'lib/ruby_lsp/requests/show_syntax_tree.rb', line 31

def run
  return ast_for_range if @range

  output_string = +""
  PP.pp(@document.tree, output_string)
  output_string
end