Skip to content

Commit e832327

Browse files
authored
Require --preview for ruff server (#10368)
## Summary Fixes #10367. While the server is still in an unstable state, requiring a `--preview` flag would be a good way to indicate this to end users.
1 parent 3243906 commit e832327

File tree

4 files changed

+13
-4
lines changed

4 files changed

+13
-4
lines changed

crates/ruff/src/args.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,11 @@ pub struct FormatCommand {
497497
}
498498

499499
#[derive(Clone, Debug, clap::Parser)]
500-
pub struct ServerCommand;
500+
pub struct ServerCommand {
501+
/// Enable preview mode; required for regular operation
502+
#[arg(long)]
503+
pub(crate) preview: bool,
504+
}
501505

502506
#[derive(Debug, Clone, Copy, clap::ValueEnum)]
503507
pub enum HelpFormat {

crates/ruff/src/commands/server.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@ use tracing_subscriber::{
99
};
1010
use tracing_tree::time::Uptime;
1111

12-
pub(crate) fn run_server(log_level: LogLevel) -> Result<ExitStatus> {
12+
pub(crate) fn run_server(preview: bool, log_level: LogLevel) -> Result<ExitStatus> {
13+
if !preview {
14+
tracing::error!("--preview needs to be provided as a command line argument while the server is still unstable.\nFor example: `ruff server --preview`");
15+
return Ok(ExitStatus::Error);
16+
}
1317
let trace_level = if log_level == LogLevel::Verbose {
1418
Level::TRACE
1519
} else {

crates/ruff/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,8 +206,8 @@ fn format(args: FormatCommand, global_options: GlobalConfigArgs) -> Result<ExitS
206206

207207
#[allow(clippy::needless_pass_by_value)] // TODO: remove once we start taking arguments from here
208208
fn server(args: ServerCommand, log_level: LogLevel) -> Result<ExitStatus> {
209-
let ServerCommand {} = args;
210-
commands::server::run_server(log_level)
209+
let ServerCommand { preview } = args;
210+
commands::server::run_server(preview, log_level)
211211
}
212212

213213
pub fn check(args: CheckCommand, global_options: GlobalConfigArgs) -> Result<ExitStatus> {

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ changelog_sections.breaking = "Breaking changes"
8181
changelog_sections.preview = "Preview features"
8282
changelog_sections.rule = "Rule changes"
8383
changelog_sections.formatter = "Formatter"
84+
changelog_sections.server = "Server"
8485
changelog_sections.cli = "CLI"
8586
changelog_sections.configuration = "Configuration"
8687
changelog_sections.bug = "Bug fixes"

0 commit comments

Comments
 (0)