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

A command to generate a struct from a tuple #26998

Closed
ghost opened this issue May 20, 2018 · 11 comments
Closed

A command to generate a struct from a tuple #26998

ghost opened this issue May 20, 2018 · 11 comments
Labels
Area-IDE Feature Request Resolution-Fixed The bug has been fixed and/or the requested behavior has been implemented
Milestone

Comments

@ghost
Copy link

ghost commented May 20, 2018

If I have a ValueTuple in code like this:
(Char From, Char To)

It will be helpful if the context menu offers a command to generate a struct with a default name from this tuple:

    public struct StructName
    {
        public Char From;
        public Char To;

        public CharRange(Char from, Char to)
        {
            From = from;
            To = to;
        }
    }

Sometimes I start with a tuple, then discover I want to reuse it many times, so it is easier if I convert it to a struct.

@CyrusNajmabadi
Copy link
Member

CyrusNajmabadi commented May 21, 2018

I like this idea. :)

If we did this, i also think it should work for anonymous-types as well.

I imagine there would be two forms of hte fix:

  1. Introduce named type for this anonymous-type/tuple
    1. Introduce named type for anonymous-type/tuple (and replace all complimentary types).

Basically, should the fix work just for the current method (which is the concept we have for anonymous-types), or should it expand to work globally.

@CyrusNajmabadi
Copy link
Member

If we did have the "global fixup" concept, we would likely want to use an IDE index to speed up searching for things. We could update the syntax-tree-index to store the shapes of anonymous-types/tuples we saw, so that we could find all possible matches in O(d) time (where 'd' was the number of files with a matching shape), instead of having to search everything.

@Neme12
Copy link
Contributor

Neme12 commented May 21, 2018

@CyrusNajmabadi Can you please clarify what you mean by "work for current method" and "work globally"? Are you talking about replacing usages of the tuple type with the generated type?

@Neme12
Copy link
Contributor

Neme12 commented May 21, 2018

Would it replace tuples that are unrelated but happen to be the same type?

@Neme12
Copy link
Contributor

Neme12 commented May 21, 2018

The design of such replacement raises the same questions as renaming tuple elements - how do we track tuple types and when do we consider them equal? There should be one answer to both (and hopefully one implementation), so this should probably wait until the design for tuple renaming is finalized.

@CyrusNajmabadi
Copy link
Member

@CyrusNajmabadi Can you please clarify what you mean by "work for current method" and "work globally"? Are you talking about replacing usages of the tuple type with the generated type?

Yes. That's what i'm referring to. I would expect to be able to make this change on a local basis versus making it globally.

how do we track tuple types and when do we consider them equal?

I would use types and names. The point of allowing the user to specify scopes is precisely around if you'd want to consider other tuples with the same 'shape' as equivalent and important to fixup or not.

@ghost
Copy link
Author

ghost commented May 21, 2018

@CyrusNajmabadi

I like this idea. :)

This is new. I should celebrate :)

If we did this, i also think it should work for anonymous-types as well.
Nice.

I

@ghost
Copy link
Author

ghost commented May 21, 2018

@Neme12

The design of such replacement raises the same questions as renaming tuple elements - how do we track tuple types and when do we consider them equal? There should be one answer to both (and hopefully one implementation), so this should probably wait until the design for tuple renaming is finalized.

I didn't ask for replacement. Gust generate the struct and I'll take it from there :)
If @CyrusNajmabadi want to do more steps, then this can be another option.

@jinujoseph jinujoseph added this to the Unknown milestone Jun 18, 2018
@CyrusNajmabadi
Copy link
Member

Fixed with #28257. @jcouv @jinujoseph can you close this issue?

@jcouv jcouv closed this as completed Jul 13, 2018
@jcouv jcouv added the Resolution-Fixed The bug has been fixed and/or the requested behavior has been implemented label Jul 13, 2018
@jcouv jcouv modified the milestones: Unknown, 16.0 Jul 13, 2018
@ghost
Copy link
Author

ghost commented Jul 13, 2018

@CyrusNajmabadi
Thanks. Great work.

@CyrusNajmabadi
Copy link
Member

You're welcome. Great idea!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-IDE Feature Request Resolution-Fixed The bug has been fixed and/or the requested behavior has been implemented
Projects
None yet
Development

No branches or pull requests

4 participants