Skip to content

Commit bbb69a8

Browse files
committed
Use the currently selected channel to format code
1 parent ad26813 commit bbb69a8

File tree

4 files changed

+40
-9
lines changed

4 files changed

+40
-9
lines changed

ui/frontend/reducers/output/format.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@ interface State {
1818
}
1919

2020
interface FormatRequestBody {
21-
code: string;
21+
channel: string;
2222
edition: string;
23+
code: string;
2324
}
2425

2526
const FormatResponseBody = z.object({

ui/frontend/selectors/index.ts

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,27 @@ const LABELS: { [index in PrimaryActionCore]: string } = {
9999

100100
export const getExecutionLabel = createSelector(primaryActionSelector, primaryAction => LABELS[primaryAction]);
101101

102+
const channelSelector = (state: State) => state.configuration.channel;
103+
104+
const selectedChannelVersionsSelector = createSelector(
105+
channelSelector,
106+
(state: State) => state.versions,
107+
(channel, versions) => {
108+
switch (channel) {
109+
case Channel.Stable:
110+
return versions.stable;
111+
case Channel.Beta:
112+
return versions.beta;
113+
case Channel.Nightly:
114+
return versions.nightly;
115+
}
116+
},
117+
)
118+
102119
const getStable = (state: State) => state.versions.stable?.rustc;
103120
const getBeta = (state: State) => state.versions.beta?.rustc;
104121
const getNightly = (state: State) => state.versions.nightly?.rustc;
105-
const getRustfmt = (state: State) => state.versions.nightly?.rustfmt;
122+
const getRustfmt = createSelector(selectedChannelVersionsSelector, (versions) => versions?.rustfmt);
106123
const getClippy = (state: State) => state.versions.nightly?.clippy;
107124
const getMiri = (state: State) => state.versions?.nightly?.miri;
108125

@@ -123,8 +140,6 @@ export const miriVersionDetailsText = createSelector(getMiri, versionDetails);
123140

124141
const editionSelector = (state: State) => state.configuration.edition;
125142

126-
const channelSelector = (state: State) => state.configuration.channel;
127-
128143
export const isNightlyChannel = createSelector(
129144
channelSelector,
130145
(channel) => channel === Channel.Nightly,
@@ -311,9 +326,10 @@ export const clippyRequestSelector = createSelector(
311326
);
312327

313328
export const formatRequestSelector = createSelector(
314-
codeSelector,
329+
channelSelector,
315330
editionSelector,
316-
(code, edition) => ({ code, edition }),
331+
codeSelector,
332+
(channel, edition, code) => ({ channel, edition, code }),
317333
);
318334

319335
const focus = (state: State) => state.output.meta.focus;

ui/src/main.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,9 +355,11 @@ struct ExecuteResponse {
355355

356356
#[derive(Debug, Clone, Deserialize)]
357357
struct FormatRequest {
358-
code: String,
358+
#[serde(default)]
359+
channel: Option<String>,
359360
#[serde(default)]
360361
edition: String,
362+
code: String,
361363
}
362364

363365
#[derive(Debug, Clone, Serialize)]

ui/src/server_axum.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1052,10 +1052,19 @@ pub(crate) mod api_orchestrator_integration_impls {
10521052
type Error = ParseFormatRequestError;
10531053

10541054
fn try_from(other: crate::FormatRequest) -> std::result::Result<Self, Self::Error> {
1055-
let crate::FormatRequest { code, edition } = other;
1055+
let crate::FormatRequest {
1056+
channel,
1057+
edition,
1058+
code,
1059+
} = other;
1060+
1061+
let channel = match channel {
1062+
Some(c) => parse_channel(&c)?,
1063+
None => Channel::Nightly,
1064+
};
10561065

10571066
Ok(FormatRequest {
1058-
channel: Channel::Nightly, // TODO: use what user has submitted
1067+
channel,
10591068
crate_type: CrateType::Binary, // TODO: use what user has submitted
10601069
edition: parse_edition(&edition)?,
10611070
code,
@@ -1065,6 +1074,9 @@ pub(crate) mod api_orchestrator_integration_impls {
10651074

10661075
#[derive(Debug, Snafu)]
10671076
pub(crate) enum ParseFormatRequestError {
1077+
#[snafu(context(false))]
1078+
Channel { source: ParseChannelError },
1079+
10681080
#[snafu(context(false))]
10691081
Edition { source: ParseEditionError },
10701082
}

0 commit comments

Comments
 (0)