Fix Issue #3863 - jump-to-def goes to exports line.

When the result of jump-to-def looks like:
exports.foo = foo;

we now will try and jump-to-def on the rhs, as that's what the user most likely really wants.  Jumping to the exports line is rarely useful.

When we get the response for a jump-to-def, if it looks like we're jumping to a member expression like the example above, then we will grab the RHS, and trigger another jump-to-def on that, which should take us to the correct place.
This commit is contained in:
Erik Tierney committed 2013-06-17 13:46:54 -04:00
1 parent 360dd8a56a
commit 269c3b77c9
2 files changed
+150 -25

No files matched your search

@@ -104,6 +104,16 @@ define(function (require, exports, module) {
Session.prototype.getOffset = function () {
var cursor = this.getCursor();
return this.getOffsetFromCursor(cursor);
};
/**
* Get the offset of a cursor position
*
* @param {{line: number, ch: number}} the line/col info
* @return {number} - the offset into the current document of the cursor
*/
Session.prototype.getOffsetFromCursor = function (cursor) {
return this.editor.indexFromPos(cursor);
};
@@ -192,6 +202,36 @@ define(function (require, exports, module) {
return prev;
};
/**
* Get the token after the one at the given cursor position
*
* @param {{line: number, ch: number}} cursor - cursor position after
* which a token should be retrieved
* @return {Object} - the CodeMirror token after the one at the given
* cursor position
*/
Session.prototype.getNextToken = function (cursor, skipWhitespace) {
var token = this.getToken(cursor),
next = token,
doc = this.editor.document;
do {
if (next.start > cursor.ch) {
cursor.ch = next.end;
} else if (next.end > 0) {
cursor.ch = next.end + 1;
} else if (cursor.line > 0) {
cursor.ch = doc.getLine(cursor.line + 1).length;
cursor.line++;
} else {
break;
}
next = this.getToken(cursor);
} while (skipWhitespace && next.string.trim() === "");
return next;
};
/**
* Calculate a query string relative to the current cursor position