steep icon indicating copy to clipboard operation
steep copied to clipboard

Suggest the correct method name in Ruby::NoMethod.

Open ksss opened this issue 6 months ago • 1 comments

This pull request introduces a new feature to provide method suggestions when a Ruby::NoMethod error occurs in the steep LSP. It leverages the did_you_mean gem to suggest possible corrections based on a dictionary of method name list by RBS.

textDocument/codeAction

I implemented this feature using textDocument/codeAction. Currently only for Ruby::NoMethod, but can be extended to support Ruby::UnknownConstant and RBS::UnknownTypeName, etc.

Implementation

I implemented Steep::Services::CodeActionProvider. It is designed for textDocument/codeAction with reference to Steep::Services::CompletionProvider.

Example

sample.rb

o = Object.new
o.calss

# @type var a: {a: 1}
a = _ = nil
x = a.foo(1)

With an editor that can use LSP, such as VSCode, it is possible to propose a “Quick Fix” and actually fix the problem.

image

ksss avatar Jun 03 '25 05:06 ksss

I reimplemented to use textDocument/codeAction. The previous version, which added hover text.

ksss avatar Jun 12 '25 08:06 ksss