Sha256: 8460a29c09a258125337a33795431c46207a308f346c5d3b77684766a4106a02

Contents?: true

Size: 1.73 KB

Versions: 16

Compression:

Stored size: 1.73 KB

Contents

# typed: strict
# frozen_string_literal: true

begin
  require "syntax_tree"
  require "syntax_tree/cli"
rescue LoadError
  return
end

module RubyLsp
  module Requests
    module Support
      # :nodoc:
      class SyntaxTreeFormatter
        extend T::Sig
        include Support::Formatter

        sig { void }
        def initialize
          @options =
            T.let(
              begin
                opts = SyntaxTree::CLI::Options.new
                opts.parse(SyntaxTree::CLI::ConfigFile.new.arguments)
                opts
              end,
              SyntaxTree::CLI::Options,
            )
        end

        sig { override.params(uri: URI::Generic, document: RubyDocument).returns(T.nilable(String)) }
        def run_formatting(uri, document)
          path = uri.to_standardized_path
          return if path && @options.ignore_files.any? { |pattern| File.fnmatch?("*/#{pattern}", path) }

          SyntaxTree.format(document.source, @options.print_width, options: @options.formatter_options)
        end

        sig { override.params(uri: URI::Generic, source: String, base_indentation: Integer).returns(T.nilable(String)) }
        def run_range_formatting(uri, source, base_indentation)
          path = uri.to_standardized_path
          return if path && @options.ignore_files.any? { |pattern| File.fnmatch?("*/#{pattern}", path) }

          SyntaxTree.format(source, @options.print_width, base_indentation, options: @options.formatter_options)
        end

        sig do
          override.params(
            uri: URI::Generic,
            document: RubyDocument,
          ).returns(T.nilable(T::Array[Interface::Diagnostic]))
        end
        def run_diagnostic(uri, document)
          nil
        end
      end
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
ruby-lsp-0.23.6 lib/ruby_lsp/requests/support/syntax_tree_formatter.rb
ruby-lsp-0.23.5 lib/ruby_lsp/requests/support/syntax_tree_formatter.rb
ruby-lsp-0.23.4 lib/ruby_lsp/requests/support/syntax_tree_formatter.rb
ruby-lsp-0.23.3 lib/ruby_lsp/requests/support/syntax_tree_formatter.rb
ruby-lsp-0.23.2 lib/ruby_lsp/requests/support/syntax_tree_formatter.rb
ruby-lsp-0.23.1 lib/ruby_lsp/requests/support/syntax_tree_formatter.rb
ruby-lsp-0.23.0 lib/ruby_lsp/requests/support/syntax_tree_formatter.rb
ruby-lsp-0.22.1 lib/ruby_lsp/requests/support/syntax_tree_formatter.rb
ruby-lsp-0.22.0 lib/ruby_lsp/requests/support/syntax_tree_formatter.rb
ruby-lsp-0.21.3 lib/ruby_lsp/requests/support/syntax_tree_formatter.rb
ruby-lsp-0.21.2 lib/ruby_lsp/requests/support/syntax_tree_formatter.rb
ruby-lsp-0.21.1 lib/ruby_lsp/requests/support/syntax_tree_formatter.rb
ruby-lsp-0.21.0 lib/ruby_lsp/requests/support/syntax_tree_formatter.rb
ruby-lsp-0.20.1 lib/ruby_lsp/requests/support/syntax_tree_formatter.rb
ruby-lsp-0.20.0 lib/ruby_lsp/requests/support/syntax_tree_formatter.rb
ruby-lsp-0.19.1 lib/ruby_lsp/requests/support/syntax_tree_formatter.rb