Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #944 - Support wildcards on activationEvents.workspaceContains #24570

Merged
merged 3 commits into from
May 29, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 29 additions & 6 deletions src/vs/workbench/node/extensionHostMain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -34,6 +36,7 @@ export class ExtensionHostMain {

private _isTerminating: boolean = false;
private _contextService: IWorkspaceContextService;
private _diskSearch: DiskSearch;
private _environment: IEnvironment;
private _extensionService: ExtHostExtensionService;

Expand Down Expand Up @@ -122,13 +125,33 @@ 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) {
// Shut down this search process after 1s
this._diskSearch = new DiskSearch(false, 1000);
}

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));
Expand Down
4 changes: 2 additions & 2 deletions src/vs/workbench/services/search/node/searchService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down