Skip to content
This repository was archived by the owner on Sep 6, 2021. It is now read-only.

Commit e75f444

Browse files
committed
Merge pull request #7226 from adobe/pflynn/jump-to-def-fixes
Fix several problems with Jump to Definition API
2 parents b2468f6 + 7b32bb1 commit e75f444

2 files changed

Lines changed: 12 additions & 9 deletions

File tree

src/editor/EditorManager.js

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -287,9 +287,11 @@ define(function (require, exports, module) {
287287
* Registers a new jump-to-definition provider. When jump-to-definition is invoked each
288288
* registered provider is asked if it wants to provide jump-to-definition results, given
289289
* the current editor and cursor location.
290+
*
290291
* @param {function(!Editor, !{line:number, ch:number}):?$.Promise} provider
291-
* The provider returns a promise that will be resolved with jump-to-definition results, or
292-
* returns null to indicate the provider doesn't want to respond to this case.
292+
* The provider returns a promise that is resolved whenever it's done handling the operation,
293+
* or returns null to indicate the provider doesn't want to respond to this case. It is entirely
294+
* up to the provider to open the file containing the definition, select the appropriate text, etc.
293295
*/
294296
function registerJumpToDefProvider(provider) {
295297
_jumpToDefProviders.push(provider);
@@ -953,24 +955,25 @@ define(function (require, exports, module) {
953955

954956
/**
955957
* Asynchronously asks providers to handle jump-to-definition.
956-
* @return {!Promise} null if no appropriate provider exists. Else, returns a promise
957-
* which is resolved by adjusting the editor selection to the requested definition.
958+
* @return {!Promise} Resolved when the provider signals that it's done; rejected if no
959+
* provider responded or the provider that responded failed.
958960
*/
959961
function _doJumpToDef() {
960962
var providers = _jumpToDefProviders;
961963
var promise,
962964
i,
963965
result = new $.Deferred();
964966

965-
if (_currentEditor) {
966-
// main editor has focus
967+
var editor = getActiveEditor();
968+
if (editor) {
969+
var pos = editor.getCursorPos();
967970

968971
PerfUtils.markStart(PerfUtils.JUMP_TO_DEFINITION);
969972

970973
// Run through providers until one responds
971974
for (i = 0; i < providers.length && !promise; i++) {
972975
var provider = providers[i];
973-
promise = provider();
976+
promise = provider(editor, pos);
974977
}
975978

976979
// Will one of them will provide a result?
@@ -1056,4 +1059,4 @@ define(function (require, exports, module) {
10561059
exports.notifyPathDeleted = notifyPathDeleted;
10571060
exports.closeCustomViewer = closeCustomViewer;
10581061
exports.showingCustomViewerForPath = showingCustomViewerForPath;
1059-
});
1062+
});

src/extensions/default/JavaScriptCodeHints/main.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -632,7 +632,7 @@ define(function (require, exports, module) {
632632

633633

634634
// Only provide jump-to-definition results when cursor is in JavaScript content
635-
if (session.editor.getModeForSelection() !== "javascript") {
635+
if (!session || session.editor.getModeForSelection() !== "javascript") {
636636
return null;
637637
}
638638

0 commit comments

Comments
 (0)