Sha256: fdcd20d7919ebbf0ad658cd98113fbcdfe9b45e513adce8ba2c466badd0e0b84

Contents?: true

Size: 1.08 KB

Versions: 13

Compression:

Stored size: 1.08 KB

Contents

# typed: strict
# frozen_string_literal: true

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

require "singleton"

module RubyLsp
  module Requests
    module Support
      # :nodoc:
      class SyntaxTreeFormattingRunner
        extend T::Sig
        include Singleton
        include Support::FormatterRunner

        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: Document).returns(T.nilable(String)) }
        def run(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
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
ruby-lsp-0.15.0 lib/ruby_lsp/requests/support/syntax_tree_formatting_runner.rb
ruby-lsp-0.14.6 lib/ruby_lsp/requests/support/syntax_tree_formatting_runner.rb
ruby-lsp-0.14.5 lib/ruby_lsp/requests/support/syntax_tree_formatting_runner.rb
ruby-lsp-0.14.4 lib/ruby_lsp/requests/support/syntax_tree_formatting_runner.rb
ruby-lsp-0.14.3 lib/ruby_lsp/requests/support/syntax_tree_formatting_runner.rb
ruby-lsp-0.14.2 lib/ruby_lsp/requests/support/syntax_tree_formatting_runner.rb
ruby-lsp-0.14.1 lib/ruby_lsp/requests/support/syntax_tree_formatting_runner.rb
ruby-lsp-0.14.0 lib/ruby_lsp/requests/support/syntax_tree_formatting_runner.rb
ruby-lsp-0.13.4 lib/ruby_lsp/requests/support/syntax_tree_formatting_runner.rb
ruby-lsp-0.13.3 lib/ruby_lsp/requests/support/syntax_tree_formatting_runner.rb
ruby-lsp-0.13.2 lib/ruby_lsp/requests/support/syntax_tree_formatting_runner.rb
ruby-lsp-0.13.1 lib/ruby_lsp/requests/support/syntax_tree_formatting_runner.rb
ruby-lsp-0.13.0 lib/ruby_lsp/requests/support/syntax_tree_formatting_runner.rb