Suggest the correct method name in Ruby::NoMethod. - #1705
Open
ksss wants to merge 2 commits into
Open
Conversation
ParadoxV5
reviewed
Jun 3, 2025
|
|
||
| def detail_lines | ||
| if defined?(DidYouMean) | ||
| corrects = DidYouMean::SpellChecker.new(dictionary: dictionary).correct(method) |
Contributor
There was a problem hiding this comment.
It doesn’t look right to construct a new temporary spellchecker for each diagnostic instance and on every call.
(Correct me if I’m wrong: I’m not familiar with how Did You Mean works.)
Contributor
Author
There was a problem hiding this comment.
The initialization cost of DidYouMean::SpellChecker is very low.
https://github.com/ruby/did_you_mean/blob/2375fc5f2a66542df62cde3f08c2263677df3511/lib/did_you_mean/spell_checker.rb#L6-L10
module DidYouMean
class SpellChecker
def initialize(dictionary:)
@dictionary = dictionary
enddictionary is a valid candidate for a method name, and I believe it's natural for the suggested candidates to differ depending on the error.
Use did_you_mean for `Ruby::NoMethod` and present the proposed fix as a “Quick Fix” in the editor.
Contributor
Author
|
I reimplemented to use |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request introduces a new feature to provide method suggestions when a
Ruby::NoMethoderror occurs in the steep LSP.It leverages the
did_you_meangem to suggest possible corrections based on a dictionary of method name list by RBS.textDocument/codeActionI implemented this feature using textDocument/codeAction.
Currently only for
Ruby::NoMethod, but can be extended to supportRuby::UnknownConstantandRBS::UnknownTypeName, etc.Implementation
I implemented
Steep::Services::CodeActionProvider.It is designed for
textDocument/codeActionwith reference toSteep::Services::CompletionProvider.Example
sample.rb
With an editor that can use LSP, such as VSCode, it is possible to propose a “Quick Fix” and actually fix the problem.