Merge pull request #57047 from Microsoft/roblou/34711
#34711 - run search for 5s, if it times out, activate the extension anyway
This commit is contained in:
commit
665b823142
5 changed files with 31 additions and 26 deletions
|
@ -214,8 +214,13 @@ export class MainThreadWorkspace implements MainThreadWorkspaceShape {
|
|||
return search;
|
||||
}
|
||||
|
||||
$checkExists(query: ISearchQuery, requestId: number): Thenable<boolean> {
|
||||
query.exists = true;
|
||||
$checkExists(includes: string[], requestId: number): Thenable<boolean> {
|
||||
const queryBuilder = this._instantiationService.createInstance(QueryBuilder);
|
||||
const folders = this._contextService.getWorkspace().folders.map(folder => folder.uri);
|
||||
const query = queryBuilder.file(folders, {
|
||||
includePattern: includes.join(', '),
|
||||
exists: true
|
||||
});
|
||||
|
||||
const tokenSource = new CancellationTokenSource();
|
||||
const search = this._searchService.search(query, tokenSource.token).then(
|
||||
|
|
|
@ -26,7 +26,7 @@ import { LabelRules } from 'vs/platform/label/common/label';
|
|||
import { LogLevel } from 'vs/platform/log/common/log';
|
||||
import { IMarkerData } from 'vs/platform/markers/common/markers';
|
||||
import { IPickOptions, IQuickInputButton, IQuickPickItem } from 'vs/platform/quickinput/common/quickInput';
|
||||
import { IPatternInfo, IQueryOptions, IRawFileMatch2, IRawSearchQuery, ISearchCompleteStats, ISearchQuery } from 'vs/platform/search/common/search';
|
||||
import { IPatternInfo, IQueryOptions, IRawFileMatch2, IRawSearchQuery, ISearchCompleteStats } from 'vs/platform/search/common/search';
|
||||
import { StatusbarAlignment as MainThreadStatusBarAlignment } from 'vs/platform/statusbar/common/statusbar';
|
||||
import { ITelemetryInfo } from 'vs/platform/telemetry/common/telemetry';
|
||||
import { ThemeColor } from 'vs/platform/theme/common/themeService';
|
||||
|
@ -472,7 +472,7 @@ export interface ExtHostUrlsShape {
|
|||
export interface MainThreadWorkspaceShape extends IDisposable {
|
||||
$startFileSearch(includePattern: string, includeFolder: string, excludePatternOrDisregardExcludes: string | false, maxResults: number, requestId: number): Thenable<UriComponents[]>;
|
||||
$startTextSearch(query: IPatternInfo, options: IQueryOptions, requestId: number): Thenable<void>;
|
||||
$checkExists(query: ISearchQuery, requestId: number): Thenable<boolean>;
|
||||
$checkExists(includes: string[], requestId: number): Thenable<boolean>;
|
||||
$cancelSearch(requestId: number): Thenable<boolean>;
|
||||
$saveAll(includeUntitled?: boolean): Thenable<boolean>;
|
||||
$updateWorkspaceFolders(extensionName: string, index: number, deleteCount: number, workspaceFoldersToAdd: { uri: UriComponents, name?: string }[]): Thenable<void>;
|
||||
|
|
|
@ -13,11 +13,9 @@ import { ExtHostExtensionService } from 'vs/workbench/api/node/extHostExtensionS
|
|||
import { ExtHostConfiguration } from 'vs/workbench/api/node/extHostConfiguration';
|
||||
import { ExtHostWorkspace } from 'vs/workbench/api/node/extHostWorkspace';
|
||||
import { IExtensionDescription } from 'vs/workbench/services/extensions/common/extensions';
|
||||
import { QueryType, ISearchQuery } from 'vs/platform/search/common/search';
|
||||
import { DiskSearch } from 'vs/workbench/services/search/node/searchService';
|
||||
import { IInitData, IEnvironment, IWorkspaceData, MainContext, MainThreadWorkspaceShape } from 'vs/workbench/api/node/extHost.protocol';
|
||||
import * as errors from 'vs/base/common/errors';
|
||||
import * as glob from 'vs/base/common/glob';
|
||||
import { ExtensionActivatedByEvent } from 'vs/workbench/api/node/extHostExtensionActivator';
|
||||
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
|
||||
import { IMessagePassingProtocol } from 'vs/base/parts/ipc/node/ipc';
|
||||
|
@ -77,6 +75,8 @@ interface ITestRunner {
|
|||
|
||||
export class ExtensionHostMain {
|
||||
|
||||
private static readonly WORKSPACE_CONTAINS_TIMEOUT = 5000;
|
||||
|
||||
private _isTerminating: boolean = false;
|
||||
private _diskSearch: DiskSearch;
|
||||
private _workspace: IWorkspaceData;
|
||||
|
@ -267,30 +267,21 @@ export class ExtensionHostMain {
|
|||
}
|
||||
|
||||
if (!this._diskSearch) {
|
||||
// Shut down this search process after 1s
|
||||
// Shut down this search process after 1s of inactivity
|
||||
this._diskSearch = new DiskSearch(false, 1000);
|
||||
}
|
||||
|
||||
const includes: glob.IExpression = {};
|
||||
globPatterns.forEach((globPattern) => {
|
||||
includes[globPattern] = true;
|
||||
});
|
||||
const requestId = this._searchRequestIdProvider.getNext();
|
||||
const searchP = this._mainThreadWorkspace.$checkExists(globPatterns, requestId);
|
||||
|
||||
const folderQueries = this._workspace.folders.map(folder => ({ folder: URI.revive(folder.uri) }));
|
||||
const config = this._extHostConfiguration.getConfiguration('search');
|
||||
const useRipgrep = config.get('useRipgrep', true);
|
||||
const followSymlinks = config.get('followSymlinks', true);
|
||||
const timer = setTimeout(async () => {
|
||||
await this._mainThreadWorkspace.$cancelSearch(requestId);
|
||||
this._extensionService.activateById(extensionId, new ExtensionActivatedByEvent(true, `workspaceContainsTimeout:${globPatterns.join(',')}`))
|
||||
.then(null, err => console.error(err));
|
||||
}, ExtensionHostMain.WORKSPACE_CONTAINS_TIMEOUT);
|
||||
|
||||
const query: ISearchQuery = {
|
||||
folderQueries,
|
||||
type: QueryType.File,
|
||||
exists: true,
|
||||
includePattern: includes,
|
||||
useRipgrep,
|
||||
ignoreSymlinks: !followSymlinks
|
||||
};
|
||||
|
||||
const exists = await this._mainThreadWorkspace.$checkExists(query, this._searchRequestIdProvider.getNext());
|
||||
const exists = await searchP;
|
||||
clearTimeout(timer);
|
||||
if (exists) {
|
||||
// a file was found matching one of the glob patterns
|
||||
return (
|
||||
|
|
|
@ -318,6 +318,14 @@ export class RuntimeExtensionsEditor extends BaseEditor {
|
|||
]
|
||||
}, "Activated because file {0} exists in your workspace", fileNameOrGlob);
|
||||
}
|
||||
} else if (/^workspaceContainsTimeout:/.test(activationTimes.activationEvent)) {
|
||||
const glob = activationTimes.activationEvent.substr('workspaceContainsTimeout:'.length);
|
||||
title = nls.localize({
|
||||
key: 'workspaceContainsTimeout',
|
||||
comment: [
|
||||
'{0} will be a glob pattern'
|
||||
]
|
||||
}, "Activated because searching for {0} took too long", glob);
|
||||
} else if (/^onLanguage:/.test(activationTimes.activationEvent)) {
|
||||
let language = activationTimes.activationEvent.substr('onLanguage:'.length);
|
||||
title = nls.localize('languageActivation', "Activated because you opened a {0} file", language);
|
||||
|
|
|
@ -96,7 +96,8 @@ export class QueryBuilder {
|
|||
disregardIgnoreFiles: options.disregardIgnoreFiles || !useIgnoreFiles,
|
||||
disregardExcludeSettings: options.disregardExcludeSettings,
|
||||
ignoreSymlinks,
|
||||
previewOptions: options.previewOptions
|
||||
previewOptions: options.previewOptions,
|
||||
exists: options.exists
|
||||
};
|
||||
|
||||
// Filter extraFileResources against global include/exclude patterns - they are already expected to not belong to a workspace
|
||||
|
|
Loading…
Reference in a new issue