@@ -71,95 +71,128 @@ function isEditorSymbolQuickPickItem(pick?: IAnythingQuickPickItem): pick is IEd
71
71
return ! ! candidate ?. range && ! ! candidate . resource ;
72
72
}
73
73
74
- export class AnythingQuickAccessProvider extends PickerQuickAccessProvider < IAnythingQuickPickItem > {
74
+ export class PickState {
75
+ picker : IQuickPick < IAnythingQuickPickItem > | undefined = undefined ;
75
76
76
- static PREFIX = '' ;
77
+ editorViewState : {
78
+ editor : EditorInput ;
79
+ group : IEditorGroup ;
80
+ state : ICodeEditorViewState | IDiffEditorViewState | undefined ;
81
+ } | undefined = undefined ;
77
82
78
- private static readonly NO_RESULTS_PICK : IAnythingQuickPickItem = {
79
- label : localize ( 'noAnythingResults' , "No matching results" )
80
- } ;
83
+ scorerCache : FuzzyScorerCache = Object . create ( null ) ;
84
+ fileQueryCache : FileQueryCacheState | undefined = undefined ;
81
85
82
- private static readonly MAX_RESULTS = 512 ;
86
+ lastOriginalFilter : string | undefined = undefined ;
87
+ lastFilter : string | undefined = undefined ;
88
+ lastRange : IRange | undefined = undefined ;
83
89
84
- private static readonly TYPING_SEARCH_DELAY = 200 ; // this delay accommodates for the user typing a word and then stops typing to start searching
90
+ lastGlobalPicks : PicksWithActive < IAnythingQuickPickItem > | undefined = undefined ;
85
91
86
- private static SYMBOL_PICKS_MERGE_DELAY = 200 ; // allow some time to merge fast and slow picks to reduce flickering
92
+ isQuickNavigating : boolean | undefined = undefined ;
87
93
88
- private readonly pickState = new class {
94
+ private readonly fileQueryBuilder = this . instantiationService . createInstance ( QueryBuilder ) ;
89
95
90
- picker : IQuickPick < IAnythingQuickPickItem > | undefined = undefined ;
96
+ constructor (
97
+ private readonly instantiationService : IInstantiationService ,
98
+ private readonly contextService : IWorkspaceContextService ,
99
+ private readonly searchService : ISearchService ,
100
+ private readonly editorService : IEditorService ) { }
101
+
102
+ set ( picker : IQuickPick < IAnythingQuickPickItem > ) : void {
103
+
104
+ // Picker for this run
105
+ this . picker = picker ;
106
+ Event . once ( picker . onDispose ) ( ( ) => {
107
+ if ( picker === this . picker ) {
108
+ this . picker = undefined ; // clear the picker when disposed to not keep it in memory for too long
109
+ }
110
+ } ) ;
91
111
92
- editorViewState : {
93
- editor : EditorInput ;
94
- group : IEditorGroup ;
95
- state : ICodeEditorViewState | IDiffEditorViewState | undefined ;
96
- } | undefined = undefined ;
112
+ // Caches
113
+ const isQuickNavigating = ! ! picker . quickNavigate ;
114
+ if ( ! isQuickNavigating ) {
115
+ this . fileQueryCache = this . createFileQueryCache ( ) ;
116
+ this . scorerCache = Object . create ( null ) ;
117
+ }
97
118
98
- scorerCache : FuzzyScorerCache = Object . create ( null ) ;
99
- fileQueryCache : FileQueryCacheState | undefined = undefined ;
119
+ // Other
120
+ this . isQuickNavigating = isQuickNavigating ;
121
+ this . lastOriginalFilter = undefined ;
122
+ this . lastFilter = undefined ;
123
+ this . lastRange = undefined ;
124
+ this . lastGlobalPicks = undefined ;
125
+ this . editorViewState = undefined ;
126
+ }
100
127
101
- lastOriginalFilter : string | undefined = undefined ;
102
- lastFilter : string | undefined = undefined ;
103
- lastRange : IRange | undefined = undefined ;
128
+ rememberEditorViewState ( ) : void {
129
+ if ( this . editorViewState ) {
130
+ return ; // return early if already done
131
+ }
104
132
105
- lastGlobalPicks : PicksWithActive < IAnythingQuickPickItem > | undefined = undefined ;
133
+ const activeEditorPane = this . editorService . activeEditorPane ;
134
+ if ( activeEditorPane ) {
135
+ this . editorViewState = {
136
+ group : activeEditorPane . group ,
137
+ editor : activeEditorPane . input ,
138
+ state : getIEditor ( activeEditorPane . getControl ( ) ) ?. saveViewState ( ) ?? undefined ,
139
+ } ;
140
+ }
141
+ }
106
142
107
- isQuickNavigating : boolean | undefined = undefined ;
143
+ getFileQueryOptions ( input : { filePattern ?: string ; cacheKey ?: string ; maxResults ?: number } ) : IFileQueryBuilderOptions {
144
+ return {
145
+ _reason : 'openFileHandler' , // used for telemetry - do not change
146
+ extraFileResources : this . instantiationService . invokeFunction ( getOutOfWorkspaceEditorResources ) ,
147
+ filePattern : input . filePattern || '' ,
148
+ cacheKey : input . cacheKey ,
149
+ maxResults : input . maxResults || 0 ,
150
+ sortByScore : true
151
+ } ;
152
+ }
108
153
109
- constructor ( private readonly provider : AnythingQuickAccessProvider , private readonly editorService : IEditorService ) { }
154
+ async restoreEditorViewState ( ) : Promise < void > {
155
+ if ( this . editorViewState ) {
156
+ const options : IEditorOptions = {
157
+ viewState : this . editorViewState . state ,
158
+ preserveFocus : true /* import to not close the picker as a result */
159
+ } ;
110
160
111
- set ( picker : IQuickPick < IAnythingQuickPickItem > ) : void {
161
+ await this . editorViewState . group . openEditor ( this . editorViewState . editor , options ) ;
162
+ }
163
+ }
112
164
113
- // Picker for this run
114
- this . picker = picker ;
115
- Event . once ( picker . onDispose ) ( ( ) => {
116
- if ( picker === this . picker ) {
117
- this . picker = undefined ; // clear the picker when disposed to not keep it in memory for too long
118
- }
119
- } ) ;
120
165
121
- // Caches
122
- const isQuickNavigating = ! ! picker . quickNavigate ;
123
- if ( ! isQuickNavigating ) {
124
- this . fileQueryCache = this . provider . createFileQueryCache ( ) ;
125
- this . scorerCache = Object . create ( null ) ;
126
- }
166
+ private createFileQueryCache ( ) : FileQueryCacheState {
167
+ return new FileQueryCacheState (
168
+ cacheKey => this . fileQueryBuilder . file ( this . contextService . getWorkspace ( ) . folders , this . getFileQueryOptions ( { cacheKey } ) ) ,
169
+ query => this . searchService . fileSearch ( query ) ,
170
+ cacheKey => this . searchService . clearCache ( cacheKey ) ,
171
+ this . fileQueryCache
172
+ ) . load ( ) ;
173
+ }
174
+ }
127
175
128
- // Other
129
- this . isQuickNavigating = isQuickNavigating ;
130
- this . lastOriginalFilter = undefined ;
131
- this . lastFilter = undefined ;
132
- this . lastRange = undefined ;
133
- this . lastGlobalPicks = undefined ;
134
- this . editorViewState = undefined ;
135
- }
176
+ export class AnythingQuickAccessProvider extends PickerQuickAccessProvider < IAnythingQuickPickItem > {
136
177
137
- rememberEditorViewState ( ) : void {
138
- if ( this . editorViewState ) {
139
- return ; // return early if already done
140
- }
178
+ static PREFIX = '' ;
141
179
142
- const activeEditorPane = this . editorService . activeEditorPane ;
143
- if ( activeEditorPane ) {
144
- this . editorViewState = {
145
- group : activeEditorPane . group ,
146
- editor : activeEditorPane . input ,
147
- state : getIEditor ( activeEditorPane . getControl ( ) ) ?. saveViewState ( ) ?? undefined ,
148
- } ;
149
- }
150
- }
180
+ private static readonly NO_RESULTS_PICK : IAnythingQuickPickItem = {
181
+ label : localize ( 'noAnythingResults' , "No matching results" )
182
+ } ;
151
183
152
- async restoreEditorViewState ( ) : Promise < void > {
153
- if ( this . editorViewState ) {
154
- const options : IEditorOptions = {
155
- viewState : this . editorViewState . state ,
156
- preserveFocus : true /* import to not close the picker as a result */
157
- } ;
184
+ private static readonly MAX_RESULTS = 512 ;
158
185
159
- await this . editorViewState . group . openEditor ( this . editorViewState . editor , options ) ;
160
- }
161
- }
162
- } ( this , this . editorService ) ;
186
+ private static readonly TYPING_SEARCH_DELAY = 200 ; // this delay accommodates for the user typing a word and then stops typing to start searching
187
+
188
+ private static SYMBOL_PICKS_MERGE_DELAY = 200 ; // allow some time to merge fast and slow picks to reduce flickering
189
+
190
+ private readonly pickState = new PickState (
191
+ this . instantiationService ,
192
+ this . contextService ,
193
+ this . searchService ,
194
+ this . editorService
195
+ ) ;
163
196
164
197
get defaultFilterValue ( ) : DefaultQuickAccessFilterValue | undefined {
165
198
if ( this . configuration . preserveInput ) {
@@ -510,14 +543,6 @@ export class AnythingQuickAccessProvider extends PickerQuickAccessProvider<IAnyt
510
543
511
544
private readonly fileQueryBuilder = this . instantiationService . createInstance ( QueryBuilder ) ;
512
545
513
- private createFileQueryCache ( ) : FileQueryCacheState {
514
- return new FileQueryCacheState (
515
- cacheKey => this . fileQueryBuilder . file ( this . contextService . getWorkspace ( ) . folders , this . getFileQueryOptions ( { cacheKey } ) ) ,
516
- query => this . searchService . fileSearch ( query ) ,
517
- cacheKey => this . searchService . clearCache ( cacheKey ) ,
518
- this . pickState . fileQueryCache
519
- ) . load ( ) ;
520
- }
521
546
522
547
private async getFilePicks ( query : IPreparedQuery , excludes : ResourceMap < boolean > , token : CancellationToken ) : Promise < Array < IAnythingQuickPickItem > > {
523
548
if ( ! query . normalized ) {
@@ -661,24 +686,14 @@ export class AnythingQuickAccessProvider extends PickerQuickAccessProvider<IAnyt
661
686
return this . searchService . fileSearch (
662
687
this . fileQueryBuilder . file (
663
688
this . contextService . getWorkspace ( ) . folders ,
664
- this . getFileQueryOptions ( {
689
+ this . pickState . getFileQueryOptions ( {
665
690
filePattern,
666
691
cacheKey : this . pickState . fileQueryCache ?. cacheKey ,
667
692
maxResults : AnythingQuickAccessProvider . MAX_RESULTS
668
693
} )
669
694
) , token ) ;
670
695
}
671
696
672
- private getFileQueryOptions ( input : { filePattern ?: string ; cacheKey ?: string ; maxResults ?: number } ) : IFileQueryBuilderOptions {
673
- return {
674
- _reason : 'openFileHandler' , // used for telemetry - do not change
675
- extraFileResources : this . instantiationService . invokeFunction ( getOutOfWorkspaceEditorResources ) ,
676
- filePattern : input . filePattern || '' ,
677
- cacheKey : input . cacheKey ,
678
- maxResults : input . maxResults || 0 ,
679
- sortByScore : true
680
- } ;
681
- }
682
697
683
698
private async getAbsolutePathFileResult ( query : IPreparedQuery , token : CancellationToken ) : Promise < URI | undefined > {
684
699
if ( ! query . containsPathSeparator ) {
0 commit comments