Class: RubyLsp::Requests::ShowSyntaxTree
- Inherits:
-
BaseRequest
- Object
- YARP::Visitor
- BaseRequest
- RubyLsp::Requests::ShowSyntaxTree
- 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
-
#initialize(document, range) ⇒ ShowSyntaxTree
constructor
A new instance of ShowSyntaxTree.
- #run ⇒ Object
Methods inherited from BaseRequest
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
#run ⇒ Object
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 |