Commit 9d728d75 authored by Jérome Perrin's avatar Jérome Perrin

monaco ZMI: partial support for typescript

parent 568cd9e3
......@@ -48,6 +48,8 @@
<script tal:attributes="src string:${options/portal_url}/monaco-editor/prettier@1.14.0/standalone.js"></script>
<script tal:attributes="src string:${options/portal_url}/monaco-editor/prettier@1.14.0/parser-babylon.js"></script>
<!-- TODO: add locally if it makes sense -->
<script src="https://unpkg.com/prettier@1.14.0/parser-typescript.js"></script>
<script>
/* we need to defer import for the monacoEditorWebPackResourceBaseUrl trick to work as expected in ZMI */
......@@ -94,12 +96,15 @@ $script.onload = function() {
/* because Alt+Click is LeftClick on ChromeOS */
multiCursorModifier: "ctrlCmd",
autoIndent: true
}
);
editor.getModel().updateOptions({
tabSize: 2,
insertSpaces: true
});
if (mode == "python") {
editor.model.updateOptions({ tabSize: 2 });
monaco.languages.setLanguageConfiguration("python", {
indentationRules: {
increaseIndentPattern: /^.*:$/
......@@ -126,6 +131,24 @@ $script.onload = function() {
];
},
});
monaco.languages.registerDocumentFormattingEditProvider('typescript', {
provideDocumentFormattingEdits(model, options, token) {
const text = prettier.format(model.getValue(), {
parser: 'typescript',
plugins: [prettierPlugins.typescript],
// see http://json.schemastore.org/prettierrc for supported options.
singleQuote: true,
tabWidth: 2
});
return [
{
range: model.getFullModelRange(),
text,
},
];
},
});
var timeout = null;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment