mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2025-12-20 22:47:59 +01:00
Show function prototype when completing JavaScript function arguments.
This commit is contained in:
@@ -1605,7 +1605,7 @@ const ItemList = Class("ItemList", {
|
||||
this._minHeight = 0;
|
||||
},
|
||||
|
||||
_dom: function (xml, map) util.xmlToDom(xml, this._doc, map),
|
||||
_dom: function (xml, map) util.xmlToDom(xml instanceof XML ? xml : <>{xml}</>, this._doc, map),
|
||||
|
||||
_autoSize: function () {
|
||||
if (this._container.collapsed)
|
||||
@@ -1707,7 +1707,7 @@ const ItemList = Class("ItemList", {
|
||||
let [start, end, waiting] = getRows(context);
|
||||
|
||||
if (context.message)
|
||||
nodes.message.textContent = context.message;
|
||||
nodes.message.appendChild(this._dom(context.message));
|
||||
nodes.message.style.display = context.message ? "block" : "none";
|
||||
nodes.waiting.style.display = waiting ? "block" : "none";
|
||||
nodes.up.style.opacity = "0";
|
||||
|
||||
@@ -439,6 +439,25 @@ const JavaScript = Module("javascript", {
|
||||
prev = v + 1;
|
||||
}
|
||||
|
||||
try {
|
||||
let i = (this._get(-2) && this._get(-2).char == "(") ? -2 : -1;
|
||||
if (this._get(i).char == "(") {
|
||||
let [offset, obj, funcName] = this._getObjKey(i-1);
|
||||
if (obj.length) {
|
||||
let func = obj[0][0][funcName];
|
||||
if (callable(func)) {
|
||||
let [, prefix, args] = /^(function .*?)\((.*)?\)/.exec(Function.prototype.toString.call(func));
|
||||
let n = this._get(i).comma.length;
|
||||
args = template.map(Iterator(args.split(", ")),
|
||||
function ([i, arg]) <span highlight={i == n ? "Filter" : ""}>{arg}</span>,
|
||||
<>, </>);
|
||||
this.context.message = <>{prefix}({args})</>;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (e) {}
|
||||
|
||||
// In a string. Check if we're dereferencing an object or
|
||||
// completing a function argument. Otherwise, do nothing.
|
||||
if (this._last == "'" || this._last == '"') {
|
||||
@@ -483,17 +502,18 @@ const JavaScript = Module("javascript", {
|
||||
if (this._get(-3, 0, "functions") != this._get(-2).offset)
|
||||
return null; // No. We're done.
|
||||
|
||||
let [offset, obj, func] = this._getObjKey(-3);
|
||||
let [offset, obj, funcName] = this._getObjKey(-3);
|
||||
if (!obj.length)
|
||||
return null;
|
||||
obj = obj.slice(0, 1);
|
||||
|
||||
try {
|
||||
var completer = obj[0][0][func].dactylCompleter;
|
||||
let func = obj[0][0][funcName];
|
||||
var completer = func.dactylCompleter;
|
||||
}
|
||||
catch (e) {}
|
||||
if (!completer)
|
||||
completer = JavaScript.completers[func];
|
||||
completer = JavaScript.completers[funcName];
|
||||
if (!completer)
|
||||
return null;
|
||||
|
||||
@@ -509,12 +529,12 @@ const JavaScript = Module("javascript", {
|
||||
args.push(key + string);
|
||||
|
||||
let compl = function (context, obj) {
|
||||
let res = completer.call(self, context, func, obj, args);
|
||||
let res = completer.call(self, context, funcName, obj, args);
|
||||
if (res)
|
||||
context.completions = res;
|
||||
};
|
||||
|
||||
obj[0][1] += "." + func + "(... [" + args.length + "]";
|
||||
obj[0][1] += "." + funcName + "(... [" + args.length + "]";
|
||||
return this._complete(obj, key, compl, string, this._last);
|
||||
}
|
||||
|
||||
|
||||
@@ -671,7 +671,7 @@ const Util = Module("Util", {
|
||||
scrollIntoView: function scrollIntoView(elem, alignWithTop) {
|
||||
let win = elem.ownerDocument.defaultView;
|
||||
let rect = elem.getBoundingClientRect();
|
||||
if (!(rect && rect.bottom <= win.innerHeight && rect.top >= 0 && rect.right <= win.innerWidth && rect.left >= 0))
|
||||
if (!(rect && rect.bottom <= win.innerHeight && rect.top >= 0 && rect.left < win.innerWidth && rect.right > 0))
|
||||
elem.scrollIntoView(arguments.length > 1 ? alignWithTop : Math.abs(rect.top) < Math.abs(win.innerHeight - rect.bottom));
|
||||
},
|
||||
|
||||
|
||||
@@ -26,8 +26,6 @@ BUGS:
|
||||
9 about:pentadactyl is currently about:undefined
|
||||
|
||||
- messages is still broken in several ways - needs testing.
|
||||
=> :ls | :echomsg "Foobar" doesn't add "Foobar" to the already open MOW.
|
||||
(NOTE: an intentional design decision by MS - Boo!)
|
||||
=> it often overwrites the open command line while editing etc.
|
||||
- <tags> and <keyword> autocmd 'keywords' are not available when adding a
|
||||
bookmark - they're being set after the observer triggers the autocmd event.
|
||||
@@ -36,7 +34,6 @@ BUGS:
|
||||
|
||||
FEATURES:
|
||||
9 Add quoting help tag
|
||||
9 JavaScript completer: show function parameter spec
|
||||
9 Fix the arbitrary distinction between 'hinttags' and
|
||||
'extendedhinttags'
|
||||
9 Support multiple bookmarks, -keyword, -tags in :delbmarks
|
||||
|
||||
Reference in New Issue
Block a user