Skip to content

Commit

Permalink
move xquery mode into separate repository
Browse files Browse the repository at this point in the history
  • Loading branch information
nightwing committed Dec 27, 2017
1 parent 6bd1b82 commit a2a3832
Show file tree
Hide file tree
Showing 9 changed files with 261 additions and 109,142 deletions.
9 changes: 8 additions & 1 deletion demo/kitchen-sink/docs/jsoniq.jq
@@ -1 +1,8 @@
TODO
let $stats := collection("stats")
for $access in $stats
group by $url := $access.url
return {
"url": $url,
"avg": avg($access.response_time),
"hits": count($access)
}
203 changes: 0 additions & 203 deletions lib/ace/mode/jsoniq.js

This file was deleted.

117 changes: 4 additions & 113 deletions lib/ace/mode/xquery.js
Expand Up @@ -30,36 +30,23 @@
define(function(require, exports, module) {
"use strict";

var WorkerClient = require("../worker/worker_client").WorkerClient;
var oop = require("../lib/oop");
var TextMode = require("./text").Mode;
var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
var XQueryLexer = require("./xquery/xquery_lexer").XQueryLexer;
var Tokenizer = require("../tokenizer").Tokenizer;
var XQueryHighlightRules = require("./xquery_highlight_rules").XQueryHighlightRules;
var Range = require("../range").Range;
var XQueryBehaviour = require("./behaviour/xquery").XQueryBehaviour;
var CStyleFoldMode = require("./folding/cstyle").FoldMode;
var Anchor = require("../anchor").Anchor;

var Mode = function() {
this.$tokenizer = new XQueryLexer();
this.HighlightRules = XQueryHighlightRules;
this.$behaviour = new XQueryBehaviour();
this.foldingRules = new CStyleFoldMode();
this.$highlightRules = new TextHighlightRules();
};

oop.inherits(Mode, TextMode);

(function() {

this.completer = {
getCompletions: function(editor, session, pos, prefix, callback) {
if (!session.$worker)
return callback();
session.$worker.emit("complete", { data: { pos: pos, prefix: prefix } });
session.$worker.on("complete", function(e){
callback(null, e.data);
});
}
};

this.getNextLineIndent = function(state, line, tab) {
var indent = this.$getIndent(line);
Expand Down Expand Up @@ -113,102 +100,6 @@ oop.inherits(Mode, TextMode);
doc.replace(range, outdent ? line.match(re)[1] : "(:" + line + ":)");
}
};

this.createWorker = function(session) {

var worker = new WorkerClient(["ace"], "ace/mode/xquery_worker", "XQueryWorker");
var that = this;

worker.attachToDocument(session.getDocument());

worker.on("ok", function(e) {
session.clearAnnotations();
});

worker.on("markers", function(e) {
session.clearAnnotations();
that.addMarkers(e.data, session);
});

worker.on("highlight", function(tokens) {
that.$tokenizer.tokens = tokens.data.tokens;
that.$tokenizer.lines = session.getDocument().getAllLines();

var rows = Object.keys(that.$tokenizer.tokens);
for(var i=0; i < rows.length; i++) {
var row = parseInt(rows[i]);
delete session.bgTokenizer.lines[row];
delete session.bgTokenizer.states[row];
session.bgTokenizer.fireUpdateEvent(row, row);
}
});

return worker;
};

this.removeMarkers = function(session) {
var markers = session.getMarkers(false);
for (var id in markers) {
// All language analysis' markers are prefixed with language_highlight
if (markers[id].clazz.indexOf('language_highlight_') === 0) {
session.removeMarker(id);
}
}
for (var i = 0; i < session.markerAnchors.length; i++) {
session.markerAnchors[i].detach();
}
session.markerAnchors = [];
};

this.addMarkers = function(annos, mySession) {
var _self = this;

if (!mySession.markerAnchors) mySession.markerAnchors = [];
this.removeMarkers(mySession);
mySession.languageAnnos = [];
annos.forEach(function(anno) {
// Certain annotations can temporarily be disabled
//if (_self.disabledMarkerTypes[anno.type])
// return;
// Multi-line markers are not supported, and typically are a result from a bad error recover, ignore
//if(anno.pos.el && anno.pos.sl !== anno.pos.el)
// return;
// Using anchors here, to automaticaly move markers as text around the marker is updated
var anchor = new Anchor(mySession.getDocument(), anno.pos.sl, anno.pos.sc || 0);
mySession.markerAnchors.push(anchor);
var markerId;
var colDiff = anno.pos.ec - anno.pos.sc;
var rowDiff = anno.pos.el - anno.pos.sl;
var gutterAnno = {
guttertext: anno.message,
type: anno.level || "warning",
text: anno.message
// row will be filled in updateFloat()
};

function updateFloat(single) {
if (markerId)
mySession.removeMarker(markerId);
gutterAnno.row = anchor.row;
if (anno.pos.sc !== undefined && anno.pos.ec !== undefined) {
var range = new Range(anno.pos.sl, anno.pos.sc, anno.pos.el, anno.pos.ec);
//var range = Range.fromPoints(anchor.getPosition(), {
// row: anchor.row + rowDiff,
// column: anchor.column + colDiff
//});
markerId = mySession.addMarker(range, "language_highlight_" + (anno.type ? anno.type : "default"));
}
if (single) mySession.setAnnotations(mySession.languageAnnos);
}
updateFloat();
anchor.on("change", function() {
updateFloat(true);
});
if (anno.message) mySession.languageAnnos.push(gutterAnno);
});
mySession.setAnnotations(mySession.languageAnnos);
};

this.$id = "ace/mode/xquery";
}).call(Mode.prototype);

Expand Down
1 change: 0 additions & 1 deletion lib/ace/mode/xquery/Readme.md

This file was deleted.

0 comments on commit a2a3832

Please sign in to comment.