LaravelTest
750 строк · 25.6 Кб
1// CodeMirror, copyright (c) by Marijn Haverbeke and others
2// Distributed under an MIT license: https://codemirror.net/LICENSE
3
4// Glue code between CodeMirror and Tern.
5//
6// Create a CodeMirror.TernServer to wrap an actual Tern server,
7// register open documents (CodeMirror.Doc instances) with it, and
8// call its methods to activate the assisting functions that Tern
9// provides.
10//
11// Options supported (all optional):
12// * defs: An array of JSON definition data structures.
13// * plugins: An object mapping plugin names to configuration
14// options.
15// * getFile: A function(name, c) that can be used to access files in
16// the project that haven't been loaded yet. Simply do c(null) to
17// indicate that a file is not available.
18// * fileFilter: A function(value, docName, doc) that will be applied
19// to documents before passing them on to Tern.
20// * switchToDoc: A function(name, doc) that should, when providing a
21// multi-file view, switch the view or focus to the named file.
22// * showError: A function(editor, message) that can be used to
23// override the way errors are displayed.
24// * completionTip: Customize the content in tooltips for completions.
25// Is passed a single argument—the completion's data as returned by
26// Tern—and may return a string, DOM node, or null to indicate that
27// no tip should be shown. By default the docstring is shown.
28// * typeTip: Like completionTip, but for the tooltips shown for type
29// queries.
30// * responseFilter: A function(doc, query, request, error, data) that
31// will be applied to the Tern responses before treating them
32//
33//
34// It is possible to run the Tern server in a web worker by specifying
35// these additional options:
36// * useWorker: Set to true to enable web worker mode. You'll probably
37// want to feature detect the actual value you use here, for example
38// !!window.Worker.
39// * workerScript: The main script of the worker. Point this to
40// wherever you are hosting worker.js from this directory.
41// * workerDeps: An array of paths pointing (relative to workerScript)
42// to the Acorn and Tern libraries and any Tern plugins you want to
43// load. Or, if you minified those into a single script and included
44// them in the workerScript, simply leave this undefined.
45
46(function(mod) {47if (typeof exports == "object" && typeof module == "object") // CommonJS48mod(require("../../lib/codemirror"));49else if (typeof define == "function" && define.amd) // AMD50define(["../../lib/codemirror"], mod);51else // Plain browser env52mod(CodeMirror);53})(function(CodeMirror) {54"use strict";55// declare global: tern56
57CodeMirror.TernServer = function(options) {58var self = this;59this.options = options || {};60var plugins = this.options.plugins || (this.options.plugins = {});61if (!plugins.doc_comment) plugins.doc_comment = true;62this.docs = Object.create(null);63if (this.options.useWorker) {64this.server = new WorkerServer(this);65} else {66this.server = new tern.Server({67getFile: function(name, c) { return getFile(self, name, c); },68async: true,69defs: this.options.defs || [],70plugins: plugins71});72}73this.trackChange = function(doc, change) { trackChange(self, doc, change); };74
75this.cachedArgHints = null;76this.activeArgHints = null;77this.jumpStack = [];78
79this.getHint = function(cm, c) { return hint(self, cm, c); };80this.getHint.async = true;81};82
83CodeMirror.TernServer.prototype = {84addDoc: function(name, doc) {85var data = {doc: doc, name: name, changed: null};86this.server.addFile(name, docValue(this, data));87CodeMirror.on(doc, "change", this.trackChange);88return this.docs[name] = data;89},90
91delDoc: function(id) {92var found = resolveDoc(this, id);93if (!found) return;94CodeMirror.off(found.doc, "change", this.trackChange);95delete this.docs[found.name];96this.server.delFile(found.name);97},98
99hideDoc: function(id) {100closeArgHints(this);101var found = resolveDoc(this, id);102if (found && found.changed) sendDoc(this, found);103},104
105complete: function(cm) {106cm.showHint({hint: this.getHint});107},108
109showType: function(cm, pos, c) { showContextInfo(this, cm, pos, "type", c); },110
111showDocs: function(cm, pos, c) { showContextInfo(this, cm, pos, "documentation", c); },112
113updateArgHints: function(cm) { updateArgHints(this, cm); },114
115jumpToDef: function(cm) { jumpToDef(this, cm); },116
117jumpBack: function(cm) { jumpBack(this, cm); },118
119rename: function(cm) { rename(this, cm); },120
121selectName: function(cm) { selectName(this, cm); },122
123request: function (cm, query, c, pos) {124var self = this;125var doc = findDoc(this, cm.getDoc());126var request = buildRequest(this, doc, query, pos);127var extraOptions = request.query && this.options.queryOptions && this.options.queryOptions[request.query.type]128if (extraOptions) for (var prop in extraOptions) request.query[prop] = extraOptions[prop];129
130this.server.request(request, function (error, data) {131if (!error && self.options.responseFilter)132data = self.options.responseFilter(doc, query, request, error, data);133c(error, data);134});135},136
137destroy: function () {138closeArgHints(this)139if (this.worker) {140this.worker.terminate();141this.worker = null;142}143}144};145
146var Pos = CodeMirror.Pos;147var cls = "CodeMirror-Tern-";148var bigDoc = 250;149
150function getFile(ts, name, c) {151var buf = ts.docs[name];152if (buf)153c(docValue(ts, buf));154else if (ts.options.getFile)155ts.options.getFile(name, c);156else157c(null);158}159
160function findDoc(ts, doc, name) {161for (var n in ts.docs) {162var cur = ts.docs[n];163if (cur.doc == doc) return cur;164}165if (!name) for (var i = 0;; ++i) {166n = "[doc" + (i || "") + "]";167if (!ts.docs[n]) { name = n; break; }168}169return ts.addDoc(name, doc);170}171
172function resolveDoc(ts, id) {173if (typeof id == "string") return ts.docs[id];174if (id instanceof CodeMirror) id = id.getDoc();175if (id instanceof CodeMirror.Doc) return findDoc(ts, id);176}177
178function trackChange(ts, doc, change) {179var data = findDoc(ts, doc);180
181var argHints = ts.cachedArgHints;182if (argHints && argHints.doc == doc && cmpPos(argHints.start, change.to) >= 0)183ts.cachedArgHints = null;184
185var changed = data.changed;186if (changed == null)187data.changed = changed = {from: change.from.line, to: change.from.line};188var end = change.from.line + (change.text.length - 1);189if (change.from.line < changed.to) changed.to = changed.to - (change.to.line - end);190if (end >= changed.to) changed.to = end + 1;191if (changed.from > change.from.line) changed.from = change.from.line;192
193if (doc.lineCount() > bigDoc && change.to - changed.from > 100) setTimeout(function() {194if (data.changed && data.changed.to - data.changed.from > 100) sendDoc(ts, data);195}, 200);196}197
198function sendDoc(ts, doc) {199ts.server.request({files: [{type: "full", name: doc.name, text: docValue(ts, doc)}]}, function(error) {200if (error) window.console.error(error);201else doc.changed = null;202});203}204
205// Completion206
207function hint(ts, cm, c) {208ts.request(cm, {type: "completions", types: true, docs: true, urls: true}, function(error, data) {209if (error) return showError(ts, cm, error);210var completions = [], after = "";211var from = data.start, to = data.end;212if (cm.getRange(Pos(from.line, from.ch - 2), from) == "[\"" &&213cm.getRange(to, Pos(to.line, to.ch + 2)) != "\"]")214after = "\"]";215
216for (var i = 0; i < data.completions.length; ++i) {217var completion = data.completions[i], className = typeToIcon(completion.type);218if (data.guess) className += " " + cls + "guess";219completions.push({text: completion.name + after,220displayText: completion.displayName || completion.name,221className: className,222data: completion});223}224
225var obj = {from: from, to: to, list: completions};226var tooltip = null;227CodeMirror.on(obj, "close", function() { remove(tooltip); });228CodeMirror.on(obj, "update", function() { remove(tooltip); });229CodeMirror.on(obj, "select", function(cur, node) {230remove(tooltip);231var content = ts.options.completionTip ? ts.options.completionTip(cur.data) : cur.data.doc;232if (content) {233tooltip = makeTooltip(node.parentNode.getBoundingClientRect().right + window.pageXOffset,234node.getBoundingClientRect().top + window.pageYOffset, content, cm, cls + "hint-doc");235}236});237c(obj);238});239}240
241function typeToIcon(type) {242var suffix;243if (type == "?") suffix = "unknown";244else if (type == "number" || type == "string" || type == "bool") suffix = type;245else if (/^fn\(/.test(type)) suffix = "fn";246else if (/^\[/.test(type)) suffix = "array";247else suffix = "object";248return cls + "completion " + cls + "completion-" + suffix;249}250
251// Type queries252
253function showContextInfo(ts, cm, pos, queryName, c) {254ts.request(cm, queryName, function(error, data) {255if (error) return showError(ts, cm, error);256if (ts.options.typeTip) {257var tip = ts.options.typeTip(data);258} else {259var tip = elt("span", null, elt("strong", null, data.type || "not found"));260if (data.doc)261tip.appendChild(document.createTextNode(" — " + data.doc));262if (data.url) {263tip.appendChild(document.createTextNode(" "));264var child = tip.appendChild(elt("a", null, "[docs]"));265child.href = data.url;266child.target = "_blank";267}268}269tempTooltip(cm, tip, ts);270if (c) c();271}, pos);272}273
274// Maintaining argument hints275
276function updateArgHints(ts, cm) {277closeArgHints(ts);278
279if (cm.somethingSelected()) return;280var state = cm.getTokenAt(cm.getCursor()).state;281var inner = CodeMirror.innerMode(cm.getMode(), state);282if (inner.mode.name != "javascript") return;283var lex = inner.state.lexical;284if (lex.info != "call") return;285
286var ch, argPos = lex.pos || 0, tabSize = cm.getOption("tabSize");287for (var line = cm.getCursor().line, e = Math.max(0, line - 9), found = false; line >= e; --line) {288var str = cm.getLine(line), extra = 0;289for (var pos = 0;;) {290var tab = str.indexOf("\t", pos);291if (tab == -1) break;292extra += tabSize - (tab + extra) % tabSize - 1;293pos = tab + 1;294}295ch = lex.column - extra;296if (str.charAt(ch) == "(") {found = true; break;}297}298if (!found) return;299
300var start = Pos(line, ch);301var cache = ts.cachedArgHints;302if (cache && cache.doc == cm.getDoc() && cmpPos(start, cache.start) == 0)303return showArgHints(ts, cm, argPos);304
305ts.request(cm, {type: "type", preferFunction: true, end: start}, function(error, data) {306if (error || !data.type || !(/^fn\(/).test(data.type)) return;307ts.cachedArgHints = {308start: start,309type: parseFnType(data.type),310name: data.exprName || data.name || "fn",311guess: data.guess,312doc: cm.getDoc()313};314showArgHints(ts, cm, argPos);315});316}317
318function showArgHints(ts, cm, pos) {319closeArgHints(ts);320
321var cache = ts.cachedArgHints, tp = cache.type;322var tip = elt("span", cache.guess ? cls + "fhint-guess" : null,323elt("span", cls + "fname", cache.name), "(");324for (var i = 0; i < tp.args.length; ++i) {325if (i) tip.appendChild(document.createTextNode(", "));326var arg = tp.args[i];327tip.appendChild(elt("span", cls + "farg" + (i == pos ? " " + cls + "farg-current" : ""), arg.name || "?"));328if (arg.type != "?") {329tip.appendChild(document.createTextNode(":\u00a0"));330tip.appendChild(elt("span", cls + "type", arg.type));331}332}333tip.appendChild(document.createTextNode(tp.rettype ? ") ->\u00a0" : ")"));334if (tp.rettype) tip.appendChild(elt("span", cls + "type", tp.rettype));335var place = cm.cursorCoords(null, "page");336var tooltip = ts.activeArgHints = makeTooltip(place.right + 1, place.bottom, tip, cm)337setTimeout(function() {338tooltip.clear = onEditorActivity(cm, function() {339if (ts.activeArgHints == tooltip) closeArgHints(ts) })340}, 20)341}342
343function parseFnType(text) {344var args = [], pos = 3;345
346function skipMatching(upto) {347var depth = 0, start = pos;348for (;;) {349var next = text.charAt(pos);350if (upto.test(next) && !depth) return text.slice(start, pos);351if (/[{\[\(]/.test(next)) ++depth;352else if (/[}\]\)]/.test(next)) --depth;353++pos;354}355}356
357// Parse arguments358if (text.charAt(pos) != ")") for (;;) {359var name = text.slice(pos).match(/^([^, \(\[\{]+): /);360if (name) {361pos += name[0].length;362name = name[1];363}364args.push({name: name, type: skipMatching(/[\),]/)});365if (text.charAt(pos) == ")") break;366pos += 2;367}368
369var rettype = text.slice(pos).match(/^\) -> (.*)$/);370
371return {args: args, rettype: rettype && rettype[1]};372}373
374// Moving to the definition of something375
376function jumpToDef(ts, cm) {377function inner(varName) {378var req = {type: "definition", variable: varName || null};379var doc = findDoc(ts, cm.getDoc());380ts.server.request(buildRequest(ts, doc, req), function(error, data) {381if (error) return showError(ts, cm, error);382if (!data.file && data.url) { window.open(data.url); return; }383
384if (data.file) {385var localDoc = ts.docs[data.file], found;386if (localDoc && (found = findContext(localDoc.doc, data))) {387ts.jumpStack.push({file: doc.name,388start: cm.getCursor("from"),389end: cm.getCursor("to")});390moveTo(ts, doc, localDoc, found.start, found.end);391return;392}393}394showError(ts, cm, "Could not find a definition.");395});396}397
398if (!atInterestingExpression(cm))399dialog(cm, "Jump to variable", function(name) { if (name) inner(name); });400else401inner();402}403
404function jumpBack(ts, cm) {405var pos = ts.jumpStack.pop(), doc = pos && ts.docs[pos.file];406if (!doc) return;407moveTo(ts, findDoc(ts, cm.getDoc()), doc, pos.start, pos.end);408}409
410function moveTo(ts, curDoc, doc, start, end) {411doc.doc.setSelection(start, end);412if (curDoc != doc && ts.options.switchToDoc) {413closeArgHints(ts);414ts.options.switchToDoc(doc.name, doc.doc);415}416}417
418// The {line,ch} representation of positions makes this rather awkward.419function findContext(doc, data) {420var before = data.context.slice(0, data.contextOffset).split("\n");421var startLine = data.start.line - (before.length - 1);422var start = Pos(startLine, (before.length == 1 ? data.start.ch : doc.getLine(startLine).length) - before[0].length);423
424var text = doc.getLine(startLine).slice(start.ch);425for (var cur = startLine + 1; cur < doc.lineCount() && text.length < data.context.length; ++cur)426text += "\n" + doc.getLine(cur);427if (text.slice(0, data.context.length) == data.context) return data;428
429var cursor = doc.getSearchCursor(data.context, 0, false);430var nearest, nearestDist = Infinity;431while (cursor.findNext()) {432var from = cursor.from(), dist = Math.abs(from.line - start.line) * 10000;433if (!dist) dist = Math.abs(from.ch - start.ch);434if (dist < nearestDist) { nearest = from; nearestDist = dist; }435}436if (!nearest) return null;437
438if (before.length == 1)439nearest.ch += before[0].length;440else441nearest = Pos(nearest.line + (before.length - 1), before[before.length - 1].length);442if (data.start.line == data.end.line)443var end = Pos(nearest.line, nearest.ch + (data.end.ch - data.start.ch));444else445var end = Pos(nearest.line + (data.end.line - data.start.line), data.end.ch);446return {start: nearest, end: end};447}448
449function atInterestingExpression(cm) {450var pos = cm.getCursor("end"), tok = cm.getTokenAt(pos);451if (tok.start < pos.ch && tok.type == "comment") return false;452return /[\w)\]]/.test(cm.getLine(pos.line).slice(Math.max(pos.ch - 1, 0), pos.ch + 1));453}454
455// Variable renaming456
457function rename(ts, cm) {458var token = cm.getTokenAt(cm.getCursor());459if (!/\w/.test(token.string)) return showError(ts, cm, "Not at a variable");460dialog(cm, "New name for " + token.string, function(newName) {461ts.request(cm, {type: "rename", newName: newName, fullDocs: true}, function(error, data) {462if (error) return showError(ts, cm, error);463applyChanges(ts, data.changes);464});465});466}467
468function selectName(ts, cm) {469var name = findDoc(ts, cm.doc).name;470ts.request(cm, {type: "refs"}, function(error, data) {471if (error) return showError(ts, cm, error);472var ranges = [], cur = 0;473var curPos = cm.getCursor();474for (var i = 0; i < data.refs.length; i++) {475var ref = data.refs[i];476if (ref.file == name) {477ranges.push({anchor: ref.start, head: ref.end});478if (cmpPos(curPos, ref.start) >= 0 && cmpPos(curPos, ref.end) <= 0)479cur = ranges.length - 1;480}481}482cm.setSelections(ranges, cur);483});484}485
486var nextChangeOrig = 0;487function applyChanges(ts, changes) {488var perFile = Object.create(null);489for (var i = 0; i < changes.length; ++i) {490var ch = changes[i];491(perFile[ch.file] || (perFile[ch.file] = [])).push(ch);492}493for (var file in perFile) {494var known = ts.docs[file], chs = perFile[file];;495if (!known) continue;496chs.sort(function(a, b) { return cmpPos(b.start, a.start); });497var origin = "*rename" + (++nextChangeOrig);498for (var i = 0; i < chs.length; ++i) {499var ch = chs[i];500known.doc.replaceRange(ch.text, ch.start, ch.end, origin);501}502}503}504
505// Generic request-building helper506
507function buildRequest(ts, doc, query, pos) {508var files = [], offsetLines = 0, allowFragments = !query.fullDocs;509if (!allowFragments) delete query.fullDocs;510if (typeof query == "string") query = {type: query};511query.lineCharPositions = true;512if (query.end == null) {513query.end = pos || doc.doc.getCursor("end");514if (doc.doc.somethingSelected())515query.start = doc.doc.getCursor("start");516}517var startPos = query.start || query.end;518
519if (doc.changed) {520if (doc.doc.lineCount() > bigDoc && allowFragments !== false &&521doc.changed.to - doc.changed.from < 100 &&522doc.changed.from <= startPos.line && doc.changed.to > query.end.line) {523files.push(getFragmentAround(doc, startPos, query.end));524query.file = "#0";525var offsetLines = files[0].offsetLines;526if (query.start != null) query.start = Pos(query.start.line - -offsetLines, query.start.ch);527query.end = Pos(query.end.line - offsetLines, query.end.ch);528} else {529files.push({type: "full",530name: doc.name,531text: docValue(ts, doc)});532query.file = doc.name;533doc.changed = null;534}535} else {536query.file = doc.name;537}538for (var name in ts.docs) {539var cur = ts.docs[name];540if (cur.changed && cur != doc) {541files.push({type: "full", name: cur.name, text: docValue(ts, cur)});542cur.changed = null;543}544}545
546return {query: query, files: files};547}548
549function getFragmentAround(data, start, end) {550var doc = data.doc;551var minIndent = null, minLine = null, endLine, tabSize = 4;552for (var p = start.line - 1, min = Math.max(0, p - 50); p >= min; --p) {553var line = doc.getLine(p), fn = line.search(/\bfunction\b/);554if (fn < 0) continue;555var indent = CodeMirror.countColumn(line, null, tabSize);556if (minIndent != null && minIndent <= indent) continue;557minIndent = indent;558minLine = p;559}560if (minLine == null) minLine = min;561var max = Math.min(doc.lastLine(), end.line + 20);562if (minIndent == null || minIndent == CodeMirror.countColumn(doc.getLine(start.line), null, tabSize))563endLine = max;564else for (endLine = end.line + 1; endLine < max; ++endLine) {565var indent = CodeMirror.countColumn(doc.getLine(endLine), null, tabSize);566if (indent <= minIndent) break;567}568var from = Pos(minLine, 0);569
570return {type: "part",571name: data.name,572offsetLines: from.line,573text: doc.getRange(from, Pos(endLine, end.line == endLine ? null : 0))};574}575
576// Generic utilities577
578var cmpPos = CodeMirror.cmpPos;579
580function elt(tagname, cls /*, ... elts*/) {581var e = document.createElement(tagname);582if (cls) e.className = cls;583for (var i = 2; i < arguments.length; ++i) {584var elt = arguments[i];585if (typeof elt == "string") elt = document.createTextNode(elt);586e.appendChild(elt);587}588return e;589}590
591function dialog(cm, text, f) {592if (cm.openDialog)593cm.openDialog(text + ": <input type=text>", f);594else595f(prompt(text, ""));596}597
598// Tooltips599
600function tempTooltip(cm, content, ts) {601if (cm.state.ternTooltip) remove(cm.state.ternTooltip);602var where = cm.cursorCoords();603var tip = cm.state.ternTooltip = makeTooltip(where.right + 1, where.bottom, content, cm);604function maybeClear() {605old = true;606if (!mouseOnTip) clear();607}608function clear() {609cm.state.ternTooltip = null;610if (tip.parentNode) fadeOut(tip)611clearActivity()612}613var mouseOnTip = false, old = false;614CodeMirror.on(tip, "mousemove", function() { mouseOnTip = true; });615CodeMirror.on(tip, "mouseout", function(e) {616var related = e.relatedTarget || e.toElement617if (!related || !CodeMirror.contains(tip, related)) {618if (old) clear();619else mouseOnTip = false;620}621});622setTimeout(maybeClear, ts.options.hintDelay ? ts.options.hintDelay : 1700);623var clearActivity = onEditorActivity(cm, clear)624}625
626function onEditorActivity(cm, f) {627cm.on("cursorActivity", f)628cm.on("blur", f)629cm.on("scroll", f)630cm.on("setDoc", f)631return function() {632cm.off("cursorActivity", f)633cm.off("blur", f)634cm.off("scroll", f)635cm.off("setDoc", f)636}637}638
639function makeTooltip(x, y, content, cm, className) {640var node = elt("div", cls + "tooltip" + " " + (className || ""), content);641node.style.left = x + "px";642node.style.top = y + "px";643var container = ((cm.options || {}).hintOptions || {}).container || document.body;644container.appendChild(node);645
646var pos = cm.cursorCoords();647var winW = window.innerWidth;648var winH = window.innerHeight;649var box = node.getBoundingClientRect();650var hints = document.querySelector(".CodeMirror-hints");651var overlapY = box.bottom - winH;652var overlapX = box.right - winW;653
654if (hints && overlapX > 0) {655node.style.left = 0;656var box = node.getBoundingClientRect();657node.style.left = (x = x - hints.offsetWidth - box.width) + "px";658overlapX = box.right - winW;659}660if (overlapY > 0) {661var height = box.bottom - box.top, curTop = pos.top - (pos.bottom - box.top);662if (curTop - height > 0) { // Fits above cursor663node.style.top = (pos.top - height) + "px";664} else if (height > winH) {665node.style.height = (winH - 5) + "px";666node.style.top = (pos.bottom - box.top) + "px";667}668}669if (overlapX > 0) {670if (box.right - box.left > winW) {671node.style.width = (winW - 5) + "px";672overlapX -= (box.right - box.left) - winW;673}674node.style.left = (x - overlapX) + "px";675}676
677return node;678}679
680function remove(node) {681var p = node && node.parentNode;682if (p) p.removeChild(node);683}684
685function fadeOut(tooltip) {686tooltip.style.opacity = "0";687setTimeout(function() { remove(tooltip); }, 1100);688}689
690function showError(ts, cm, msg) {691if (ts.options.showError)692ts.options.showError(cm, msg);693else694tempTooltip(cm, String(msg), ts);695}696
697function closeArgHints(ts) {698if (ts.activeArgHints) {699if (ts.activeArgHints.clear) ts.activeArgHints.clear()700remove(ts.activeArgHints)701ts.activeArgHints = null702}703}704
705function docValue(ts, doc) {706var val = doc.doc.getValue();707if (ts.options.fileFilter) val = ts.options.fileFilter(val, doc.name, doc.doc);708return val;709}710
711// Worker wrapper712
713function WorkerServer(ts) {714var worker = ts.worker = new Worker(ts.options.workerScript);715worker.postMessage({type: "init",716defs: ts.options.defs,717plugins: ts.options.plugins,718scripts: ts.options.workerDeps});719var msgId = 0, pending = {};720
721function send(data, c) {722if (c) {723data.id = ++msgId;724pending[msgId] = c;725}726worker.postMessage(data);727}728worker.onmessage = function(e) {729var data = e.data;730if (data.type == "getFile") {731getFile(ts, data.name, function(err, text) {732send({type: "getFile", err: String(err), text: text, id: data.id});733});734} else if (data.type == "debug") {735window.console.log(data.message);736} else if (data.id && pending[data.id]) {737pending[data.id](data.err, data.body);738delete pending[data.id];739}740};741worker.onerror = function(e) {742for (var id in pending) pending[id](e);743pending = {};744};745
746this.addFile = function(name, text) { send({type: "add", name: name, text: text}); };747this.delFile = function(name) { send({type: "del", name: name}); };748this.request = function(body, c) { send({type: "req", body: body}, c); };749}750});751