Commit df7eb0fd authored by Arnaud Fontaine's avatar Arnaud Fontaine

erp5_code_mirror: Add linter to check Python syntax in real time.

This will display warnings/errors icons next to the line number, likewise Ace
Editor implementation.
parent 63567372
...@@ -64,6 +64,11 @@ ...@@ -64,6 +64,11 @@
<script type="text/javascript" src="&dtml-portal_url;/codemirror/addon/merge/dep/diff_match_patch.js"></script>\n <script type="text/javascript" src="&dtml-portal_url;/codemirror/addon/merge/dep/diff_match_patch.js"></script>\n
<script type="text/javascript" src="&dtml-portal_url;/codemirror/addon/merge/merge.js"></script>\n <script type="text/javascript" src="&dtml-portal_url;/codemirror/addon/merge/merge.js"></script>\n
\n \n
<!-- Lint\n
TODO: Only support Python for now -->\n
<link rel="stylesheet" href="&dtml-portal_url;/codemirror/addon/lint/lint.css">\n
<script type="text/javascript" src="&dtml-portal_url;/codemirror/addon/lint/lint.js"></script>\n
\n
<style type="text/css">\n <style type="text/css">\n
.maximize_fullscreen_message {\n .maximize_fullscreen_message {\n
display: table;\n display: table;\n
...@@ -116,6 +121,17 @@ ...@@ -116,6 +121,17 @@
.CodeMirror pre, .CodeMirror span {\n .CodeMirror pre, .CodeMirror span {\n
font-family: monospace !important;\n font-family: monospace !important;\n
}\n }\n
\n
/* Workaround for lint icons "multiple" icons hiding "warning/errors" icons\n
because of "background-color: inherit" defined by erp5, and also to fix\n
background color of the gutter (cosmetic) */\n
.CodeMirror-lint-marker-multiple,\n
.CodeMirror-lint-marker-error,\n
.CodeMirror-lint-marker-warning,\n
.CodeMirror-gutters,\n
.CodeMirror-gutter-elt {\n
background-color: transparent !important;\n
}\n
</style>\n </style>\n
\n \n
<input type="button" value="Maximize" onclick="maximize()"\n <input type="button" value="Maximize" onclick="maximize()"\n
...@@ -383,6 +399,28 @@ ...@@ -383,6 +399,28 @@
\n \n
is_maximized = true;\n is_maximized = true;\n
}\n }\n
\n
function checkPythonSourceCode(cm, updateLinting, options) {\n
// CodeMirror.registerHelper("lint", "python", function(text) {\n
$.post(\n
\'&dtml-portal_url;/ERP5Site_checkPythonSourceCodeAsJSON\',\n
{\'data\': JSON.stringify({code: cm.getValue()})},\n
function(data){\n
var messages = data.annotations;\n
var found = [];\n
for(var i = 0; i < messages.length; i++) {\n
message = messages[i];\n
found.push({\n
from: CodeMirror.Pos(message.row, message.column - 1),\n
to: CodeMirror.Pos(message.row, message.column),\n
message: message.text,\n
severity: message.type\n
});\n
}\n
\n
updateLinting(cm, found);\n
});\n
}\n
\n \n
// CodeMirror expects a DOM element, not a JQuery Object\n // CodeMirror expects a DOM element, not a JQuery Object\n
var cm = CodeMirror.fromTextArea(\n var cm = CodeMirror.fromTextArea(\n
...@@ -399,8 +437,12 @@ ...@@ -399,8 +437,12 @@
"Ctrl-S": function(cm){saveDocument(cm, $.Event(\'click\'))}},\n "Ctrl-S": function(cm){saveDocument(cm, $.Event(\'click\'))}},\n
foldGutter: true,\n foldGutter: true,\n
lineWrapping: true,\n lineWrapping: true,\n
gutters: ["CodeMirror-linenumbers",\n gutters: ["CodeMirror-lint-markers",\n
"CodeMirror-foldgutter"]});\n "CodeMirror-linenumbers",\n
"CodeMirror-foldgutter"],\n
lintWith: {"getAnnotations": checkPythonSourceCode,\n
"async": true}\n
});\n
//cm.foldCode(CodeMirror.Pos(8, 0));\n //cm.foldCode(CodeMirror.Pos(8, 0));\n
\n \n
updateErrorWarningMessageDivWithJump();\n updateErrorWarningMessageDivWithJump();\n
......
2015-01-16 arnaud.fontaine
* Add linter to check Python syntax in real time and display warnings/errors icons next to the line number (likewise Ace Editor implementation).
2015-01-16 arnaud.fontaine 2015-01-16 arnaud.fontaine
* Remove 'title' attribute of editor field. * Remove 'title' attribute of editor field.
......
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