Verified Commit 0378c741 authored by Camil Staps's avatar Camil Staps 🚀

Resolve #119: give required_context hints

parent 657bf5d7
Subproject commit 1643295f13b0e2da735975ecfb6abe4ed1579e69
Subproject commit c31413250077579ecc9d9fbbb2270d9018e990f7
......@@ -49,7 +49,7 @@ CACHE_PREFETCH :== 5
, c_page :: Int
}
derive JSONEncode Kind, ClassOrGeneric, Type, RequestCacheKey
derive JSONEncode Kind, Type, RequestCacheKey, TypeRestriction
instance toString RequestCacheKey
where toString rck = toString $ toJSON rck
......
......@@ -153,7 +153,7 @@ predefFunctions
, {zero & fe_type=Just $ Func [Type "Bool" [], Var "a", Var "a"] (Var "a") []}
)
, ( Builtin "dynamic"
, {zero & fe_type=Just $ Func [Var "a"] (Type "Dynamic" []) [(Class "TC", Var "a")]}
, {zero & fe_type=Just $ Func [Var "a"] (Type "Dynamic" []) [Instance "TC" [Var "a"]]}
)
]
......
......@@ -75,6 +75,7 @@ function makeSummary(hidden) {
sumlen++;
if (sumlen != hidden.length) {
hidden.push([null, null, 'more information']);
sumlen++;
restore = true;
}
......@@ -124,6 +125,63 @@ function makeParametersHTML(name, params) {
return name + 's:<ul><li>' + params.join('</li><li>').makeParagraphs() + '</li></ul>';
}
function makeLocationUrl(loc) {
var dclUrl =
'src?lib=' + encodeURIComponent(loc[0]) +
'#' + encodeURIComponent(loc[1]);
var iclUrl = dclUrl + ';icl';
if (loc[2].length > 1)
dclUrl += ';line=' + loc[2][1];
if (loc[3].length > 1)
iclUrl += ';line=' + loc[3][1];
return loc[1] +
' (<a target="_blank" href="' + dclUrl + '">dcl' +
(loc[2].length > 1 ? ':' + loc[2][1] : '') + '</a>; ' +
'<a target="_blank" href="' + iclUrl + '">icl' +
(loc[3].length > 1 ? ':' + loc[3][1] : '') + '</a>) ' +
'(' + loc[0] + ')';
}
function makeLocationUrls(locs) {
var html = '';
for (var j in locs) {
if (html != '')
html += ', ';
html += makeLocationUrl(locs[j]);
}
return html;
}
function makeUnifier(ufr) {
var from_left = ufr.left_to_right;
var from_right = ufr.right_to_left;
var s = '';
for (i in from_right)
s += '<tt>' + from_right[i][0] + '</tt> &rarr; <tt>' + from_right[i][1] + '</tt>; ';
for (i in from_left)
s += '<tt>' + from_left[i][1] + '</tt> &larr; <tt>' + from_left[i][0] + '</tt>; ';
return s.substring(0, s.length - 2);
}
function makeRequiredContext(context) {
var html = '<table>';
for (var i in context) {
html += '<tr><td>' +
'<code>' + highlightFunction(context[i][0], highlightCallback) + '</code>' +
'</td><td>' +
(context[i][1].length > 0
? makeLocationUrls(context[i][1])
: 'Not currently known to Cloogle.') +
'</td></tr>';
}
html += '</table>';
return html;
}
function getResults(str, libs, include_builtins, include_core, page) {
if (str == null) str = old_str;
if (libs == null) libs = old_libs;
......@@ -173,25 +231,6 @@ function getResults(str, libs, include_builtins, include_core, page) {
var instances = '<table>';
var makeInstanceUrl = function (loc) {
var dclUrl =
'src?lib=' + encodeURIComponent(loc[0]) +
'#' + encodeURIComponent(loc[1]);
var iclUrl = dclUrl + ';icl';
if (loc[2].length > 1)
dclUrl += ';line=' + loc[2][1];
if (loc[3].length > 1)
iclUrl += ';line=' + loc[3][1];
return loc[1] +
' (<a target="_blank" href="' + dclUrl + '">dcl' +
(loc[2].length > 1 ? ':' + loc[2][1] : '') + '</a>; ' +
'<a target="_blank" href="' + iclUrl + '">icl' +
(loc[3].length > 1 ? ':' + loc[3][1] : '') + '</a>) ' +
'(' + loc[0] + ')';
}
for (var i in list) {
instances += '<tr><th>';
if (typeof list[i][0] === 'object') {
......@@ -219,20 +258,11 @@ function getResults(str, libs, include_builtins, include_core, page) {
instances += '</td>';
}
var locs = '';
var locsidx = list[i].length - 1;
for (var j in list[i][locsidx]) {
var loc = list[i][locsidx][j];
if (locs != '') {
locs += ', ';
}
locs += makeInstanceUrl(loc);
}
if (list[i][locsidx].length == 0)
instances += '<td></td></tr>'
else
instances += '<td>&nbsp;in ' + locs + '</td></tr>';
instances += '<td>&nbsp;in ' + makeLocationUrls(list[i][locsidx]) + '</td></tr>';
}
instances += '</table>';
......@@ -306,6 +336,9 @@ function getResults(str, libs, include_builtins, include_core, page) {
' ' + extra['cls']['cls_vars'].join(' '),
highlightCallback, 'className') + '</code>');
if ('required_context' in extra && extra['required_context'].length > 0) {
hidden.push(['Required context', makeRequiredContext(extra['required_context'])]);
}
if ('unifier' in extra &&
(extra['unifier'].left_to_right.length > 0
|| extra['unifier'].right_to_left.length > 0))
......@@ -499,19 +532,6 @@ function getResults(str, libs, include_builtins, include_core, page) {
}
}
function makeUnifier(ufr) {
var from_left = ufr.left_to_right;
var from_right = ufr.right_to_left;
var s = '';
for (i in from_right)
s += '<tt>' + from_right[i][0] + '</tt> &rarr; <tt>' + from_right[i][1] + '</tt>; ';
for (i in from_left)
s += '<tt>' + from_left[i][1] + '</tt> &larr; <tt>' + from_left[i][0] + '</tt>; ';
return s.substring(0, s.length - 2);
}
function getLibs() {
if (!advanced)
return -1;
......
Subproject commit 3d4a0e40ac847dfac4cdd034670a2ce84d6ff2c1
Subproject commit ecaa9005c61d3ed1c2b7521fbbf50f102af17392
......@@ -4,6 +4,14 @@ pre {
tab-size: 4;
}
table {
border-spacing: 0;
}
td, th {
padding-right: 1em;
}
.toggle-container .toggler {
cursor: pointer;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment