rust-analyzer icon indicating copy to clipboard operation
rust-analyzer copied to clipboard

Implement `gen` block and function parsing

Open mohe2015 opened this issue 2 years ago • 9 comments

https://github.com/rust-lang/rust-analyzer/issues/16156

Blocked on https://github.com/rust-lang/rust-analyzer/issues/16324

Things I need help with / need some pointers and TODOs:

  • [x] ~~Only parse gen as keyword in 2024 edition~~
  • [x] Hovering function name doesn't show gen in hover
  • [x] Hovering over gen in block doesn't show keyword information. (no doc like https://doc.rust-lang.org/nightly/std/keyword.await.html for gen and yield)
  • [x] When rust-analyzer is loading, vscode doesn't color the keyword correctly (https://github.com/dustypomerleau/rust-syntax/pull/41)
  • [x] Yield autocompletion in gen fn and async gen fn
  • [x] inferred type of async gen block is wrong
  • [x] https://github.com/compiler-errors/rust/tree/closure-kind desugar to closure, https://github.com/compiler-errors/rust/blob/closure-kind/compiler/rustc_ast_lowering/src/expr.rs, https://github.com/compiler-errors/rust/blob/closure-kind/compiler/rustc_ast/src/ast.rs
  • [x] Split off rename generator -> coroutine
  • [x] Fix lowering async closures. They may need a nested closure or something
  • [x] Fix return type inference of empty `gen fn'
  • [x] Duplicate and wrong types in check_infer
  • [x] Hover over function shows wrong return type
  • [x] Type inference of resume of coroutine broken (seems like already before this PR)
  • [x] Lots of tests

mohe2015 avatar Dec 21 '23 00:12 mohe2015

Only parse gen as keyword in 2024 edition

Of note here is that our parsing is currently not edition aware at all (we just assume edition 2021 parsing), so we need to fix that first (as a separate PR if any).

Veykril avatar Dec 22 '23 07:12 Veykril

Is this ready for review? Note that this won't be merged until we have solved the edition dependent parsing, as gen is a heavily used identifier I imagine.

Veykril avatar Jan 03 '24 14:01 Veykril

It's not ready for review (I realize marking as draft is not enough as you also use the S-waiting-on-author label), I mostly opened this PR to avoid duplicate work and to allow others to look at my messy code and use this if they need it. I would definitely need to clean this up before a review and if somebody else wants to take parts of this that's also fine as this is my first PR to rust-analyzer and I only have a very limited understanding of many parts of it that I touched here.

mohe2015 avatar Jan 03 '24 18:01 mohe2015

:umbrella: The latest upstream changes (presumably #16256) made this pull request unmergeable. Please resolve the merge conflicts.

bors avatar Jan 05 '24 14:01 bors

:umbrella: The latest upstream changes (presumably #16447) made this pull request unmergeable. Please resolve the merge conflicts.

bors avatar Jan 30 '24 11:01 bors

https://github.com/rust-lang/rust-analyzer/pull/17620 should implement the parsing in an edition aware manner, unblocking the remainder of this

Veykril avatar Jul 19 '24 13:07 Veykril

That's nice! I'm currently writing my thesis so I probably won't have time for this. So anybody feel free to take this over.

mohe2015 avatar Jul 19 '24 13:07 mohe2015

Squashed and rebased

Veykril avatar Jul 25 '24 11:07 Veykril

:umbrella: The latest upstream changes (presumably #17791) made this pull request unmergeable. Please resolve the merge conflicts.

bors avatar Aug 05 '24 14:08 bors

I'm not too sure what needs to be done on top of rebasing this, but I'd be happy to take it up. Does anyone have any pointers?

snprajwal avatar Mar 13 '25 10:03 snprajwal

I'll close this. The PR is quite outdated by now, and a bunch of refactors have landed since (and are still about to land especially the new trait solver). We should attempt this again after those.

Veykril avatar Apr 07 '25 07:04 Veykril