Skip to content

feature: paste json as code #308

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

Open
bosvik opened this issue Apr 10, 2025 · 4 comments
Open

feature: paste json as code #308

bosvik opened this issue Apr 10, 2025 · 4 comments

Comments

@bosvik
Copy link
Contributor

bosvik commented Apr 10, 2025

I stumbled upon json-to-types.nvim.
Works sort of. Only supports Newtonsoft.Json and namespace is off OOTB.
Under the hood it relies on quicktype.js wich can be configured to work nicely with System.Text.Json too and accepts namespace as input.
Is this something you would consider bringing into easy-dotnet?
I'm a bit torn. On one hand it would make a nice addition to the toolbox but on the other hand there is already an existing plugin (which would need some tweaking to make it work the way I want it too for c#).
quicktype.js is a ready lib to use and I don't really see an easy way to implement in lua so it would add a dependency on node.
idk, it would be neat to have a tailored c# implementation with all the goodies from easy-dotnet, namespace recognition, configurable implementation (NJ/STJ).

The options are:

 --framework NewtonSoft|SystemTextJson                       Serialization framework
 --namespace NAME                                            Generated namespace
 --csharp-version 5|6                                        C# version
 --density normal|dense                                      Property density
 --array-type array|list                                     Use T[] or List<T>
 --number-type double|decimal                                Type to use for numbers
 --any-type object|dynamic                                   Type to use for "any"
 --[no-]virtual                                              Generate virtual properties (off by default)
 --features complete|attributes-only|just-types-and-         Output features
 namespace|just-types
 --base-class EntityData|Object                              Base class
 --[no-]check-required                                       Fail if required properties are missing (off by default)
 --[no-]keep-property-name                                   Keep original field name generate (off by default)

None which are configurable in json-to-types.nvim.

Thoughts?

@GustavEikaas
Copy link
Owner

Looks really cool, IIRC I looked into something like this previously.

It would be interesting to make a POC to test out the idea. im not really sure what the user flow should be. Usually in C# one class == one file. So do you create a file from clipboard contents or do you create the file first and then paste the json into the file and the plugin magically turns it into a class?

@bosvik
Copy link
Contributor Author

bosvik commented Apr 11, 2025

I'm a bit torn here. Direct paste from clipboard would require guessing namespace. Creating a class beforehand sort of overrules the purpose. Maybe cut some corners and paste class into a temp buffer to let user yank and paste into a position suitable? Would love to get rid of external dependency on node and quicktype but as it is available...

@GustavEikaas
Copy link
Owner

I'm not sure I follow, how would you provoke this temp buffer? Command?
Anyways I like the idea and I think we can make something like this work. Hopefully it's possible to find/make a C# or F# version of it? I agree node dependency is a stretch

@bosvik
Copy link
Contributor Author

bosvik commented Apr 22, 2025

sorry, been zoomed out for a while. best way to incorporate I believe should be:

  • create a new bootstrapped file
  • Dotnet command to paste the yanked json and turn it into properties.

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