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

Feature Requests about Code Actions/Snippets #10911

Open
IndianBoy42 opened this issue Dec 3, 2021 · 5 comments
Open

Feature Requests about Code Actions/Snippets #10911

IndianBoy42 opened this issue Dec 3, 2021 · 5 comments
Labels
A-assists C-feature Category: feature request

Comments

@IndianBoy42
Copy link

Convert to destructured form

let input = (1, 1);
// <=>
let (a, b) = (1, 1);

It would be nice if this could use snippets somehow so that the cursor jumps to fill in the variable names.
But most other assists don't do this for the identifiers so maybe not necessary.

Generate closure template based on the signature inferred at that point

iter.map(<closure>)

This should probably be a snippet with nodes at the arguments and then function body.
The reason this should be from rust-analyzer is that it with type information we can generate the argument list better.
The function body could probably be just unimplemented!("<return type name>")

Convert between function name and closure

str::parse
// <=>
|s| str::parse(s)
// OR
|s| s.parse()

The last transform would require us to check whether it is a inherent method. Maybe another assist that converts inherent method calls to UFCS style could also be useful

@Veykril
Copy link
Member

Veykril commented Dec 3, 2021

Convert to destructured form

I think we can do this, the problem with this currently though is that we can't set multiple cursors yet, that is we can't set a multi-cursor on all ocurrences of a, and another for b(if my memory serves right in that lsp doesn't allow us to yet). Though maybe things have changed.

Generate closure template based on the signature inferred at that point

Do you mean this in the context of completions or an assist that generates the closure signature for you that is expected here?

@Veykril Veykril added A-assists C-feature Category: feature request labels Dec 3, 2021
@IndianBoy42
Copy link
Author

Do you mean this in the context of completions or an assist that generates the closure signature for you that is expected here?

I think this would be most convenient as a completion. so for example the user types | in a place where a closure is required and a completiong is returned that expands to a closure with the correct function signature.

The destructuring idea also maybe could be done as a completion, like if you start typing in a place that expects a pattern, then you can suggest certain destructurings that are valid in that position.

that is we can't set a multi-cursor on all ocurrences of a, and another for b(if my memory serves right in that lsp doesn't allow us to yet)

What do you mean by all occurences of a? In that example a, b would be some new identifiers (probably based on the field names of the type we are destructuring) so I don't think its likely to have any occurences of it yet.

Oh, while typing this I think I figured it out, did you mean any uses of the original binding name would also be transformed. To some kind of restructuring?

@Veykril
Copy link
Member

Veykril commented Dec 3, 2021

The destructuring idea also maybe could be done as a completion, like if you start typing in a place that expects a pattern, then you can suggest certain destructurings that are valid in that position.

We already do that for namable things like structs, though not for tuples since we can't do a completion on (.

What do you mean by all occurences of a? In that example a, b would be some new identifiers (probably based on the field names of the type we are destructuring) so I don't think its likely to have any occurences of it yet.

let x = (0, 1);
let _ = x.0;
let _ = x.1;

becomes

let (_0, _1) = (0, 1);
let _ = _0;
let _ = _1;

in this case putting snippets on just the identifiers in the first let statement might be a bit annoying, as you can't just rename them without invoking an actual rename operation unless all occurences are selected at the same time.

Note we already have an assist for tuple binding destructuring which does this(without snippets).

@TonalidadeHidrica
Copy link
Contributor

This issue requests multiple distinct features. Why don't we split them into three separate tickets?

@Veykril
Copy link
Member

Veykril commented Dec 30, 2021

Ye it would probably make more sense to split this, though the first two we actually already track elsewhere.

Generate closure template based on the signature inferred at that point

Is #8676

Convert to destructured form

Is #8673

Convert between function name and closure

I don't think we have an issue tracking this one though, so it would probably make sense to close this and re-open a new issue just for that part

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-assists C-feature Category: feature request
Projects
None yet
Development

No branches or pull requests

3 participants