extension.js 1.3 KB

12345678910111213141516171819202122232425262728
  1. // E2E 扩展 fixture(docs/plugins/extension-host.md §16.6):纯 JS,不需要构建。
  2. // 命令 search 是 composer.mention 条目的 target:参数 { query },返回候选项数组。
  3. // query 越短返回越慢(每少一个字多等 1.5 秒,4 个字以上立即返回):快速输入时,旧查询的结果晚于新查询到达,
  4. // E2E 用它验证 Renderer 只采用最新一次。运行时证据写进日志(E2E_MENTION_*),不记候选内容以外的东西。
  5. const SLOW_STEP_MS = 1500;
  6. const FAST_LENGTH = 4;
  7. export function activate(ctx) {
  8. ctx.commands.register("search", async ({ scope, args }) => {
  9. const query = String(args?.query ?? "");
  10. const delay = Math.max(0, FAST_LENGTH - query.length) * SLOW_STEP_MS;
  11. ctx.log.info(
  12. `E2E_MENTION_QUERY q=${JSON.stringify(query)} scope=${scope.kind}:${scope.sessionId ?? ""} delay=${delay}`,
  13. );
  14. await new Promise((resolve) => setTimeout(resolve, delay));
  15. ctx.log.info(`E2E_MENTION_DONE q=${JSON.stringify(query)}`);
  16. const tag = query || "all";
  17. return [1, 2, 3].map((n) => ({
  18. id: `${tag}-${n}`,
  19. label: `E2E ${tag} #${n}`,
  20. description: `Candidate ${n} for "${query}"`,
  21. icon: "file-text",
  22. insertText: `E2E_MENTION_INSERT[${tag}#${n}]`,
  23. }));
  24. });
  25. }
  26. export function deactivate() {}