Sha256: 9abf4c19db715133df3e841af74ee9ebb99f56d280314d34f3ff9493ded212bc

Contents?: true

Size: 1.18 KB

Versions: 9

Compression:

Stored size: 1.18 KB

Contents

# typed: strict
# frozen_string_literal: true

require "syntax_tree/cli"
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)
          relative_path = Pathname.new(T.must(uri.to_standardized_path || uri.opaque))
            .relative_path_from(T.must(WORKSPACE_URI.to_standardized_path))
          return if @options.ignore_files.any? { |pattern| File.fnmatch(pattern, relative_path) }

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

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
ruby-lsp-0.10.1 lib/ruby_lsp/requests/support/syntax_tree_formatting_runner.rb
ruby-lsp-0.10.0 lib/ruby_lsp/requests/support/syntax_tree_formatting_runner.rb
ruby-lsp-0.9.4 lib/ruby_lsp/requests/support/syntax_tree_formatting_runner.rb
ruby-lsp-0.9.3 lib/ruby_lsp/requests/support/syntax_tree_formatting_runner.rb
ruby-lsp-0.9.2 lib/ruby_lsp/requests/support/syntax_tree_formatting_runner.rb
ruby-lsp-0.9.1 lib/ruby_lsp/requests/support/syntax_tree_formatting_runner.rb
ruby-lsp-0.9.0 lib/ruby_lsp/requests/support/syntax_tree_formatting_runner.rb
ruby-lsp-0.8.1 lib/ruby_lsp/requests/support/syntax_tree_formatting_runner.rb
ruby-lsp-0.8.0 lib/ruby_lsp/requests/support/syntax_tree_formatting_runner.rb