ui: remove useless wastyle

This commit is contained in:
undefined committed 2022-01-09 05:41:38 +08:00
1 parent fda667c424
commit a93ff2a3d8
4 files changed
+11 -52

No files matched your search

+3 -20
View File
@@ -1,6 +1,4 @@
import * as monaco from 'monaco-editor/esm/vs/editor/editor.api';
import loadFormatter from 'vj/components/wastyle/index';
import Notification from 'vj/components/notification';
import './monaco.css';
export default monaco;
@@ -31,23 +29,8 @@ export function registerAction(editor, model, element) {
editor.addCommand(monaco.KeyMod.CtrlCmd | monaco.KeyMod.Shift | monaco.KeyCode.KeyP, () => {
editor.getAction('editor.action.quickCommand').run();
});
loadFormatter().then(([loaded, format]) => {
if (!loaded) return;
editor.addAction({
id: 'hydro.format',
label: 'Format Code',
contextMenuOrder: 0,
contextMenuGroupId: 'operation',
keybindings: [monaco.KeyMod.Alt | monaco.KeyMod.Shift | monaco.KeyCode.KeyF],
run: () => {
if (!['cpp', 'c'].includes(model._languageIdentifier.language)) return;
const [success, result] = format(editor.getValue(), `${UserContext.astyleOptions.trim()} mode=c`);
if (success) editor.setValue(result);
else Notification.warn(result);
},
});
editor.addCommand(monaco.KeyMod.Alt | monaco.KeyMod.Shift | monaco.KeyCode.KeyF, () => {
editor.getAction('hydro.format').run();
});
editor.addCommand(monaco.KeyMod.Alt | monaco.KeyMod.Shift | monaco.KeyCode.KeyF, () => {
const action = editor.getAction('editor.action.format') || editor.getAction('editor.action.formatDocument');
if (action) action.run();
});
}
@@ -1,16 +0,0 @@
import astyleBinaryUrl from 'wastyle/dist/astyle-optimize-size.wasm';
export default async function load() {
const { init, format } = await import('wastyle');
try {
await init(astyleBinaryUrl);
console.log('WAstyle is ready!');
const formatter = (code, options) => {
const [success, result] = format(code, options);
return [success, (result || '').replace(/^#(include|import)[\t ]*(<|")/gm, (match, p1, p2) => `#${p1} ${p2}`)];
};
return [true, formatter];
} catch (e) {
return [false, e.message];
}
}