Sha256: 7583d9a3480d2d76f53ca89add1560efcafd431ae912f93a0d00c21313484782

Contents?: true

Size: 1.59 KB

Versions: 7

Compression:

Stored size: 1.59 KB

Contents

# typed: strict
# frozen_string_literal: true

module RubyLsp
  module DependencyDetector
    class << self
      extend T::Sig

      sig { returns(String) }
      def detected_formatter
        # NOTE: Intentionally no $ at end, since we want to match rubocop-shopify, etc.
        if direct_dependency?(/^rubocop/)
          "rubocop"
        elsif direct_dependency?(/^syntax_tree$/)
          "syntax_tree"
        else
          "none"
        end
      end

      sig { returns(String) }
      def detected_test_library
        # A Rails app may have a dependency on minitest, but we would instead want to use the Rails test runner provided
        # by ruby-lsp-rails.
        if direct_dependency?(/^rails$/)
          "rails"
        # NOTE: Intentionally ends with $ to avoid mis-matching minitest-reporters, etc. in a Rails app.
        elsif direct_dependency?(/^minitest$/)
          "minitest"
        elsif direct_dependency?(/^test-unit/)
          "test-unit"
        elsif direct_dependency?(/^rspec/)
          "rspec"
        else
          "unknown"
        end
      end

      sig { returns(T::Boolean) }
      def typechecker?
        direct_dependency?(/^sorbet/) || direct_dependency?(/^sorbet-static-and-runtime/)
      end

      sig { params(gem_pattern: Regexp).returns(T::Boolean) }
      def direct_dependency?(gem_pattern)
        Bundler.with_original_env { Bundler.default_gemfile } &&
          Bundler.locked_gems.dependencies.keys.grep(gem_pattern).any?
      rescue Bundler::GemfileNotFound
        false
      end
    end

    HAS_TYPECHECKER = T.let(typechecker?, T::Boolean)
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

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