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

feat: deserializer POC #620

Closed
wants to merge 2 commits into from
Closed

feat: deserializer POC #620

wants to merge 2 commits into from

Conversation

Conaclos
Copy link
Member

@Conaclos Conaclos commented Oct 28, 2023

This PR presents a POC to write for write once deserialization code for biome configurations.
To demonstrate the feasibility of this, I only wrote the serialization of the configuration of useNamingConvention rule.

POC v1 is in commit 1.
POC v2 is in commit 2.

The system relies on two main traits defined in biome_deserialize::visitor:

  • NodeVisitor (DeserializationVisitor in POC v2) which allows visiting a value (array, map, boolean ,string, ...)
  • DeserializableLanguage that implements the specific code for every language

NodeVisitor is implemented by bool, String, Vec<T>, NamingConventionOptions and EnumMemberCase.
DeserializableLanguage is implemented by JsonLanguage (see biome_deserialize::json).

DeserializableLanguage requires the implementation of a method named deserailize_value that takes a visitor and a value (synatx node) as parameters.
An implantation of this method has to call the corresponding visit_ method of the given visitor according to the type of the given node.

For convenience, the POC v2 provides a third trait named Desrializable with a method desrializable. The trait is implemented by SyntaxNode<L>.

In contrast to the first POC, POC v2, the visitor is not implemented for the instance of a type, but for the type itself. Instead of modifying the visited instance, it produces an instance of the visited type. This removes the constraint to have types that implement Default. This also provides a cleaner way to deserialize enums and other values.

POC v2 also introduces a new struct DeserializationDiagnostics that simplifies creation of a diagnostic and ensure that users use a curated list of diagnostics.

In comparison to the previous approach we can easily add a config language by implementing DeserializableLanguage.
We also avoids leaking representation information outside a type. Only the type know how deserialize itself.

@Conaclos Conaclos temporarily deployed to Website deployment October 28, 2023 12:21 — with GitHub Actions Inactive
@github-actions github-actions bot added A-Linter Area: linter L-JavaScript Language: JavaScript and super languages labels Oct 28, 2023
@Conaclos Conaclos force-pushed the conaclos/deseializer-poc branch from e3ec595 to 52ecb2d Compare October 29, 2023 23:15
@Conaclos Conaclos force-pushed the conaclos/deseializer-poc branch from 52ecb2d to 694783f Compare October 31, 2023 16:17
@Conaclos
Copy link
Member Author

Conaclos commented Nov 9, 2023

Closing in favor of #683

@Conaclos Conaclos closed this Nov 9, 2023
@Conaclos Conaclos deleted the conaclos/deseializer-poc branch February 15, 2024 00:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Linter Area: linter L-JavaScript Language: JavaScript and super languages
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant