summaryrefslogtreecommitdiff
path: root/js
diff options
context:
space:
mode:
authorAleš Smodiš <aless@guru.si>2015-09-17 19:46:34 +0200
committerAleš Smodiš <aless@guru.si>2015-09-17 19:46:34 +0200
commit31cc69df82abce2250505c1e088d3f787a521a13 (patch)
tree9dc4b22fab25ea6c88d5676a0bbb081459b4cf53 /js
parentacad5db74baf202e26cb2ba2e8f32c3d6ae0ef63 (diff)
Implemented support for an array of static hints, which are displayed in sequence after pressing the "more" button.
Diffstat (limited to 'js')
-rw-r--r--js/codeq/hint.js64
1 files changed, 54 insertions, 10 deletions
diff --git a/js/codeq/hint.js b/js/codeq/hint.js
index ffae638..c22f39f 100644
--- a/js/codeq/hint.js
+++ b/js/codeq/hint.js
@@ -10,6 +10,7 @@
codeq.makeHinter = function (jqHints, jqEditor, editor, hintDefs) {
var hintCounter = 0, // for generating unique class-names
hintCleaners = [],
+
clearHints = function () {
var i;
for (i = hintCleaners.length - 1; i >= 0; i--) {
@@ -18,6 +19,7 @@
hintCleaners.length = 0;
hintCounter = 0;
},
+
addMark = function (start, end) {
var posStart = editor.posFromIndex(start),
posEnd = editor.posFromIndex(end),
@@ -28,6 +30,7 @@
hintCounter++;
return result;
},
+
processTemplate = function (template, args) {
if (!args)
return template;
@@ -35,11 +38,49 @@
return args[name];
});
},
+
typeHandlers = {
'static': function (type, template, serverHint) {
- codeq.log.debug('Processing static hint');
- var message = processTemplate(template, serverHint.args);
- jqHints.append('<div class="hint-static">' + message + '</div>');
+ var jqContainer, jqButton, promise, i, lastIndex;
+ if (template instanceof Array) { // unwrap the template if there's only one
+ if (template.length == 0) template = '';
+ else if (template.length == 1) template = template[0] + '';
+ }
+ if (template instanceof Array) {
+ codeq.log.debug('Processing an array of static hints');
+ jqContainer = $('<div class="hint-static-group"></div>');
+ jqButton = $('<button type="button">More...</button>'); // TODO: translate "more"
+ jqHints.append(jqContainer);
+ lastIndex = template.length - 1;
+ promise = Q();
+ for (i = 0; i <= lastIndex; i++) {
+ promise = promise.then((function (tmpl, index) {
+ return Q.Promise(function (resolve, reject) {
+ var message = processTemplate(tmpl, serverHint.args),
+ onClick;
+ jqContainer.append('<div class="hint-static">' + message + '</div>');
+ if (index < lastIndex) {
+ onClick = function () {
+ jqButton.off('click', onClick);
+ jqButton.remove();
+ resolve();
+ };
+ jqContainer.append(jqButton);
+ jqButton.on('click', onClick);
+ }
+ else {
+ resolve();
+ }
+ });
+ })(template[i], i));
+ }
+ promise.done();
+ }
+ else {
+ codeq.log.debug('Processing a single static hint');
+ var message = processTemplate(template, serverHint.args);
+ jqHints.append('<div class="hint-static">' + message + '</div>');
+ }
// no hint cleaner here, a static hint remains on the screen
},
@@ -102,21 +143,24 @@
/** HintDefinition */ hintDef,
hintType, hintTemplate, t, fn, indices;
clearHints();
+ mainLoop:
for (i = 0; i < n; i++) {
serverHint = serverHints[i];
hintDef = hintDefs[serverHint.id];
+ if (!hintDef) {
+ codeq.log.error('Undefined hint ' + serverHint.id);
+ continue;
+ }
if (serverHint.indices) {
- indices = serverHint.indices
+ indices = serverHint.indices;
for (i = 0; i < indices.length; i++) {
hintDef = hintDef[indices[i]];
- if (!hintDef)
- break;
+ if (!hintDef) {
+ codeq.log.error('Undefined hint ' + serverHint.id + ' with indices ' + serverHint.indices);
+ continue mainLoop;
+ }
}
}
- if (!hintDef) {
- codeq.log.error('Undefined hint ' + serverHint.id + ' with indices ' + serverHint.indices);
- continue;
- }
t = typeof hintDef;
if (t === 'object') {
hintType = hintDef.type;