Commit c12a5b40 authored by Jérome Perrin's avatar Jérome Perrin

codemirror: integrate jedi to autocomplete python code

parent f298c971
import jedi
import json
# XXX this page is not up to date
# https://jedi.readthedocs.org/en/latest/docs/plugin-api.html
def getCompletionList(self, source, line, column, bound_names=None, params=None, REQUEST=None):
line = int(line)
column = int(column)
script = jedi.Script(source, line, column, '')
if REQUEST:
REQUEST.RESPONSE.setHeader('content-type', 'application/json')
return json.dumps([completion.name for completion in script.completions()])
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="Extension Component" module="erp5.portal_type"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_recorded_property_dict</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value>
</item>
<item>
<key> <string>default_reference</string> </key>
<value> <string>JediUtils</string> </value>
</item>
<item>
<key> <string>description</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>extension.erp5.JediUtils</string> </value>
</item>
<item>
<key> <string>portal_type</string> </key>
<value> <string>Extension Component</string> </value>
</item>
<item>
<key> <string>sid</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>text_content_error_message</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>text_content_warning_message</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>version</string> </key>
<value> <string>erp5</string> </value>
</item>
<item>
<key> <string>workflow_history</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAM=</string> </persistent>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="2" aka="AAAAAAAAAAI=">
<pickle>
<global name="PersistentMapping" module="Persistence.mapping"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>data</string> </key>
<value>
<dictionary/>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="3" aka="AAAAAAAAAAM=">
<pickle>
<global name="PersistentMapping" module="Persistence.mapping"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>data</string> </key>
<value>
<dictionary>
<item>
<key> <string>component_validation_workflow</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAQ=</string> </persistent>
</value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="4" aka="AAAAAAAAAAQ=">
<pickle>
<global name="WorkflowHistoryList" module="Products.ERP5Type.patches.WorkflowTool"/>
</pickle>
<pickle>
<tuple>
<none/>
<list>
<dictionary>
<item>
<key> <string>action</string> </key>
<value> <string>validate</string> </value>
</item>
<item>
<key> <string>validation_state</string> </key>
<value> <string>validated</string> </value>
</item>
</dictionary>
</list>
</tuple>
</pickle>
</record>
</ZopeData>
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="ExternalMethod" module="Products.ExternalMethod.ExternalMethod"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_function</string> </key>
<value> <string>getCompletionList</string> </value>
</item>
<item>
<key> <string>_module</string> </key>
<value> <string>JediUtils</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>ERP5Site_getPythonSourceCodeCompletionList</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
......@@ -513,6 +513,42 @@
if(parent_height !== undefined && parent_height > (300 * 0.8)) {\n
cm.setSize(undefined, parent_height);\n
}\n
\n
\n
CodeMirror.registerHelper(\n
"hint", "ajax",\n
function (mirror, callback, options) {\n
var cur = mirror.getCursor();\n
var tok = mirror.getTokenAt(cur);\n
\n
var completion_parameters = {source: cm.getValue(), column: cur.ch, line: cur.line+1};\n
<dtml-if bound_names>\n
completion_parameters[\'bound_names\'] = <dtml-var name="bound_names">;\n
completion_parameters[\'params\'] = $(\'input[name="params"]\').val();\n
</dtml-if>\n
console.log("Checking at", cur.ch, " ", cur.line);\n
$.getJSON(\n
"&dtml-portal_url;/ERP5Site_getPythonSourceCodeCompletionList",\n
completion_parameters,\n
function (res) {\n
console.log("Got response ", res);\n
console.log("Returing", { list: res,\n
from: CodeMirror.Pos(cur.line, tok.start),\n
to: CodeMirror.Pos(cur.line, tok.end)\n
});\n
callback({ list: res,\n
from: CodeMirror.Pos(cur.line, tok.start),\n
to: CodeMirror.Pos(cur.line, tok.end)\n
})\n
})\n
})\n
\n
CodeMirror.registerHelper(\n
"hint", "python",\n
function (mirror, options) {\n
CodeMirror.commands.autocomplete(mirror, CodeMirror.hint.ajax, { async: true })\n
})\n
\n
\n
updateErrorWarningMessageDivWithJump();\n
\n
......
......@@ -11,4 +11,4 @@ jshint.js (under modified MIT license):
Copyright (c) 2002 Douglas Crockford (www.JSLint.com)
csslint.js (under MIT license):
Copyright (c) 2009-2011 Nicholas C. Zakas. All rights reserved.
Copyright (c) 2009-2011 Nicholas C. Zakas. All rights reserved.
\ No newline at end of file
extension.erp5.JediUtils
\ No newline at end of file
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