marijnh/CodeMirror — pull request #1359 by angelozerr (2013-03-14 10:13:27+00:00)
Title: XQuery Hint features

Hi Marijnh,

Here my big pull request about my work with XQUery Hint. here some explanation about this patch :

1) demo/xquerycomplete.html

The demo with XQuery Hint which uses too the new theme xq-light.css.

2) mode/xquery/xquery.js

I have modified the xquery mode to :

a) add 'at' as keyword.
b) fix problem with multi line string.
c) manage trackContext to track context and update the sate with varDecl, functionDecl, moduleDecl (a kind of AST) that I use after in the xquery-hint.js

As you have suggested, the state is updated with varDecl, functionDecl, moduleDecl ONLY if trackContext is setted to truewith options :

--------------------------------------------------------------------------------
CodeMirror.commands.autocomplete = function(cm) {
CodeMirror.showHint(cm, CodeMirror.xqueryHint);
}

var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
trackContext: true,
extraKeys: {
"Ctrl-Space": "autocomplete"
}});
--------------------------------------------------------------------------------

3) addon/hint/xquery/xquery-hint.js

The XQuery Hint. As you can see I have setted this hint in the addon/hint/xquery. I think it should be very clean if each modes stores her hint in their folder.

This hint manages several completion :

a) completion with variables declared by let, variable, for, and parameters of function :

Ex:
--------------------------------------------------------------------------------
let $a := ()
let $b := ()
(here Ctrl+Space displays $a, $b)
--------------------------------------------------------------------------------

The completion displays type too. Ex:

--------------------------------------------------------------------------------
declare function ns:f($a as xs:string, $b as xs:int) {
(here Ctrl+Space displays $a - xs:string, $b - xs:int)
--------------------------------------------------------------------------------

b) completion with declared function (local functions).

--------------------------------------------------------------------------------
declare function ns:f($a as xs:string, $b as xs:int) {
}

(here Ctrl+Space displays ns:f($a as xs:string, $b as xs:int))
--------------------------------------------------------------------------------

c) completion with imported modules

--------------------------------------------------------------------------------
import module namespace user = "http://marklogic.com/plugins/security/user" at "../models/user-model.xqy";

(here Ctrl+Space displays user - http://marklogic.com/plugins/security/user)
--------------------------------------------------------------------------------

d) completion with default modules

In XQuery you can have default module (like fn:*) an dyou not need to import it. For instance in the Marklogic you have default xdmp map modules.
So if you do Ctrl+Space, it displays xdmp, and map

To manage that, you register the module with a prefix (and functions) like this :

--------------------------------------------------------------------------------
CodeMirror.defineXQueryModule({"prefix":"xdmp","namespace":"http://marklogic.com/xdmp","functions":[...
--------------------------------------------------------------------------------

If you don't declare prefix, you must to use import module to use it.

e) completion with functions of imported/default modules

if you do xdmp:, the completion displays the function of the module.

f) completion with namespace.

if you do (not in this demo) Ctrl+Space after import module namespace user = "
it displays list of namespace which comes from modules registered CodeMirror.defineXQueryModule (without prefix).

4) addon/hint/xquery/xquery-hint.css

This CSS contains the whole CSS image types (function, local var, etc) for the XQUery completion item.

5) addon/hint/show-hint-eclipse.css

The show hint CSS to have the same look than Eclipse completion.

6) theme/xq-ligth.css

New CSS theme for xquery which looks like the XQDT Eclipse Plugin (http://wiki.eclipse.org/XQDT).

7) demo/theme.css

Add xq-light.css in the theme demo.