Stream: t-compiler/wg-rls-2.0

Topic: New API for assists


matklad (May 07 2020 at 12:48, on Zulip):

Hey, in https://github.com/rust-analyzer/rust-analyzer/pull/4350 I propose to change our API for assists. I feel like the new version is better, but I want to bump the visibility of this, in case someone comes up with even a better improvement, before I refactored all 30-ish existing assists :)

matklad (May 07 2020 at 12:48, on Zulip):

The new API mirrors the one from completions, where we split & context and &mut accumulator.

matklad (May 07 2020 at 12:52, on Zulip):

The two main changes are:

Coenen Benjamin (May 07 2020 at 12:56, on Zulip):

Yay multi assists <3

Coenen Benjamin (May 07 2020 at 12:59, on Zulip):

I think it could also be easier with this refactor if as in completions we want to have a kind of scoring to manage assists orders

matklad (May 07 2020 at 12:59, on Zulip):

For assist, we already have this actually

Coenen Benjamin (May 07 2020 at 13:00, on Zulip):

Based on alphabetical order ?

matklad (May 07 2020 at 13:00, on Zulip):

https://github.com/rust-analyzer/rust-analyzer/blob/f4cd75ac06dff7f5a95065a6c3868669e5c2ab27/crates/ra_assists/src/lib.rs#L93

Coenen Benjamin (May 07 2020 at 13:00, on Zulip):

Oh ok ! I missed it

matklad (May 07 2020 at 13:00, on Zulip):

and then, solely for tie-breaking, https://github.com/rust-analyzer/rust-analyzer/blob/f4cd75ac06dff7f5a95065a6c3868669e5c2ab27/crates/ra_assists/src/lib.rs#L177-L180

bjorn3 (May 07 2020 at 13:03, on Zulip):

Why does it return Option<()> instead of ()?

matklad (May 07 2020 at 13:06, on Zulip):

That's a hack to make ? work

matklad (May 07 2020 at 13:07, on Zulip):

Ideally, it should return some ZST which is convertable from NoneError, but that's not stable yet

Coenen Benjamin (May 07 2020 at 13:08, on Zulip):

What is ZST ? :)

bjorn3 (May 07 2020 at 13:08, on Zulip):

zero sized type

Coenen Benjamin (May 07 2020 at 13:08, on Zulip):

Ok sorry :)

matklad (May 07 2020 at 13:10, on Zulip):

That's no reason to say sorry :) It's useful to know jargon, but we all at some point didn't know it

Jeremy Kolb (May 07 2020 at 13:15, on Zulip):

What's the difference between an unresolved/resolved assist?

matklad (May 07 2020 at 13:17, on Zulip):

https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ra_assists/src/assist_ctx.rs#L47-L77

matklad (May 07 2020 at 13:17, on Zulip):

see these docs

matklad (May 07 2020 at 13:17, on Zulip):

We want to optimize assists to only compute the edit if the user selected the assist

matklad (May 07 2020 at 13:18, on Zulip):

We dont' do this in practice yet, (as LSP doesn't have resolveAssist), but our internal API is build around this idea

matklad (May 07 2020 at 13:18, on Zulip):

(that's the reason for -> Option<_> and closure-based .add_assist)

Last update: May 29 2020 at 16:35UTC