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

Integrate Thot.Generator with Ionide #34

Closed
MangelMaxime opened this issue Nov 8, 2019 · 7 comments
Closed

Integrate Thot.Generator with Ionide #34

MangelMaxime opened this issue Nov 8, 2019 · 7 comments

Comments

@MangelMaxime
Copy link
Contributor

Issue by MangelMaxime
Wednesday Apr 11, 2018 at 08:42 GMT
Originally opened as MangelMaxime/Thoth#20


@MangelMaxime
Copy link
Contributor Author

Comment by MangelMaxime
Sunday May 13, 2018 at 20:50 GMT


@Krzysztof-Cieslak

Are you still ok to integrate Thoth.Json.Generator into Ionide ? What should I do ?

I made a quick WIP on my computer by using directly FCS and I am able to retrieve all the information I want from it. So I guess FSAC should also be able to do it.

But I am not sure if FSAC maintainers would agree to add such specific code for a library. I thinked about it a lot and had the next idea.

We could add an endpoint to FSAC who give by all the types info for a given record:

  • Record name
  • Fields and types info
  • etc.

Having this endpoint in FSAC would help us integrate Thoth.Json.Generator and also also allow me to work on Stub generation at the same time. Both required the same info coming from the records.

@MangelMaxime
Copy link
Contributor Author

Comment by MangelMaxime
Monday May 14, 2018 at 07:49 GMT


Scratch my idea.

Both feature will not have the same entry point. For Thoth.Json.Generator I need to find the type definition at (line, col). And for the Stub generation I need to find the declaration of a type based on it's usage/signature.

@MangelMaxime
Copy link
Contributor Author

Comment by Krzysztof-Cieslak
Monday May 14, 2018 at 13:53 GMT


Well, I'm the FSAC maintainer so merging in anything shouldn't be a problem ;)

But in general I think that having some more "generic" endpoint (like returning all information about given symbol) sounds like good idea - it may be also useful for other features.

@MangelMaxime
Copy link
Contributor Author

Comment by MangelMaxime
Monday May 14, 2018 at 14:28 GMT


Well, I'm the FSAC maintainer so merging in anything shouldn't be a problem ;)

Ah yes that's true.

Would you be ok to have tchat on Slack to discuss the feature either for Thoth or "returning all information about given symbol".

And I will post a summary of the decision in the open after and start working on the feature.

@MangelMaxime
Copy link
Contributor Author

Comment by MangelMaxime
Monday May 14, 2018 at 14:45 GMT


@Krzysztof-Cieslak To give you a better idea of what Thoth.Json.Generator do (in my head) here is a list of feature.

Thoth.Json.Generator features:

  1. User is able to right click on a Type definition and do:

    • Generate Decoder
    • Generate Encoder
        type User =
            { Firstname : string
              Surname : string }
    
        // After generation
    
        type User =
            { Firstname : string
              Surname : string }
            
            static member Decoder =
                Decode.decode
                    (fun firstname surname ->
                        { Firstname = firstname 
                          Surname = surname } : User )
                    |> Decode.required "firstname" Decode.string
                    |> Decode.required "surname" Decode.string
    
            static member Encoder (user : User) =
                Encode.object [
                    "firstname", Encode.string user.Firstname
                    "surname", Encode.string user.Surname
                ]
  2. In the future, be able to update existing Decoder/Encoder in case of a new field added etc.

  3. Could be nice a the future to mark types that need a Decoder/Encoder generation. And allow users to run "F#: Generate all decoder/encoder"

        [<GenerateEncoder; GenerateDecoder>]
        type User =
            { Firstname : string
              Surname : string }

    This point is useful when you are working with a lot of types. Another solution in order to avoid using attributes could be to generate all decoder/encoder for current selection or file for example.

    One benefit of using Attribute is we could have quick fix tooltip.

  4. We also need to support some others type than Record like enum at least for now.

        type Supplier =
            | SupplierA = 0
            | SupplierB = 1    
    
        let decodeSupplier : Decode.Decoder<Supplier> =
            Decode.int
            |> Decode.andThen (
                function
                | 0 -> Decode.succeed Supplier.SupplierA
                | 1 -> Decode.succeed Supplier.SupplierB
                | unkown -> sprintf "Unkown Supplier for value `%i`" unkown
                            |> Decode.fail
            )
    
        let encodeSupplier (supplier : Supplier) =
            match supplier with
            | Supplier.SupplierA ->
                Encode.int (int supplier)
            | Supplier.SupplierB ->
                Encode.int (int supplier)
            | unkown -> failwithf "Failed encoding Supplier because unkown Supplier `%A`" unkown

For now, we can focus on point 1 only which is the main feature.

@baronfel
Copy link

baronfel commented Dec 4, 2019

An IDE-agnostic approach would be to use Myriad to create the encoders at compile-time for you, then you wouldn't need any specific FSAC/Ionide integration.

@MangelMaxime
Copy link
Contributor Author

Close in favor of #95 (it has the right title in it) ^^

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants