@@ -32,6 +32,7 @@ define(function (require, exports, module) {
3232 var MultiRangeInlineEditor = brackets . getModule ( "editor/MultiRangeInlineEditor" ) . MultiRangeInlineEditor ,
3333 FileIndexManager = brackets . getModule ( "project/FileIndexManager" ) ,
3434 EditorManager = brackets . getModule ( "editor/EditorManager" ) ,
35+ DocumentManager = brackets . getModule ( "document/DocumentManager" ) ,
3536 JSUtils = brackets . getModule ( "language/JSUtils" ) ,
3637 PerfUtils = brackets . getModule ( "utils/PerfUtils" ) ;
3738
@@ -103,26 +104,71 @@ define(function (require, exports, module) {
103104 * or null if we're not going to provide anything.
104105 */
105106 function _createInlineEditor ( hostEditor , functionName ) {
107+ // Use Tern jump-to-definition helper, if it's available, to find InlineEditor target.
108+ var helper = brackets . _jsCodeHintsHelper ;
109+ if ( helper === null ) {
110+ return null ;
111+ }
112+
106113 var result = new $ . Deferred ( ) ;
107114 PerfUtils . markStart ( PerfUtils . JAVASCRIPT_INLINE_CREATE ) ;
108-
109- _findInProject ( functionName ) . done ( function ( functions ) {
110- if ( functions && functions . length > 0 ) {
111- var jsInlineEditor = new MultiRangeInlineEditor ( functions ) ;
112- jsInlineEditor . load ( hostEditor ) ;
113-
114- PerfUtils . addMeasurement ( PerfUtils . JAVASCRIPT_INLINE_CREATE ) ;
115- result . resolve ( jsInlineEditor ) ;
116- } else {
117- // No matching functions were found
118- PerfUtils . addMeasurement ( PerfUtils . JAVASCRIPT_INLINE_CREATE ) ;
115+
116+ var response = helper ( ) ;
117+ if ( response . hasOwnProperty ( "promise" ) ) {
118+ response . promise . done ( function ( jumpResp ) {
119+ var resolvedPath = jumpResp . fullPath ;
120+ if ( resolvedPath ) {
121+
122+ // Tern doesn't always return entire function extent.
123+ // Use QuickEdit search now that we know which file to look at.
124+ var fileInfos = [ ] ;
125+ fileInfos . push ( { name : jumpResp . resultFile , fullPath : resolvedPath } ) ;
126+ JSUtils . findMatchingFunctions ( functionName , fileInfos )
127+ . done ( function ( functions ) {
128+ if ( functions && functions . length > 0 ) {
129+ var jsInlineEditor = new MultiRangeInlineEditor ( functions ) ;
130+ jsInlineEditor . load ( hostEditor ) ;
131+
132+ PerfUtils . addMeasurement ( PerfUtils . JAVASCRIPT_INLINE_CREATE ) ;
133+ result . resolve ( jsInlineEditor ) ;
134+ } else {
135+ // No matching functions were found
136+ PerfUtils . addMeasurement ( PerfUtils . JAVASCRIPT_INLINE_CREATE ) ;
137+ result . reject ( ) ;
138+ }
139+ } )
140+ . fail ( function ( ) {
141+ PerfUtils . addMeasurement ( PerfUtils . JAVASCRIPT_INLINE_CREATE ) ;
142+ result . reject ( ) ;
143+ } ) ;
144+
145+ } else { // no result from Tern. Fall back to _findInProject().
146+
147+ _findInProject ( functionName ) . done ( function ( functions ) {
148+ if ( functions && functions . length > 0 ) {
149+ var jsInlineEditor = new MultiRangeInlineEditor ( functions ) ;
150+ jsInlineEditor . load ( hostEditor ) ;
151+
152+ PerfUtils . addMeasurement ( PerfUtils . JAVASCRIPT_INLINE_CREATE ) ;
153+ result . resolve ( jsInlineEditor ) ;
154+ } else {
155+ // No matching functions were found
156+ PerfUtils . addMeasurement ( PerfUtils . JAVASCRIPT_INLINE_CREATE ) ;
157+ result . reject ( ) ;
158+ }
159+ } ) . fail ( function ( ) {
160+ PerfUtils . finalizeMeasurement ( PerfUtils . JAVASCRIPT_INLINE_CREATE ) ;
161+ result . reject ( ) ;
162+ } ) ;
163+ }
164+
165+ } ) . fail ( function ( ) {
166+ PerfUtils . finalizeMeasurement ( PerfUtils . JAVASCRIPT_INLINE_CREATE ) ;
119167 result . reject ( ) ;
120- }
121- } ) . fail ( function ( ) {
122- PerfUtils . finalizeMeasurement ( PerfUtils . JAVASCRIPT_INLINE_CREATE ) ;
123- result . reject ( ) ;
124- } ) ;
125-
168+ } ) ;
169+
170+ }
171+
126172 return result . promise ( ) ;
127173 }
128174
@@ -147,14 +193,14 @@ define(function (require, exports, module) {
147193 if ( sel . start . line !== sel . end . line ) {
148194 return null ;
149195 }
150-
196+
151197 // Always use the selection start for determining the function name. The pos
152198 // parameter is usually the selection end.
153199 var functionName = _getFunctionName ( hostEditor , sel . start ) ;
154200 if ( ! functionName ) {
155201 return null ;
156202 }
157-
203+
158204 return _createInlineEditor ( hostEditor , functionName ) ;
159205 }
160206
0 commit comments