Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Completion for superclasses #7841

Open
jez opened this issue Apr 17, 2024 · 0 comments
Open

Completion for superclasses #7841

jez opened this issue Apr 17, 2024 · 0 comments
Labels
enhancement New feature or surprising current feature IDE Relating to Sorbet's LSP server or VS Code extension

Comments

@jez
Copy link
Collaborator

jez commented Apr 17, 2024

Input

→ View on sorbet.run

# typed: true
class Parent; end
class Child < Pare
  #               ^ completion: Parent

Observed output

s(:begin,
  s(:class,
    s(:const, nil, :Parent), nil, nil),
  s(:class,
    s(:const, nil, :Child),
    s(:const, nil, :Pare), nil))
editor.rb:4: unexpected token "end of file" https://srb.help/2001
     4 |  #               ^ completion: Parent
     5 |

editor.rb:3: Hint: this "class" token is not closed before the end of the file https://srb.help/2003
     3 |class Child < Pare
        ^^^^^

editor.rb:3: Unable to resolve constant Pare https://srb.help/5002
     3 |class Child < Pare
                      ^^^^
  Did you mean Rake? Use -a to autocorrect
    editor.rb:3: Replace with Rake
     3 |class Child < Pare
                      ^^^^
    https://github.com/sorbet/sorbet/tree/master/rbi/gems/rake.rbi#L6: Rake defined here
     6 |module Rake
        ^^^^^^^^^^^
  Did you mean Date? Use -a to autocorrect
    editor.rb:3: Replace with Date
     3 |class Child < Pare
                      ^^^^
    https://github.com/sorbet/sorbet/tree/master/rbi/stdlib/date.rbi#L159: Date defined here
     159 |class Date
          ^^^^^^^^^^
  Did you mean Parent? Use -a to autocorrect
    editor.rb:3: Replace with Parent
     3 |class Child < Pare
                      ^^^^
    editor.rb:2: Parent defined here
     2 |class Parent; end
        ^^^^^^^^^^^^

editor.rb:3: Unable to resolve constant Pare https://srb.help/5002
     3 |class Child < Pare
                      ^^^^
  Did you mean Rake? Use -a to autocorrect
    editor.rb:3: Replace with Rake
     3 |class Child < Pare
                      ^^^^
    https://github.com/sorbet/sorbet/tree/master/rbi/gems/rake.rbi#L6: Rake defined here
     6 |module Rake
        ^^^^^^^^^^^
  Did you mean Date? Use -a to autocorrect
    editor.rb:3: Replace with Date
     3 |class Child < Pare
                      ^^^^
    https://github.com/sorbet/sorbet/tree/master/rbi/stdlib/date.rbi#L159: Date defined here
     159 |class Date
          ^^^^^^^^^^
  Did you mean Parent? Use -a to autocorrect
    editor.rb:3: Replace with Parent
     3 |class Child < Pare
                      ^^^^
    editor.rb:2: Parent defined here
     2 |class Parent; end
        ^^^^^^^^^^^^
Errors: 4

Expected behavior

It would be nice to show completion results for constant literals in superclass positions.
It's quite possible that this would not be immediately useful, because every keystroke would trigger a slow path edit, which would be prohibitively expensive on large codebases, but it would be passable on small codebases and would be a step in the right direction for large codebases.


Note that we already recover from the typical parse error that users would see here, so there's likely no parser changes holding us back from making practical improvements here.

@jez jez added enhancement New feature or surprising current feature IDE Relating to Sorbet's LSP server or VS Code extension labels Apr 17, 2024
@jez jez added this to the Autocompletion milestone Apr 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or surprising current feature IDE Relating to Sorbet's LSP server or VS Code extension
Projects
None yet
Development

No branches or pull requests

1 participant