Sha256: 2ebad828c57b423d4f384c9fe477bfe3cb9cc2348787d208725e4b6d10f1c0d2

Contents?: true

Size: 1.28 KB

Versions: 17

Compression:

Stored size: 1.28 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: Document).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 do
          override.params(
            uri: URI::Generic,
            document: Document,
          ).returns(T.nilable(T::Array[Interface::Diagnostic]))
        end
        def run_diagnostic(uri, document)
          nil
        end
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
ruby-lsp-0.17.13 lib/ruby_lsp/requests/support/syntax_tree_formatter.rb
ruby-lsp-0.17.12 lib/ruby_lsp/requests/support/syntax_tree_formatter.rb
ruby-lsp-0.17.11 lib/ruby_lsp/requests/support/syntax_tree_formatter.rb
ruby-lsp-0.17.10 lib/ruby_lsp/requests/support/syntax_tree_formatter.rb
ruby-lsp-0.17.9 lib/ruby_lsp/requests/support/syntax_tree_formatter.rb
ruby-lsp-0.17.8 lib/ruby_lsp/requests/support/syntax_tree_formatter.rb
ruby-lsp-0.17.7 lib/ruby_lsp/requests/support/syntax_tree_formatter.rb
ruby-lsp-0.17.6 lib/ruby_lsp/requests/support/syntax_tree_formatter.rb
ruby-lsp-0.17.5 lib/ruby_lsp/requests/support/syntax_tree_formatter.rb
ruby-lsp-0.17.4 lib/ruby_lsp/requests/support/syntax_tree_formatter.rb
ruby-lsp-0.17.3 lib/ruby_lsp/requests/support/syntax_tree_formatter.rb
ruby-lsp-0.17.2 lib/ruby_lsp/requests/support/syntax_tree_formatter.rb
ruby-lsp-0.17.1 lib/ruby_lsp/requests/support/syntax_tree_formatter.rb
ruby-lsp-0.17.0 lib/ruby_lsp/requests/support/syntax_tree_formatter.rb
ruby-lsp-0.16.6 lib/ruby_lsp/requests/support/syntax_tree_formatter.rb
ruby-lsp-0.16.5 lib/ruby_lsp/requests/support/syntax_tree_formatter.rb
ruby-lsp-0.16.4 lib/ruby_lsp/requests/support/syntax_tree_formatter.rb