Skip to content
angelozerr edited this page Mar 21, 2013 · 11 revisions

CodeMirror provides the hint feature to manage completion in the editor. CodeMirror-XQuery uses this feature to support completion for XQuery in several context :

Completion with variables

Completion works with global (declare variable) and local (let) variables :

Completion Variable Let

Completion works with parameters function:

Completion Function Params

Completion with declared functions

Completion works with declared functions :

Completion Functions

Completion with imported modules prefix

Completion Imported Module Prefix

Completion with default modules prefix

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

Completion Default Module Prefix

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

CodeMirror.defineXQueryModule({
  "prefix" : "map",
  "namespace" : "http://marklogic.com/xdmp/map",
  "functions" : [ {
    "name" : "clear",
    "as" : "empty-sequence()",
    "params" : [ {
      "name" : "map",
      "as" : "map:map"
    } ]
  }, 
...  
   ]
});

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

Completion with functions of imported/default modules

if you type map: the completion displays the function of the module :

Completion Module Functions

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).

Clone this wiki locally