From 10c0610a6dafc5d7932126678f660e77c895e65c Mon Sep 17 00:00:00 2001 From: Eric Amodio Date: Wed, 12 Apr 2017 00:27:35 -0400 Subject: [PATCH 1/2] Fixes #944 - Support wildcards on activationEvents.workspaceContains --- src/vs/workbench/node/extensionHostMain.ts | 34 ++++++++++++++++++---- 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/src/vs/workbench/node/extensionHostMain.ts b/src/vs/workbench/node/extensionHostMain.ts index d84ec84c92426..ae3bd6cb18bc6 100644 --- a/src/vs/workbench/node/extensionHostMain.ts +++ b/src/vs/workbench/node/extensionHostMain.ts @@ -12,6 +12,8 @@ import { join } from 'path'; import { IRemoteCom } from 'vs/platform/extensions/common/ipcRemoteCom'; import { ExtHostExtensionService } from 'vs/workbench/api/node/extHostExtensionService'; import { ExtHostThreadService } from 'vs/workbench/services/thread/common/extHostThreadService'; +import { QueryType, ISearchQuery } from 'vs/platform/search/common/search'; +import { DiskSearch } from 'vs/workbench/services/search/node/searchService'; import { RemoteTelemetryService } from 'vs/workbench/api/node/extHostTelemetry'; import { IWorkspaceContextService, WorkspaceContextService } from 'vs/platform/workspace/common/workspace'; import { IInitData, IEnvironment, MainContext } from 'vs/workbench/api/node/extHost.protocol'; @@ -34,6 +36,7 @@ export class ExtensionHostMain { private _isTerminating: boolean = false; private _contextService: IWorkspaceContextService; + private _diskSearch: DiskSearch; private _environment: IEnvironment; private _extensionService: ExtHostExtensionService; @@ -122,13 +125,32 @@ export class ExtensionHostMain { } }); - const fileNames = Object.keys(desiredFilesMap); + const matchingPatterns = Object.keys(desiredFilesMap).map(p => { + // TODO: This is a bit hacky -- maybe this should be implemented by using something like + // `workspaceGlob` or something along those lines? + if (p.indexOf('*') > -1 || p.indexOf('?') > -1) { + if (!this._diskSearch) { + this._diskSearch = new DiskSearch(false); + } + + const query: ISearchQuery = { + folderResources: [workspace.resource], + type: QueryType.File, + maxResults: 1, + includePattern: { [p]: true } + }; + + return this._diskSearch.search(query).then(result => result.results.length ? p : undefined); + } else { + return pfs.exists(join(folderPath, p)).then(exists => exists ? p : undefined); + } + }); - return TPromise.join(fileNames.map(f => pfs.exists(join(folderPath, f)))).then(exists => { - fileNames - .filter((f, i) => exists[i]) - .forEach(fileName => { - const activationEvent = `workspaceContains:${fileName}`; + return TPromise.join(matchingPatterns).then(patterns => { + patterns + .filter(p => p !== undefined) + .forEach(p => { + const activationEvent = `workspaceContains:${p}`; this._extensionService.activateByEvent(activationEvent) .done(null, err => console.error(err)); From a336df99e34f266920f5f4cc677fde810f6b5003 Mon Sep 17 00:00:00 2001 From: Alex Dima Date: Mon, 29 May 2017 17:24:43 +0200 Subject: [PATCH 2/2] Shutdown glob pattern searching process after 1s of idle time --- src/vs/workbench/node/extensionHostMain.ts | 3 ++- src/vs/workbench/services/search/node/searchService.ts | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/vs/workbench/node/extensionHostMain.ts b/src/vs/workbench/node/extensionHostMain.ts index ae3bd6cb18bc6..fd41b0c29fe16 100644 --- a/src/vs/workbench/node/extensionHostMain.ts +++ b/src/vs/workbench/node/extensionHostMain.ts @@ -130,7 +130,8 @@ export class ExtensionHostMain { // `workspaceGlob` or something along those lines? if (p.indexOf('*') > -1 || p.indexOf('?') > -1) { if (!this._diskSearch) { - this._diskSearch = new DiskSearch(false); + // Shut down this search process after 1s + this._diskSearch = new DiskSearch(false, 1000); } const query: ISearchQuery = { diff --git a/src/vs/workbench/services/search/node/searchService.ts b/src/vs/workbench/services/search/node/searchService.ts index b1317d6b7cca6..1c2d62c29d14c 100644 --- a/src/vs/workbench/services/search/node/searchService.ts +++ b/src/vs/workbench/services/search/node/searchService.ts @@ -200,12 +200,12 @@ export class DiskSearch { private raw: IRawSearchService; - constructor(verboseLogging: boolean) { + constructor(verboseLogging: boolean, timeout: number = 60 * 60 * 1000) { const client = new Client( uri.parse(require.toUrl('bootstrap')).fsPath, { serverName: 'Search', - timeout: 60 * 60 * 1000, + timeout: timeout, args: ['--type=searchService'], env: { AMD_ENTRYPOINT: 'vs/workbench/services/search/node/searchApp',