Skip to content

Commit

Permalink
Use tab width in measure_text helper
Browse files Browse the repository at this point in the history
  • Loading branch information
cnpryer committed Aug 26, 2023
1 parent 6a2a21e commit 3db7e57
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion crates/ruff_formatter/src/builders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ where
#[derive(Copy, Clone)]
pub struct LineSuffix<'a, Context> {
content: Argument<'a, Context>,
reserved_width: u32, // TODO(cnpryer): `TextWidth`
reserved_width: u32,
}

impl<Context> Format<Context> for LineSuffix<'_, Context> {
Expand Down
12 changes: 9 additions & 3 deletions crates/ruff_python_formatter/src/comments/format.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use ruff_python_ast::Ranged;
use ruff_text_size::{TextLen, TextRange, TextSize};

use ruff_formatter::{format_args, write, FormatError, SourceCode};
use ruff_formatter::{format_args, write, FormatError, FormatOptions, SourceCode};
use ruff_python_ast::node::{AnyNodeRef, AstNode};
use ruff_python_trivia::{lines_after, lines_after_ignoring_trivia, lines_before};
use unicode_width::UnicodeWidthChar;
Expand Down Expand Up @@ -174,7 +174,10 @@ impl Format<PyFormatContext<'_>> for FormatTrailingComments<'_> {
[
line_suffix(
&format_args![space(), space(), format_comment(trailing)],
measure_text(&f.context().source()[slice.range()], 2) + 2 // Account for two added spaces TODO(cnpryer): Tab width
measure_text(
&f.context().source()[slice.range()],
f.options().tab_width().value()
) + 2 // Account for two added spaces
),
expand_parent()
]
Expand Down Expand Up @@ -284,7 +287,10 @@ impl Format<PyFormatContext<'_>> for FormatDanglingOpenParenthesisComments<'_> {
line_suffix(
&format_args!(space(), space(), format_comment(comment)),
// Marking the comment as a line suffix with reserved width is safe since we expect the comment to be end of line.
measure_text(&f.context().source()[slice.range()], 2) + 2 // Account for two added spaces TODO(cnpryer): Tab width
measure_text(
&f.context().source()[slice.range()],
f.options().tab_width().value()
) + 2 // Account for two added spaces
),
expand_parent()
]
Expand Down

0 comments on commit 3db7e57

Please sign in to comment.