From e832327a56be73d48733506863711a3740f15877 Mon Sep 17 00:00:00 2001 From: Jane Lewis Date: Wed, 13 Mar 2024 16:52:44 -0700 Subject: [PATCH] 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. --- crates/ruff/src/args.rs | 6 +++++- crates/ruff/src/commands/server.rs | 6 +++++- crates/ruff/src/lib.rs | 4 ++-- pyproject.toml | 1 + 4 files changed, 13 insertions(+), 4 deletions(-) diff --git a/crates/ruff/src/args.rs b/crates/ruff/src/args.rs index 059d2eb10f9b9..c4f9f7a247136 100644 --- a/crates/ruff/src/args.rs +++ b/crates/ruff/src/args.rs @@ -497,7 +497,11 @@ pub struct FormatCommand { } #[derive(Clone, Debug, clap::Parser)] -pub struct ServerCommand; +pub struct ServerCommand { + /// Enable preview mode; required for regular operation + #[arg(long)] + pub(crate) preview: bool, +} #[derive(Debug, Clone, Copy, clap::ValueEnum)] pub enum HelpFormat { diff --git a/crates/ruff/src/commands/server.rs b/crates/ruff/src/commands/server.rs index 5ca37ed2b5007..e6b9c5e4dba4e 100644 --- a/crates/ruff/src/commands/server.rs +++ b/crates/ruff/src/commands/server.rs @@ -9,7 +9,11 @@ use tracing_subscriber::{ }; use tracing_tree::time::Uptime; -pub(crate) fn run_server(log_level: LogLevel) -> Result { +pub(crate) fn run_server(preview: bool, log_level: LogLevel) -> Result { + if !preview { + tracing::error!("--preview needs to be provided as a command line argument while the server is still unstable.\nFor example: `ruff server --preview`"); + return Ok(ExitStatus::Error); + } let trace_level = if log_level == LogLevel::Verbose { Level::TRACE } else { diff --git a/crates/ruff/src/lib.rs b/crates/ruff/src/lib.rs index c8381ffc82855..1e74a42aac5fa 100644 --- a/crates/ruff/src/lib.rs +++ b/crates/ruff/src/lib.rs @@ -206,8 +206,8 @@ fn format(args: FormatCommand, global_options: GlobalConfigArgs) -> Result Result { - let ServerCommand {} = args; - commands::server::run_server(log_level) + let ServerCommand { preview } = args; + commands::server::run_server(preview, log_level) } pub fn check(args: CheckCommand, global_options: GlobalConfigArgs) -> Result { diff --git a/pyproject.toml b/pyproject.toml index b67cf40362466..18744d4a0b334 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -81,6 +81,7 @@ changelog_sections.breaking = "Breaking changes" changelog_sections.preview = "Preview features" changelog_sections.rule = "Rule changes" changelog_sections.formatter = "Formatter" +changelog_sections.server = "Server" changelog_sections.cli = "CLI" changelog_sections.configuration = "Configuration" changelog_sections.bug = "Bug fixes"