update completion_ and objection_info_request

both requests take:

- code (up to full cell)
- cursor_pos (cursor offset in unicode characters)

and object_info_replies return a mime-bundle, instead of structured data
pull/37/head
MinRK 12 years ago
parent 98c408cbd1
commit a74c79ceab

@ -1,13 +1,10 @@
//----------------------------------------------------------------------------
// Copyright (C) 2008-2012 The IPython Development Team
//
// Distributed under the terms of the BSD License. The full license is in
// the file COPYING, distributed as part of this software.
//----------------------------------------------------------------------------
// Copyright (c) IPython Development Team.
// Distributed under the terms of the Modified BSD License.
//============================================================================
// Utilities
//============================================================================
IPython.namespace('IPython.utils');
IPython.utils = (function (IPython) {
@ -430,7 +427,7 @@ IPython.utils = (function (IPython) {
var escape_html = function (text) {
// escape text to HTML
return $("<div/>").text(text).html();
}
};
var get_body_data = function(key) {
@ -439,8 +436,19 @@ IPython.utils = (function (IPython) {
// until we are building an actual request
return decodeURIComponent($('body').data(key));
};
var absolute_cursor_pos = function (cm, cursor) {
// get the absolute cursor position from CodeMirror's col, ch
if (!cursor) {
cursor = cm.getCursor();
}
var cursor_pos = cursor.ch;
for (var i = 0; i < cursor.line; i++) {
cursor_pos += cm.getLine(i).length + 1;
}
return cursor_pos;
};
// http://stackoverflow.com/questions/2400935/browser-detection-in-javascript
var browser = (function() {
if (typeof navigator === 'undefined') {
@ -465,13 +473,13 @@ IPython.utils = (function (IPython) {
if (navigator.appVersion.indexOf("Mac")!=-1) OSName="MacOS";
if (navigator.appVersion.indexOf("X11")!=-1) OSName="UNIX";
if (navigator.appVersion.indexOf("Linux")!=-1) OSName="Linux";
return OSName
return OSName;
})();
var is_or_has = function (a, b) {
// Is b a child of a or a itself?
return a.has(b).length !==0 || a.is(b);
}
};
var is_focused = function (e) {
// Is element e, or one of its children focused?
@ -486,7 +494,7 @@ IPython.utils = (function (IPython) {
} else {
return false;
}
}
};
var log_ajax_error = function (jqXHR, status, error) {
// log ajax failures with informative messages
@ -499,7 +507,7 @@ IPython.utils = (function (IPython) {
}
console.log(msg);
};
return {
regex_split : regex_split,
uuid : uuid,
@ -515,6 +523,7 @@ IPython.utils = (function (IPython) {
splitext : splitext,
escape_html : escape_html,
always_new : always_new,
absolute_cursor_pos : absolute_cursor_pos,
browser : browser,
platform: platform,
is_or_has : is_or_has,

@ -1,6 +1,10 @@
// function completer.
// Copyright (c) IPython Development Team.
// Distributed under the terms of the Modified BSD License.
// Completer
//
// completer should be a class that takes an cell instance
// Completer is be a class that takes a cell instance.
var IPython = (function (IPython) {
// that will prevent us from misspelling
"use strict";
@ -145,11 +149,14 @@ var IPython = (function (IPython) {
// we fork here and directly call finish completing if kernel is busy
if (this.skip_kernel_completion) {
this.finish_completing({
'matches': [],
matches: [],
matched_text: ""
});
} else {
this.cell.kernel.complete(line, cur.ch, $.proxy(this.finish_completing, this));
var cursor_pos = IPython.utils.absolute_cursor_pos(this.editor, cur);
this.cell.kernel.complete(this.editor.getValue(), cursor_pos,
$.proxy(this.finish_completing, this)
);
}
};

@ -1,9 +1,6 @@
//----------------------------------------------------------------------------
// Copyright (C) 2008-2011 The IPython Development Team
//
// Distributed under the terms of the BSD License. The full license is in
// the file COPYING, distributed as part of this software.
//----------------------------------------------------------------------------
// Copyright (c) IPython Development Team.
// Distributed under the terms of the Modified BSD License.
//============================================================================
// Tooltip
//============================================================================
@ -105,8 +102,8 @@ var IPython = (function (IPython) {
this.tooltip.append(this.text);
// function that will be called if you press tab 1, 2, 3... times in a row
this.tabs_functions = [function (cell, text) {
that._request_tooltip(cell, text);
this.tabs_functions = [function (cell, text, cursor) {
that._request_tooltip(cell, text, cursor);
}, function () {
that.expand();
}, function () {
@ -131,13 +128,10 @@ var IPython = (function (IPython) {
Tooltip.prototype.showInPager = function (cell) {
// reexecute last call in pager by appending ? to show back in pager
var that = this;
var callbacks = {'shell' : {
'payload' : {
'page' : $.proxy(cell._open_with_pager, cell)
}
}
};
cell.kernel.execute(that.name + '?', callbacks, {'silent': false, 'store_history': true});
var payload = {};
payload.text = that._reply.content.data['text/plain'];
$([IPython.events]).trigger('open_with_text.Pager', payload);
this.remove_and_cancel_tooltip();
};
@ -222,10 +216,9 @@ var IPython = (function (IPython) {
return Tooltip.last_token_re.exec(line);
};
Tooltip.prototype._request_tooltip = function (cell, line) {
Tooltip.prototype._request_tooltip = function (cell, text, cursor_pos) {
var callbacks = $.proxy(this._show, this);
var oir_token = this.extract_oir_token(line);
var msg_id = cell.kernel.object_info(oir_token, callbacks);
var msg_id = cell.kernel.object_info(text, cursor_pos, callbacks);
};
// make an imediate completion request
@ -236,10 +229,8 @@ var IPython = (function (IPython) {
this.cancel_pending();
var editor = cell.code_mirror;
var cursor = editor.getCursor();
var text = editor.getRange({
line: cursor.line,
ch: 0
}, cursor).trim();
var cursor_pos = IPython.utils.absolute_cursor_pos(editor, cursor);
var text = cell.get_text();
this._hide_if_no_docstring = hide_if_no_docstring;
@ -260,17 +251,17 @@ var IPython = (function (IPython) {
this.reset_tabs_function (cell, text);
}
// don't do anything if line beggin with '(' or is empty
if (text === "" || text === "(") {
return;
}
// don't do anything if line begins with '(' or is empty
// if (text === "" || text === "(") {
// return;
// }
this.tabs_functions[this._consecutive_counter](cell, text);
this.tabs_functions[this._consecutive_counter](cell, text, cursor_pos);
// then if we are at the end of list function, reset
if (this._consecutive_counter == this.tabs_functions.length) {
this.reset_tabs_function (cell, text);
}
this.reset_tabs_function (cell, text, cursor);
}
return;
};
@ -302,6 +293,7 @@ var IPython = (function (IPython) {
Tooltip.prototype._show = function (reply) {
// move the bubble if it is not hidden
// otherwise fade it
this._reply = reply;
var content = reply.content;
if (!content.found) {
// object not found, nothing to show
@ -338,43 +330,14 @@ var IPython = (function (IPython) {
this.arrow.animate({
'left': posarrowleft + 'px'
});
// build docstring
var defstring = content.call_def;
if (!defstring) {
defstring = content.init_definition;
}
if (!defstring) {
defstring = content.definition;
}
var docstring = content.call_docstring;
if (!docstring) {
docstring = content.init_docstring;
}
if (!docstring) {
docstring = content.docstring;
}
if (!docstring) {
// For reals this time, no docstring
if (this._hide_if_no_docstring) {
return;
} else {
docstring = "<empty docstring>";
}
}
this._hidden = false;
this.tooltip.fadeIn('fast');
this.text.children().remove();
// This should support rich data types, but only text/plain for now
// Any HTML within the docstring is escaped by the fixConsole() method.
var pre = $('<pre/>').html(utils.fixConsole(docstring));
if (defstring) {
var defstring_html = $('<pre/>').html(utils.fixConsole(defstring));
this.text.append(defstring_html);
}
var pre = $('<pre/>').html(utils.fixConsole(content.data['text/plain']));
this.text.append(pre);
// keep scroll top to be sure to always see the first line
this.text.scrollTop(0);

@ -263,7 +263,8 @@ var IPython = (function (IPython) {
/**
* Get info on an object
*
* @param objname {string}
* @param code {string}
* @param cursor_pos {integer}
* @param callback {function}
* @method object_info
*
@ -271,20 +272,18 @@ var IPython = (function (IPython) {
* The callback will be passed the complete `object_info_reply` message documented
* [here](http://ipython.org/ipython-doc/dev/development/messaging.html#object-information)
*/
Kernel.prototype.object_info = function (objname, callback) {
Kernel.prototype.object_info = function (code, cursor_pos, callback) {
var callbacks;
if (callback) {
callbacks = { shell : { reply : callback } };
}
if (typeof(objname) !== null && objname !== null) {
var content = {
oname : objname.toString(),
detail_level : 0,
};
return this.send_shell_message("object_info_request", content, callbacks);
}
return;
var content = {
code : code,
cursor_pos : cursor_pos,
detail_level : 0,
};
return this.send_shell_message("object_info_request", content, callbacks);
};
/**
@ -360,21 +359,19 @@ var IPython = (function (IPython) {
* [here](http://ipython.org/ipython-doc/dev/development/messaging.html#complete)
*
* @method complete
* @param line {integer}
* @param code {string}
* @param cursor_pos {integer}
* @param callback {function}
*
*/
Kernel.prototype.complete = function (line, cursor_pos, callback) {
Kernel.prototype.complete = function (code, cursor_pos, callback) {
var callbacks;
if (callback) {
callbacks = { shell : { reply : callback } };
}
var content = {
text : '',
line : line,
block : null,
cursor_pos : cursor_pos
code : code,
cursor_pos : cursor_pos,
};
return this.send_shell_message("complete_request", content, callbacks);
};

Loading…
Cancel
Save