Skip to content

Commit 31b3fcb

Browse files
authored
Merge pull request #999 from rust-lang/no-hide-fmt-error
Do not hide rustfmt output when it failed
2 parents b4f8269 + 5497162 commit 31b3fcb

File tree

5 files changed

+83
-61
lines changed

5 files changed

+83
-61
lines changed

ui/frontend/.eslintrc.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ module.exports = {
7979
'reducers/output/gist.ts',
8080
'reducers/output/hir.ts',
8181
'reducers/output/llvmIr.ts',
82+
'reducers/output/meta.ts',
8283
'reducers/output/mir.ts',
8384
'reducers/output/wasm.ts',
8485
'reducers/websocket.ts',

ui/frontend/.prettierignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ node_modules
3030
!reducers/output/gist.ts
3131
!reducers/output/hir.ts
3232
!reducers/output/llvmIr.ts
33+
!reducers/output/meta.ts
3334
!reducers/output/mir.ts
3435
!reducers/output/wasm.ts
3536
!reducers/websocket.ts

ui/frontend/Output.tsx

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React, { useCallback } from 'react';
22
import { useSelector, useDispatch } from 'react-redux';
33

4-
import * as actions from './actions';
4+
import { changeFocus } from './reducers/output/meta';
55
import { State } from './reducers';
66
import { Focus } from './types';
77

@@ -52,18 +52,18 @@ const Output: React.FC = () => {
5252
useSelector((state: State) => state.output);
5353

5454
const dispatch = useDispatch();
55-
const focusClose = useCallback(() => dispatch(actions.changeFocus()), [dispatch]);
56-
const focusExecute = useCallback(() => dispatch(actions.changeFocus(Focus.Execute)), [dispatch]);
57-
const focusFormat = useCallback(() => dispatch(actions.changeFocus(Focus.Format)), [dispatch]);
58-
const focusClippy = useCallback(() => dispatch(actions.changeFocus(Focus.Clippy)), [dispatch]);
59-
const focusMiri = useCallback(() => dispatch(actions.changeFocus(Focus.Miri)), [dispatch]);
60-
const focusMacroExpansion = useCallback(() => dispatch(actions.changeFocus(Focus.MacroExpansion)), [dispatch]);
61-
const focusAssembly = useCallback(() => dispatch(actions.changeFocus(Focus.Asm)), [dispatch]);
62-
const focusLlvmIr = useCallback(() => dispatch(actions.changeFocus(Focus.LlvmIr)), [dispatch]);
63-
const focusMir = useCallback(() => dispatch(actions.changeFocus(Focus.Mir)), [dispatch]);
64-
const focusHir = useCallback(() => dispatch(actions.changeFocus(Focus.Hir)), [dispatch]);
65-
const focusWasm = useCallback(() => dispatch(actions.changeFocus(Focus.Wasm)), [dispatch]);
66-
const focusGist = useCallback(() => dispatch(actions.changeFocus(Focus.Gist)), [dispatch]);
55+
const focusClose = useCallback(() => dispatch(changeFocus()), [dispatch]);
56+
const focusExecute = useCallback(() => dispatch(changeFocus(Focus.Execute)), [dispatch]);
57+
const focusFormat = useCallback(() => dispatch(changeFocus(Focus.Format)), [dispatch]);
58+
const focusClippy = useCallback(() => dispatch(changeFocus(Focus.Clippy)), [dispatch]);
59+
const focusMiri = useCallback(() => dispatch(changeFocus(Focus.Miri)), [dispatch]);
60+
const focusMacroExpansion = useCallback(() => dispatch(changeFocus(Focus.MacroExpansion)), [dispatch]);
61+
const focusAssembly = useCallback(() => dispatch(changeFocus(Focus.Asm)), [dispatch]);
62+
const focusLlvmIr = useCallback(() => dispatch(changeFocus(Focus.LlvmIr)), [dispatch]);
63+
const focusMir = useCallback(() => dispatch(changeFocus(Focus.Mir)), [dispatch]);
64+
const focusHir = useCallback(() => dispatch(changeFocus(Focus.Hir)), [dispatch]);
65+
const focusWasm = useCallback(() => dispatch(changeFocus(Focus.Wasm)), [dispatch]);
66+
const focusGist = useCallback(() => dispatch(changeFocus(Focus.Gist)), [dispatch]);
6767

6868
const showStdin = useSelector(selectors.showStdinSelector);
6969

ui/frontend/actions.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import {
1616
DemangleAssembly,
1717
Edition,
1818
Editor,
19-
Focus,
2019
Mode,
2120
Notification,
2221
Orientation,
@@ -86,7 +85,6 @@ export enum ActionType {
8685
ChangeMode = 'CHANGE_MODE',
8786
ChangeEdition = 'CHANGE_EDITION',
8887
ChangeBacktrace = 'CHANGE_BACKTRACE',
89-
ChangeFocus = 'CHANGE_FOCUS',
9088
EditCode = 'EDIT_CODE',
9189
AddMainFunction = 'ADD_MAIN_FUNCTION',
9290
AddImport = 'ADD_IMPORT',
@@ -174,9 +172,6 @@ export const reExecuteWithBacktrace = (): ThunkAction => dispatch => {
174172
dispatch(performExecuteOnly());
175173
};
176174

177-
export const changeFocus = (focus?: Focus) =>
178-
createAction(ActionType.ChangeFocus, { focus });
179-
180175
type FetchArg = Parameters<typeof fetch>[0];
181176

182177
export function jsonGet(url: FetchArg) {
@@ -634,7 +629,6 @@ export type Action =
634629
| ReturnType<typeof changeDemangleAssembly>
635630
| ReturnType<typeof changeEditionRaw>
636631
| ReturnType<typeof changeEditor>
637-
| ReturnType<typeof changeFocus>
638632
| ReturnType<typeof changeKeybinding>
639633
| ReturnType<typeof changeMode>
640634
| ReturnType<typeof changeOrientation>

ui/frontend/reducers/output/meta.ts

Lines changed: 68 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,90 @@
1-
import { Action, ActionType } from '../../actions';
1+
import { PayloadAction, createSlice } from '@reduxjs/toolkit';
2+
import { Draft } from 'immer';
3+
4+
import { ActionType } from '../../actions';
25
import { Focus } from '../../types';
3-
import { performGistLoad, performGistSave } from './gist';
4-
import { performFormat } from './format';
5-
import { performExecute, wsExecuteRequest } from './execute';
66
import { performCompileAssembly } from './assembly';
7+
import { performExecute, wsExecuteRequest } from './execute';
8+
import { performFormat } from './format';
9+
import { performGistLoad, performGistSave } from './gist';
710
import { performCompileHir } from './hir';
811
import { performCompileLlvmIr } from './llvmIr';
912
import { performCompileMir } from './mir';
1013
import { performCompileWasm } from './wasm';
1114

12-
const DEFAULT: State = {
13-
};
15+
const initialState: State = {};
1416

1517
interface State {
1618
focus?: Focus;
1719
}
1820

19-
export default function meta(state = DEFAULT, action: Action) {
20-
switch (action.type) {
21-
case ActionType.ChangeFocus:
22-
return { ...state, focus: action.focus };
21+
function setExecute(state: Draft<State>) {
22+
state.focus = Focus.Execute;
23+
}
24+
function setGist(state: Draft<State>) {
25+
state.focus = Focus.Gist;
26+
}
2327

24-
case ActionType.RequestClippy:
25-
return { ...state, focus: Focus.Clippy };
28+
const slice = createSlice({
29+
name: 'output/meta',
30+
initialState,
31+
reducers: {
32+
changeFocus: (state, action: PayloadAction<Focus | undefined>) => {
33+
state.focus = action.payload;
34+
},
35+
},
36+
extraReducers: (builder) => {
37+
builder
38+
.addCase(ActionType.RequestClippy, (state) => {
39+
state.focus = Focus.Clippy;
40+
})
2641

27-
case ActionType.RequestMiri:
28-
return { ...state, focus: Focus.Miri };
42+
.addCase(ActionType.RequestMiri, (state) => {
43+
state.focus = Focus.Miri;
44+
})
2945

30-
case ActionType.RequestMacroExpansion:
31-
return { ...state, focus: Focus.MacroExpansion };
46+
.addCase(ActionType.RequestMacroExpansion, (state) => {
47+
state.focus = Focus.MacroExpansion;
48+
})
3249

33-
case performExecute.pending.type:
34-
case wsExecuteRequest.type:
35-
return { ...state, focus: Focus.Execute };
50+
.addCase(performExecute.pending, setExecute)
51+
.addCase(wsExecuteRequest, setExecute)
3652

37-
case performCompileAssembly.pending.type:
38-
return { ...state, focus: Focus.Asm };
53+
.addCase(performCompileAssembly.pending, (state) => {
54+
state.focus = Focus.Asm;
55+
})
3956

40-
case performCompileHir.pending.type:
41-
return { ...state, focus: Focus.Hir };
57+
.addCase(performCompileHir.pending, (state) => {
58+
state.focus = Focus.Hir;
59+
})
4260

43-
case performCompileLlvmIr.pending.type:
44-
return { ...state, focus: Focus.LlvmIr };
61+
.addCase(performCompileLlvmIr.pending, (state) => {
62+
state.focus = Focus.LlvmIr;
63+
})
4564

46-
case performCompileMir.pending.type:
47-
return { ...state, focus: Focus.Mir };
65+
.addCase(performCompileMir.pending, (state) => {
66+
state.focus = Focus.Mir;
67+
})
4868

49-
case performCompileWasm.pending.type:
50-
return { ...state, focus: Focus.Wasm };
69+
.addCase(performCompileWasm.pending, (state) => {
70+
state.focus = Focus.Wasm;
71+
})
5172

52-
default: {
53-
if (performGistLoad.pending.match(action) || performGistSave.pending.match(action)) {
54-
return { ...state, focus: Focus.Gist };
55-
} else if (performFormat.pending.match(action)) {
56-
return { ...state, focus: Focus.Format };
57-
} else if (performFormat.fulfilled.match(action)) {
58-
return { ...state, focus: undefined };
59-
} else {
60-
return state;
61-
}
62-
}
63-
}
64-
}
73+
.addCase(performFormat.pending, (state) => {
74+
state.focus = Focus.Format;
75+
})
76+
77+
.addCase(performFormat.fulfilled, (state, action) => {
78+
if (action.payload.success) {
79+
state.focus = undefined;
80+
}
81+
})
82+
83+
.addCase(performGistLoad.pending, setGist)
84+
.addCase(performGistSave.pending, setGist);
85+
},
86+
});
87+
88+
export const { changeFocus } = slice.actions;
89+
90+
export default slice.reducer;

0 commit comments

Comments
 (0)