extension.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. // E2E 扩展 fixture(docs/plugins/extension-host.md §16.4、§16.5):纯 JS,不需要构建。
  2. // - 视图 nav:nav.primary 的 view 条目打开它。
  3. // - 视图 file:file.viewer 为 .e2eview 打开它,实例带 view.input = { kind: "file", path, workspace }。
  4. // 两个视图共用一个页面;页面调工具 describe 读实例的 viewId、作用域与 input,写进 body 的 data-*。
  5. // 运行时证据写进日志(E2E_ENTRY_*);每次激活把扩展进程 pid 写进状态文件,E2E 用它杀进程。
  6. import { writeFile } from "node:fs/promises";
  7. import { join } from "node:path";
  8. export async function activate(ctx) {
  9. const track = (view) => {
  10. ctx.log.info(
  11. `E2E_ENTRY_VIEW_OPEN view=${view.viewId} instance=${view.id} scope=${view.scope.kind} input=${JSON.stringify(view.input ?? null)}`,
  12. );
  13. };
  14. for (const viewId of ["nav", "file"]) {
  15. ctx.views.register(viewId, {
  16. entry: "./view.html",
  17. onDidOpen: track,
  18. tools: {
  19. describe: {
  20. description: "Describe this view instance",
  21. inputSchema: { type: "object", properties: {} },
  22. run: (_input, call) => ({
  23. viewId: call.view.viewId,
  24. instance: call.view.id,
  25. scope: call.view.scope.kind,
  26. input: call.view.input ?? null,
  27. }),
  28. },
  29. },
  30. });
  31. }
  32. await writeFile(
  33. join(ctx.extension.path, "..", "e2e-ext-entries-state.json"),
  34. JSON.stringify({ pid: process.pid, activatedAt: Date.now() }),
  35. );
  36. }
  37. export function deactivate() {}