diff --git a/ui/frontend/reducers/output/format.ts b/ui/frontend/reducers/output/format.ts index e03a550d8..d16f92e5d 100644 --- a/ui/frontend/reducers/output/format.ts +++ b/ui/frontend/reducers/output/format.ts @@ -18,8 +18,9 @@ interface State { } interface FormatRequestBody { - code: string; + channel: string; edition: string; + code: string; } const FormatResponseBody = z.object({ diff --git a/ui/frontend/selectors/index.ts b/ui/frontend/selectors/index.ts index c63cd02cb..3e9a20492 100644 --- a/ui/frontend/selectors/index.ts +++ b/ui/frontend/selectors/index.ts @@ -99,10 +99,27 @@ const LABELS: { [index in PrimaryActionCore]: string } = { export const getExecutionLabel = createSelector(primaryActionSelector, primaryAction => LABELS[primaryAction]); +const channelSelector = (state: State) => state.configuration.channel; + +const selectedChannelVersionsSelector = createSelector( + channelSelector, + (state: State) => state.versions, + (channel, versions) => { + switch (channel) { + case Channel.Stable: + return versions.stable; + case Channel.Beta: + return versions.beta; + case Channel.Nightly: + return versions.nightly; + } + }, +) + const getStable = (state: State) => state.versions.stable?.rustc; const getBeta = (state: State) => state.versions.beta?.rustc; const getNightly = (state: State) => state.versions.nightly?.rustc; -const getRustfmt = (state: State) => state.versions.nightly?.rustfmt; +const getRustfmt = createSelector(selectedChannelVersionsSelector, (versions) => versions?.rustfmt); const getClippy = (state: State) => state.versions.nightly?.clippy; const getMiri = (state: State) => state.versions?.nightly?.miri; @@ -123,8 +140,6 @@ export const miriVersionDetailsText = createSelector(getMiri, versionDetails); const editionSelector = (state: State) => state.configuration.edition; -const channelSelector = (state: State) => state.configuration.channel; - export const isNightlyChannel = createSelector( channelSelector, (channel) => channel === Channel.Nightly, @@ -311,9 +326,10 @@ export const clippyRequestSelector = createSelector( ); export const formatRequestSelector = createSelector( - codeSelector, + channelSelector, editionSelector, - (code, edition) => ({ code, edition }), + codeSelector, + (channel, edition, code) => ({ channel, edition, code }), ); const focus = (state: State) => state.output.meta.focus; diff --git a/ui/src/main.rs b/ui/src/main.rs index 184765b3a..f00a97d8d 100644 --- a/ui/src/main.rs +++ b/ui/src/main.rs @@ -355,9 +355,11 @@ struct ExecuteResponse { #[derive(Debug, Clone, Deserialize)] struct FormatRequest { - code: String, + #[serde(default)] + channel: Option, #[serde(default)] edition: String, + code: String, } #[derive(Debug, Clone, Serialize)] diff --git a/ui/src/server_axum.rs b/ui/src/server_axum.rs index 1341a4570..d01e7a9eb 100644 --- a/ui/src/server_axum.rs +++ b/ui/src/server_axum.rs @@ -1052,10 +1052,19 @@ pub(crate) mod api_orchestrator_integration_impls { type Error = ParseFormatRequestError; fn try_from(other: crate::FormatRequest) -> std::result::Result { - let crate::FormatRequest { code, edition } = other; + let crate::FormatRequest { + channel, + edition, + code, + } = other; + + let channel = match channel { + Some(c) => parse_channel(&c)?, + None => Channel::Nightly, + }; Ok(FormatRequest { - channel: Channel::Nightly, // TODO: use what user has submitted + channel, crate_type: CrateType::Binary, // TODO: use what user has submitted edition: parse_edition(&edition)?, code, @@ -1065,6 +1074,9 @@ pub(crate) mod api_orchestrator_integration_impls { #[derive(Debug, Snafu)] pub(crate) enum ParseFormatRequestError { + #[snafu(context(false))] + Channel { source: ParseChannelError }, + #[snafu(context(false))] Edition { source: ParseEditionError }, }