Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (/^workspaceContains:/.test(activationEvent)) {
const fileNameOrGlob = activationEvent.substr('workspaceContains:'.length);
if (fileNameOrGlob.indexOf('*') >= 0 || fileNameOrGlob.indexOf('?') >= 0) {
includePatterns.push(fileNameOrGlob);
} else {
paths.push(fileNameOrGlob);
}
}
}
const activatePlugin = () => manager.$activateByEvent(`onPlugin:${plugin.metadata.model.id}`);
const promises: Promise[] = [];
if (paths.length) {
promises.push(this.workspaceService.containsSome(paths));
}
if (includePatterns.length) {
const tokenSource = new CancellationTokenSource();
const searchTimeout = setTimeout(() => {
tokenSource.cancel();
// activate eagerly if took to long to search
activatePlugin();
}, 7000);
promises.push((async () => {
try {
const result = await this.fileSearchService.find('', {
rootUris: this.workspaceService.tryGetRoots().map(r => r.uri),
includePatterns,
limit: 1
}, tokenSource.token);
return result.length > 0;
} catch (e) {
if (!isCancelled(e)) {
console.error(e);
protected cancelSave(): CancellationToken {
this.saveCancellationTokenSource.cancel();
this.saveCancellationTokenSource = new CancellationTokenSource();
return this.saveCancellationTokenSource.token;
}
async onType(lookFor: string, acceptor: (items: QuickOpenItem[]) => void): Promise {
if (this.languages.workspaceSymbolProviders) {
this.cancellationSource.cancel();
const newCancellationSource = new CancellationTokenSource();
this.cancellationSource = newCancellationSource;
const param: WorkspaceSymbolParams = {
query: lookFor,
};
const items: QuickOpenItem[] = [];
for (const provider of this.languages.workspaceSymbolProviders) {
provider.provideWorkspaceSymbols(param, newCancellationSource.token).then(symbols => {
if (symbols && !newCancellationSource.token.isCancellationRequested) {
for (const symbol of symbols) {
items.push(this.createItem(symbol));
}
acceptor(items);
}
async scheduleInstall(): Promise {
if (this.installationTokenSource) {
this.installationTokenSource.cancel();
}
this.installationTokenSource = new CancellationTokenSource();
const token = this.installationTokenSource.token;
this.installed = this.installed.then(() => this.install(token));
await this.installed;
}
protected updateStatus = debounce(async (): Promise => {
this.toDispose.dispose();
const tokenSource = new CancellationTokenSource();
this.toDispose.push(Disposable.create(() => tokenSource.cancel()));
const token = tokenSource.token;
const source = this.selectedRepository;
if (source) {
const status = await this.git.status(source);
this.setStatus({ source, status }, token);
this.toDispose.push(this.gitWatcher.onGitEvent(event => {
if (event.source.localUri === source.localUri) {
this.setStatus(event, token);
}
}));
this.toDispose.push(await this.gitWatcher.watchGitChanges(source));
} else {
this.setStatus(undefined, token);
}
}, 50);
async search(searchTerm: string, searchOptions: SearchInWorkspaceOptions): Promise {
this.searchTerm = searchTerm;
const collapseValue: string = this.searchInWorkspacePreferences['search.collapseResults'];
this.resultTree.clear();
this.cancelIndicator.cancel();
this.cancelIndicator = new CancellationTokenSource();
const token = this.cancelIndicator.token;
if (searchTerm === '') {
this.refreshModelChildren();
return;
}
const progress = await this.progressService.showProgress({ text: `search: ${searchTerm}`, options: { location: 'search' } });
const searchId = await this.searchService.search(searchTerm, {
onResult: (aSearchId: number, result: SearchInWorkspaceResult) => {
if (token.isCancellationRequested || aSearchId !== searchId) {
return;
}
const { path } = this.filenameAndPath(result.root, result.fileUri);
const tree = this.resultTree;
const rootFolderNode = tree.get(result.root);
if (rootFolderNode) {
async find(searchPattern: string, options: FileSearchService.Options, clientToken?: CancellationToken): Promise {
const cancellationSource = new CancellationTokenSource();
if (clientToken) {
clientToken.onCancellationRequested(() => cancellationSource.cancel());
}
const token = cancellationSource.token;
const opts = {
fuzzyMatch: true,
limit: Number.MAX_SAFE_INTEGER,
useGitIgnore: true,
...options
};
const roots: FileSearchService.RootOptions = options.rootOptions || {};
if (options.rootUris) {
for (const rootUri of options.rootUris) {
if (!roots[rootUri]) {
roots[rootUri] = {};
protected cancelSync(): CancellationToken {
this.syncCancellationTokenSource.cancel();
this.syncCancellationTokenSource = new CancellationTokenSource();
return this.syncCancellationTokenSource.token;
}