mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-12 02:58:31 -05:00
* Merge from vscode 64980ea1f3f532c82bb6c28d27bba9ef2c5b4463 * fix config changes * fix strictnull checks
285 lines
9.3 KiB
TypeScript
285 lines
9.3 KiB
TypeScript
/*---------------------------------------------------------------------------------------------
|
|
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
|
*--------------------------------------------------------------------------------------------*/
|
|
|
|
import { Event } from 'vs/base/common/event';
|
|
import Severity from 'vs/base/common/severity';
|
|
import { URI } from 'vs/base/common/uri';
|
|
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
|
|
import { IExtensionPoint } from 'vs/workbench/services/extensions/common/extensionsRegistry';
|
|
import { ExtensionIdentifier, IExtension, ExtensionType, IExtensionDescription } from 'vs/platform/extensions/common/extensions';
|
|
import { getGalleryExtensionId } from 'vs/platform/extensionManagement/common/extensionManagementUtil';
|
|
import { IMessagePassingProtocol } from 'vs/base/parts/ipc/common/ipc';
|
|
|
|
export const nullExtensionDescription = Object.freeze(<IExtensionDescription>{
|
|
identifier: new ExtensionIdentifier('nullExtensionDescription'),
|
|
name: 'Null Extension Description',
|
|
version: '0.0.0',
|
|
publisher: 'vscode',
|
|
enableProposedApi: false,
|
|
engines: { vscode: '' },
|
|
extensionLocation: URI.parse('void:location'),
|
|
isBuiltin: false,
|
|
});
|
|
|
|
export const IExtensionService = createDecorator<IExtensionService>('extensionService');
|
|
|
|
export interface IMessage {
|
|
type: Severity;
|
|
message: string;
|
|
extensionId: ExtensionIdentifier;
|
|
extensionPointId: string;
|
|
}
|
|
|
|
export interface IExtensionsStatus {
|
|
messages: IMessage[];
|
|
activationTimes: ActivationTimes | undefined;
|
|
runtimeErrors: Error[];
|
|
}
|
|
|
|
export type ExtensionActivationError = string | MissingDependencyError;
|
|
export class MissingDependencyError {
|
|
constructor(readonly dependency: string) { }
|
|
}
|
|
|
|
/**
|
|
* e.g.
|
|
* ```
|
|
* {
|
|
* startTime: 1511954813493000,
|
|
* endTime: 1511954835590000,
|
|
* deltas: [ 100, 1500, 123456, 1500, 100000 ],
|
|
* ids: [ 'idle', 'self', 'extension1', 'self', 'idle' ]
|
|
* }
|
|
* ```
|
|
*/
|
|
export interface IExtensionHostProfile {
|
|
/**
|
|
* Profiling start timestamp in microseconds.
|
|
*/
|
|
startTime: number;
|
|
/**
|
|
* Profiling end timestamp in microseconds.
|
|
*/
|
|
endTime: number;
|
|
/**
|
|
* Duration of segment in microseconds.
|
|
*/
|
|
deltas: number[];
|
|
/**
|
|
* Segment identifier: extension id or one of the four known strings.
|
|
*/
|
|
ids: ProfileSegmentId[];
|
|
|
|
/**
|
|
* Get the information as a .cpuprofile.
|
|
*/
|
|
data: object;
|
|
|
|
/**
|
|
* Get the aggregated time per segmentId
|
|
*/
|
|
getAggregatedTimes(): Map<ProfileSegmentId, number>;
|
|
}
|
|
|
|
export interface IExtensionHostStarter {
|
|
readonly onExit: Event<[number, string | null]>;
|
|
|
|
start(): Promise<IMessagePassingProtocol> | null;
|
|
getInspectPort(): number | undefined;
|
|
dispose(): void;
|
|
}
|
|
|
|
|
|
/**
|
|
* Extension id or one of the four known program states.
|
|
*/
|
|
export type ProfileSegmentId = string | 'idle' | 'program' | 'gc' | 'self';
|
|
|
|
export class ActivationTimes {
|
|
constructor(
|
|
public readonly startup: boolean,
|
|
public readonly codeLoadingTime: number,
|
|
public readonly activateCallTime: number,
|
|
public readonly activateResolvedTime: number,
|
|
public readonly activationEvent: string
|
|
) {
|
|
}
|
|
}
|
|
|
|
export class ExtensionPointContribution<T> {
|
|
readonly description: IExtensionDescription;
|
|
readonly value: T;
|
|
|
|
constructor(description: IExtensionDescription, value: T) {
|
|
this.description = description;
|
|
this.value = value;
|
|
}
|
|
}
|
|
|
|
export const ExtensionHostLogFileName = 'exthost';
|
|
|
|
export interface IWillActivateEvent {
|
|
readonly event: string;
|
|
readonly activation: Promise<void>;
|
|
}
|
|
|
|
export interface IResponsiveStateChangeEvent {
|
|
isResponsive: boolean;
|
|
}
|
|
|
|
export interface IExtensionService {
|
|
_serviceBrand: undefined;
|
|
|
|
/**
|
|
* An event emitted when extensions are registered after their extension points got handled.
|
|
*
|
|
* This event will also fire on startup to signal the installed extensions.
|
|
*
|
|
* @returns the extensions that got registered
|
|
*/
|
|
onDidRegisterExtensions: Event<void>;
|
|
|
|
/**
|
|
* @event
|
|
* Fired when extensions status changes.
|
|
* The event contains the ids of the extensions that have changed.
|
|
*/
|
|
onDidChangeExtensionsStatus: Event<ExtensionIdentifier[]>;
|
|
|
|
/**
|
|
* Fired when the available extensions change (i.e. when extensions are added or removed).
|
|
*/
|
|
onDidChangeExtensions: Event<void>;
|
|
|
|
/**
|
|
* An event that is fired when activation happens.
|
|
*/
|
|
onWillActivateByEvent: Event<IWillActivateEvent>;
|
|
|
|
/**
|
|
* An event that is fired when an extension host changes its
|
|
* responsive-state.
|
|
*/
|
|
onDidChangeResponsiveChange: Event<IResponsiveStateChangeEvent>;
|
|
|
|
/**
|
|
* Send an activation event and activate interested extensions.
|
|
*/
|
|
activateByEvent(activationEvent: string): Promise<void>;
|
|
|
|
/**
|
|
* An promise that resolves when the installed extensions are registered after
|
|
* their extension points got handled.
|
|
*/
|
|
whenInstalledExtensionsRegistered(): Promise<boolean>;
|
|
|
|
/**
|
|
* Return all registered extensions
|
|
*/
|
|
getExtensions(): Promise<IExtensionDescription[]>;
|
|
|
|
/**
|
|
* Return a specific extension
|
|
* @param id An extension id
|
|
*/
|
|
getExtension(id: string): Promise<IExtensionDescription | undefined>;
|
|
|
|
/**
|
|
* Returns `true` if the given extension can be added. Otherwise `false`.
|
|
* @param extension An extension
|
|
*/
|
|
canAddExtension(extension: IExtensionDescription): boolean;
|
|
|
|
/**
|
|
* Returns `true` if the given extension can be removed. Otherwise `false`.
|
|
* @param extension An extension
|
|
*/
|
|
canRemoveExtension(extension: IExtensionDescription): boolean;
|
|
|
|
/**
|
|
* Read all contributions to an extension point.
|
|
*/
|
|
readExtensionPointContributions<T>(extPoint: IExtensionPoint<T>): Promise<ExtensionPointContribution<T>[]>;
|
|
|
|
/**
|
|
* Get information about extensions status.
|
|
*/
|
|
getExtensionsStatus(): { [id: string]: IExtensionsStatus };
|
|
|
|
/**
|
|
* Return the inspect port or `0`, the latter means inspection
|
|
* is not possible.
|
|
*/
|
|
getInspectPort(): number;
|
|
|
|
/**
|
|
* Restarts the extension host.
|
|
*/
|
|
restartExtensionHost(): void;
|
|
|
|
/**
|
|
* Modify the environment of the remote extension host
|
|
* @param env New properties for the remote extension host
|
|
*/
|
|
setRemoteEnvironment(env: { [key: string]: string | null }): Promise<void>;
|
|
|
|
_logOrShowMessage(severity: Severity, msg: string): void;
|
|
_activateById(extensionId: ExtensionIdentifier, activationEvent: string): Promise<void>;
|
|
_onWillActivateExtension(extensionId: ExtensionIdentifier): void;
|
|
_onDidActivateExtension(extensionId: ExtensionIdentifier, startup: boolean, codeLoadingTime: number, activateCallTime: number, activateResolvedTime: number, activationEvent: string): void;
|
|
_onExtensionRuntimeError(extensionId: ExtensionIdentifier, err: Error): void;
|
|
_onExtensionHostExit(code: number): void;
|
|
}
|
|
|
|
export interface ProfileSession {
|
|
stop(): Promise<IExtensionHostProfile>;
|
|
}
|
|
|
|
export function checkProposedApiEnabled(extension: IExtensionDescription): void {
|
|
if (!extension.enableProposedApi) {
|
|
throwProposedApiError(extension);
|
|
}
|
|
}
|
|
|
|
export function throwProposedApiError(extension: IExtensionDescription): never {
|
|
throw new Error(`[${extension.identifier.value}]: Proposed API is only available when running out of dev or with the following command line switch: --enable-proposed-api ${extension.identifier.value}`);
|
|
}
|
|
|
|
export function toExtension(extensionDescription: IExtensionDescription): IExtension {
|
|
return {
|
|
type: extensionDescription.isBuiltin ? ExtensionType.System : ExtensionType.User,
|
|
identifier: { id: getGalleryExtensionId(extensionDescription.publisher, extensionDescription.name), uuid: extensionDescription.uuid },
|
|
manifest: extensionDescription,
|
|
location: extensionDescription.extensionLocation,
|
|
};
|
|
}
|
|
|
|
|
|
export class NullExtensionService implements IExtensionService {
|
|
_serviceBrand: undefined;
|
|
onDidRegisterExtensions: Event<void> = Event.None;
|
|
onDidChangeExtensionsStatus: Event<ExtensionIdentifier[]> = Event.None;
|
|
onDidChangeExtensions: Event<void> = Event.None;
|
|
onWillActivateByEvent: Event<IWillActivateEvent> = Event.None;
|
|
onDidChangeResponsiveChange: Event<IResponsiveStateChangeEvent> = Event.None;
|
|
activateByEvent(_activationEvent: string): Promise<void> { return Promise.resolve(undefined); }
|
|
whenInstalledExtensionsRegistered(): Promise<boolean> { return Promise.resolve(true); }
|
|
getExtensions(): Promise<IExtensionDescription[]> { return Promise.resolve([]); }
|
|
getExtension() { return Promise.resolve(undefined); }
|
|
readExtensionPointContributions<T>(_extPoint: IExtensionPoint<T>): Promise<ExtensionPointContribution<T>[]> { return Promise.resolve(Object.create(null)); }
|
|
getExtensionsStatus(): { [id: string]: IExtensionsStatus; } { return Object.create(null); }
|
|
getInspectPort(): number { return 0; }
|
|
restartExtensionHost(): void { }
|
|
async setRemoteEnvironment(_env: { [key: string]: string | null }): Promise<void> { }
|
|
canAddExtension(): boolean { return false; }
|
|
canRemoveExtension(): boolean { return false; }
|
|
_logOrShowMessage(_severity: Severity, _msg: string): void { }
|
|
_activateById(_extensionId: ExtensionIdentifier, _activationEvent: string): Promise<void> { return Promise.resolve(); }
|
|
_onWillActivateExtension(_extensionId: ExtensionIdentifier): void { }
|
|
_onDidActivateExtension(_extensionId: ExtensionIdentifier, _startup: boolean, _codeLoadingTime: number, _activateCallTime: number, _activateResolvedTime: number, _activationEvent: string): void { }
|
|
_onExtensionRuntimeError(_extensionId: ExtensionIdentifier, _err: Error): void { }
|
|
_onExtensionHostExit(code: number): void { }
|
|
}
|