用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/csharpfritz/SquadUI --skill vscode-optional-service-injection命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
正在显示 SKILL.md
基于 SOC 职业分类
| name | vscode-optional-service-injection |
| description | Pattern for VS Code tree views that consume optional services with graceful degradation |
| domain | vscode-extensions |
| confidence | medium |
| source | earned |
VS Code tree views often need data from services that may not be available at activation time (e.g., API services requiring auth tokens, services built by other team members in parallel). The tree should work without the service and enhance when it becomes available.
Instead of requiring the service in the constructor, expose a setService() method. This allows the extension to wire the service when available without blocking tree view creation.
export class MyTreeProvider implements vscode.TreeDataProvider<MyItem> {
private optionalService: IMyService | undefined;
constructor(private dataProvider: DataProvider) {}
setService(service: IMyService): void {
this.optionalService = service;
}
}
When fetching optional data, check for service existence first, then wrap the call in try/catch to handle runtime failures (network errors, auth issues, etc.).
private async getOptionalItems(): Promise<MyItem[]> {
if (!this.optionalService) {
return [];
}
try {
const data = await this.optionalService.getData();
return data.map(d => this.createItem(d));
} catch {
return [];
}
}
Define the contract in models (not in the service file) so consumers can compile without the concrete implementation existing yet.
// src/models/index.ts
export interface IMyService {
getData(root: string): Promise<Map<string, MyData[]>>;
}
getChildren() — VS Code shows ugly error UI