lib/ruby_indexer/lib/ruby_indexer/entry.rb in ruby-lsp-0.13.1 vs lib/ruby_indexer/lib/ruby_indexer/entry.rb in ruby-lsp-0.13.2

- old
+ new

@@ -79,13 +79,17 @@ extend T::Helpers extend T::Sig abstract! + # Name includes just the name of the parameter, excluding symbols like splats sig { returns(Symbol) } attr_reader :name + # Decorated name is the parameter name including the splat or block prefix, e.g.: `*foo`, `**foo` or `&block` + alias_method :decorated_name, :name + sig { params(name: Symbol).void } def initialize(name:) @name = name end end @@ -98,29 +102,52 @@ class OptionalParameter < Parameter end # An required keyword method parameter, e.g. `def foo(a:)` class KeywordParameter < Parameter + sig { override.returns(Symbol) } + def decorated_name + :"#{@name}:" + end end # An optional keyword method parameter, e.g. `def foo(a: 123)` class OptionalKeywordParameter < Parameter + sig { override.returns(Symbol) } + def decorated_name + :"#{@name}:" + end end # A rest method parameter, e.g. `def foo(*a)` class RestParameter < Parameter DEFAULT_NAME = T.let(:"<anonymous splat>", Symbol) + + sig { override.returns(Symbol) } + def decorated_name + :"*#{@name}" + end end # A keyword rest method parameter, e.g. `def foo(**a)` class KeywordRestParameter < Parameter DEFAULT_NAME = T.let(:"<anonymous keyword splat>", Symbol) + + sig { override.returns(Symbol) } + def decorated_name + :"**#{@name}" + end end # A block method parameter, e.g. `def foo(&block)` class BlockParameter < Parameter DEFAULT_NAME = T.let(:"<anonymous block>", Symbol) + + sig { override.returns(Symbol) } + def decorated_name + :"&#{@name}" + end end class Member < Entry extend T::Sig extend T::Helpers @@ -218,11 +245,11 @@ end end rest = parameters_node.rest - if rest + if rest.is_a?(Prism::RestParameterNode) rest_name = rest.name || RestParameter::DEFAULT_NAME parameters << RestParameter.new(name: rest_name) end keyword_rest = parameters_node.keyword_rest @@ -258,9 +285,11 @@ rest = node.rest if rest.is_a?(Prism::SplatNode) name = rest.expression&.slice names << (rest.operator == "*" ? "*#{name}".to_sym : name&.to_sym) end + + names << nil if rest.is_a?(Prism::ImplicitRestNode) names.concat(node.rights.map { |parameter_node| parameter_name(parameter_node) }) names_with_commas = names.join(", ") :"(#{names_with_commas})"