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

Fix: support configuring the indent_width for markdown files #132

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/configuration/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ impl ConfigurationBuilder {
self.insert("lineWidth", (value as i32).into())
}

pub fn indent_width(&mut self, value: u32) -> &mut Self {
self.insert("indentWidth", (value as i32).into())
}
Copy link
Member

@dsherret dsherret Dec 10, 2024

Choose a reason for hiding this comment

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

Have you tested this out? I don't think it will work. I never added indent width to markdown because markdown is very specific about how indentation works. For example, code blocks are 4 spaces and some indent is 3 spaces.

Copy link
Author

Choose a reason for hiding this comment

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

I will add a test to verify if it works correctly. Thank you for bringing this to my attention.

Copy link
Author

Choose a reason for hiding this comment

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

@dsherret You’re right. I tried testing it after the modification, but it failed. Do you have any suggestions that could help resolve this issue?


/// The kind of newline to use.
/// Default: `NewLineKind::LineFeed`
pub fn new_line_kind(&mut self, value: NewLineKind) -> &mut Self {
Expand Down Expand Up @@ -136,6 +140,7 @@ mod tests {
config
.new_line_kind(NewLineKind::CarriageReturnLineFeed)
.line_width(90)
.indent_width(2)
.text_wrap(TextWrap::Always)
.emphasis_kind(EmphasisKind::Asterisks)
.strong_kind(StrongKind::Underscores)
Expand All @@ -146,7 +151,7 @@ mod tests {
.ignore_end_directive("test");

let inner_config = config.get_inner_config();
assert_eq!(inner_config.len(), 10);
assert_eq!(inner_config.len(), 11);
let diagnostics = resolve_config(inner_config, &Default::default()).diagnostics;
assert_eq!(diagnostics.len(), 0);
}
Expand All @@ -161,6 +166,7 @@ mod tests {
let mut config_builder = ConfigurationBuilder::new();
let config = config_builder.global_config(global_config).build();
assert_eq!(config.line_width, 90);
assert_eq!(config.indent_width, 2);
assert_eq!(config.new_line_kind == NewLineKind::CarriageReturnLineFeed, true);
}

Expand All @@ -170,6 +176,7 @@ mod tests {
let mut config_builder = ConfigurationBuilder::new();
let config = config_builder.global_config(global_config).build();
assert_eq!(config.line_width, 80); // this is different
assert_eq!(config.indent_width, 2);
assert_eq!(config.new_line_kind == NewLineKind::LineFeed, true);
}
}
6 changes: 6 additions & 0 deletions src/configuration/resolve_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ pub fn resolve_config(
global_config.line_width.unwrap_or(80),
&mut diagnostics,
),
indent_width: get_value(
&mut config,
"indentWidth",
global_config.indent_width.unwrap_or(2).into(),
&mut diagnostics,
),
new_line_kind: get_value(
&mut config,
"newLineKind",
Expand Down
1 change: 1 addition & 0 deletions src/configuration/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use serde::Serialize;
#[serde(rename_all = "camelCase")]
pub struct Configuration {
pub line_width: u32,
pub indent_width: u32,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could you add a test that exercises this option?

pub new_line_kind: NewLineKind,
pub text_wrap: TextWrap,
pub emphasis_kind: EmphasisKind,
Expand Down