Skip to content

Commit

Permalink
Fix(vscode): Respect line length ruff.toml configuration (#7306)
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaReiser authored Sep 12, 2023
1 parent ee0f127 commit e561f57
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
6 changes: 4 additions & 2 deletions crates/ruff_cli/src/commands/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,14 @@ pub(crate) fn format(
return None;
};

let preview = match pyproject_config.settings.lib.preview {
let resolved_settings = resolver.resolve(path, &pyproject_config);

let preview = match resolved_settings.preview {
PreviewMode::Enabled => ruff_python_formatter::PreviewMode::Enabled,
PreviewMode::Disabled => ruff_python_formatter::PreviewMode::Disabled,
};
let line_length = resolved_settings.line_length;

let line_length = resolver.resolve(path, &pyproject_config).line_length;
let options = PyFormatOptions::from_source_type(source_type)
.with_line_width(LineWidth::from(NonZeroU16::from(line_length)))
.with_preview(preview);
Expand Down
15 changes: 14 additions & 1 deletion crates/ruff_cli/src/commands/format_stdin.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
use std::io::{stdout, Write};
use std::num::NonZeroU16;
use std::path::Path;

use anyhow::Result;
use log::warn;
use ruff::settings::types::PreviewMode;
use ruff_formatter::LineWidth;

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

// Format the file.
let path = cli.stdin_filename.as_deref();

let preview = match pyproject_config.settings.lib.preview {
PreviewMode::Enabled => ruff_python_formatter::PreviewMode::Enabled,
PreviewMode::Disabled => ruff_python_formatter::PreviewMode::Disabled,
};
let line_length = pyproject_config.settings.lib.line_length;

let options = path
.map(PyFormatOptions::from_extension)
.unwrap_or_default();
.unwrap_or_default()
.with_line_width(LineWidth::from(NonZeroU16::from(line_length)))
.with_preview(preview);

match format_source(path, options, mode) {
Ok(result) => match mode {
FormatMode::Write => Ok(ExitStatus::Success),
Expand Down

0 comments on commit e561f57

Please sign in to comment.