跳转到内容

上下文

宿主向 mount、activate 和命令处理器传入上下文。可选能力取决于声明、挂载位置和宿主支持,调用前应检查是否存在。将订阅加入 subscriptions;signal 随调用方作用域结束,共享 background 连接有独立的生命周期。

使用指南: views. API 索引.

签名、参数及返回类型从 SDK 自动生成;可选成员不保证在每个宿主和上下文中存在。

源码

readonly signal: AbortSignal;
readonly subscriptions: {
add<T extends Disposable>(value: T): T;
};

关联类型: Disposable.

源码

readonly background?: PluginBackground;
readonly fs?: PluginFileSystem;
readonly filemeta?: PluginFileMeta;
readonly storage?: PluginStorage;
已废弃
readonly network?: PluginNetwork;
readonly settings?: Pick<PluginSettings, "get">;
readonly connections?: PluginConnections;
readonly ui: HostUI;

关联类型: PluginBackground, PluginFileSystem, PluginFileMeta, PluginStorage, PluginNetwork, PluginSettings, PluginConnections, HostUI.

源码

interface CommonContext extends Lifetime { /* members below */ }
readonly i18n: PluginI18n;
readonly capabilities: CommonCapabilities;

关联类型: PluginI18n, CommonCapabilities, Lifetime.

源码

readonly locale: string;
t(key: string, values?: Record<string, string | number>): string;
参数 类型 必填
key string 是
values Record<string, string &#124; number> 否

返回值: string.

onDidChangeLocale(listener: (event: {
locale: string;
}) => void): Disposable;
参数 类型 必填
listener (event: { locale: string; }) => void 是

返回值: Disposable.

关联类型: Disposable.

源码

interface ViewCapabilities extends CommonCapabilities { /* members below */ }
readonly explorer?: ExplorerContext;
readonly document?: TextDocument;
readonly eidos?: EidosCapabilities;

关联类型: ExplorerContext, TextDocument, EidosCapabilities, CommonCapabilities.

源码

interface ViewContext extends CommonContext { /* members below */ }
readonly presentation?: {
mode: "standalone" | "embedded";
};
readonly binding: ViewBinding;
readonly capabilities: ViewCapabilities;

关联类型: ViewBinding, ViewCapabilities, CommonContext.

源码

export type TextFileViewContext = ViewContext & {
readonly binding: Extract<ViewBinding, {
kind: "file";
}>;
readonly capabilities: ViewCapabilities & {
readonly document: TextDocument;
};
};

关联类型: ViewContext, ViewBinding, ViewCapabilities, TextDocument.

源码

export type TableFileViewContext = ViewContext & {
readonly binding: Extract<ViewBinding, {
kind: "file";
}>;
readonly capabilities: ViewCapabilities & {
readonly eidos: EidosCapabilities & {
readonly table: EidosTable;
};
};
};

关联类型: ViewContext, ViewBinding, ViewCapabilities, EidosCapabilities, EidosTable.

源码

interface ActionContext extends CommonContext { /* members below */ }
readonly binding: ActionBinding;
readonly capabilities: CommonCapabilities & {
readonly document?: TextDocument;
readonly settings: PluginSettings;
};

关联类型: ActionBinding, CommonCapabilities, TextDocument, PluginSettings, CommonContext.

源码

interface ExtensionContext extends Lifetime { /* members below */ }
readonly i18n: PluginI18n;
readonly capabilities: {
readonly hooks: {
register(id: string, handler: FileHookHandler): Disposable;
};
readonly formatters: {
register(id: string, provider: FormatterProvider): Disposable;
};
readonly actions: {
registerTableProvider(id: string, provider: TableActionProvider): Disposable;
register(id: string, handler: (ctx: ActionContext) => void | Promise<void>): Disposable;
};
};

关联类型: PluginI18n, FileHookHandler, Disposable, FormatterProvider, TableActionProvider, ActionContext, Lifetime.

源码

readonly i18n: PluginI18n;
readonly signal: AbortSignal;
readonly capabilities: TableActionCapabilities;

关联类型: PluginI18n, TableActionCapabilities.

源码

export type Mount = (ctx: ViewContext, root: HTMLElement) => void | Disposable | Promise<void | Disposable>;

关联类型: ViewContext, Disposable.

源码

export type Activate = (ctx: ExtensionContext) => void | Disposable | Promise<void | Disposable>;

关联类型: ExtensionContext, Disposable.