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

LSP Code Action: Generate dynamic decoder #4106

Merged
merged 10 commits into from
Dec 28, 2024

Conversation

GearsDatapacks
Copy link
Member

Closes #2955
This PR implements a code action to generate a dynamic decoder for a custom type.

@GearsDatapacks
Copy link
Member Author

Oh, do we want to add support for decoding tuples as well? If so, what would that decoder look like (I've only done basic decoding thus far)

@lpil
Copy link
Member

lpil commented Dec 23, 2024

Yes please! Something like this:

use hostname <- decode.field("hostname", decode.string)
use ip <- decode.field("ip", {
  use a <- decode.field(0, decode.int)
  use b <- decode.field(1, decode.int)
  use c <- decode.field(2, decode.int)
  use d <- decode.field(3, decode.int)
  decode.success(#(a, b, c, d))  
})
decode.success(Server(hostname:, ip:))

@GearsDatapacks
Copy link
Member Author

Ah I see, you can use field with more than just strings. Thanks!

Copy link
Member

@lpil lpil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Super cool! Neat how little code it is too. Very clean! Thank you!


decode.success(#(a, b, c))
})

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we remove these empty lines please 🙏

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll do it 👍

@lpil lpil merged commit 08aef44 into gleam-lang:main Dec 28, 2024
12 checks passed
@GearsDatapacks GearsDatapacks deleted the generate-dynamic-decoder branch December 28, 2024 17:23
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

Successfully merging this pull request may close these issues.

LSP code action: generate dynamic decoder
2 participants