Skip to content

Commit e561f57

Browse files
authored
Fix(vscode): Respect line length ruff.toml configuration (#7306)
1 parent ee0f127 commit e561f57

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

crates/ruff_cli/src/commands/format.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,14 @@ pub(crate) fn format(
7373
return None;
7474
};
7575

76-
let preview = match pyproject_config.settings.lib.preview {
76+
let resolved_settings = resolver.resolve(path, &pyproject_config);
77+
78+
let preview = match resolved_settings.preview {
7779
PreviewMode::Enabled => ruff_python_formatter::PreviewMode::Enabled,
7880
PreviewMode::Disabled => ruff_python_formatter::PreviewMode::Disabled,
7981
};
82+
let line_length = resolved_settings.line_length;
8083

81-
let line_length = resolver.resolve(path, &pyproject_config).line_length;
8284
let options = PyFormatOptions::from_source_type(source_type)
8385
.with_line_width(LineWidth::from(NonZeroU16::from(line_length)))
8486
.with_preview(preview);

crates/ruff_cli/src/commands/format_stdin.rs

+14-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
use std::io::{stdout, Write};
2+
use std::num::NonZeroU16;
23
use std::path::Path;
34

45
use anyhow::Result;
56
use log::warn;
7+
use ruff::settings::types::PreviewMode;
8+
use ruff_formatter::LineWidth;
69

710
use ruff_python_formatter::{format_module, PyFormatOptions};
811
use ruff_workspace::resolver::python_file_at_path;
@@ -35,9 +38,19 @@ pub(crate) fn format_stdin(cli: &FormatArguments, overrides: &Overrides) -> Resu
3538

3639
// Format the file.
3740
let path = cli.stdin_filename.as_deref();
41+
42+
let preview = match pyproject_config.settings.lib.preview {
43+
PreviewMode::Enabled => ruff_python_formatter::PreviewMode::Enabled,
44+
PreviewMode::Disabled => ruff_python_formatter::PreviewMode::Disabled,
45+
};
46+
let line_length = pyproject_config.settings.lib.line_length;
47+
3848
let options = path
3949
.map(PyFormatOptions::from_extension)
40-
.unwrap_or_default();
50+
.unwrap_or_default()
51+
.with_line_width(LineWidth::from(NonZeroU16::from(line_length)))
52+
.with_preview(preview);
53+
4154
match format_source(path, options, mode) {
4255
Ok(result) => match mode {
4356
FormatMode::Write => Ok(ExitStatus::Success),

0 commit comments

Comments
 (0)