ruby-lsp icon indicating copy to clipboard operation
ruby-lsp copied to clipboard

Deprecated ruby methods do not have strikethrough

Open professor opened this issue 2 years ago • 6 comments

Operating System

macOS Sonoma 14.1.1

Ruby version

ruby 3.2.2 (2023-03-30 revision e51014f9c0) +YJIT [arm64-darwin22]

Project has a bundle

  • [X] Has bundle

Ruby version manager being used

rbenv

Description

Type: Bug

I tried two ways of deprecating a method in ruby, and neither shows up as a strikethrough

  1. heredoc
  # @deprecated
  def my_method
  end
  1. Rail's Deprecation
  def my_method
     ActiveSupport::Deprecation.warn('my_method is deprecated, use X instead')
  end

The expected output would be

company.~my_method~

VS Code version: Code 1.84.2 (Universal) (1a5daa3a0231a0fbba4f14db7ec463cf99d7768e, 2023-11-09T10:52:33.687Z) OS version: Darwin arm64 23.1.0 Modes:

System Info
Item Value
CPUs Apple M1 Pro (8 x 24)
GPU Status 2d_canvas: enabled
canvas_oop_rasterization: enabled_on
direct_rendering_display_compositor: disabled_off_ok
gpu_compositing: enabled
multiple_raster_threads: enabled_on
opengl: enabled_on
rasterization: enabled
raw_draw: disabled_off_ok
video_decode: enabled
video_encode: enabled
vulkan: disabled_off
webgl: enabled
webgl2: enabled
webgpu: enabled
Load (avg) 6, 6, 7
Memory (System) 32.00GB (0.07GB free)
Process Argv --crash-reporter-id 44edb388-cd1b-44e3-a0d8-121365572d89
Screen Reader no
VM 0%
Extensions (10)
Extension Author (truncated) Version
vscode-eslint dba 2.4.2
prettier-vscode esb 10.1.0
workbench-vscode gus 0.0.4
code-ownership-vscode Gus 0.0.7
packwerk-vscode Gus 0.0.5
vscode-docker ms- 1.28.0
remote-containers ms- 0.321.0
vscode-rubocop rub 0.7.0
ruby-lsp Sho 0.4.19
sorbet-vscode-extension sor 0.3.26
A/B Experiments
vsliv368:30146709
vsreu685:30147344
python383:30185418
vspor879:30202332
vspor708:30202333
vspor363:30204092
vswsl492:30256859
vslsvsres303:30308271
vserr242cf:30382550
pythontb:30283811
vsjup518:30340749
pythonptprofiler:30281270
vshan820:30294714
vstes263cf:30335440
vscod805cf:30301675
binariesv615:30325510
bridge0708:30335490
bridge0723:30353136
vsaa593:30376534
pythonvs932:30410667
py29gd2263cf:30880073
vsclangdf:30486550
c4g48928:30535728
dsvsc012cf:30540253
pynewext54:30695312
azure-dev_surveyone:30548225
3biah626:30602489
f6dab269:30613381
a9j8j154:30646983
showlangstatbar:30737416
pythonfmttext:30731395
fixshowwlkth:30771522
showindicator:30805244
pythongtdpath:30769146
i26e3531:30792625
welcomedialogc:30887144
pythonnosmt12:30797651
pythonidxpt:30866567
pythonnoceb:30805159
asynctok:30869155
dsvsc013:30795093
dsvsc014:30804076
dsvsc015:30845448
pythontestfixt:30871694
pythonregdiag2:30871582
pyreplss1:30897532
pythonmypyd1:30879173
pythoncet0:30885854
pythontbext0:30879054
accentitlementst:30887150
dsvsc016:30886110
dsvsc017cf:30886113
dsvsc018:30886114
aa_t_chat:30882232

I tried disabling these extensions just to be safe...

code-ownership-vscode
packwerk-vscode	
vscode-docker	
sorbet-vscode-extension	
vscode-rubocop	

Originally posted https://github.com/microsoft/vscode/issues/198886

professor avatar Nov 23 '23 15:11 professor

Thank you for the bug report! We indeed don't have support for showing deprecations yet.

I do want to point out that neither of those are a part of the language itself though. The @deprecated comment comes from YARD if I remember correctly.

The second option, coming from Active Support, is harder to support without a proper typechecker given that it's just Ruby code and you can do whatever you want with it in theory. E.g.:

def my_method(a, b, c)
 if b.is_a?(Integer) && c == 5
   ActiveSupport::Deprecation.warn('Do not invoke `my_method` with and Integer b and c as 5!')
 end
end

It would be nice if Ruby had some built-in annotation to mark methods as deprecated, so that we could rely on the language itself. Might be worth suggesting the feature in the bug tracker if it hasn't been brought up yet.

It would also greatly benefit Ruby/gem upgrades since tooling like the Ruby LSP could help people get rid of deprecations more easily.

vinistock avatar Nov 23 '23 15:11 vinistock

Thank you for the thoughtful response.

My immediate goal is to get some kind of feature compatibility between RubyMine and VS Code. I noticed that RubyMine added yard deprecated support for # @deprecated before 2013 and that felt this is the easier way to move forward without getting a language change.

I'm assuming that many before me have tried to get the Ruby language to add a deprecated method feature and failed. I can start researching this.

I've been using ActiveSupport::Deprecation.warn when our code base is no longer using a method and I want to confirm that it is safe to remove on production. In my current use case, I have 100+ methods that we want developers to stop using moving forward. The strikethrough VS Code feature seemed the best way to communicate it to our developers. I was happy to see that # @deprecated worked in RubyMine, but most of our developers use VS Code.

professor avatar Nov 27 '23 06:11 professor

This'd be really good to see! Is there a recommended way this should be implemented? rbs does provide it in their annotations in some cases: https://github.com/ruby/rbs/pull/2693/files

connorshea avatar Nov 06 '25 23:11 connorshea

That's using RBS' free style annotation %a{} where you can write whatever you want inside and the tools assign meaning to it. But then lots of existing code uses the YARD style # @deprecated on top.

Also, you can only write RBS in RBS files or using inline comments. However, if you're already using it in comments, would we use # %a{deprecated} instead of # @deprecated?

It would be nice to first establish a standard, so that we don't end up making every tool support a multitude of ways of expressing the same thing.

Maybe it's %a{deprecated} in RBS files and # @deprecated in Ruby files?

vinistock avatar Nov 07 '25 15:11 vinistock

Maybe it's %a{deprecated} in RBS files and # @deprecated in Ruby files?

I think that makes the most sense, yeah

connorshea avatar Nov 10 '25 23:11 connorshea

Based on https://github.com/ruby/rbs/commit/caecdfe2be0bc4fda77ccfb4b5672e5eaed999b5 you're right that that's how it's intended to be done in RBS, and the LSP recognizing this would be very useful.

connorshea avatar Nov 10 '25 23:11 connorshea