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 symbols used inside a block pass #7839

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

Completion for symbols used inside a block pass #7839

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

[1].map(&:ev)
#           ^ completion: even?, ...

# Note that Sorbet treats this like this:
[1].map do |*__block_pass__|
  __block_pass__[0].ev(*__block_pass__[1, 2147483647])
end

Observed output

begin
  <emptyTree>
  class <emptyTree><<C <root>>> < (::<todo sym>)
    def self.<static-init><<static-init>$156>(<blk>)
      begin
        [1].map() do |*<block-pass>$2$1|
          ::<Magic>.<call-with-splat>(<block-pass>$2$1.[](0), :ev, ::<Magic>.<splat>(<block-pass>$2$1.[](1, 2147483647)), nil)
        end
        [1].map() do |*__block_pass__$2|
          ::<Magic>.<call-with-splat>(__block_pass__$2.[](0), :ev, ::<Magic>.<splat>(__block_pass__$2.[](1, 2147483647)), nil)
        end
        <emptyTree>
      end
    end
  end
  <emptyTree>
end
editor.rb:3: Method ev does not exist on Integer https://srb.help/7003
     3 |[1].map(&:ev)
                 ^^^
  Got Integer originating from:
    editor.rb:3:
     3 |[1].map(&:ev)
                 ^

editor.rb:8: Method ev does not exist on Integer https://srb.help/7003
     8 |  __block_pass__[0].ev(*__block_pass__[1, 2147483647])
                            ^^
  Got Integer originating from:
    editor.rb:8:
     8 |  __block_pass__[0].ev(*__block_pass__[1, 2147483647])
          ^^^^^^^^^^^^^^^^^
Errors: 2

Expected behavior

At the position indicated by the ^ completion assertion, Sorbet should be able to produce a list of completion items that starts with even?


Note that really supporting this well might involve making Sorbet recover better from programs like these:

[1].map(&:)

Right now Sorbet's parse result for this program doesn't keep around anything that we might be able to use to recover the fact that there's a block pass (&) here.

We might be able to make Sorbet parse this like

[1].map(&:'')

But that might be a pretty big yak shave, so we don't need to block the completion feature on it.

@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