@@ -31,27 +31,20 @@ import {ICodeEditor} from 'vs/editor/browser/editorBrowser';
3131import { EditorBrowserRegistry } from 'vs/editor/browser/editorBrowserExtensions' ;
3232import { IPeekViewService , getOuterEditor } from 'vs/editor/contrib/zoneWidget/browser/peekViewWidget' ;
3333import { findReferences } from '../common/referenceSearch' ;
34- import { EventType , ReferencesModel } from './referenceSearchModel' ;
34+ import { ReferencesModel , OneReference } from './referenceSearchModel' ;
3535import { ReferenceWidget , LayoutData } from './referenceSearchWidget' ;
3636import { ServicesAccessor } from 'vs/platform/instantiation/common/instantiation' ;
3737
3838export class FindReferencesController implements editorCommon . IEditorContribution {
3939
4040 public static ID = 'editor.contrib.findReferencesController' ;
4141
42- private _editor :ICodeEditor ;
43- private _widget :ReferenceWidget ;
44- private _requestIdPool : number ;
45- private _callOnClear :Function [ ] ;
46- private _model :ReferencesModel ;
47- private _modelRevealing :boolean ;
48-
49- private editorService : IEditorService ;
50- private telemetryService : ITelemetryService ;
51- private messageService : IMessageService ;
52- private instantiationService : IInstantiationService ;
53- private contextService : IWorkspaceContextService ;
54- private peekViewService : IPeekViewService ;
42+ private _editor : ICodeEditor ;
43+ private _widget : ReferenceWidget ;
44+ private _model : ReferencesModel ;
45+ private _requestIdPool = 0 ;
46+ private _callOnClear : Function [ ] = [ ] ;
47+ private _ignoreModelChangeEvent = false ;
5548
5649 private _startTime : number = - 1 ;
5750 private _referenceSearchVisible : IKeybindingContextKey < boolean > ;
@@ -62,24 +55,15 @@ export class FindReferencesController implements editorCommon.IEditorContributio
6255
6356 public constructor (
6457 editor : ICodeEditor ,
65- @IEditorService editorService : IEditorService ,
66- @ITelemetryService telemetryService : ITelemetryService ,
67- @IMessageService messageService : IMessageService ,
68- @IInstantiationService instantiationService : IInstantiationService ,
6958 @IKeybindingService keybindingService : IKeybindingService ,
70- @IWorkspaceContextService contextService : IWorkspaceContextService ,
59+ @IEditorService private _editorService : IEditorService ,
60+ @ITelemetryService private _telemetryService : ITelemetryService ,
61+ @IMessageService private _messageService : IMessageService ,
62+ @IInstantiationService private _instantiationService : IInstantiationService ,
63+ @IWorkspaceContextService private _contextService : IWorkspaceContextService ,
7164 @IStorageService private _storageService : IStorageService ,
72- @optional ( IPeekViewService ) peekViewService : IPeekViewService
65+ @optional ( IPeekViewService ) private _peekViewService : IPeekViewService
7366 ) {
74- this . _requestIdPool = 0 ;
75- this . _callOnClear = [ ] ;
76- this . editorService = editorService ;
77- this . telemetryService = telemetryService ;
78- this . messageService = messageService ;
79- this . instantiationService = instantiationService ;
80- this . peekViewService = peekViewService ;
81- this . contextService = contextService ;
82- this . _modelRevealing = false ;
8367 this . _editor = editor ;
8468 this . _referenceSearchVisible = keybindingService . createKey ( CONTEXT_REFERENCE_SEARCH_VISIBLE , false ) ;
8569 }
@@ -97,7 +81,7 @@ export class FindReferencesController implements editorCommon.IEditorContributio
9781 }
9882
9983 public isInPeekView ( ) : boolean {
100- return this . peekViewService && this . peekViewService . isActive ;
84+ return this . _peekViewService && this . _peekViewService . isActive ;
10185 }
10286
10387 public closeReferenceSearch ( ) : void {
@@ -120,13 +104,13 @@ export class FindReferencesController implements editorCommon.IEditorContributio
120104 // close the widget on model/mode changes
121105 this . _callOnClear . push ( this . _editor . addListener ( editorCommon . EventType . ModelModeChanged , ( ) => { this . clear ( ) ; } ) ) ;
122106 this . _callOnClear . push ( this . _editor . addListener ( editorCommon . EventType . ModelChanged , ( ) => {
123- if ( ! this . _modelRevealing ) {
107+ if ( ! this . _ignoreModelChangeEvent ) {
124108 this . clear ( ) ;
125109 }
126110 } ) ) ;
127111 const storageKey = 'peekViewLayout' ;
128112 const data = < LayoutData > JSON . parse ( this . _storageService . get ( storageKey , undefined , '{}' ) ) ;
129- this . _widget = new ReferenceWidget ( this . _editor , data , this . editorService , this . contextService , this . instantiationService ) ;
113+ this . _widget = new ReferenceWidget ( this . _editor , data , this . _editorService , this . _contextService , this . _instantiationService ) ;
130114 this . _widget . setTitle ( nls . localize ( 'labelLoading' , "Loading..." ) ) ;
131115 this . _widget . show ( range ) ;
132116 this . _callOnClear . push ( this . _widget . onDidClose ( ( ) => {
@@ -137,31 +121,27 @@ export class FindReferencesController implements editorCommon.IEditorContributio
137121 this . clear ( ) ;
138122 } ) . dispose ) ;
139123
140- this . _callOnClear . push ( this . _widget . onDidDoubleClick ( event => {
141-
142- if ( ! event . reference ) {
143- return ;
144- }
145-
146- // open editor
147- this . editorService . openEditor ( {
148- resource : event . reference ,
149- options : { selection : event . range }
150- } , event . originalEvent . ctrlKey || event . originalEvent . metaKey ) . done ( null , onUnexpectedError ) ;
151-
152- // close zone
153- if ( ! ( event . originalEvent . ctrlKey || event . originalEvent . metaKey ) ) {
154- this . clear ( ) ;
124+ this . _callOnClear . push ( this . _widget . onDidSelectReference ( event => {
125+ let { element, kind} = event ;
126+ switch ( kind ) {
127+ case 'side' :
128+ case 'open' :
129+ this . _openReference ( element , kind === 'side' ) ;
130+ break ;
131+ case 'goto' :
132+ this . _gotoReference ( element ) ;
133+ break ;
155134 }
156135 } ) . dispose ) ;
136+
157137 var requestId = ++ this . _requestIdPool ,
158138 editorModel = this . _editor . getModel ( ) ;
159139
160- var timer = this . telemetryService . timedPublicLog ( 'findReferences' , {
140+ var timer = this . _telemetryService . timedPublicLog ( 'findReferences' , {
161141 mode : editorModel . getMode ( ) . getId ( )
162142 } ) ;
163143
164- referencesPromise . then ( ( references : IReference [ ] ) => {
144+ referencesPromise . then ( references => {
165145
166146 // still current request? widget still open?
167147 if ( requestId !== this . _requestIdPool || ! this . _widget ) {
@@ -177,38 +157,7 @@ export class FindReferencesController implements editorCommon.IEditorContributio
177157 }
178158
179159 // create result model
180- this . _model = new ReferencesModel ( references , this . editorService ) ;
181- this . _model . currentReference = this . _model . findReference ( editorModel . getAssociatedResource ( ) , range . getStartPosition ( ) ) ;
182-
183- var unbind = this . _model . addListener ( EventType . CurrentReferenceChanged , ( ) => {
184-
185- this . _modelRevealing = true ;
186-
187- this . editorService . openEditor ( {
188- resource : this . _model . currentReference . resource ,
189- options : { selection : this . _model . currentReference . range }
190- } ) . done ( ( openedEditor ) => {
191- if ( ! openedEditor || openedEditor . getControl ( ) !== this . _editor ) {
192- // TODO@Alex TODO@Joh
193- // when opening the current reference we might end up
194- // in a different editor instance. that means we also have
195- // a different instance of this reference search controller
196- // and cannot hold onto the widget (which likely doesn't
197- // exist). Instead of bailing out we should find the
198- // 'sister' action and pass our current model on to it.
199- this . clear ( ) ;
200- return ;
201- }
202- this . _modelRevealing = false ;
203- this . _widget . show ( this . _model . currentReference . range ) ;
204- this . _widget . focus ( ) ;
205- } , ( err ) => {
206- this . _modelRevealing = false ;
207- onUnexpectedError ( err ) ;
208- } ) ;
209- } ) ;
210-
211- this . _callOnClear . push ( unbind ) ;
160+ this . _model = new ReferencesModel ( references , this . _editorService ) ;
212161
213162 // show widget
214163 this . _startTime = Date . now ( ) ;
@@ -219,25 +168,25 @@ export class FindReferencesController implements editorCommon.IEditorContributio
219168 timer . stop ( ) ;
220169
221170 } , ( error :any ) => {
222- this . messageService . show ( Severity . Error , error ) ;
171+ this . _messageService . show ( Severity . Error , error ) ;
223172 timer . stop ( ) ;
224173 } ) ;
225174
226175 return this . _widget ;
227176 }
228177
229- private clear ( ) :boolean {
178+ private clear ( ) : boolean {
230179
231180 if ( this . _startTime !== - 1 ) {
232- this . telemetryService . publicLog ( 'zoneWidgetShown' , {
181+ this . _telemetryService . publicLog ( 'zoneWidgetShown' , {
233182 mode : 'reference search' ,
234183 elapsedTime : Date . now ( ) - this . _startTime
235184 } ) ;
236185 this . _startTime = - 1 ;
237186 }
238187
239188 var result = false ;
240- if ( this . _widget ) {
189+ if ( this . _widget ) {
241190 this . _widget . dispose ( ) ;
242191 this . _widget = null ;
243192 result = true ;
@@ -254,8 +203,50 @@ export class FindReferencesController implements editorCommon.IEditorContributio
254203 return result ;
255204 }
256205
257- }
206+ private _gotoReference ( ref : OneReference ) : void {
207+ this . _ignoreModelChangeEvent = true ;
208+ const { resource, range} = ref ;
209+
210+ this . _editorService . openEditor ( {
211+ resource,
212+ options : { selection : range }
213+ } ) . done ( openedEditor => {
214+ this . _ignoreModelChangeEvent = false ;
215+
216+ if ( ! openedEditor || openedEditor . getControl ( ) !== this . _editor ) {
217+ // TODO@Alex TODO@Joh
218+ // when opening the current reference we might end up
219+ // in a different editor instance. that means we also have
220+ // a different instance of this reference search controller
221+ // and cannot hold onto the widget (which likely doesn't
222+ // exist). Instead of bailing out we should find the
223+ // 'sister' action and pass our current model on to it.
224+ this . clear ( ) ;
225+ return ;
226+ }
258227
228+ this . _widget . show ( range ) ;
229+ this . _widget . focus ( ) ;
230+
231+ } , ( err ) => {
232+ this . _ignoreModelChangeEvent = false ;
233+ onUnexpectedError ( err ) ;
234+ } ) ;
235+ }
236+
237+ private _openReference ( ref : OneReference , sideBySide : boolean ) : void {
238+ const { resource, range} = ref ;
239+ this . _editorService . openEditor ( {
240+ resource,
241+ options : { selection : range }
242+ } , sideBySide ) ;
243+
244+ // clear stage
245+ if ( ! sideBySide ) {
246+ this . clear ( ) ;
247+ }
248+ }
249+ }
259250
260251export class ReferenceAction extends EditorAction {
261252
0 commit comments