Fixes #98083: Add onStartup activation event

This commit is contained in:
Alex Dima 2020-06-01 23:04:02 +02:00
parent 7e9abe577d
commit 827cbdd472
No known key found for this signature in database
GPG key ID: 6E58D7B045760DA0
4 changed files with 40 additions and 0 deletions

View file

@ -432,11 +432,37 @@ export abstract class AbstractExtHostExtensionService implements ExtHostExtensio
this._logService.error(err);
});
for (const desc of this._registry.getAllExtensionDescriptions()) {
if (desc.activationEvents) {
for (const activationEvent of desc.activationEvents) {
if (/^onStartup:/.test(activationEvent)) {
const strTime = activationEvent.substr('onStartup:'.length);
const time = parseInt(strTime, 10);
if (!isNaN(time)) {
this._activateDelayed(desc, activationEvent, time);
}
}
}
}
}
this._disposables.add(this._extHostWorkspace.onDidChangeWorkspace((e) => this._handleWorkspaceContainsEagerExtensions(e.added)));
const folders = this._extHostWorkspace.workspace ? this._extHostWorkspace.workspace.folders : [];
return this._handleWorkspaceContainsEagerExtensions(folders);
}
private _activateDelayed(desc: IExtensionDescription, activationEvent: string, delayMs: number): void {
setTimeout(() => {
this._activateById(desc.identifier, {
startup: true,
extensionId: desc.identifier,
activationEvent: activationEvent
}).then(undefined, (err) => {
this._logService.error(err);
});
}, delayMs);
}
private _handleWorkspaceContainsEagerExtensions(folders: ReadonlyArray<vscode.WorkspaceFolder>): Promise<void> {
if (folders.length === 0) {
return Promise.resolve(undefined);

View file

@ -372,6 +372,9 @@ export class RuntimeExtensionsEditor extends BaseEditor {
'{0} will be a glob pattern'
]
}, "Activated by {1} because searching for {0} took too long", glob, activationId);
} else if (/^onStartup:/.test(activationEvent)) {
const time = activationEvent.substr('onStartup:'.length);
title = nls.localize('startupActivation', "Activated by {0} with a delay of {1} ms on start-up", activationId, time);
} else if (/^onLanguage:/.test(activationEvent)) {
let language = activationEvent.substr('onLanguage:'.length);
title = nls.localize('languageActivation', "Activated by {1} because you opened a {0} file", language, activationId);

View file

@ -269,6 +269,11 @@ export const schema: IJSONSchema = {
description: nls.localize('vscode.extension.activationEvents.workspaceContains', 'An activation event emitted whenever a folder is opened that contains at least a file matching the specified glob pattern.'),
body: 'workspaceContains:${4:filePattern}'
},
{
label: 'onStartup',
description: nls.localize('vscode.extension.activationEvents.onStartup', 'An activation event emitted a certain amount of milliseconds after the start-up.'),
body: 'onStartup:${1:2000}'
},
{
label: 'onFileSystem',
description: nls.localize('vscode.extension.activationEvents.onFileSystem', 'An activation event emitted whenever a file or folder is accessed with the given scheme.'),

View file

@ -323,6 +323,12 @@ export class ExtensionService extends AbstractExtensionService implements IExten
shouldActivateReason = activationEvent;
break;
}
if (/^onStartup/.test(activationEvent)) {
shouldActivate = true;
shouldActivateReason = activationEvent;
break;
}
}
}