rbs icon indicating copy to clipboard operation
rbs copied to clipboard

Add a way to mark a method as deprecated in inline RBS

Open connorshea opened this issue 1 month ago • 3 comments

For editor support in the Ruby LSP, it'd be great if this were standardized by rbs. See also https://github.com/Shopify/ruby-lsp/issues/1773

I see that there are deprecation signatures in RBS syntax that are generally standardized: https://github.com/ruby/rbs/blob/031f319726752e74499fc7036c9593a3b5d87ed0/sig/definition.rbs#L100

But is there a way to do this in an inline RBS signature? Should there be? Should we consider a @deprecated tag at the start of a comment line to be the standard way to do this, to match YARD/JSDoc and all the gems that already use this syntax?

class Foo
  # @deprecated Use #new_thing instead.
  #: -> String
  def old_thing
    return 'bad'
  end

  #: -> String
  def new_thing
    return 'better'
  end
end

I see that there is one example of an inline comment for a deprecated method, in the tests, but I don't think it technically means anything here.

https://github.com/ruby/rbs/blob/031f319726752e74499fc7036c9593a3b5d87ed0/test/rbs/inline_parser_test.rb#L1305-L1306

I am very much looking forward to Inline RBS! :)

connorshea avatar Nov 10 '25 23:11 connorshea

The rbs-inline provides syntax for annotations.

https://github.com/soutaro/rbs-inline/wiki/Syntax-guide#rbs-annotations

In this case, you can write it like this.

  # @rbs %a{deprecated: Use #new_thing instead.}
  #: -> String
  def old_thing
    return 'bad'
  end

However, please note that this is an experimental feature, and parsing is not yet implemented in the rbs repo.

ksss avatar Nov 11 '25 00:11 ksss

Does that work with #: style, or only @rbs?

connorshea avatar Nov 11 '25 00:11 connorshea

It seems that the #: style is already supported after trying it out.

  #: %a{deprecated: Use #new_thing instead.} -> String
  def old_thing
    return 'bad'
  end

However, it does not seem to be written in the any document...

ksss avatar Nov 11 '25 01:11 ksss