Skip to content

Commit 677b68d

Browse files
author
Benjamin Pasero
committed
qick open - tweak delay and cancellation further
1 parent 0ee556c commit 677b68d

2 files changed

Lines changed: 9 additions & 13 deletions

File tree

src/vs/workbench/parts/search/browser/openAnythingHandler.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@ export class OpenAnythingHandler extends QuickOpenHandler {
3737

3838
private static readonly LINE_COLON_PATTERN = /[#|:|\(](\d*)([#|:|,](\d*))?\)?$/;
3939

40-
private static readonly FILE_SEARCH_DELAY = 200;
41-
private static readonly SYMBOL_SEARCH_DELAY = 500; // go easier on those symbols!
40+
private static readonly TYPING_SEARCH_DELAY = 200; // This delay accommodates for the user typing a word and then stops typing to start searching
4241

4342
private static readonly MAX_DISPLAYED_RESULTS = 512;
4443

@@ -57,7 +56,7 @@ export class OpenAnythingHandler extends QuickOpenHandler {
5756
super();
5857

5958
this.scorerCache = Object.create(null);
60-
this.searchDelayer = new ThrottledDelayer<QuickOpenModel>(OpenAnythingHandler.FILE_SEARCH_DELAY);
59+
this.searchDelayer = new ThrottledDelayer<QuickOpenModel>(OpenAnythingHandler.TYPING_SEARCH_DELAY);
6160

6261
this.openSymbolHandler = instantiationService.createInstance(OpenSymbolHandler);
6362
this.openFileHandler = instantiationService.createInstance(OpenFileHandler);
@@ -103,7 +102,7 @@ export class OpenAnythingHandler extends QuickOpenHandler {
103102
}
104103

105104
// The throttler needs a factory for its promises
106-
const promiseFactory = () => {
105+
const resultsPromise = () => {
107106
const resultPromises: TPromise<QuickOpenModel | FileQuickOpenModel>[] = [];
108107

109108
// File Results
@@ -155,7 +154,7 @@ export class OpenAnythingHandler extends QuickOpenHandler {
155154
};
156155

157156
// Trigger through delayer to prevent accumulation while the user is typing (except when expecting results to come from cache)
158-
return this.hasShortResponseTime() ? promiseFactory() : this.searchDelayer.trigger(promiseFactory, this.includeSymbols ? OpenAnythingHandler.SYMBOL_SEARCH_DELAY : OpenAnythingHandler.FILE_SEARCH_DELAY);
157+
return this.hasShortResponseTime() ? resultsPromise() : this.searchDelayer.trigger(resultsPromise, OpenAnythingHandler.TYPING_SEARCH_DELAY);
159158
}
160159

161160
hasShortResponseTime(): boolean {

src/vs/workbench/parts/search/browser/openSymbolHandler.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { IAutoFocus, Mode, IEntryRunContext } from 'vs/base/parts/quickopen/comm
1515
import * as filters from 'vs/base/common/filters';
1616
import * as strings from 'vs/base/common/strings';
1717
import { Range } from 'vs/editor/common/core/range';
18-
import { EditorInput, IWorkbenchEditorConfiguration } from 'vs/workbench/common/editor';
18+
import { IWorkbenchEditorConfiguration } from 'vs/workbench/common/editor';
1919
import { symbolKindToCssClass } from 'vs/editor/common/modes';
2020
import { IResourceInput } from 'vs/platform/editor/common/editor';
2121
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
@@ -71,10 +71,7 @@ class SymbolEntry extends EditorQuickOpenEntry {
7171
run(mode: Mode, context: IEntryRunContext): boolean {
7272

7373
// resolve this type bearing if neccessary
74-
if (!this.bearingResolve
75-
&& typeof this.provider.resolveWorkspaceSymbol === 'function'
76-
&& !this.bearing.location.range
77-
) {
74+
if (!this.bearingResolve && typeof this.provider.resolveWorkspaceSymbol === 'function' && !this.bearing.location.range) {
7875
this.bearingResolve = Promise.resolve(this.provider.resolveWorkspaceSymbol(this.bearing, CancellationToken.None)).then(result => {
7976
this.bearing = result || this.bearing;
8077

@@ -90,7 +87,7 @@ class SymbolEntry extends EditorQuickOpenEntry {
9087
return mode === Mode.OPEN;
9188
}
9289

93-
getInput(): IResourceInput | EditorInput {
90+
getInput(): IResourceInput {
9491
const input: IResourceInput = {
9592
resource: this.bearing.location.uri,
9693
options: {
@@ -130,15 +127,15 @@ export class OpenSymbolHandler extends QuickOpenHandler {
130127

131128
static readonly ID = 'workbench.picker.symbols';
132129

133-
private static readonly SEARCH_DELAY = 200; // This delay accommodates for the user typing a word and then stops typing to start searching
130+
private static readonly TYPING_SEARCH_DELAY = 200; // This delay accommodates for the user typing a word and then stops typing to start searching
134131

135132
private delayer: ThrottledDelayer<QuickOpenEntry[]>;
136133
private options: IOpenSymbolOptions;
137134

138135
constructor(@IInstantiationService private instantiationService: IInstantiationService) {
139136
super();
140137

141-
this.delayer = new ThrottledDelayer<QuickOpenEntry[]>(OpenSymbolHandler.SEARCH_DELAY);
138+
this.delayer = new ThrottledDelayer<QuickOpenEntry[]>(OpenSymbolHandler.TYPING_SEARCH_DELAY);
142139
this.options = Object.create(null);
143140
}
144141

0 commit comments

Comments
 (0)