Sha256: 847d4931f069c9272140cc95f182a22b901565e6530c72ea85830c8812267bf2

Contents?: true

Size: 1.18 KB

Versions: 65

Compression:

Stored size: 1.18 KB

Contents

# typed: strict
# frozen_string_literal: true

module RubyLsp
  module Requests
    module Support
      class Annotation
        extend T::Sig
        sig do
          params(
            arity: T.any(Integer, T::Range[Integer]),
            receiver: T::Boolean,
          ).void
        end
        def initialize(arity:, receiver: false)
          @arity = arity
          @receiver = receiver
        end

        sig { params(node: Prism::CallNode).returns(T::Boolean) }
        def match?(node)
          receiver_matches?(node) && arity_matches?(node)
        end

        private

        sig { params(node: Prism::CallNode).returns(T::Boolean) }
        def receiver_matches?(node)
          node_receiver = node.receiver
          (node_receiver && @receiver && node_receiver.location.slice == "T") || (!node_receiver && !@receiver)
        end

        sig { params(node: Prism::CallNode).returns(T::Boolean) }
        def arity_matches?(node)
          node_arity = node.arguments&.arguments&.size || 0

          case @arity
          when Integer
            node_arity == @arity
          when Range
            @arity.cover?(node_arity)
          end
        end
      end
    end
  end
end

Version data entries

65 entries across 65 versions & 2 rubygems

Version Path
ruby-lsp-0.22.1 lib/ruby_lsp/requests/support/annotation.rb
ruby-lsp-0.22.0 lib/ruby_lsp/requests/support/annotation.rb
ruby-lsp-0.21.3 lib/ruby_lsp/requests/support/annotation.rb
ruby-lsp-0.21.2 lib/ruby_lsp/requests/support/annotation.rb
ruby-lsp-0.21.1 lib/ruby_lsp/requests/support/annotation.rb
ruby-lsp-0.21.0 lib/ruby_lsp/requests/support/annotation.rb
ruby-lsp-0.20.1 lib/ruby_lsp/requests/support/annotation.rb
ruby-lsp-0.20.0 lib/ruby_lsp/requests/support/annotation.rb
ruby-lsp-0.19.1 lib/ruby_lsp/requests/support/annotation.rb
ruby-lsp-0.19.0 lib/ruby_lsp/requests/support/annotation.rb
ruby-lsp-0.18.4 lib/ruby_lsp/requests/support/annotation.rb
ruby-lsp-0.18.3 lib/ruby_lsp/requests/support/annotation.rb
ruby-lsp-0.18.2 lib/ruby_lsp/requests/support/annotation.rb
ruby-lsp-0.18.1 lib/ruby_lsp/requests/support/annotation.rb
ruby-lsp-0.18.0 lib/ruby_lsp/requests/support/annotation.rb
ruby-lsp-0.17.17 lib/ruby_lsp/requests/support/annotation.rb
ruby-lsp-0.17.16 lib/ruby_lsp/requests/support/annotation.rb
ruby-lsp-0.17.15 lib/ruby_lsp/requests/support/annotation.rb
ruby-lsp-0.17.14 lib/ruby_lsp/requests/support/annotation.rb
ruby-lsp-0.17.13 lib/ruby_lsp/requests/support/annotation.rb