summaryrefslogtreecommitdiff
path: root/js/codeq/hint.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/codeq/hint.js')
-rw-r--r--js/codeq/hint.js68
1 files changed, 31 insertions, 37 deletions
diff --git a/js/codeq/hint.js b/js/codeq/hint.js
index 1b97afc..d30f934 100644
--- a/js/codeq/hint.js
+++ b/js/codeq/hint.js
@@ -7,7 +7,7 @@
var firstCharacterPos = {'line': 0, 'ch': 0},
sel_no_scroll = {'scroll': false};
- codeq.makeHinter = function (jqHints, jqEditor, editor, trNamespace, hintDefsA, commonHintDefsA, planDef) {
+ codeq.makeHinter = function (jqHints, jqEditor, editor, trNamespace, problemDef, commonDef) {
var hintCounter = 0, // for generating unique class-names
hintCleaners = [],
planIdx = 0,
@@ -133,25 +133,15 @@
codeq.tr.registerDictionary(trNamespace, dictionary);
- // TODO: below is a temporary code to bridge the old implementation with the new data format
- if (planDef.sl) planDef = planDef.sl;
- else planDef = planDef.en || [];
- var hintDefs = {}, t1, t2, k;
- if (hintDefsA.sl) t1 = hintDefsA.sl;
- else t1 = hintDefsA.en || {};
- if (commonHintDefsA.sl) t2 = commonHintDefsA.sl;
- else t2 = commonHintDefsA.en || {};
- for (k in t2) {
- if (!t2.hasOwnProperty(k)) continue;
- hintDefs[k] = t2[k];
- }
- for (k in t1) {
- if (!t1.hasOwnProperty(k)) continue;
- hintDefs[k] = t1[k];
- }
+ var hintProblemDefs = problemDef.hint_type,
+ hintCommonDefs = commonDef.hint_type,
+ hintProblemTr = problemDef.hint,
+ hintCommonTr = commonDef.hint,
+ planDef = problemDef.plan.sl;
return {
- /** Display the next "planning" hint and return whether there are
+ /**
+ * Display the next "planning" hint and return whether there are
* any more available.
*/
'planNext': function () {
@@ -170,46 +160,50 @@
*/
'handle': function (serverHints) {
var n = serverHints.length,
- /** number */ i,
- /** ServerHint */ serverHint,
- /** HintDefinition */ hintDef,
- hintType, hintTemplate, t, fn, indices;
+ i, serverHint, hintId, hintDef, hintContent, hintType, hintTemplate, t, fn, indices;
clearHints();
mainLoop:
for (i = 0; i < n; i++) {
serverHint = serverHints[i];
- hintDef = hintDefs[serverHint.id];
+ hintId = serverHint.id;
+ hintDef = hintProblemDefs[hintId];
+ if (hintDef) {
+ hintContent = hintProblemTr[hintId];
+ }
+ else {
+ hintDef = hintCommonDefs[hintId];
+ hintContent = hintCommonTr[hintId];
+ }
if (!hintDef) {
- codeq.log.error('Undefined hint ' + serverHint.id);
+ codeq.log.error('Undefined hint: ' + hintId);
+ continue;
+ }
+ if (!hintContent) {
+ codeq.log.error('Hint without content: ' + hintId);
continue;
}
if (serverHint.indices) {
indices = serverHint.indices;
for (i = 0; i < indices.length; i++) {
- hintDef = hintDef[indices[i]];
- if (!hintDef) {
- codeq.log.error('Undefined hint ' + serverHint.id + ' with indices ' + serverHint.indices);
+ hintContent = hintContent[indices[i]];
+ if (!hintContent) {
+ codeq.log.error('Cannot reference hint ' + hintId + ' with indices ' + serverHint.indices);
continue mainLoop;
}
}
}
+
t = typeof hintDef;
- if ((t === 'string') || (hintDef instanceof Array)) {
- hintType = 'static';
- hintTemplate = hintDef;
- }
- else if (t === 'object') {
- hintType = hintDef.type;
- hintTemplate = hintDef.message;
- }
+ if (t === 'string') hintType = hintDef;
+ else if ((t === 'object') && (hintDef !== null)) hintType = hintDef.type;
else {
- codeq.log.error('Unsupported hint definition: ' + t);
+ codeq.log.error('Cannot determine type of hint ' + hintId + ' from: ' + hintDef);
continue;
}
fn = typeHandlers[hintType];
if (!fn) codeq.log.error('Unsupported hint type: ' + hintType);
- else fn(hintType, hintTemplate, serverHint);
+ else fn(hintType, hintContent.sl, serverHint);
}
},