mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-28 21:05:08 +00:00
Fix(vscode): Respect line length ruff.toml configuration (#7306)
This commit is contained in:
parent
ee0f1270cf
commit
e561f5783b
2 changed files with 18 additions and 3 deletions
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
@ -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),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue