Sha256: 5106a17617112e7b483f84e2fe88f0f16e34e7fbd33b1600695652a256f0e6e5

Contents?: true

Size: 891 Bytes

Versions: 4

Compression:

Stored size: 891 Bytes

Contents

# typed: strict
# frozen_string_literal: true

module RubyLsp
  module Requests
    # ![Show syntax tree demo](../../show_syntax_tree.gif)
    #
    # Show syntax tree is a custom [LSP
    # request](https://microsoft.github.io/language-server-protocol/specification#requestMessage) that displays the AST
    # for the current document 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")))))
    # ```
    #
    class ShowSyntaxTree < BaseRequest
      extend T::Sig

      sig { override.returns(String) }
      def run
        return "Document contains syntax error" if @document.syntax_error?

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

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
ruby-lsp-0.7.3 lib/ruby_lsp/requests/show_syntax_tree.rb
ruby-lsp-0.7.2 lib/ruby_lsp/requests/show_syntax_tree.rb
ruby-lsp-0.7.1 lib/ruby_lsp/requests/show_syntax_tree.rb
ruby-lsp-0.7.0 lib/ruby_lsp/requests/show_syntax_tree.rb