Update xqlint version

This commit is contained in:
William Candillon 2014-04-04 11:29:19 +02:00 • committed by nightwing
commit 6c38e136c1
4 changed files with 62 additions and 30 deletions

File diff suppressed because one or more lines are too long

View file

@ -1009,6 +1009,7 @@ function retrievePrecedingIdentifier(text, pos, regex) {
} }
return buf.reverse().join(''); return buf.reverse().join('');
} }
/* /*
function retrieveFollowingIdentifier(text, pos, regex) { function retrieveFollowingIdentifier(text, pos, regex) {
regex = regex || ID_REGEX; regex = regex || ID_REGEX;
@ -1023,6 +1024,7 @@ function retrieveFollowingIdentifier(text, pos, regex) {
return buf; return buf;
} }
*/ */
function prefixBinarySearch(items, prefix) { function prefixBinarySearch(items, prefix) {
var startIndex = 0; var startIndex = 0;
var stopIndex = items.length - 1; var stopIndex = items.length - 1;
@ -1092,7 +1094,8 @@ var completePrefix = function(identifier, pos, sctx){
var match = function(name) { var match = function(name) {
return { return {
name: name + ':', name: name + ':',
value: name + ':' value: name + ':',
meta: 'prefix'
}; };
}; };
return matches.map(match); return matches.map(match);
@ -1111,8 +1114,11 @@ var completeFunction = function(identifier, pos, sctx){
if(idx !== -1){ if(idx !== -1){
prefix = identifier.substring(0, idx); prefix = identifier.substring(0, idx);
name = identifier.substring(idx + 1); name = identifier.substring(idx + 1);
var ns = sctx.getNamespaceByPrefix(prefix);
if(ns){
uri = sctx.getNamespaceByPrefix(prefix).uri; uri = sctx.getNamespaceByPrefix(prefix).uri;
} }
}
Object.keys(functions).forEach(function(key){ Object.keys(functions).forEach(function(key){
var fn = functions[key]; var fn = functions[key];
var ns = key.substring(0, key.indexOf('#')); var ns = key.substring(0, key.indexOf('#'));
@ -1130,7 +1136,8 @@ var completeFunction = function(identifier, pos, sctx){
var match = function(name) { var match = function(name) {
return { return {
name: name, name: name,
value: name value: name,
meta: 'function'
}; };
}; };
return matches.map(match); return matches.map(match);
@ -1191,7 +1198,8 @@ var completeModuleUri = function(line, pos, sctx){
var match = function(name) { var match = function(name) {
return { return {
name: name, name: name,
value: name value: name,
meta: 'module'
}; };
}; };
return matches.map(match); return matches.map(match);
@ -1208,6 +1216,7 @@ exports.complete = function(source, ast, rootSctx, pos){
return completeExpr(line, pos, sctx); return completeExpr(line, pos, sctx);
} }
}; };
}, },
{"../tree_ops":10}], {"../tree_ops":10}],
6:[function(_dereq_,module,exports){ 6:[function(_dereq_,module,exports){
@ -78568,7 +78577,9 @@ exports.TreeOps = {
flatten: function(node){ flatten: function(node){
var that = this; var that = this;
var value = ''; var value = '';
if (node.value === undefined) { if(!node) {
throw new Error('Invalid node found');
} else if (node.value === undefined) {
node.children.forEach(function(child){ node.children.forEach(function(child){
value += that.flatten(child); value += that.flatten(child);
}); });

View file

@ -35,29 +35,11 @@ var oop = require("../lib/oop");
var Mirror = require("../worker/mirror").Mirror; var Mirror = require("../worker/mirror").Mirror;
var XQLintLib = require("./xquery/xqlint"); var XQLintLib = require("./xquery/xqlint");
var XQLint = XQLintLib.XQLint; var XQLint = XQLintLib.XQLint;
var Modules = require("./xquery/modules").Modules;
var XQueryWorker = exports.XQueryWorker = function(sender) { var getModuleResolverFromModules = function(modules){
Mirror.call(this, sender); return function(uri){
this.setTimeout(200); var index = modules;
this.opts = {
styleCheck: false,
staticContext: XQLintLib.createStaticContext()
};
var that = this;
this.sender.on("complete", function(e){
that.sender.emit("markers", that.xqlint.getMarkers());
var pos = { line: e.data.pos.row, col: e.data.pos.column };
var proposals = that.xqlint.getCompletions(pos);
that.sender.emit("complete", proposals);
});
this.sender.on("setAvailableModuleNamespaces", function(e){
that.opts.sctx.availableModuleNamespaces = e.data;
});
this.sender.on("setModuleUriResolver", function(e){
sctx.setModuleResolver(function(uri){
var mod = index[uri]; var mod = index[uri];
var variables = {}; var variables = {};
var functions = {}; var functions = {};
@ -77,7 +59,31 @@ var XQueryWorker = exports.XQueryWorker = function(sender) {
variables: variables, variables: variables,
functions: functions functions: functions
}; };
};
};
var XQueryWorker = exports.XQueryWorker = function(sender) {
Mirror.call(this, sender);
this.setTimeout(200);
this.opts = {
styleCheck: false
};
this.availableModuleNamespaces = Object.keys(Modules);
this.moduleResolver = getModuleResolverFromModules(Modules);
var that = this;
this.sender.on("complete", function(e){
var pos = { line: e.data.pos.row, col: e.data.pos.column };
var proposals = that.xqlint.getCompletions(pos);
that.sender.emit("complete", proposals);
}); });
this.sender.on("setAvailableModuleNamespaces", function(e){
that.availableModuleNamespaces = e.data;
});
this.sender.on("setModuleResolver", function(e){
that.moduleResolver = getModuleResolverFromModules(e.data);
}); });
}; };
@ -88,7 +94,18 @@ oop.inherits(XQueryWorker, Mirror);
this.onUpdate = function() { this.onUpdate = function() {
this.sender.emit("start"); this.sender.emit("start");
var value = this.doc.getValue(); var value = this.doc.getValue();
this.xqlint = new XQLint(value, this.opts); var sctx = XQLintLib.createStaticContext();
if(this.moduleResolver) {
sctx.setModuleResolver(this.moduleResolver);
}
if(this.availableModuleNamespaces) {
sctx.availableModuleNamespaces = this.availableModuleNamespaces;
}
var opts = {
styleCheck: this.styleCheck,
staticContext: sctx,
};
this.xqlint = new XQLint(value, opts);
this.sender.emit("markers", this.xqlint.getMarkers()); this.sender.emit("markers", this.xqlint.getMarkers());
}; };
}).call(XQueryWorker.prototype); }).call(XQueryWorker.prototype);

View file

@ -72,7 +72,7 @@ var deps = {
xqlint: { xqlint: {
path: "mode/xquery/xqlint.js", path: "mode/xquery/xqlint.js",
browserify: { browserify: {
npmModule: "git+https://github.com/wcandillon/xqlint.git#master", npmModule: "git+https://github.com/wcandillon/xqlint.git#0.0.8",
path: "xqlint/lib/xqlint.js", path: "xqlint/lib/xqlint.js",
exports: "XQLint" exports: "XQLint"
}, },