-
Notifications
You must be signed in to change notification settings - Fork 664
feat(rome_service): configuration file shape #2825
Conversation
Deploying with Cloudflare Pages
|
indent_size: u8, | ||
|
||
/// What's the max width of a line. Defaults to 80. | ||
pub line_width: u16, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's a bit confusing to have line_width
be a raw u16
rather than just keeping it as a LineWidth
.
If the reason for that is that LineWidth
doesn't implement Deserialize
, I think you can work around that with something like:
/// What's the max width of a line. Defaults to 80.
#[serde(with = "LineWidthDef")]
pub line_width: LineWidth,
}
#[derive(Deserialize)]
#[serde(remote = "LineWidth")]
pub struct LineWidthDef(pub u16);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you make the u16
in LineWidth
private again (based on the comment from @leops), then I think something like this would still work:
/// What's the max width of a line. Defaults to 80.
#[serde(deserialize_with = "deserialize_line_width")]
pub line_width: LineWidth,
}
fn deserialize_line_width<'de, D>(deserializer: D) -> Result<LineWidth, D::Error>
where
D: serde::de::Deserializer<'de>,
{
let value: u16 = Deserialize::deserialize(deserializer)?;
LineWidth::try_from(value).map_err(serde::de::Error::custom)
}
You'd need to implement Display
for LineWidthFromIntError
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately doing so will force us to bypass the LineWidth::try_from
. This feature requires having a impl From<LineWidthDef> for LineWidth
, which goes in conflict with TryFrom
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The second snippet I posted wouldn't require a new LineWidthDef
struct at all. It's an alternative to the "remote" approach from that first snippet. It seems to work fine when I test it locally.
But I don't think it's a big deal if you want to keep this as line_width: u16
I'll just defer to @leops for this PR since he made this crate.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the easiest way to deal with this would be to implement Display
for LineWidthFromIntError
, then we may be able to simply write this:
pub line_width: u16, | |
#[serde(try_from = "u16")] | |
pub line_width: LineWidth, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't know about the serde try_from
attribute. That's much better!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Summary
This PR closes #2823
I created a new data structure to track the configuration, called
Configuration
. This object is a separated entity from theWorkspaceSettings
because the configuration that we will store in the json file is going to be different.An example is the
enabled
field underformatter
. Another example will be theextend
field, which belongs exclusively to the configuration file.For this reason, the resolution of the
WorkspaceSettings
will be done in a different step, where it will be joined withConfiguration
.The first shape of the configuration file is the following:
Test Plan
I crated a small test to make sure that ALL fields are correctly mapped and read. Another one to make sure that the default values are correctly initialized by serde.