дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-12-04 01:01:17 +02:00
Порівняти коміти
9
Коміти
| Автор | SHA1 | Дата | |
|---|---|---|---|
|
|
e5edba1986 | ||
|
|
98da80b2b3 | ||
|
|
5c2e7ff92a | ||
|
|
e86a853048 | ||
|
|
fd8f0eb99c | ||
|
|
121e1fa535 | ||
|
|
5859cf9f5b | ||
|
|
21b187f2d5 | ||
|
|
7febc5270a |
No files matched your search
@@ -155,6 +155,8 @@ When a project loads and unloads:
|
||||
|
||||
**Open now** lists the loaded projects, each with what it is doing (answering a request, kept open by a run, or how long it has been idle and when it unloads) and an **Unload** button. Unloading does not wait for **Apply**. The project loads again on the next tool call that names it, if the setting still serves it.
|
||||
|
||||
While any project is loaded, the **Background Projects** item in the status bar (a layers icon and the count) opens the same list. Each row has the **Open in New Window** and **Unload** icon buttons, and below the list are **Unload All** and **MCP Server Settings…**.
|
||||
|
||||
What trust decides: a trusted project works as one open in a window, with its language servers and the tools that write. A listed folder you have not trusted opens in Restricted Mode and gets only the read-only tools.
|
||||
|
||||
A background project has no window, so some tools differ:
|
||||
|
||||
@@ -154,6 +154,8 @@ stdio 配置大致如下(路径以你机器上的为准):
|
||||
|
||||
**当前已打开** 列出已加载的项目,每个项目显示它正在做什么(正在处理请求、因某个运行保持打开,或已空闲多久以及何时卸载),并带有 **卸载** 按钮。卸载不必等到 **应用**。如果设置仍然提供该项目,下一次指向它的工具调用会再次加载它。
|
||||
|
||||
只要有项目处于加载状态,状态栏中的 **后台项目**(层叠图标和数量)就会打开同样的列表。每一行有 **在新窗口中打开** 和 **卸载** 两个图标按钮,列表下方是 **全部卸载** 和 **MCP 服务器设置…**。
|
||||
|
||||
信任决定什么:受信任的项目与在窗口中打开的项目一样,可以使用语言服务器和会写入的工具。你没有信任的列出文件夹会以受限模式打开,只开放只读工具。
|
||||
|
||||
后台项目没有窗口,所以有些工具不同:
|
||||
|
||||
@@ -65,6 +65,7 @@ test("completion lists the server's items and inserts the chosen one", async ({
|
||||
const popup = page.locator(".cm-tooltip-autocomplete");
|
||||
await expect(popup.getByText("total", { exact: true })).toBeVisible();
|
||||
await expect(popup.getByText("toDto", { exact: true })).toBeVisible();
|
||||
expect((await popup.boundingBox())!.width).toBeLessThan(360);
|
||||
const field = popup.locator("li").filter({ has: page.locator(".cm-completionLabel", { hasText: /^total$/ }) });
|
||||
await expect(field.locator(".cm-completionDetail")).toHaveCount(0);
|
||||
await expect(field.locator(".cm-lsp-type")).toHaveText("BigDecimal");
|
||||
@@ -83,6 +84,17 @@ test("completion lists the server's items and inserts the chosen one", async ({
|
||||
const label = await method.locator(".cm-completionLabel").boundingBox();
|
||||
// Subpixel rounding differs per platform/font; a mis-set inset is a whole icon column off.
|
||||
expect(Math.abs(label!.x - wordStart)).toBeLessThanOrEqual(2);
|
||||
const zoomedSize = await editor.locator(".cm-content").evaluate(async (content) => {
|
||||
const viewModule = "/node_modules/.vite/deps/@codemirror_view.js";
|
||||
const prefsModule = "/src/editor/core/cm/prefs.ts";
|
||||
const { EditorView } = await import(/* @vite-ignore */ viewModule);
|
||||
const { stepFontZoom } = await import(/* @vite-ignore */ prefsModule);
|
||||
const fontSize = Number.parseFloat(getComputedStyle(content).fontSize);
|
||||
stepFontZoom(EditorView.findFromDOM(content as HTMLElement)!, 6);
|
||||
return `${fontSize + 6}px`;
|
||||
});
|
||||
await expect(editor.locator(".cm-content")).toHaveCSS("font-size", zoomedSize);
|
||||
await expect(method.locator(".cm-completionLabel")).toHaveCSS("font-size", zoomedSize);
|
||||
await page.keyboard.type("toD");
|
||||
await expect(popup.getByText("total", { exact: true })).toBeHidden();
|
||||
// Refreshing the results rebuilds the list; the hint bar must stay below it, not jump to the top.
|
||||
@@ -98,6 +110,76 @@ test("completion lists the server's items and inserts the chosen one", async ({
|
||||
expect((await ipcCalls(page, "lsp_completion")).length).toBeGreaterThan(0);
|
||||
});
|
||||
|
||||
test("long completion signatures fit the editor when the workbench is narrowed", async ({ workbench: page }) => {
|
||||
const editor = await openSample(page);
|
||||
const label = "transformOrder" + "AcrossParticipatingRegions".repeat(5);
|
||||
await page.evaluate((label) => {
|
||||
const item: CompletionItem = {
|
||||
label,
|
||||
labelDetail: "(order: Order, options: TransformationOptions)",
|
||||
labelDescription: "Promise<TransformationResult>",
|
||||
detail: `${label}(order: Order, options: TransformationOptions): Promise<TransformationResult>`,
|
||||
kind: "method",
|
||||
documentation: { kind: "markdown", value: "Transforms the order." },
|
||||
sortText: null,
|
||||
filterText: null,
|
||||
preselect: true,
|
||||
deprecated: false,
|
||||
insertText: `${label}()`,
|
||||
isSnippet: false,
|
||||
replaceRange: null,
|
||||
replaceRangeTab: null,
|
||||
additionalEdits: [],
|
||||
commitCharacters: [],
|
||||
command: null,
|
||||
data: null,
|
||||
server: 1,
|
||||
};
|
||||
window.__ipc.handlers.lsp_completion = () => ({ isIncomplete: false, items: [item] });
|
||||
}, label);
|
||||
await editor.locator(".cm-line", { hasText: "return order.toDto()" }).click();
|
||||
await page.keyboard.press("End");
|
||||
await page.keyboard.press("Enter");
|
||||
await page.keyboard.type("order.");
|
||||
await page.keyboard.press("Control+Space");
|
||||
|
||||
const popup = page.locator(".cm-tooltip-autocomplete");
|
||||
const option = popup.getByRole("option").filter({
|
||||
has: page.locator(".cm-completionLabel", { hasText: label }),
|
||||
});
|
||||
await expect(option.locator(".cm-completionLabel")).toHaveText(label);
|
||||
await page.setViewportSize({ width: 580, height: 900 });
|
||||
const bounds = (await editor.boundingBox())!;
|
||||
await expect
|
||||
.poll(async () => {
|
||||
const box = (await popup.boundingBox())!;
|
||||
return Math.max(bounds.x - box.x, box.x + box.width - (bounds.x + bounds.width));
|
||||
})
|
||||
.toBeLessThanOrEqual(2);
|
||||
const geometry = await option.evaluate((row) => {
|
||||
const label = row.querySelector<HTMLElement>(".cm-completionLabel")!;
|
||||
const type = row.querySelector<HTMLElement>(".cm-lsp-type")!;
|
||||
return {
|
||||
nameTruncated: label.scrollWidth > label.clientWidth,
|
||||
nameWidth: label.clientWidth,
|
||||
typeWidth: type.clientWidth,
|
||||
typeOverflow: type.getBoundingClientRect().right - row.getBoundingClientRect().right,
|
||||
};
|
||||
});
|
||||
expect(geometry.nameTruncated).toBe(true);
|
||||
expect(geometry.nameWidth).toBeGreaterThan(40);
|
||||
expect(geometry.typeWidth).toBeGreaterThan(16);
|
||||
expect(geometry.typeOverflow).toBeLessThanOrEqual(1);
|
||||
|
||||
await page.keyboard.press("F1");
|
||||
await expect(popup.locator(".cm-completionInfo")).toContainText(
|
||||
`${label}(order: Order, options: TransformationOptions)`,
|
||||
);
|
||||
await page.keyboard.press("Enter");
|
||||
await expect(popup).toBeHidden();
|
||||
await expect(editor.locator(".cm-activeLine")).toContainText(`order.${label}()`);
|
||||
});
|
||||
|
||||
test("documentation shows beside the lookup instead of being clipped by it", async ({ workbench: page }, info) => {
|
||||
const editor = await openSample(page);
|
||||
await page.evaluate(async () => {
|
||||
@@ -345,6 +427,70 @@ test("Find Usages from the editor context menu lists every usage by file and ope
|
||||
).toHaveAttribute("aria-selected", "true");
|
||||
});
|
||||
|
||||
test("usage locations and preview stay readable as the available space changes", async ({ workbench: page }) => {
|
||||
await page.setViewportSize({ width: 1040, height: 760 });
|
||||
const editor = await openSample(page);
|
||||
await page.evaluate(
|
||||
({ file, other }) => {
|
||||
const locations = [
|
||||
{ path: file, range: { start: { line: 16, col: 8 }, end: { line: 16, col: 15 } } },
|
||||
{ path: file, range: { start: { line: 20, col: 27 }, end: { line: 20, col: 34 } } },
|
||||
{ path: other, range: { start: { line: 0, col: 0 }, end: { line: 0, col: 7 } } },
|
||||
];
|
||||
window.__ipc.handlers.lsp_references = () => ({
|
||||
locations,
|
||||
classified: [{ location: locations[2], kind: "code", text: "service.submit(order)" }],
|
||||
incomplete: null,
|
||||
librariesSkipped: true,
|
||||
});
|
||||
},
|
||||
{ file: FILE, other: `${ROOT}/domain/checkout/processing/calculations/PaymentProcessingService.kt` },
|
||||
);
|
||||
await caretAt(editor, page, "val order: Order", "service");
|
||||
await page.keyboard.press("Meta+Alt+F7");
|
||||
const popup = page.getByRole("dialog", { name: "Usages" });
|
||||
const scope = popup.getByRole("button", { name: "Scope" });
|
||||
const openWindow = popup.getByRole("button", { name: /^Open in Find Window/ });
|
||||
await expect(popup.getByTestId("usage-row")).toHaveCount(3);
|
||||
await popup.getByRole("button", { name: "Show Preview" }).click();
|
||||
const code = popup.getByRole("region", { name: "Preview" });
|
||||
await expect(code.locator(".cm-content")).toContainText("service.find(status");
|
||||
|
||||
await page.setViewportSize({ width: 480, height: 470 });
|
||||
const within = async (child: Locator, parent: Locator) => {
|
||||
const [c, p] = await Promise.all([child.boundingBox(), parent.boundingBox()]);
|
||||
return (
|
||||
!!c &&
|
||||
!!p &&
|
||||
c.x >= p.x - 1 &&
|
||||
c.y >= p.y - 1 &&
|
||||
c.x + c.width <= p.x + p.width + 1 &&
|
||||
c.y + c.height <= p.y + p.height + 1
|
||||
);
|
||||
};
|
||||
await expect.poll(() => within(scope, popup)).toBe(true);
|
||||
await expect.poll(() => within(openWindow, popup)).toBe(true);
|
||||
await expect.poll(() => within(code, popup)).toBe(true);
|
||||
const results = popup.getByRole("listbox", { name: "Usages" });
|
||||
await expect.poll(() => within(popup.getByTestId("usage-row").last(), results)).toBe(true);
|
||||
const firstRow = popup.getByTestId("usage-row").first();
|
||||
const file = firstRow.getByText("build.gradle.kts", { exact: true });
|
||||
await expect(file).toBeVisible();
|
||||
const [filename, snippet] = await Promise.all([file.boundingBox(), firstRow.locator("mark").boundingBox()]);
|
||||
expect(filename!.x + filename!.width).toBeLessThan(snippet!.x);
|
||||
await openWindow.click();
|
||||
|
||||
const tree = page.getByRole("tree", { name: "Usages" });
|
||||
const target = tree.getByRole("treeitem", { name: /^17 service\.find\(status/ });
|
||||
await target.click();
|
||||
const preview = page.getByRole("region", { name: "Preview" });
|
||||
await expect(preview).toContainText("service.find(status");
|
||||
await expect.poll(async () => (await preview.boundingBox())!.y > (await tree.boundingBox())!.y).toBe(true);
|
||||
await page.setViewportSize({ width: 1040, height: 760 });
|
||||
await expect.poll(async () => (await preview.boundingBox())!.x > (await tree.boundingBox())!.x).toBe(true);
|
||||
await expect(preview).toContainText("service.find(status");
|
||||
});
|
||||
|
||||
test("⇧F6 renames in place and sends the server's edit to be applied", async ({ workbench: page }) => {
|
||||
const editor = await openSample(page);
|
||||
await page.evaluate(
|
||||
@@ -416,6 +562,85 @@ test("indexed single-file rename previews all anchors and applies only after con
|
||||
expect(apply.edit).toMatchObject({ preconditions: [{ path: FILE, hash: "indexed-snapshot" }] });
|
||||
});
|
||||
|
||||
test("intention previews fit narrow windows and wrap long code lines", async ({ workbench: page }) => {
|
||||
await page.setViewportSize({ width: 1600, height: 900 });
|
||||
const editor = await openSample(page);
|
||||
await page.evaluate(async () => {
|
||||
const path = "/src/platform/project.ts";
|
||||
const { useProject } = await import(/* @vite-ignore */ path);
|
||||
const { settings } = useProject.getState();
|
||||
useProject.setState({ settings: { ...settings, editor: { ...settings?.editor, fontSize: 16 } } });
|
||||
});
|
||||
await expect(editor.locator(".cm-content")).toHaveCSS("font-size", "16px");
|
||||
const replacement = "com.acme.orders." + "SharedDevelopmentOrderModel".repeat(6);
|
||||
await page.evaluate(
|
||||
({ file, replacement, edit }) => {
|
||||
window.__ipc.handlers.lsp_code_actions = () => [
|
||||
{
|
||||
title: "Replace Order with the fully qualified shared development order model",
|
||||
kind: "quickfix",
|
||||
isPreferred: true,
|
||||
disabledReason: null,
|
||||
edit: { files: [{ kind: "edit", path: file, edits: [{ range: edit, new_text: replacement }] }] },
|
||||
command: null,
|
||||
data: null,
|
||||
server: 1,
|
||||
},
|
||||
...Array.from({ length: 11 }, (_, i) => ({
|
||||
title: `Create alternative Order model ${i + 1}`,
|
||||
kind: "quickfix",
|
||||
isPreferred: false,
|
||||
disabledReason: null,
|
||||
edit: null,
|
||||
command: null,
|
||||
data: null,
|
||||
server: 1,
|
||||
})),
|
||||
];
|
||||
window.__ipc.handlers.lsp_execute_code_action = () => [];
|
||||
},
|
||||
{ file: FILE, replacement, edit: range(20, 19, 24) },
|
||||
);
|
||||
await caretAt(editor, page, "val order: Order", "Order ");
|
||||
await page.keyboard.press("Alt+Enter");
|
||||
const popup = page.getByRole("dialog", { name: "Intentions", exact: true });
|
||||
const options = popup.getByRole("listbox", { name: "Intentions" });
|
||||
const preview = popup.locator('[aria-label="Preview"]');
|
||||
await expect(preview.locator("pre")).toContainText(replacement);
|
||||
const wide = (await options.boundingBox())!;
|
||||
const widePreview = (await preview.boundingBox())!;
|
||||
expect(widePreview.x).toBeGreaterThanOrEqual(wide.x + wide.width - 1);
|
||||
|
||||
await page.setViewportSize({ width: 1050, height: 900 });
|
||||
await expect
|
||||
.poll(async () => {
|
||||
const list = (await options.boundingBox())!;
|
||||
const code = (await preview.boundingBox())!;
|
||||
return code.x + code.width - list.x;
|
||||
})
|
||||
.toBeLessThanOrEqual(1);
|
||||
|
||||
await page.setViewportSize({ width: 520, height: 540 });
|
||||
await expect
|
||||
.poll(async () => {
|
||||
const menu = (await popup.boundingBox())!;
|
||||
const list = (await options.boundingBox())!;
|
||||
const code = (await preview.boundingBox())!;
|
||||
return {
|
||||
popupFits: menu.x >= 0 && menu.y >= 0 && menu.x + menu.width <= 521 && menu.y + menu.height <= 541,
|
||||
previewBelow: code.y >= list.y + list.height - 1,
|
||||
previewFits: code.x >= menu.x && code.x + code.width <= menu.x + menu.width + 1,
|
||||
};
|
||||
})
|
||||
.toEqual({ popupFits: true, previewBelow: true, previewFits: true });
|
||||
expect(await preview.evaluate((el) => el.scrollWidth - el.clientWidth)).toBeLessThanOrEqual(1);
|
||||
await expect(preview.locator("pre")).toHaveCSS("font-size", "16px");
|
||||
await expect(options).toBeFocused();
|
||||
await page.keyboard.press("Enter");
|
||||
await expect(popup).toBeHidden();
|
||||
await expect.poll(() => ipcCalls(page, "lsp_execute_code_action")).toHaveLength(1);
|
||||
});
|
||||
|
||||
test("diagnostics underline the range and ⌥⏎ applies the preferred quick fix", async ({ workbench: page }) => {
|
||||
const editor = await openSample(page);
|
||||
await page.evaluate(
|
||||
|
||||
@@ -133,6 +133,64 @@ test("breadcrumbs follow the caret into the symbol under it", async ({ workbench
|
||||
await expect(bar).toBeHidden();
|
||||
});
|
||||
|
||||
test("narrow breadcrumb bars keep the current symbol visible and allow opening earlier crumbs", async ({
|
||||
workbench: page,
|
||||
}) => {
|
||||
const editor = await openFromTree(page, "build.gradle.kts");
|
||||
const path = page.getByRole("navigation", { name: "Breadcrumbs", exact: true });
|
||||
const code = page.getByRole("navigation", { name: "Code breadcrumbs" });
|
||||
await editor.locator(".cm-line", { hasText: "service.find(status" }).click();
|
||||
await expect(code).toContainText("list()");
|
||||
|
||||
await page.evaluate(async () => {
|
||||
const documentModule = "/src/editor/core/model/document.ts";
|
||||
const editorModule = "/src/editor/core/controller.ts";
|
||||
const projectModule = "/src/platform/project.ts";
|
||||
const schemaModule = "/src/features/settings/model/schema.ts";
|
||||
const [{ useOutline }, { useEditorStatus }, { useProject }, { DEFAULT_SETTINGS }] = await Promise.all([
|
||||
import(/* @vite-ignore */ documentModule),
|
||||
import(/* @vite-ignore */ editorModule),
|
||||
import(/* @vite-ignore */ projectModule),
|
||||
import(/* @vite-ignore */ schemaModule),
|
||||
]);
|
||||
const base = useProject.getState().settings ?? DEFAULT_SETTINGS;
|
||||
useProject.setState({ settings: { ...base, editor: { ...base.editor, fontSize: 17 } } });
|
||||
const activePath = useEditorStatus.getState().status.path;
|
||||
let outline = useOutline.getState()[activePath];
|
||||
for (const name of ["OrderProcessingStrategies", "SalesApplicationRouting", "CheckoutWorkspaceConfiguration"]) {
|
||||
outline = [{ ...outline[0], name, detail: null, children: outline }];
|
||||
}
|
||||
useOutline.setState({ [activePath]: outline });
|
||||
});
|
||||
|
||||
await page.setViewportSize({ width: 620, height: 620 });
|
||||
const fullyInBar = (bar: typeof path, label: string) =>
|
||||
bar.evaluate((nav, text) => {
|
||||
const crumb = [...nav.querySelectorAll("button")].find((button) => button.textContent === text);
|
||||
if (!crumb) return false;
|
||||
const { left, right } = nav.getBoundingClientRect();
|
||||
const rect = crumb.getBoundingClientRect();
|
||||
return rect.width > 0 && rect.left >= left - 1 && rect.right <= right + 1;
|
||||
}, label);
|
||||
for (const bar of [path, code]) {
|
||||
await expect.poll(() => fullyInBar(bar, "list()")).toBe(true);
|
||||
await expect(bar.locator('[aria-current="location"]')).toHaveText("list()");
|
||||
}
|
||||
await expect(code.locator('[aria-current="location"]')).toHaveCSS("font-size", "17px");
|
||||
await code.hover();
|
||||
await page.mouse.wheel(0, -1200);
|
||||
await expect.poll(() => fullyInBar(code, "CheckoutWorkspaceConfiguration")).toBe(true);
|
||||
|
||||
const current = path.locator('[aria-current="location"]');
|
||||
await current.focus();
|
||||
await current.press("Home");
|
||||
const project = path.getByRole("button", { name: /acme-api/ }).first();
|
||||
await expect(project).toBeFocused();
|
||||
await expect.poll(() => fullyInBar(path, "acme-api")).toBe(true);
|
||||
await project.press("ArrowDown");
|
||||
await expect(page.getByRole("listbox", { name: "acme-api" })).toBeVisible();
|
||||
});
|
||||
|
||||
/** What the in-memory backend has saved for `path`. */
|
||||
const saved = (page: Page, path: string) =>
|
||||
page.evaluate(async (path) => {
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
import type { Page } from "@playwright/test";
|
||||
import { expect, openFromTree, stubDesktop, test } from "./fixtures";
|
||||
|
||||
async function quickDocumentation(page: Page, markdown: string) {
|
||||
const editor = await openFromTree(page, "build.gradle.kts");
|
||||
await stubDesktop(page);
|
||||
await page.evaluate((value) => {
|
||||
window.__ipc.handlers.lsp_hover = () => ({ contents: { kind: "markdown", value }, range: null });
|
||||
}, markdown);
|
||||
const line = editor.locator(".cm-line", { hasText: "return order.toDto()" });
|
||||
await line.click();
|
||||
await page.keyboard.press("End");
|
||||
await page.keyboard.press("ArrowLeft");
|
||||
await page.keyboard.press("ArrowLeft");
|
||||
await page.keyboard.press("ArrowLeft");
|
||||
await page.keyboard.press("F1");
|
||||
const popup = page.getByRole("dialog", { name: "Documentation", exact: true });
|
||||
await expect(popup.locator(".cm-lsp-markdown")).toBeVisible();
|
||||
return popup;
|
||||
}
|
||||
|
||||
test("short quick documentation uses a readable width and a compact corner of actions", async ({ workbench: page }) => {
|
||||
const popup = await quickDocumentation(page, "Returns the total.");
|
||||
const back = popup.getByRole("button", { name: "Back", exact: true });
|
||||
const dock = popup.getByRole("button", { name: "Show in Documentation Tool Window" });
|
||||
await expect(dock).toBeVisible();
|
||||
const bounds = (await popup.boundingBox())!;
|
||||
expect(bounds.width).toBeGreaterThanOrEqual(298);
|
||||
expect(bounds.width).toBeLessThan(320);
|
||||
const backBounds = (await back.boundingBox())!;
|
||||
const dockBounds = (await dock.boundingBox())!;
|
||||
expect(backBounds.x).toBeGreaterThan(bounds.x + bounds.width / 2);
|
||||
expect(bounds.x + bounds.width - dockBounds.x - dockBounds.width).toBeLessThan(16);
|
||||
await expect(popup.locator(".cm-lsp-markdown")).toHaveCSS("font-size", "13px");
|
||||
await page.keyboard.press("Escape");
|
||||
await expect(popup).toBeHidden();
|
||||
});
|
||||
|
||||
test("long quick documentation scrolls with its actions in view", async ({ workbench: page }) => {
|
||||
const signature = "fun calculateTotal(order: Order, options: ExtendedPricingOptions): CalculationResult";
|
||||
const markdown = [
|
||||
`\`\`\`kotlin\n${signature}\n\`\`\``,
|
||||
...Array.from({ length: 22 }, (_, i) => {
|
||||
return `Section ${i + 1}. Explains the applicable pricing rules, shipping restrictions and currency options.`;
|
||||
}),
|
||||
"End of pricing documentation.",
|
||||
].join("\n\n");
|
||||
const popup = await quickDocumentation(page, markdown);
|
||||
const dock = popup.getByRole("button", { name: "Show in Documentation Tool Window" });
|
||||
await expect(dock).toBeVisible();
|
||||
expect((await popup.boundingBox())!.width).toBeLessThan(508);
|
||||
await page.setViewportSize({ width: 430, height: 500 });
|
||||
await expect
|
||||
.poll(async () => {
|
||||
const box = (await popup.boundingBox())!;
|
||||
return Math.max(-box.x, -box.y, box.x + box.width - 430, box.y + box.height - 500);
|
||||
})
|
||||
.toBeLessThanOrEqual(1);
|
||||
const body = popup.locator(".cm-lsp-markdown").locator("..");
|
||||
const last = popup.getByText("End of pricing documentation.");
|
||||
const dockBefore = (await dock.boundingBox())!;
|
||||
await expect(body.locator("pre")).toContainText(signature);
|
||||
const scroll = await body.evaluate((node) => {
|
||||
node.scrollTop = node.scrollHeight;
|
||||
return { top: node.scrollTop, horizontalOverflow: node.scrollWidth - node.clientWidth };
|
||||
});
|
||||
expect(scroll.top).toBeGreaterThan(0);
|
||||
expect(scroll.horizontalOverflow).toBeLessThanOrEqual(1);
|
||||
const lastBounds = (await last.boundingBox())!;
|
||||
expect(lastBounds.y + lastBounds.height).toBeLessThanOrEqual(dockBefore.y + 1);
|
||||
expect(await dock.boundingBox()).toEqual(dockBefore);
|
||||
await expect(dock).toBeInViewport();
|
||||
});
|
||||
@@ -1,8 +1,8 @@
|
||||
import type { Page } from "@playwright/test";
|
||||
import { expect, test } from "./fixtures";
|
||||
|
||||
async function openConfigurations(page: Page) {
|
||||
await page.evaluate(async () => {
|
||||
async function openConfigurations(page: Page, target?: string) {
|
||||
await page.evaluate(async (target) => {
|
||||
const path = "/src/features/run/store.ts";
|
||||
const { useRun } = await import(/* @vite-ignore */ path);
|
||||
const base = {
|
||||
@@ -21,6 +21,7 @@ async function openConfigurations(page: Page) {
|
||||
...base,
|
||||
id: "layout:app",
|
||||
name: "Payments development server",
|
||||
target,
|
||||
beforeLaunch: [{ kind: "run", target: "layout:prepare" }],
|
||||
},
|
||||
{ ...base, id: "layout:prepare", name: "Prepare generated sources for the payments development server" },
|
||||
@@ -29,10 +30,31 @@ async function openConfigurations(page: Page) {
|
||||
loaded: true,
|
||||
editorOpen: true,
|
||||
});
|
||||
});
|
||||
}, target);
|
||||
await expect(page.getByRole("dialog", { name: "Run/Debug Configurations", exact: true })).toBeVisible();
|
||||
}
|
||||
|
||||
test("long run target names leave room for configuration names in the sidebar", async ({ workbench: page }) => {
|
||||
const target = "payments-development-shared-staging-runner-west";
|
||||
await openConfigurations(page, target);
|
||||
const dialog = page.getByRole("dialog", { name: "Run/Debug Configurations", exact: true });
|
||||
const tree = dialog.getByRole("tree", { name: "Run configurations", exact: true });
|
||||
const row = tree.getByRole("treeitem", { name: /^Payments development server/ });
|
||||
const name = row.getByText("Payments development server", { exact: true });
|
||||
const badge = row.getByText(`@ ${target}`, { exact: true });
|
||||
await expect(badge).toBeVisible();
|
||||
|
||||
for (const width of [1100, 520]) {
|
||||
await page.setViewportSize({ width, height: 820 });
|
||||
await expect.poll(async () => (await name.boundingBox())!.width).toBeGreaterThan(width === 1100 ? 80 : 50);
|
||||
await expect.poll(() => tree.evaluate((el) => el.scrollWidth - el.clientWidth)).toBeLessThanOrEqual(1);
|
||||
}
|
||||
|
||||
await expect(badge).toBeHidden();
|
||||
await expect(row).toHaveAttribute("title", new RegExp(`Payments development server @ ${target}`));
|
||||
await expect(dialog.getByRole("textbox", { name: "Name", exact: true })).toHaveValue("Payments development server");
|
||||
});
|
||||
|
||||
test("run configuration sidebar resizes with mouse and keyboard and remembers the layout", async ({
|
||||
workbench: page,
|
||||
}) => {
|
||||
|
||||
@@ -218,15 +218,44 @@
|
||||
min-width: 0;
|
||||
overflow: hidden;
|
||||
}
|
||||
.crumbButton {
|
||||
flex: none;
|
||||
max-width: 240px;
|
||||
gap: 5px;
|
||||
color: var(--fg);
|
||||
}
|
||||
.crumbButton:last-child {
|
||||
flex: 0 1 auto;
|
||||
.crumbStrip {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
min-width: 0;
|
||||
overflow-x: auto;
|
||||
overflow-y: hidden;
|
||||
scrollbar-width: none;
|
||||
}
|
||||
.crumbStrip::-webkit-scrollbar {
|
||||
display: none;
|
||||
}
|
||||
.crumbStrip:is([data-crumbs-before], [data-crumbs-after]) {
|
||||
--crumb-mask: linear-gradient(
|
||||
to right,
|
||||
var(--crumb-start, black),
|
||||
black var(--space-3),
|
||||
black calc(100% - var(--space-3)),
|
||||
var(--crumb-end, black)
|
||||
);
|
||||
-webkit-mask-image: var(--crumb-mask);
|
||||
mask-image: var(--crumb-mask);
|
||||
}
|
||||
.crumbStrip[data-crumbs-before] {
|
||||
--crumb-start: transparent;
|
||||
}
|
||||
.crumbStrip[data-crumbs-after] {
|
||||
--crumb-end: transparent;
|
||||
}
|
||||
.crumbStrip .crumbButton {
|
||||
flex: none;
|
||||
max-width: min(240px, 100%);
|
||||
margin: 0;
|
||||
padding: 0 var(--space-1);
|
||||
font: inherit;
|
||||
color: inherit;
|
||||
}
|
||||
.crumbStrip .crumbButton[aria-current="location"] {
|
||||
color: var(--fg);
|
||||
}
|
||||
.crumbIcon {
|
||||
flex: none;
|
||||
@@ -240,7 +269,6 @@
|
||||
.statusSep {
|
||||
flex: none;
|
||||
color: var(--fg-faint);
|
||||
margin: 0 2px;
|
||||
}
|
||||
.lock {
|
||||
display: inline-flex;
|
||||
@@ -339,13 +367,23 @@
|
||||
flex: none;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: var(--space-0-5);
|
||||
height: 26px;
|
||||
padding: 0 8px;
|
||||
height: max(24px, calc(1em + var(--space-2)));
|
||||
padding: 0 var(--space-2);
|
||||
overflow: hidden;
|
||||
background: var(--bg-editor, var(--bg-island));
|
||||
color: var(--fg-muted);
|
||||
font-size: var(--fs-small);
|
||||
font-family: var(--font-mono);
|
||||
font-size: var(--fs-code);
|
||||
}
|
||||
.codeCrumbs .crumbStrip {
|
||||
gap: var(--space-0-5);
|
||||
}
|
||||
.codeCrumbs .crumbButton {
|
||||
height: max(20px, calc(1em + var(--space-1)));
|
||||
max-width: 100%;
|
||||
}
|
||||
.codeCrumbs .crumbButton[aria-current="location"] {
|
||||
background: var(--bg-tree-selected-inactive);
|
||||
}
|
||||
.codeCrumbsTop {
|
||||
border-bottom: 1px solid var(--border-editor-tabs, var(--border));
|
||||
|
||||
@@ -1,15 +1,16 @@
|
||||
/** Status bar widgets of the active text editor (design footer). */
|
||||
import { Fragment, useRef, useState } from "react";
|
||||
import { Fragment, useLayoutEffect, useRef, useState, type ComponentPropsWithoutRef } from "react";
|
||||
import clsx from "clsx";
|
||||
import { useShallow } from "zustand/react/shallow";
|
||||
import { executeAction } from "@/platform/actions";
|
||||
import { shortcutLabel } from "@/platform/keymap";
|
||||
import { basename, dirname, projectFolder, relativePath, useProject } from "@/platform/project";
|
||||
import type { LineEnding, OutlineItem } from "@/platform/ipc";
|
||||
import { BarButton, Icon, Menu, badgeKind, fileIconName } from "@/ui";
|
||||
import { BarButton, Icon, Menu, badgeKind, fileIconName, revealHorizontally } from "@/ui";
|
||||
import { notifications, useProjectViewLead } from "@/workbench/contributions";
|
||||
import { useDistractionFree } from "@/workbench/distractionFree";
|
||||
import { ENCODING_CHOICES, useEditorPrefs } from "@/platform/editorSettings";
|
||||
import { BUNDLED_MONO_FAMILY, monoFontFamily } from "@/platform/fonts";
|
||||
import {
|
||||
gitRevisionOf,
|
||||
isUntitledUri,
|
||||
@@ -145,15 +146,39 @@ function pathCrumbs(project: { root: string; name: string } | null, path: string
|
||||
return segments;
|
||||
}
|
||||
|
||||
/** A row of crumbs; a segment with `nav` opens a popup of its children. */
|
||||
function CrumbNav({ segments, className, ariaLabel }: { segments: Crumb[]; className?: string; ariaLabel?: string }) {
|
||||
const [popup, setPopup] = useState<{ nav: NavSegment; anchor: HTMLElement } | null>(null);
|
||||
function updateBreadcrumbEdges(row: HTMLDivElement) {
|
||||
row.toggleAttribute("data-crumbs-before", row.scrollLeft > 1);
|
||||
row.toggleAttribute("data-crumbs-after", row.scrollLeft + row.clientWidth < row.scrollWidth - 1);
|
||||
}
|
||||
|
||||
function BreadcrumbStrip({
|
||||
trail,
|
||||
activateOnDown = false,
|
||||
children,
|
||||
...props
|
||||
}: ComponentPropsWithoutRef<"nav"> & { trail: string; activateOnDown?: boolean }) {
|
||||
const strip = useRef<HTMLDivElement>(null);
|
||||
useLayoutEffect(() => {
|
||||
const row = strip.current;
|
||||
if (!row) return;
|
||||
const revealCurrent = () => {
|
||||
const focused = document.activeElement;
|
||||
if (focused instanceof HTMLElement && row.contains(focused)) revealHorizontally(row, focused);
|
||||
else row.scrollLeft = row.scrollWidth;
|
||||
updateBreadcrumbEdges(row);
|
||||
};
|
||||
revealCurrent();
|
||||
if (typeof ResizeObserver === "undefined") return;
|
||||
const resize = new ResizeObserver(revealCurrent);
|
||||
resize.observe(row);
|
||||
return () => resize.disconnect();
|
||||
}, [trail]);
|
||||
return (
|
||||
<nav
|
||||
className={className}
|
||||
aria-label={ariaLabel}
|
||||
{...props}
|
||||
onKeyDown={(e) => {
|
||||
const buttons = [...e.currentTarget.querySelectorAll<HTMLButtonElement>("button")];
|
||||
if (e.altKey || e.ctrlKey || e.metaKey) return;
|
||||
const buttons = [...(strip.current?.querySelectorAll("button") ?? [])];
|
||||
const index = buttons.indexOf(e.target as HTMLButtonElement);
|
||||
if (index < 0) return;
|
||||
let next: number;
|
||||
@@ -161,7 +186,7 @@ function CrumbNav({ segments, className, ariaLabel }: { segments: Crumb[]; class
|
||||
else if (e.key === "ArrowRight") next = Math.min(buttons.length - 1, index + 1);
|
||||
else if (e.key === "Home") next = 0;
|
||||
else if (e.key === "End") next = buttons.length - 1;
|
||||
else if (e.key === "ArrowDown") {
|
||||
else if (e.key === "ArrowDown" && activateOnDown) {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
buttons[index]?.click();
|
||||
@@ -172,30 +197,64 @@ function CrumbNav({ segments, className, ariaLabel }: { segments: Crumb[]; class
|
||||
buttons[next]?.focus();
|
||||
}}
|
||||
>
|
||||
{segments.map((s, i) => (
|
||||
<Fragment key={i}>
|
||||
{i > 0 && <Icon name="chevron-right" size={12} className={styles.statusSep} />}
|
||||
<BarButton
|
||||
className={styles.crumbButton}
|
||||
tooltip={s.title}
|
||||
aria-haspopup={s.nav ? "listbox" : undefined}
|
||||
onClick={(e) => {
|
||||
const nav = s.nav;
|
||||
const anchor = e.currentTarget;
|
||||
if (nav) setPopup((p) => (p?.anchor === anchor ? null : { nav, anchor }));
|
||||
else s.run?.();
|
||||
}}
|
||||
>
|
||||
{s.icon && <Icon name={s.icon} size={16} className={styles.crumbIcon} />}
|
||||
<span className={styles.crumbLabel}>{s.label}</span>
|
||||
</BarButton>
|
||||
</Fragment>
|
||||
))}
|
||||
{popup && <NavChildrenPopup segment={popup.nav} anchor={popup.anchor} onClose={() => setPopup(null)} />}
|
||||
<div
|
||||
ref={strip}
|
||||
className={styles.crumbStrip}
|
||||
onScroll={(e) => updateBreadcrumbEdges(e.currentTarget)}
|
||||
onWheel={(e) => {
|
||||
if (e.shiftKey || e.ctrlKey || e.deltaX) return;
|
||||
const row = e.currentTarget;
|
||||
const scale = e.deltaMode === 1 ? 16 : e.deltaMode === 2 ? row.clientWidth : 1;
|
||||
row.scrollLeft += e.deltaY * scale;
|
||||
}}
|
||||
>
|
||||
{children}
|
||||
</div>
|
||||
</nav>
|
||||
);
|
||||
}
|
||||
|
||||
/** A row of crumbs; a segment with `nav` opens a popup of its children. */
|
||||
function CrumbNav({ segments, className }: { segments: Crumb[]; className?: string }) {
|
||||
const [popup, setPopup] = useState<{ nav: NavSegment; anchor: HTMLElement } | null>(null);
|
||||
return (
|
||||
<BreadcrumbStrip
|
||||
trail={segments.map((s) => s.title).join("\n")}
|
||||
activateOnDown
|
||||
className={className}
|
||||
aria-label={tx("Breadcrumbs")}
|
||||
>
|
||||
{segments.map((s, i) => {
|
||||
const current = i === segments.length - 1;
|
||||
const icon = s.nav?.kind === "dir" && !s.nav.root && !current ? undefined : s.icon;
|
||||
return (
|
||||
<Fragment key={i}>
|
||||
{i > 0 && <Icon name="chevron-right" size={12} className={styles.statusSep} />}
|
||||
<BarButton
|
||||
className={styles.crumbButton}
|
||||
tooltip={s.title}
|
||||
aria-current={current ? "location" : undefined}
|
||||
aria-haspopup={s.nav ? "listbox" : undefined}
|
||||
onClick={(e) => {
|
||||
const nav = s.nav;
|
||||
const anchor = e.currentTarget;
|
||||
if (nav) setPopup((p) => (p?.anchor === anchor ? null : { nav, anchor }));
|
||||
else s.run?.();
|
||||
}}
|
||||
>
|
||||
{icon && (
|
||||
<Icon name={icon} size={s.nav?.kind === "dir" && s.nav.root ? 12 : 16} className={styles.crumbIcon} />
|
||||
)}
|
||||
<span className={styles.crumbLabel}>{s.label}</span>
|
||||
</BarButton>
|
||||
</Fragment>
|
||||
);
|
||||
})}
|
||||
{popup && <NavChildrenPopup segment={popup.nav} anchor={popup.anchor} onClose={() => setPopup(null)} />}
|
||||
</BreadcrumbStrip>
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* IDEA new UI navigation bar (the top of the workbench, or the status bar
|
||||
* footer via `inStatusBar`): project › dirs › file › symbols, with icons;
|
||||
@@ -241,7 +300,7 @@ export function Breadcrumbs({ className, inStatusBar = false }: { className?: st
|
||||
segments.push(projectCrumb(project ?? currentProject));
|
||||
}
|
||||
if (!segments.length) return null;
|
||||
return <CrumbNav segments={segments} className={className ?? styles.status} ariaLabel={tx("Breadcrumbs")} />;
|
||||
return <CrumbNav segments={segments} className={className ?? styles.status} />;
|
||||
}
|
||||
|
||||
/** The status bar instance of the navigation bar; renders only for `statusBar`. */
|
||||
@@ -262,7 +321,8 @@ export function CodeBreadcrumbs({
|
||||
tabId: string;
|
||||
position: "top" | "bottom";
|
||||
}) {
|
||||
const prefs = useEditorPrefs().breadcrumbs;
|
||||
const { breadcrumbs: prefs, fallbackFont } = useEditorPrefs();
|
||||
const editorSettings = useProject((s) => s.settings?.editor);
|
||||
const language = useDocMeta((s) => s[path]?.language);
|
||||
const outline = useOutline((s) => s[path]);
|
||||
let chain = useCaretSymbols(path, outline);
|
||||
@@ -278,29 +338,35 @@ export function CodeBreadcrumbs({
|
||||
!chain.length
|
||||
)
|
||||
return null;
|
||||
const family = editorSettings?.fontFamily;
|
||||
const fontFamily =
|
||||
(family && family !== BUNDLED_MONO_FAMILY) || fallbackFont.trim()
|
||||
? monoFontFamily(family, fallbackFont, "var(--font-mono)")
|
||||
: undefined;
|
||||
const fontSize = editorSettings?.fontSize ?? undefined;
|
||||
return (
|
||||
<nav
|
||||
<BreadcrumbStrip
|
||||
trail={JSON.stringify([path, fontFamily, fontSize, ...chain.map((item) => item.name)])}
|
||||
style={{ fontFamily, fontSize }}
|
||||
className={clsx(styles.codeCrumbs, position === "top" ? styles.codeCrumbsTop : styles.codeCrumbsBottom)}
|
||||
aria-label={tx("Code breadcrumbs")}
|
||||
>
|
||||
{chain.map((item, i) => (
|
||||
<Fragment key={i}>
|
||||
{i > 0 && <Icon name="chevron-right" size={12} className={styles.statusSep} />}
|
||||
<BarButton
|
||||
className={styles.crumbButton}
|
||||
tooltip={item.detail ?? item.name}
|
||||
onClick={() =>
|
||||
void editorController().openFile(path, {
|
||||
selection: { line: item.selection_range.start.line, col: item.selection_range.start.col },
|
||||
})
|
||||
}
|
||||
>
|
||||
<Icon name={`symbol-${badgeKind(item.kind)}`} size={14} className={styles.crumbIcon} />
|
||||
<span className={styles.crumbLabel}>{item.name}</span>
|
||||
</BarButton>
|
||||
</Fragment>
|
||||
<BarButton
|
||||
key={i}
|
||||
className={styles.crumbButton}
|
||||
tooltip={item.detail ?? item.name}
|
||||
aria-current={i === chain.length - 1 ? "location" : undefined}
|
||||
onClick={() =>
|
||||
void editorController().openFile(path, {
|
||||
selection: { line: item.selection_range.start.line, col: item.selection_range.start.col },
|
||||
})
|
||||
}
|
||||
>
|
||||
<span className={styles.crumbLabel}>{item.name}</span>
|
||||
</BarButton>
|
||||
))}
|
||||
</nav>
|
||||
</BreadcrumbStrip>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -30,8 +30,7 @@
|
||||
}
|
||||
.withPreview {
|
||||
flex-direction: row;
|
||||
width: auto;
|
||||
max-width: min(1160px, 94vw);
|
||||
min-width: 0;
|
||||
}
|
||||
.listMain {
|
||||
display: flex;
|
||||
@@ -39,6 +38,11 @@
|
||||
min-width: 0;
|
||||
flex: none;
|
||||
}
|
||||
.withPreview .listMain {
|
||||
flex: 1 1 320px;
|
||||
min-width: 300px;
|
||||
min-height: 0;
|
||||
}
|
||||
.mnemonic {
|
||||
width: 10px;
|
||||
flex: none;
|
||||
@@ -48,14 +52,39 @@
|
||||
text-align: right;
|
||||
}
|
||||
.previewPanel {
|
||||
width: 420px;
|
||||
flex: none;
|
||||
flex: 0 1 var(--list-preview-width);
|
||||
min-width: 300px;
|
||||
min-height: 60px;
|
||||
max-height: 340px;
|
||||
max-height: 300px;
|
||||
overflow: auto;
|
||||
border-left: 1px solid var(--border-popup);
|
||||
background: var(--bg-popup-inline, var(--bg-elev));
|
||||
}
|
||||
.previewLeft {
|
||||
flex-direction: row-reverse;
|
||||
}
|
||||
.previewLeft .previewPanel {
|
||||
border-left: 0;
|
||||
border-right: 1px solid var(--border-popup);
|
||||
}
|
||||
.previewBelow {
|
||||
flex-direction: column;
|
||||
}
|
||||
.previewBelow .listMain {
|
||||
flex: 0 1 auto;
|
||||
min-width: 0;
|
||||
}
|
||||
.previewBelow .previewPanel {
|
||||
flex: 0 1 auto;
|
||||
min-width: 0;
|
||||
min-height: 0;
|
||||
max-height: min(300px, 40vh);
|
||||
border-left: 0;
|
||||
border-top: 1px solid var(--border-popup);
|
||||
}
|
||||
.previewBelow .previewPanel[aria-busy] {
|
||||
height: 60px;
|
||||
}
|
||||
.previewText {
|
||||
padding: 8px 10px;
|
||||
font-size: var(--fs-small);
|
||||
@@ -66,12 +95,13 @@
|
||||
padding: 6px 0;
|
||||
font-family: var(--openidea-editor-font, var(--font-mono));
|
||||
font-weight: var(--fw-code);
|
||||
font-size: var(--fs-small);
|
||||
font-size: var(--openidea-editor-font-size, var(--fs-code));
|
||||
color: var(--fg-editor);
|
||||
}
|
||||
.diffLine {
|
||||
padding: 0 10px;
|
||||
white-space: pre;
|
||||
white-space: pre-wrap;
|
||||
overflow-wrap: anywhere;
|
||||
min-height: 1.4em;
|
||||
}
|
||||
.diff-added {
|
||||
@@ -238,6 +268,10 @@
|
||||
flex-direction: column;
|
||||
overflow: hidden;
|
||||
}
|
||||
.docPopup:not([data-resized]) {
|
||||
width: max-content;
|
||||
min-width: min(300px, 90vw);
|
||||
}
|
||||
.docScope {
|
||||
display: contents;
|
||||
}
|
||||
@@ -246,21 +280,32 @@
|
||||
}
|
||||
.docPopup .docFrame {
|
||||
flex: 1 1 auto;
|
||||
min-width: 0;
|
||||
min-height: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
.docPopup:not([data-resized]) .docFrame {
|
||||
max-width: min(600px, 90vw);
|
||||
max-height: 420px;
|
||||
max-width: min(500px, 90vw);
|
||||
max-height: 500px;
|
||||
}
|
||||
.docPopup .docBody {
|
||||
flex: 1 1 auto;
|
||||
min-height: 0;
|
||||
overflow: auto;
|
||||
overscroll-behavior: contain;
|
||||
padding: var(--space-2) var(--space-4) var(--space-1);
|
||||
}
|
||||
.docPopup .docToolbar {
|
||||
position: static;
|
||||
flex: none;
|
||||
align-self: flex-end;
|
||||
margin: 0 var(--space-2) var(--space-1);
|
||||
padding: 0;
|
||||
border: 0;
|
||||
}
|
||||
.docPopup .docToolbar .spacer {
|
||||
display: none;
|
||||
}
|
||||
.docWindowFrame {
|
||||
height: 100%;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/** React popups for LSP editor features, rendered as a workbench overlay. */
|
||||
import { useEffect, useMemo, useRef, useState, type KeyboardEvent } from "react";
|
||||
import { useEffect, useMemo, useRef, useState, type CSSProperties, type KeyboardEvent } from "react";
|
||||
import clsx from "clsx";
|
||||
import {
|
||||
Checkbox,
|
||||
@@ -49,11 +49,17 @@ function ItemIcon({ item }: { item: ListPopupItem }) {
|
||||
return <span className={styles.iconSpacer} />;
|
||||
}
|
||||
|
||||
function ListPreviewPanel({ preview }: { preview: ListPreview | null | "loading" }) {
|
||||
function ListPreviewPanel({
|
||||
preview,
|
||||
themeClasses,
|
||||
}: {
|
||||
preview: ListPreview | null | "loading";
|
||||
themeClasses?: string;
|
||||
}) {
|
||||
if (preview === "loading") return <div className={styles.previewPanel} aria-busy="true" />;
|
||||
if (!preview) return null;
|
||||
return (
|
||||
<div className={styles.previewPanel} aria-label={tx("Preview")}>
|
||||
<div className={clsx(styles.previewPanel, themeClasses)} role="region" aria-label={tx("Preview")}>
|
||||
{preview.kind === "text" ? (
|
||||
<div className={styles.previewText}>{preview.text}</div>
|
||||
) : (
|
||||
@@ -70,6 +76,9 @@ function ListPreviewPanel({ preview }: { preview: ListPreview | null | "loading"
|
||||
);
|
||||
}
|
||||
|
||||
const LIST_PREVIEW_WIDTH = 420;
|
||||
const MIN_SIDE_BY_SIDE_WIDTH = 660;
|
||||
|
||||
function ListPopup({ popup }: { popup: Extract<LspPopup, { kind: "list" }> }) {
|
||||
const [query, setQuery] = useState("");
|
||||
const filtered = useMemo(() => {
|
||||
@@ -91,6 +100,13 @@ function ListPopup({ popup }: { popup: Extract<LspPopup, { kind: "list" }> }) {
|
||||
|
||||
const [preview, setPreview] = useState<{ id: string; data: ListPreview | null } | null>(null);
|
||||
const fetchPreview = popup.preview;
|
||||
const [viewportWidth, setViewportWidth] = useState(() => window.innerWidth);
|
||||
useEffect(() => {
|
||||
if (!fetchPreview) return;
|
||||
const resize = () => setViewportWidth(window.innerWidth);
|
||||
window.addEventListener("resize", resize);
|
||||
return () => window.removeEventListener("resize", resize);
|
||||
}, [fetchPreview]);
|
||||
useEffect(() => {
|
||||
if (!fetchPreview || !activeItem || activeItem.disabled) return;
|
||||
const ctrl = new AbortController();
|
||||
@@ -164,22 +180,46 @@ function ListPopup({ popup }: { popup: Extract<LspPopup, { kind: "list" }> }) {
|
||||
? ("loading" as const)
|
||||
: null
|
||||
: null;
|
||||
const hasPreview = shownPreview !== null;
|
||||
const previewBelow = hasPreview && viewportWidth <= MIN_SIDE_BY_SIDE_WIDTH;
|
||||
const previewLeft =
|
||||
hasPreview &&
|
||||
!previewBelow &&
|
||||
popup.anchor.x + width + LIST_PREVIEW_WIDTH > viewportWidth - 6 &&
|
||||
popup.anchor.x >= LIST_PREVIEW_WIDTH + 6;
|
||||
const anchor = useMemo(() => {
|
||||
if (!fetchPreview) return popup.anchor;
|
||||
const x = popup.anchor.x - (previewLeft ? LIST_PREVIEW_WIDTH : 0);
|
||||
return {
|
||||
getBoundingClientRect: () =>
|
||||
new DOMRect(
|
||||
Math.max(0, Math.min(x, window.innerWidth)),
|
||||
Math.max(0, Math.min(popup.anchor.y, window.innerHeight)),
|
||||
0,
|
||||
0,
|
||||
),
|
||||
};
|
||||
}, [fetchPreview, popup.anchor, previewLeft]);
|
||||
const popupSize = {
|
||||
width: hasPreview ? width + LIST_PREVIEW_WIDTH : width,
|
||||
"--list-preview-width": `${LIST_PREVIEW_WIDTH}px`,
|
||||
} as CSSProperties;
|
||||
const indexOf = (item: ListPopupItem) => popup.items.indexOf(item);
|
||||
return (
|
||||
<Popup
|
||||
open
|
||||
anchor={popup.anchor}
|
||||
anchor={anchor}
|
||||
onClose={closePopup}
|
||||
aria-label={popup.title}
|
||||
className={clsx(styles.listPopup, popup.preview && styles.withPreview)}
|
||||
style={popup.preview ? undefined : { width }}
|
||||
className={clsx(
|
||||
styles.listPopup,
|
||||
hasPreview && styles.withPreview,
|
||||
previewBelow && styles.previewBelow,
|
||||
previewLeft && styles.previewLeft,
|
||||
)}
|
||||
style={popupSize}
|
||||
>
|
||||
<div
|
||||
className={styles.listMain}
|
||||
style={popup.preview ? { width } : undefined}
|
||||
data-testid="list-popup"
|
||||
aria-busy={popup.busy || undefined}
|
||||
>
|
||||
<div className={styles.listMain} data-testid="list-popup" aria-busy={popup.busy || undefined}>
|
||||
<div className={styles.listHeader}>
|
||||
<span className={styles.listTitle}>{popup.title}</span>
|
||||
{popup.busy && <Spinner size={12} />}
|
||||
@@ -260,7 +300,7 @@ function ListPopup({ popup }: { popup: Extract<LspPopup, { kind: "list" }> }) {
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
{popup.preview && <ListPreviewPanel preview={shownPreview} />}
|
||||
{popup.preview && <ListPreviewPanel preview={shownPreview} themeClasses={popup.themeClasses} />}
|
||||
{sub?.item.submenu && (
|
||||
<Popup
|
||||
open
|
||||
@@ -356,6 +396,19 @@ function DocPopup({ popup }: { popup: Extract<LspPopup, { kind: "doc" }> }) {
|
||||
const focusSeq = useLspPopup((s) => s.focusSeq);
|
||||
const scope = useRef<HTMLDivElement>(null);
|
||||
const opened = useRef(focusSeq);
|
||||
// The captured caret can end up outside the viewport while the popup is open.
|
||||
const anchor = useMemo(
|
||||
() => ({
|
||||
getBoundingClientRect: () =>
|
||||
new DOMRect(
|
||||
Math.max(0, Math.min(popup.anchor.x, window.innerWidth)),
|
||||
Math.max(0, Math.min(popup.anchor.y, window.innerHeight)),
|
||||
0,
|
||||
0,
|
||||
),
|
||||
}),
|
||||
[popup.anchor],
|
||||
);
|
||||
useEffect(() => {
|
||||
if (focusSeq !== opened.current)
|
||||
scope.current?.querySelector<HTMLElement>("[data-lsp-doc]")?.focus({ preventScroll: true });
|
||||
@@ -364,7 +417,7 @@ function DocPopup({ popup }: { popup: Extract<LspPopup, { kind: "doc" }> }) {
|
||||
return (
|
||||
<Popup
|
||||
open
|
||||
anchor={popup.anchor}
|
||||
anchor={anchor}
|
||||
onClose={closePopup}
|
||||
aria-label="Documentation"
|
||||
className={styles.docPopup}
|
||||
|
||||
@@ -25,7 +25,7 @@ import {
|
||||
type CompletionSource,
|
||||
} from "@codemirror/autocomplete";
|
||||
import { EditorSelection, EditorState, Prec, StateEffect, StateField, type Text } from "@codemirror/state";
|
||||
import { EditorView, ViewPlugin, keymap, type Rect, type ViewUpdate } from "@codemirror/view";
|
||||
import { EditorView, ViewPlugin, getTooltip, keymap, showTooltip, type Rect, type ViewUpdate } from "@codemirror/view";
|
||||
import {
|
||||
call,
|
||||
commands,
|
||||
@@ -59,6 +59,8 @@ import { showHint } from "./hint";
|
||||
import { inplaceRenameActive } from "./inplaceRename";
|
||||
import { languageSemantics } from "./semantic";
|
||||
import { remoteChange } from "@/editor/api";
|
||||
import { tooltipBounds } from "@/editor/core/cm/setup";
|
||||
import { completionLabelOffset } from "./theme";
|
||||
|
||||
interface RequestContext {
|
||||
doc: number;
|
||||
@@ -983,36 +985,45 @@ function sortToggle(view: EditorView): HTMLElement {
|
||||
return button;
|
||||
}
|
||||
|
||||
/** IDEA's advertiser bar under the list (one tip: "Press ↵ to insert, ⇥ to replace") and its Sort by Name toggle. */
|
||||
const completionFooter = ViewPlugin.fromClass(
|
||||
const completionPopup = ViewPlugin.fromClass(
|
||||
class {
|
||||
constructor(private view: EditorView) {}
|
||||
update(u: ViewUpdate) {
|
||||
if (completionStatus(u.state) !== "active") return;
|
||||
this.view.requestMeasure({
|
||||
read: () => null,
|
||||
write: () => {
|
||||
const scope = this.view.dom.ownerDocument;
|
||||
const tooltips = [
|
||||
...this.view.dom.querySelectorAll<HTMLElement>(".cm-tooltip-autocomplete"),
|
||||
...scope.querySelectorAll<HTMLElement>(".cm-tooltip-autocomplete"),
|
||||
];
|
||||
for (const t of tooltips) {
|
||||
let footer = t.querySelector<HTMLElement>(":scope > .cm-lsp-completion-footer");
|
||||
if (footer) {
|
||||
// CodeMirror rebuilds the option list by appending a fresh <ul>,
|
||||
// which would leave an existing footer above the list.
|
||||
const list = t.querySelector(":scope > ul");
|
||||
if (list && list.nextElementSibling !== footer) list.after(footer);
|
||||
continue;
|
||||
}
|
||||
key: this,
|
||||
read: () => {
|
||||
const { left, right } = tooltipBounds(this.view);
|
||||
return {
|
||||
width: `${Math.max(0, Math.floor(right - left))}px`,
|
||||
fontSize: getComputedStyle(this.view.contentDOM).fontSize,
|
||||
};
|
||||
},
|
||||
write: ({ width, fontSize }) => {
|
||||
const popup = this.view.state
|
||||
.facet(showTooltip)
|
||||
.map((tooltip) => tooltip && getTooltip(this.view, tooltip))
|
||||
.find((tooltip) => tooltip?.dom.classList.contains("cm-lsp-completion"));
|
||||
if (!popup) return;
|
||||
// Apply the label alignment inside CodeMirror's viewport clamp.
|
||||
popup.offset = { x: -completionLabelOffset, y: 0 };
|
||||
const t = popup.dom;
|
||||
if (t.style.getPropertyValue("--cm-completion-max-width") !== width)
|
||||
t.style.setProperty("--cm-completion-max-width", width);
|
||||
// The body-level tooltip does not inherit the editor's temporary font zoom.
|
||||
if (t.style.getPropertyValue("--openidea-editor-font-size") !== fontSize)
|
||||
t.style.setProperty("--openidea-editor-font-size", fontSize);
|
||||
let footer = t.querySelector<HTMLElement>(":scope > .cm-lsp-completion-footer");
|
||||
if (!footer) {
|
||||
footer = document.createElement("div");
|
||||
footer.className = "cm-lsp-completion-footer";
|
||||
const tip = document.createElement("span");
|
||||
tip.textContent = tx("Press ↵ to insert, ⇥ to replace");
|
||||
footer.append(tip, sortToggle(this.view));
|
||||
t.appendChild(footer);
|
||||
}
|
||||
// CodeMirror appends a fresh list when the candidates change.
|
||||
const list = t.querySelector(":scope > ul");
|
||||
if (list && list.nextElementSibling !== footer) list.after(footer);
|
||||
},
|
||||
});
|
||||
}
|
||||
@@ -1067,7 +1078,7 @@ export function completionExtension() {
|
||||
tooltipClass: () => "cm-lsp-completion",
|
||||
positionInfo: positionCompletionInfo,
|
||||
}),
|
||||
completionFooter,
|
||||
completionPopup,
|
||||
lookupTracker,
|
||||
serverInsertAt,
|
||||
caretAfterServerInsert,
|
||||
|
||||
@@ -552,6 +552,7 @@ export async function showIntentions(view: EditorView) {
|
||||
items,
|
||||
busy,
|
||||
preview,
|
||||
themeClasses: view.themeClasses,
|
||||
onClose: () => {
|
||||
dismissed = true;
|
||||
},
|
||||
|
||||
@@ -104,6 +104,7 @@ export type LspPopup =
|
||||
pin?: { label: string; run: () => void };
|
||||
/** Side panel for the selected row, fetched lazily; `signal` aborts when the selection moves. */
|
||||
preview?: (item: ListPopupItem, signal: AbortSignal) => Promise<ListPreview | null>;
|
||||
themeClasses?: string;
|
||||
/** Runs when the popup goes away (closed, replaced or a row ran). */
|
||||
onClose?: () => void;
|
||||
}
|
||||
|
||||
@@ -10,19 +10,17 @@ const tooltipSurface = {
|
||||
color: "var(--fg)",
|
||||
};
|
||||
|
||||
/**
|
||||
* Row metrics that put a label one icon column right of the popup's left edge. They live on the
|
||||
* popup as custom properties so every rule consuming them — including the popup's negative
|
||||
* offset below — changes together. The remaining 1px is tooltipSurface's border, shared with
|
||||
* the hover and signature tooltips.
|
||||
*/
|
||||
const completionInsets = { edge: 4, padding: 6, icon: 16, gap: 6 };
|
||||
export const completionLabelOffset =
|
||||
1 + completionInsets.edge + completionInsets.padding + completionInsets.icon + completionInsets.gap;
|
||||
|
||||
const completionRowMetrics = {
|
||||
// Rows grow with the editor font size (lookup text uses the editor font, as typed text does).
|
||||
"--cm-completion-row": "max(var(--h-list-row), calc(var(--openidea-editor-font-size, var(--fs-code)) * 1.7))",
|
||||
"--cm-completion-edge": "4px",
|
||||
"--cm-completion-inset": "6px",
|
||||
"--cm-completion-icon": "16px",
|
||||
"--cm-completion-gap": "6px",
|
||||
"--cm-completion-edge": `${completionInsets.edge}px`,
|
||||
"--cm-completion-inset": `${completionInsets.padding}px`,
|
||||
"--cm-completion-icon": `${completionInsets.icon}px`,
|
||||
"--cm-completion-gap": `${completionInsets.gap}px`,
|
||||
};
|
||||
|
||||
const markdown = {
|
||||
@@ -103,22 +101,19 @@ export const lspTheme = EditorView.theme({
|
||||
fontFamily: "var(--openidea-editor-font, var(--font-mono))",
|
||||
fontWeight: "var(--fw-code, 400)",
|
||||
fontSize: "var(--openidea-editor-font-size, var(--fs-code))",
|
||||
// CodeMirror anchors the popup at the completed word's start. Pull it left by one row's
|
||||
// leading inset so the labels, not the icon column, sit on the text. CodeMirror's horizontal
|
||||
// clamp measures the border box (margins excluded), so this offset sits outside its math:
|
||||
// near the right edge it leaves that much extra space, and a word starting within one inset
|
||||
// of the viewport's left edge would let the popup clip there. The normal editor layout
|
||||
// (gutter + project sidebar) keeps the word well clear of that edge.
|
||||
marginLeft:
|
||||
"calc(-1 * (1px + var(--cm-completion-edge) + var(--cm-completion-inset) + var(--cm-completion-icon) + var(--cm-completion-gap)))",
|
||||
display: "flex",
|
||||
flexDirection: "column",
|
||||
width: "max-content",
|
||||
maxWidth: "min(720px, var(--cm-completion-max-width, 100vw))",
|
||||
// No overflow clipping: CodeMirror nests the documentation pane in this box and
|
||||
// positions it outside it (see `positionCompletionInfo`). The footer rounds itself.
|
||||
},
|
||||
".cm-tooltip.cm-tooltip-autocomplete.cm-lsp-completion > ul": {
|
||||
fontFamily: "var(--openidea-editor-font, var(--font-mono))",
|
||||
fontWeight: "var(--fw-code, 400)",
|
||||
minWidth: "420px",
|
||||
maxWidth: "min(720px, 80vw)",
|
||||
minWidth: "0",
|
||||
maxWidth: "100%",
|
||||
height: "auto",
|
||||
maxHeight: "calc(var(--cm-completion-row) * 11 + 8px)",
|
||||
padding: "4px 0",
|
||||
},
|
||||
@@ -153,9 +148,15 @@ export const lspTheme = EditorView.theme({
|
||||
alignItems: "center",
|
||||
justifyContent: "center",
|
||||
},
|
||||
".cm-lsp-completion .cm-completionLabel": { flex: "none", overflow: "hidden", textOverflow: "ellipsis" },
|
||||
".cm-lsp-completion .cm-completionLabel": {
|
||||
flex: "0 1 auto",
|
||||
minWidth: "0",
|
||||
overflow: "hidden",
|
||||
textOverflow: "ellipsis",
|
||||
},
|
||||
".cm-lsp-completion .cm-completionDetail": {
|
||||
flex: "0 1 auto",
|
||||
minWidth: "0",
|
||||
marginLeft: "0",
|
||||
fontStyle: "normal",
|
||||
color: "var(--fg-subtle)",
|
||||
@@ -172,7 +173,8 @@ export const lspTheme = EditorView.theme({
|
||||
marginLeft: "calc(-1 * var(--cm-completion-gap))",
|
||||
},
|
||||
".cm-lsp-completion .cm-lsp-type": {
|
||||
flex: "1 0 auto",
|
||||
flex: "0 1 auto",
|
||||
minWidth: "0",
|
||||
maxWidth: "60%",
|
||||
marginLeft: "auto",
|
||||
paddingLeft: "16px",
|
||||
@@ -188,18 +190,21 @@ export const lspTheme = EditorView.theme({
|
||||
},
|
||||
".cm-lsp-completion-footer": {
|
||||
display: "flex",
|
||||
flex: "none",
|
||||
flexWrap: "wrap",
|
||||
alignItems: "center",
|
||||
padding: "5px 12px",
|
||||
backgroundColor: "var(--bg-popup-inline, var(--bg-elev))",
|
||||
color: "var(--fg-subtle)",
|
||||
fontFamily: "var(--font-ui)",
|
||||
fontSize: "var(--fs-small)",
|
||||
whiteSpace: "nowrap",
|
||||
gap: "12px",
|
||||
gap: "var(--space-1) var(--space-3)",
|
||||
justifyContent: "space-between",
|
||||
borderRadius: "0 0 calc(var(--radius-popup) - 1px) calc(var(--radius-popup) - 1px)",
|
||||
},
|
||||
".cm-lsp-completion-sort": {
|
||||
flex: "none",
|
||||
maxWidth: "100%",
|
||||
padding: "0",
|
||||
border: "none",
|
||||
background: "none",
|
||||
|
||||
@@ -54,6 +54,7 @@ vi.mock("@/platform/ipc", async (original) => ({
|
||||
agentCommands: async () => ok([]),
|
||||
vcsBranchInfo: async () => ok({ head: "main" }),
|
||||
vcsConfigGet: async () => ok(null),
|
||||
vcsRemotes: async () => ok([]),
|
||||
vcsBranches: async () => ok([]),
|
||||
agentCreate: (request: NewAgentTask) => backend.create(request),
|
||||
agentEntries: async () => ok([{ type: "user", text: "Earlier message", attachments: [] }] satisfies AgentEntry[]),
|
||||
|
||||
@@ -5,18 +5,27 @@
|
||||
overflow: hidden;
|
||||
}
|
||||
.header {
|
||||
height: 26px;
|
||||
flex: none;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: var(--space-2);
|
||||
padding: 0 10px;
|
||||
flex-wrap: wrap;
|
||||
min-height: var(--h-field);
|
||||
gap: var(--space-0-5) var(--space-2);
|
||||
padding: var(--space-0-5) 10px;
|
||||
border-bottom: 1px solid var(--border-popup);
|
||||
font-size: var(--fs-small);
|
||||
font-size: var(--fs-ui);
|
||||
color: var(--fg-muted);
|
||||
}
|
||||
.actions {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
flex-wrap: wrap;
|
||||
min-width: 0;
|
||||
gap: var(--space-0-5) var(--space-2);
|
||||
font-size: var(--fs-small);
|
||||
}
|
||||
.scope {
|
||||
flex: none;
|
||||
max-width: min(100%, 18em);
|
||||
}
|
||||
|
||||
.searching {
|
||||
@@ -26,23 +35,32 @@
|
||||
}
|
||||
|
||||
.title {
|
||||
flex: 1;
|
||||
flex: 1 1 160px;
|
||||
display: flex;
|
||||
align-items: baseline;
|
||||
gap: var(--space-1);
|
||||
min-width: 0;
|
||||
color: var(--fg-emphasis);
|
||||
}
|
||||
.titleLabel {
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
color: var(--fg-emphasis);
|
||||
}
|
||||
.count {
|
||||
flex: none;
|
||||
white-space: nowrap;
|
||||
font-size: var(--fs-small);
|
||||
color: var(--fg-subtle);
|
||||
}
|
||||
.link {
|
||||
flex: none;
|
||||
max-width: 100%;
|
||||
border: none;
|
||||
background: none;
|
||||
padding: 0;
|
||||
font: inherit;
|
||||
color: var(--link);
|
||||
text-align: left;
|
||||
cursor: pointer;
|
||||
}
|
||||
.link:hover {
|
||||
@@ -52,7 +70,6 @@
|
||||
.body {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
min-height: 24px;
|
||||
padding: 2px 0;
|
||||
box-sizing: content-box;
|
||||
}
|
||||
@@ -60,21 +77,31 @@
|
||||
flex: 1;
|
||||
}
|
||||
.row {
|
||||
display: flex;
|
||||
display: grid;
|
||||
grid-template-columns: min(34%, 176px) 5ch minmax(0, 1fr);
|
||||
align-items: center;
|
||||
gap: var(--space-2);
|
||||
min-width: 0;
|
||||
width: 100%;
|
||||
}
|
||||
.file {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: var(--space-1);
|
||||
min-width: 0;
|
||||
}
|
||||
.icon {
|
||||
flex: none;
|
||||
color: var(--fg-muted);
|
||||
}
|
||||
.spacer {
|
||||
flex: 1;
|
||||
.fileName {
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
.where {
|
||||
flex: none;
|
||||
.line {
|
||||
overflow: hidden;
|
||||
text-align: right;
|
||||
font-variant-numeric: tabular-nums;
|
||||
font-size: var(--fs-small);
|
||||
color: var(--fg-subtle);
|
||||
}
|
||||
@@ -95,12 +122,15 @@
|
||||
outline: none;
|
||||
}
|
||||
.filter {
|
||||
flex: none;
|
||||
max-width: 12ch;
|
||||
font-family: var(--font-mono);
|
||||
color: var(--fg-strong);
|
||||
background: var(--accent-soft);
|
||||
border-radius: var(--radius-small);
|
||||
padding: 0 4px;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.noMatch {
|
||||
color: var(--danger);
|
||||
@@ -111,8 +141,9 @@
|
||||
font-size: var(--fs-small);
|
||||
}
|
||||
.preview {
|
||||
flex: none;
|
||||
height: 200px;
|
||||
flex: 0 1 auto;
|
||||
height: min(164px, 32vh);
|
||||
min-height: min(64px, 18vh);
|
||||
border-top: 1px solid var(--border-popup);
|
||||
overflow: hidden;
|
||||
}
|
||||
@@ -131,3 +162,9 @@
|
||||
.previewMatch {
|
||||
background: var(--bg-text-search-result);
|
||||
}
|
||||
|
||||
@media (max-width: 600px) {
|
||||
.title {
|
||||
flex-basis: 100%;
|
||||
}
|
||||
}
|
||||
@@ -93,6 +93,7 @@ function UsagesPopupInner() {
|
||||
const [active, setActive] = useState(0);
|
||||
const current = Math.min(active, items.length - 1);
|
||||
const total = usageCount(groups);
|
||||
const rowCount = Math.max(1, Math.min(14, items.length));
|
||||
const pick = (u: Usage | undefined) => {
|
||||
if (!u) return;
|
||||
close();
|
||||
@@ -158,46 +159,48 @@ function UsagesPopupInner() {
|
||||
>
|
||||
<div className={styles.header}>
|
||||
<span className={styles.title}>
|
||||
{symbol ? tx`Usages of ${symbol}` : tx("Usages")}{" "}
|
||||
<span className={styles.titleLabel}>{symbol ? tx`Usages of ${symbol}` : tx("Usages")}</span>{" "}
|
||||
<span className={styles.count}>
|
||||
{filter || items.length !== total ? tx`${items.length} of ${total} found` : tx`${total} found`}
|
||||
</span>
|
||||
</span>
|
||||
{scope && (
|
||||
<Select<UsageScope>
|
||||
variant="ghost"
|
||||
aria-label={tx("Scope")}
|
||||
className={styles.scope}
|
||||
value={scope}
|
||||
options={[
|
||||
{ value: "project", label: tx("Project Files") },
|
||||
{ value: "libraries", label: tx("Project and Libraries") },
|
||||
]}
|
||||
onChange={setUsagesPopupScope}
|
||||
<div className={styles.actions}>
|
||||
{scope && (
|
||||
<Select<UsageScope>
|
||||
variant="ghost"
|
||||
aria-label={tx("Scope")}
|
||||
className={styles.scope}
|
||||
value={scope}
|
||||
options={[
|
||||
{ value: "project", label: tx("Project Files") },
|
||||
{ value: "libraries", label: tx("Project and Libraries") },
|
||||
]}
|
||||
onChange={setUsagesPopupScope}
|
||||
/>
|
||||
)}
|
||||
{loading && (
|
||||
<span className={styles.searching} role="status" aria-label={tx("Searching for more usages")}>
|
||||
<Spinner size={16} variant="spokes" />
|
||||
</span>
|
||||
)}
|
||||
{filter && (
|
||||
<span className={clsx(styles.filter, !items.length && styles.noMatch)} role="status">
|
||||
{filter}
|
||||
</span>
|
||||
)}
|
||||
<IconButton
|
||||
icon="preview-details"
|
||||
size="small"
|
||||
title="Show Preview"
|
||||
pressed={preview}
|
||||
onMouseDown={(e) => e.preventDefault()}
|
||||
onClick={() => setUsagesPopupPreview(!preview)}
|
||||
/>
|
||||
)}
|
||||
{loading && (
|
||||
<span className={styles.searching} role="status" aria-label={tx("Searching for more usages")}>
|
||||
<Spinner size={16} variant="spokes" />
|
||||
</span>
|
||||
)}
|
||||
{filter && (
|
||||
<span className={clsx(styles.filter, !items.length && styles.noMatch)} role="status">
|
||||
{filter}
|
||||
</span>
|
||||
)}
|
||||
<IconButton
|
||||
icon="preview-details"
|
||||
size="small"
|
||||
title="Show Preview"
|
||||
pressed={preview}
|
||||
onMouseDown={(e) => e.preventDefault()}
|
||||
onClick={() => setUsagesPopupPreview(!preview)}
|
||||
/>
|
||||
<button type="button" className={styles.link} onClick={openInFindWindow}>
|
||||
{tx("Open in Find Window")}
|
||||
{keys ? ` ${keys}` : ""}
|
||||
</button>
|
||||
<button type="button" className={styles.link} onClick={openInFindWindow}>
|
||||
{tx("Open in Find Window")}
|
||||
{keys ? ` ${keys}` : ""}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<UsageAccessFilter items={all} />
|
||||
{note && (
|
||||
@@ -205,7 +208,10 @@ function UsagesPopupInner() {
|
||||
{note}
|
||||
</div>
|
||||
)}
|
||||
<div className={styles.body} style={{ height: Math.max(1, Math.min(14, items.length)) * ROW }}>
|
||||
<div
|
||||
className={styles.body}
|
||||
style={{ height: rowCount * ROW, minHeight: `min(${Math.min(rowCount, 3) * ROW}px, 18vh)` }}
|
||||
>
|
||||
<List
|
||||
items={items}
|
||||
getKey={(u) =>
|
||||
@@ -225,12 +231,14 @@ function UsagesPopupInner() {
|
||||
}
|
||||
renderItem={(u) => (
|
||||
<div className={styles.row} data-testid="usage-row" data-path={u.path} data-line={u.line}>
|
||||
<Icon name={fileIconName(basename(u.path), u.path)} size={16} className={styles.icon} />
|
||||
<UsagePreview usage={u} />
|
||||
<span className={styles.spacer} />
|
||||
<span className={styles.where}>
|
||||
{basename(u.path)}:{u.line + 1}
|
||||
<span className={styles.file}>
|
||||
<Icon name={fileIconName(basename(u.path), u.path)} size={16} className={styles.icon} />
|
||||
<span className={styles.fileName} title={u.path}>
|
||||
{basename(u.path)}
|
||||
</span>
|
||||
</span>
|
||||
<span className={styles.line}>{u.line + 1}</span>
|
||||
<UsagePreview usage={u} />
|
||||
</div>
|
||||
)}
|
||||
/>
|
||||
|
||||
@@ -25,15 +25,15 @@
|
||||
background: var(--border);
|
||||
}
|
||||
.summary {
|
||||
height: 26px;
|
||||
min-height: 26px;
|
||||
flex: none;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: var(--space-1-5);
|
||||
padding: 0 10px;
|
||||
flex-wrap: wrap;
|
||||
gap: var(--space-0-5) var(--space-1-5);
|
||||
padding: var(--space-0-5) 10px;
|
||||
font-size: var(--fs-ui);
|
||||
color: var(--fg-subtle);
|
||||
white-space: nowrap;
|
||||
}
|
||||
.groupLabel {
|
||||
color: var(--fg);
|
||||
@@ -42,12 +42,13 @@
|
||||
color: var(--danger);
|
||||
}
|
||||
.link {
|
||||
flex: none;
|
||||
max-width: 100%;
|
||||
border: none;
|
||||
background: none;
|
||||
padding: 0;
|
||||
font: inherit;
|
||||
color: var(--link);
|
||||
text-align: left;
|
||||
cursor: pointer;
|
||||
}
|
||||
.link:hover {
|
||||
@@ -81,9 +82,18 @@
|
||||
flex: none;
|
||||
}
|
||||
.file {
|
||||
flex: none;
|
||||
max-width: 56%;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
color: var(--fg);
|
||||
}
|
||||
.muted,
|
||||
.directory {
|
||||
min-width: 0;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
color: var(--fg-subtle);
|
||||
}
|
||||
.count {
|
||||
flex: none;
|
||||
color: var(--fg-subtle);
|
||||
@@ -101,7 +111,7 @@
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
font-family: var(--font-mono);
|
||||
font-size: var(--fs-ui);
|
||||
font-size: var(--fs-code);
|
||||
color: var(--fg);
|
||||
}
|
||||
.match {
|
||||
@@ -135,3 +145,18 @@
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
}
|
||||
.splitFrame {
|
||||
display: flex;
|
||||
min-width: 0;
|
||||
}
|
||||
.sourcePreview {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
font-family: var(--font-mono);
|
||||
font-size: var(--fs-code);
|
||||
line-height: 1.45;
|
||||
}
|
||||
.sourcePreview .sourceText[role="region"] {
|
||||
font: inherit;
|
||||
font-weight: var(--fw-code);
|
||||
}
|
||||
@@ -2,11 +2,13 @@
|
||||
* "usages" tool window: Find Usages results grouped by file with line
|
||||
* previews, one tab per search (pinnable, as the Find tool window's tabs).
|
||||
*/
|
||||
import { useCallback, useMemo, useRef, useState, type KeyboardEvent, type ReactNode } from "react";
|
||||
import { useCallback, useLayoutEffect, useMemo, useRef, useState, type KeyboardEvent, type ReactNode } from "react";
|
||||
import clsx from "clsx";
|
||||
import { create } from "zustand";
|
||||
import { previewColors, tokenSpans, useLineTokens } from "@/editor/lineTokens";
|
||||
import { formatMessage, useTx } from "@/platform/i18n";
|
||||
import { useEditorPrefs } from "@/platform/editorSettings";
|
||||
import { BUNDLED_MONO_FAMILY, monoFontFamily } from "@/platform/fonts";
|
||||
import { shortcutLabel } from "@/platform/keymap";
|
||||
import { basename, relativeDir, useProject } from "@/platform/project";
|
||||
import { maybeEditorService, useOccurrenceNavigator } from "@/workbench/contributions";
|
||||
@@ -245,8 +247,12 @@ export function UsagesView() {
|
||||
return (
|
||||
<span className={clsx(styles.row, isExcluded(n) && styles.excluded)}>
|
||||
<Icon name={fileIconName(basename(path), path)} size={16} className={styles.icon} />
|
||||
<span className={styles.file}>{basename(path)}</span>
|
||||
<span className={styles.muted}>{relativeDir(root, path)}</span>
|
||||
<span className={styles.file} title={path}>
|
||||
{basename(path)}
|
||||
</span>
|
||||
<span className={styles.directory} title={path}>
|
||||
{relativeDir(root, path)}
|
||||
</span>
|
||||
<span className={styles.count}>
|
||||
{n.group.usages.length} {tx(n.group.usages.length === 1 ? "usage" : "usages")}
|
||||
</span>
|
||||
@@ -401,34 +407,62 @@ export function useUsagesHeaderMenu(): MenuItem[] {
|
||||
|
||||
function UsagesSplit({ preview, children }: { preview: ReactNode; children: ReactNode }) {
|
||||
const show = useUsagesOptions((s) => s.preview);
|
||||
const frame = useRef<HTMLDivElement>(null);
|
||||
const [stacked, setStacked] = useState(false);
|
||||
useLayoutEffect(() => {
|
||||
const el = frame.current;
|
||||
if (!show || !el) return;
|
||||
const measure = () => setStacked(el.clientWidth < 580);
|
||||
measure();
|
||||
if (typeof ResizeObserver === "undefined") return;
|
||||
const observer = new ResizeObserver(measure);
|
||||
observer.observe(el);
|
||||
return () => observer.disconnect();
|
||||
}, [show]);
|
||||
if (!show) return children;
|
||||
return (
|
||||
<SplitGroup orientation="horizontal" id="usages-preview-split" storageKey="openidea.usages.previewSplit">
|
||||
<SplitPanel id="usages" minSize={160} className={styles.panel}>
|
||||
{children}
|
||||
</SplitPanel>
|
||||
<SplitHandle />
|
||||
<SplitPanel id="preview" minSize={160} defaultSize="45%" className={styles.panel}>
|
||||
{preview}
|
||||
</SplitPanel>
|
||||
</SplitGroup>
|
||||
<div ref={frame} className={styles.splitFrame}>
|
||||
<SplitGroup
|
||||
orientation={stacked ? "vertical" : "horizontal"}
|
||||
id="usages-preview-split"
|
||||
storageKey={stacked ? "openidea.usages.previewSplit.vertical" : "openidea.usages.previewSplit"}
|
||||
>
|
||||
<SplitPanel id="usages" minSize={stacked ? "30%" : 160} className={styles.panel}>
|
||||
{children}
|
||||
</SplitPanel>
|
||||
<SplitHandle />
|
||||
<SplitPanel id="preview" minSize={stacked ? "30%" : 160} defaultSize="45%" className={styles.panel}>
|
||||
{preview}
|
||||
</SplitPanel>
|
||||
</SplitGroup>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function UsagesPreview({ node }: { node: Node | null }) {
|
||||
const usage = node?.kind === "usage" ? node.usage : node?.kind === "file" ? (node.group.usages[0] ?? null) : null;
|
||||
const search = useUsages(activeUsageSearch);
|
||||
const settings = useProject((s) => s.settings?.editor);
|
||||
const { fallbackFont } = useEditorPrefs();
|
||||
const family = settings?.fontFamily;
|
||||
const fontFamily =
|
||||
(family && family !== BUNDLED_MONO_FAMILY) || fallbackFont.trim()
|
||||
? monoFontFamily(family, fallbackFont, "var(--font-mono)")
|
||||
: undefined;
|
||||
const highlights = useMemo(() => {
|
||||
const group = usage && search?.groups.find((g) => g.path === usage.path);
|
||||
return (group?.usages ?? []).map((u) => ({ line: u.line, ranges: [[u.col, u.endCol] as const] }));
|
||||
}, [usage, search?.groups]);
|
||||
return (
|
||||
<SourcePreview
|
||||
path={usage?.path ?? null}
|
||||
line={usage?.line ?? 0}
|
||||
highlights={highlights}
|
||||
load={previewText}
|
||||
colorize={previewColors}
|
||||
/>
|
||||
<div className={styles.sourcePreview} style={{ fontFamily, fontSize: settings?.fontSize ?? undefined }}>
|
||||
<SourcePreview
|
||||
path={usage?.path ?? null}
|
||||
line={usage?.line ?? 0}
|
||||
highlights={highlights}
|
||||
load={previewText}
|
||||
colorize={previewColors}
|
||||
className={styles.sourceText}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -135,7 +135,7 @@
|
||||
.redirects {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 2px;
|
||||
gap: var(--space-0-5);
|
||||
padding: 2px 8px;
|
||||
border-bottom: 1px solid var(--border);
|
||||
font-family: var(--font-mono);
|
||||
|
||||
@@ -0,0 +1,119 @@
|
||||
/* Mirrors the title bar's project popup: two-line project rows, then action rows. */
|
||||
.panel {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
width: 400px;
|
||||
padding: var(--space-1-5) 0;
|
||||
font-family: var(--font-ui);
|
||||
font-size: var(--fs-ui);
|
||||
color: var(--fg);
|
||||
outline: none;
|
||||
}
|
||||
.header {
|
||||
padding: var(--space-1) var(--space-4);
|
||||
color: var(--fg-muted);
|
||||
font-size: var(--fs-small);
|
||||
font-weight: 600;
|
||||
}
|
||||
.projects {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
max-height: 320px;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
overflow-y: auto;
|
||||
list-style: none;
|
||||
}
|
||||
.project {
|
||||
position: relative;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: var(--space-3);
|
||||
min-width: 0;
|
||||
margin: 0 var(--space-1-5);
|
||||
padding: var(--space-1-5) var(--space-2);
|
||||
border-radius: var(--radius-selection);
|
||||
}
|
||||
.project:hover,
|
||||
.project:focus-within {
|
||||
background: var(--bg-tree-selected);
|
||||
}
|
||||
.text {
|
||||
display: flex;
|
||||
flex: 1;
|
||||
flex-direction: column;
|
||||
gap: var(--space-0-5);
|
||||
min-width: 0;
|
||||
}
|
||||
.top {
|
||||
display: flex;
|
||||
align-items: baseline;
|
||||
justify-content: space-between;
|
||||
gap: var(--space-3);
|
||||
min-width: 0;
|
||||
}
|
||||
.name,
|
||||
.path,
|
||||
.state {
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.name {
|
||||
color: var(--fg-strong);
|
||||
}
|
||||
.path,
|
||||
.state {
|
||||
color: var(--fg-subtle);
|
||||
font-size: var(--fs-small);
|
||||
}
|
||||
.state {
|
||||
flex: none;
|
||||
max-width: 60%;
|
||||
}
|
||||
/* The row's actions take the place of its state while the row is hovered or focused. */
|
||||
.actions {
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
right: var(--space-2);
|
||||
display: flex;
|
||||
gap: var(--space-0-5);
|
||||
transform: translateY(-50%);
|
||||
opacity: 0;
|
||||
}
|
||||
.project:hover .actions,
|
||||
.project:focus-within .actions {
|
||||
opacity: 1;
|
||||
}
|
||||
.project:hover .state,
|
||||
.project:focus-within .state {
|
||||
visibility: hidden;
|
||||
}
|
||||
.project:hover .path,
|
||||
.project:focus-within .path {
|
||||
padding-right: 52px;
|
||||
}
|
||||
.separator {
|
||||
height: 1px;
|
||||
margin: var(--space-1-5) var(--space-3);
|
||||
background: var(--border);
|
||||
}
|
||||
.action {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
min-height: var(--h-list-row);
|
||||
margin: 0 var(--space-1-5);
|
||||
padding: 0 var(--space-2);
|
||||
border: 0;
|
||||
border-radius: var(--radius-selection);
|
||||
background: none;
|
||||
color: var(--fg-strong);
|
||||
font: inherit;
|
||||
text-align: left;
|
||||
cursor: default;
|
||||
}
|
||||
.action:hover,
|
||||
.action:focus-visible {
|
||||
background: var(--bg-tree-selected);
|
||||
outline: none;
|
||||
}
|
||||
@@ -0,0 +1,139 @@
|
||||
import { act, cleanup, fireEvent, render, screen, within } from "@testing-library/react";
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import type { McpBackgroundProject } from "@/bindings";
|
||||
|
||||
const mocks = vi.hoisted(() => ({
|
||||
list: vi.fn(),
|
||||
unload: vi.fn(),
|
||||
execute: vi.fn(async (_id: string, _arg?: unknown) => {}),
|
||||
}));
|
||||
vi.mock("@/platform/actions", async (original) => ({
|
||||
...(await original<object>()),
|
||||
executeAction: mocks.execute,
|
||||
}));
|
||||
vi.mock("@/platform/ipc", async (original) => {
|
||||
const real = await original<typeof import("@/platform/ipc")>();
|
||||
return {
|
||||
...real,
|
||||
isTauri: () => true,
|
||||
commands: { ...real.commands, mcpBackgroundProjects: mocks.list, mcpUnloadBackgroundProject: mocks.unload },
|
||||
};
|
||||
});
|
||||
|
||||
const { emitLocalIdeEvent } = await import("@/platform/ipc");
|
||||
const { useRemote } = await import("@/platform/remote");
|
||||
const { BackgroundStatus } = await import("./BackgroundStatus");
|
||||
|
||||
const ok = <T,>(data: T) => ({ status: "ok" as const, data });
|
||||
const project = (root: string, patch: Partial<McpBackgroundProject> = {}): McpBackgroundProject => ({
|
||||
root,
|
||||
idleSeconds: 0,
|
||||
...patch,
|
||||
});
|
||||
const inventory = project("/projects/inventory");
|
||||
const billing = project("/projects/billing", { keptOpenBy: { kind: "request" } });
|
||||
|
||||
async function show(projects: McpBackgroundProject[]) {
|
||||
mocks.list.mockResolvedValue(ok(projects));
|
||||
render(<BackgroundStatus />);
|
||||
await act(async () => {});
|
||||
}
|
||||
const openPopup = async () => {
|
||||
fireEvent.click(screen.getByRole("button", { name: /Background Projects/ }));
|
||||
await act(async () => {});
|
||||
return screen.getByRole("dialog", { name: "Background Projects" });
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
mocks.list.mockReset();
|
||||
mocks.unload.mockReset().mockResolvedValue(ok(null));
|
||||
mocks.execute.mockClear();
|
||||
});
|
||||
afterEach(() => {
|
||||
cleanup();
|
||||
useRemote.setState({ session: null });
|
||||
});
|
||||
|
||||
describe("background projects in the status bar", () => {
|
||||
it("renders nothing while no project is loaded", async () => {
|
||||
await show([]);
|
||||
expect(screen.queryByRole("button")).toBeNull();
|
||||
});
|
||||
|
||||
it("shows how many projects are loaded", async () => {
|
||||
await show([inventory, billing]);
|
||||
expect(screen.getByRole("button", { name: /Background Projects/ })).toHaveTextContent("2");
|
||||
});
|
||||
|
||||
it("lists each project with its name, path and state", async () => {
|
||||
await show([inventory, billing]);
|
||||
const popup = await openPopup();
|
||||
expect(within(popup).getByText("inventory")).toBeInTheDocument();
|
||||
expect(within(popup).getByText("/projects/billing")).toBeInTheDocument();
|
||||
expect(within(popup).getByText("Answering a request")).toBeInTheDocument();
|
||||
expect(within(popup).getByText("Last request just now")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("opens with the focus on the list, so no row's state gives way to its actions", async () => {
|
||||
await show([inventory]);
|
||||
const popup = await openPopup();
|
||||
expect(popup.contains(document.activeElement)).toBe(true);
|
||||
expect(document.activeElement).not.toBeInstanceOf(HTMLButtonElement);
|
||||
});
|
||||
|
||||
it("stays hidden in a remote window, whose server serves no background projects", async () => {
|
||||
useRemote.setState({
|
||||
session: { root: "/srv/app" } as NonNullable<ReturnType<typeof useRemote.getState>["session"]>,
|
||||
});
|
||||
await show([inventory]);
|
||||
expect(screen.queryByRole("button")).toBeNull();
|
||||
});
|
||||
|
||||
it("names a project at the file system root by its path", async () => {
|
||||
await show([project("/")]);
|
||||
const popup = await openPopup();
|
||||
expect(within(popup).getAllByText("/").length).toBe(2);
|
||||
});
|
||||
|
||||
it("opens a project in its own window from its row", async () => {
|
||||
await show([inventory, billing]);
|
||||
const popup = await openPopup();
|
||||
fireEvent.click(within(popup).getByRole("button", { name: "Open /projects/billing in a new window" }));
|
||||
expect(mocks.execute).toHaveBeenCalledWith("file.openInNewWindow", "/projects/billing");
|
||||
});
|
||||
|
||||
it("unloads the project of the row", async () => {
|
||||
await show([inventory, billing]);
|
||||
const popup = await openPopup();
|
||||
fireEvent.click(within(popup).getByRole("button", { name: "Unload /projects/inventory" }));
|
||||
expect(mocks.unload).toHaveBeenCalledTimes(1);
|
||||
expect(mocks.unload).toHaveBeenCalledWith("/projects/inventory");
|
||||
});
|
||||
|
||||
it("unloads every listed project once with Unload All", async () => {
|
||||
await show([inventory, billing]);
|
||||
const popup = await openPopup();
|
||||
fireEvent.click(within(popup).getByRole("button", { name: "Unload All" }));
|
||||
expect(mocks.unload.mock.calls.map((c) => c[0])).toEqual(["/projects/inventory", "/projects/billing"]);
|
||||
});
|
||||
|
||||
it("closes the popup before it opens the MCP server settings", async () => {
|
||||
await show([inventory]);
|
||||
const popup = await openPopup();
|
||||
mocks.execute.mockImplementationOnce(async () => {
|
||||
expect(popup.isConnected).toBe(false);
|
||||
});
|
||||
fireEvent.click(within(popup).getByRole("button", { name: "MCP Server Settings…" }));
|
||||
expect(mocks.execute).toHaveBeenCalledWith("file.settings", "agents.mcpServer");
|
||||
expect(screen.queryByRole("dialog", { name: "Background Projects" })).toBeNull();
|
||||
});
|
||||
|
||||
it("closes the popup and hides the item when the last project unloads", async () => {
|
||||
await show([inventory]);
|
||||
await openPopup();
|
||||
mocks.list.mockResolvedValue(ok([]));
|
||||
await act(async () => emitLocalIdeEvent({ type: "mcpBackgroundProjectsChanged" }));
|
||||
expect(screen.queryByRole("dialog", { name: "Background Projects" })).toBeNull();
|
||||
expect(screen.queryByRole("button")).toBeNull();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,112 @@
|
||||
import { useRef, useState } from "react";
|
||||
import { flushSync } from "react-dom";
|
||||
import { BarButton, Icon, IconButton, Popup, T } from "@/ui";
|
||||
import { executeAction } from "@/platform/actions";
|
||||
import { useTx } from "@/platform/i18n";
|
||||
import { backgroundProjectState, unloadBackgroundProject, useBackgroundProjects } from "@/platform/mcpBackground";
|
||||
import { basename } from "@/platform/project";
|
||||
import { useRemote } from "@/platform/remote";
|
||||
import { ProjectBadge } from "@/workbench/ProjectBadge";
|
||||
import styles from "./BackgroundStatus.module.css";
|
||||
|
||||
/** Status bar item for the projects the MCP server holds open without a window. */
|
||||
export function BackgroundStatus() {
|
||||
const t = useTx();
|
||||
const loaded = useBackgroundProjects();
|
||||
// A remote window's commands reach its server, which serves none: the desktop's list stays out of it.
|
||||
const remote = useRemote((s) => s.session !== null);
|
||||
const projects = remote ? [] : loaded;
|
||||
const [open, setOpen] = useState(false);
|
||||
const ref = useRef<HTMLButtonElement>(null);
|
||||
const count = projects.length;
|
||||
|
||||
// Reset during render, so the popup does not reappear with the next project that loads.
|
||||
if (count === 0 && open) setOpen(false);
|
||||
|
||||
if (count === 0) return null;
|
||||
return (
|
||||
<>
|
||||
<BarButton
|
||||
ref={ref}
|
||||
aria-expanded={open}
|
||||
aria-label={t`Background Projects: ${count}`}
|
||||
tooltip={t("Projects the MCP server holds open without a window")}
|
||||
onClick={() => setOpen((o) => !o)}
|
||||
>
|
||||
<Icon name="layers" size={14} />
|
||||
{count}
|
||||
</BarButton>
|
||||
<Popup
|
||||
open={open}
|
||||
anchor={ref}
|
||||
placement="top-end"
|
||||
offset={6}
|
||||
onClose={() => setOpen(false)}
|
||||
aria-label={t("Background Projects")}
|
||||
>
|
||||
{/* The focus starts on the list: on a row it would swap that row's state for its actions. */}
|
||||
<div className={styles.panel} tabIndex={-1} data-autofocus>
|
||||
<div className={styles.header}>
|
||||
<T>Served without a window</T>
|
||||
</div>
|
||||
<ul className={styles.projects}>
|
||||
{projects.map((project) => {
|
||||
const path = project.root;
|
||||
const name = basename(path) || path;
|
||||
return (
|
||||
<li key={path} className={styles.project}>
|
||||
<ProjectBadge name={name} path={path} />
|
||||
<div className={styles.text}>
|
||||
<span className={styles.top}>
|
||||
<span className={styles.name} title={name}>
|
||||
{name}
|
||||
</span>
|
||||
<span className={styles.state}>{backgroundProjectState(project)}</span>
|
||||
</span>
|
||||
<span className={styles.path} title={path}>
|
||||
{path}
|
||||
</span>
|
||||
</div>
|
||||
<span className={styles.actions}>
|
||||
<IconButton
|
||||
icon="external-link"
|
||||
size="small"
|
||||
title="Open in New Window"
|
||||
aria-label={t`Open ${path} in a new window`}
|
||||
onClick={() => void executeAction("file.openInNewWindow", path)}
|
||||
/>
|
||||
<IconButton
|
||||
icon="close"
|
||||
size="small"
|
||||
title="Unload"
|
||||
aria-label={t`Unload ${path}`}
|
||||
onClick={() => unloadBackgroundProject(path)}
|
||||
/>
|
||||
</span>
|
||||
</li>
|
||||
);
|
||||
})}
|
||||
</ul>
|
||||
<div className={styles.separator} role="separator" />
|
||||
<button
|
||||
type="button"
|
||||
className={styles.action}
|
||||
onClick={() => projects.forEach((p) => unloadBackgroundProject(p.root))}
|
||||
>
|
||||
<T>Unload All</T>
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
className={styles.action}
|
||||
onClick={() => {
|
||||
flushSync(() => setOpen(false));
|
||||
void executeAction("file.settings", "agents.mcpServer");
|
||||
}}
|
||||
>
|
||||
<T>MCP Server Settings…</T>
|
||||
</button>
|
||||
</div>
|
||||
</Popup>
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -4,12 +4,21 @@ import { commands, call, onIdeEvent, ideEventsReady } from "@/platform/ipc";
|
||||
import { useProject } from "@/platform/project";
|
||||
import { useRemote } from "@/platform/remote";
|
||||
|
||||
import { registerOverlay } from "@/workbench/contributions";
|
||||
import { registerOverlay, registerStatusItem } from "@/workbench/contributions";
|
||||
import { BackgroundStatus } from "./BackgroundStatus";
|
||||
import { McpConfirmHost } from "./ConfirmDialog";
|
||||
import { denyAll, dropConfirm, handleMcpRequest } from "./requests";
|
||||
|
||||
export function activate(): () => void {
|
||||
const offOverlay = registerOverlay({ id: "mcp.confirm", component: McpConfirmHost });
|
||||
const offStatus = registerStatusItem({
|
||||
id: "mcp.background",
|
||||
align: "right",
|
||||
priority: 4,
|
||||
title: "Background Projects",
|
||||
component: BackgroundStatus,
|
||||
lightEdit: true,
|
||||
});
|
||||
const offRequests = onIdeEvent("mcpRequest", (e) => void handleMcpRequest(e.id, e.request));
|
||||
const offClosed = onIdeEvent("mcpRequestClosed", (e) => dropConfirm(e.id));
|
||||
const ready = () => {
|
||||
@@ -104,6 +113,7 @@ export function activate(): () => void {
|
||||
disposed = true;
|
||||
unload();
|
||||
offOverlay();
|
||||
offStatus();
|
||||
offRequests();
|
||||
offClosed();
|
||||
window.removeEventListener("beforeunload", unload);
|
||||
|
||||
@@ -73,8 +73,13 @@ vi.mock("@/platform/ipc", () => ({
|
||||
mcpSetFocusedEditor: state.reportFocused,
|
||||
},
|
||||
}));
|
||||
vi.mock("@/workbench/contributions", () => ({ registerOverlay: () => () => {}, editorService: vi.fn() }));
|
||||
vi.mock("@/workbench/contributions", () => ({
|
||||
registerOverlay: () => () => {},
|
||||
registerStatusItem: () => () => {},
|
||||
editorService: vi.fn(),
|
||||
}));
|
||||
vi.mock("./ConfirmDialog", () => ({ McpConfirmHost: () => null }));
|
||||
vi.mock("./BackgroundStatus", () => ({ BackgroundStatus: () => null }));
|
||||
const { activate } = await import("./index");
|
||||
|
||||
describe("MCP editor reports", () => {
|
||||
|
||||
@@ -511,6 +511,7 @@ function EditConfigsDialog() {
|
||||
aria-expanded={!collapsed.has(r.key)}
|
||||
className={styles.editItem}
|
||||
style={{ paddingLeft: 6 }}
|
||||
title={tx(r.label)}
|
||||
onClick={() => toggle(r.key)}
|
||||
onDragOver={(e) => e.preventDefault()}
|
||||
onDrop={(e) => onDrop(e, r.kind, null)}
|
||||
@@ -534,6 +535,7 @@ function EditConfigsDialog() {
|
||||
aria-expanded={!collapsed.has(r.key)}
|
||||
className={clsx(styles.editItem, sel && styles.editItemSelected)}
|
||||
style={{ paddingLeft: 22 }}
|
||||
title={r.name}
|
||||
onClick={() => setSelection({ type: "folder", kind: r.kind, name: r.name })}
|
||||
onDoubleClick={() => toggle(r.key)}
|
||||
onDragOver={(e) => e.preventDefault()}
|
||||
@@ -547,6 +549,9 @@ function EditConfigsDialog() {
|
||||
}
|
||||
const c = r.config;
|
||||
const isTomcat = c.kind === "tomcat";
|
||||
const name = c.name || tx("Unnamed");
|
||||
const target = c.target ? targetName(c, runTargets) : null;
|
||||
const scope = !c.detected && !isTomcat ? (c.local ? "local" : "user") : null;
|
||||
const tomcatNoArtifact =
|
||||
isTomcat &&
|
||||
((c.params?.deployment ?? "artifact") === "artifact"
|
||||
@@ -561,7 +566,9 @@ function EditConfigsDialog() {
|
||||
className={clsx(styles.editItem, current?.id === c.id && styles.editItemSelected)}
|
||||
style={{ paddingLeft: r.depth === 2 ? 50 : 34 }}
|
||||
onClick={() => setSelection({ type: "config", id: c.id })}
|
||||
title={commandLine(c)}
|
||||
title={[name + (target ? ` @ ${target}` : "") + (scope ? ` (${scope})` : ""), commandLine(c)]
|
||||
.filter(Boolean)
|
||||
.join("\n")}
|
||||
draggable
|
||||
onDragStart={(e) => {
|
||||
dragged.current = c.id;
|
||||
@@ -579,11 +586,9 @@ function EditConfigsDialog() {
|
||||
)}
|
||||
</span>
|
||||
<span className={styles.chooserName}>{c.name || <T>Unnamed</T>}</span>
|
||||
{c.target && <span className={styles.chooserMuted}>@ {targetName(c, runTargets)}</span>}
|
||||
{target && <span className={clsx(styles.chooserMuted, styles.editTarget)}>@ {target}</span>}
|
||||
{errorsById[c.id] && <Icon name="error" size={12} className={styles.failed} label="Invalid" />}
|
||||
{!c.detected && !isTomcat && (
|
||||
<span className={styles.chooserMuted}>{c.local ? "local" : "user"}</span>
|
||||
)}
|
||||
{scope && <span className={styles.chooserMuted}>{scope}</span>}
|
||||
</button>
|
||||
);
|
||||
})}
|
||||
|
||||
@@ -553,6 +553,7 @@
|
||||
flex: 1;
|
||||
}
|
||||
.editSidebar {
|
||||
container: run-config-navigation / inline-size;
|
||||
min-height: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
@@ -596,6 +597,22 @@
|
||||
background: var(--bg-selected-strong);
|
||||
color: var(--fg-strong);
|
||||
}
|
||||
.editTarget {
|
||||
flex: 0 1 auto;
|
||||
min-width: 0;
|
||||
max-width: 25%;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.editItem .failed {
|
||||
flex: none;
|
||||
}
|
||||
@container run-config-navigation (max-width: 220px) {
|
||||
.editItem .chooserMuted {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
.editForm {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
@@ -701,6 +718,7 @@
|
||||
}
|
||||
.editGroupName {
|
||||
color: var(--fg-strong);
|
||||
font-weight: 600;
|
||||
}
|
||||
.editEmpty {
|
||||
flex: 1;
|
||||
|
||||
@@ -12,43 +12,52 @@
|
||||
align-items: center;
|
||||
gap: var(--space-2);
|
||||
}
|
||||
.path {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
font-family: var(--font-mono);
|
||||
font-size: var(--fs-small);
|
||||
}
|
||||
/* Framed like the Folders list above it; rows as in the status bar's Background Projects popup. */
|
||||
.projects {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: var(--space-2);
|
||||
width: 100%;
|
||||
max-width: 480px;
|
||||
min-width: 0;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
border-radius: var(--radius-small);
|
||||
box-shadow: inset 0 0 0 1px var(--border-strong);
|
||||
list-style: none;
|
||||
}
|
||||
.project {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: var(--space-2);
|
||||
gap: var(--space-3);
|
||||
min-width: 0;
|
||||
padding: var(--space-2) var(--space-3);
|
||||
}
|
||||
.project + .project {
|
||||
border-top: 1px solid var(--border);
|
||||
}
|
||||
.projectText {
|
||||
display: flex;
|
||||
flex: 1;
|
||||
flex-direction: column;
|
||||
gap: var(--space-0-5);
|
||||
min-width: 0;
|
||||
}
|
||||
.projectName {
|
||||
.projectName,
|
||||
.projectPath,
|
||||
.projectState {
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
font-weight: 600;
|
||||
}
|
||||
.projectName {
|
||||
color: var(--fg-strong);
|
||||
}
|
||||
.projectPath,
|
||||
.projectState {
|
||||
color: var(--fg-subtle);
|
||||
font-size: var(--fs-small);
|
||||
}
|
||||
|
||||
.unload {
|
||||
flex: none;
|
||||
}
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
/** Built-in MCP server status and client configurations. */
|
||||
import { useEffect, useState } from "react";
|
||||
import { commands, call, isTauri, onIdeEvent, type McpServerStatus } from "@/platform/ipc";
|
||||
import { backgroundProjectState, useBackgroundProjects } from "@/platform/mcpBackground";
|
||||
import { backgroundProjectState, unloadBackgroundProject, useBackgroundProjects } from "@/platform/mcpBackground";
|
||||
import { basename, useProject } from "@/platform/project";
|
||||
import { WORKFLOW_LIMITS } from "@/platform/workflowSettings";
|
||||
import { useTx } from "@/platform/i18n";
|
||||
import { ProjectBadge } from "@/workbench/ProjectBadge";
|
||||
import { useRemote } from "@/platform/remote";
|
||||
import { Button, Input, T, copyText } from "@/ui";
|
||||
import { GlobListEditor, Row, SettingNumber, SettingSelect } from "../components/Form";
|
||||
@@ -233,7 +234,6 @@ function BackgroundOpenNow() {
|
||||
const projects = remote ? [] : loaded;
|
||||
const [mode] = useSetting<string>("mcpServer.backgroundProjects");
|
||||
const [enabled] = useSetting<boolean>("mcpServer.enabled");
|
||||
const unload = (root: string) => void call(commands.mcpUnloadBackgroundProject(root)).catch(() => undefined);
|
||||
return (
|
||||
<Row
|
||||
label="Open now"
|
||||
@@ -255,23 +255,24 @@ function BackgroundOpenNow() {
|
||||
) : (
|
||||
<ul className={styles.projects}>
|
||||
{projects.map((project) => {
|
||||
const name = basename(project.root);
|
||||
const name = basename(project.root) || project.root;
|
||||
return (
|
||||
<li key={project.root} className={styles.project}>
|
||||
<ProjectBadge name={name} path={project.root} />
|
||||
<div className={styles.projectText}>
|
||||
<span className={styles.projectName} title={name}>
|
||||
{name}
|
||||
</span>
|
||||
<span className={styles.path} title={project.root}>
|
||||
<span className={styles.projectPath} title={project.root}>
|
||||
{project.root}
|
||||
</span>
|
||||
<span className={styles.status}>{backgroundProjectState(project)}</span>
|
||||
<span className={styles.projectState}>{backgroundProjectState(project)}</span>
|
||||
</div>
|
||||
<Button
|
||||
size="small"
|
||||
className={styles.unload}
|
||||
aria-label={tx`Unload ${project.root}`}
|
||||
onClick={() => unload(project.root)}
|
||||
onClick={() => unloadBackgroundProject(project.root)}
|
||||
>
|
||||
<T>Unload</T>
|
||||
</Button>
|
||||
|
||||
@@ -1739,6 +1739,13 @@
|
||||
"Unload {path}": "Unload {path}",
|
||||
"Background projects are off": "Background projects are off",
|
||||
"A remote host serves only the project open in its window": "A remote host serves only the project open in its window",
|
||||
"Served without a window": "Served without a window",
|
||||
"Background Projects": "Background Projects",
|
||||
"Background Projects: {count}": "Background Projects: {count}",
|
||||
"Projects the MCP server holds open without a window": "Projects the MCP server holds open without a window",
|
||||
"Open {path} in a new window": "Open {path} in a new window",
|
||||
"Unload All": "Unload All",
|
||||
"MCP Server Settings…": "MCP Server Settings…",
|
||||
"The MCP server is off": "The MCP server is off",
|
||||
"Archived ({count})": "Archived ({count})",
|
||||
"Insert": "Insert",
|
||||
|
||||
@@ -8142,6 +8142,13 @@
|
||||
"Unload {path}": "卸载 {path}",
|
||||
"Background projects are off": "后台项目已关闭",
|
||||
"A remote host serves only the project open in its window": "远程主机只为其窗口中打开的项目提供服务",
|
||||
"Served without a window": "无窗口提供服务",
|
||||
"Background Projects": "后台项目",
|
||||
"Background Projects: {count}": "后台项目:{count}",
|
||||
"Projects the MCP server holds open without a window": "MCP 服务器在没有窗口的情况下保持打开的项目",
|
||||
"Open {path} in a new window": "在新窗口中打开 {path}",
|
||||
"Unload All": "全部卸载",
|
||||
"MCP Server Settings…": "MCP 服务器设置…",
|
||||
"The MCP server is off": "MCP 服务器已关闭",
|
||||
"Archived ({count})": "归档({count})",
|
||||
"Insert": "插入",
|
||||
|
||||
@@ -23,6 +23,11 @@ export function backgroundProjectState(project: McpBackgroundProject): string {
|
||||
return tx`Idle ${n} min, unloads in ${m} min`;
|
||||
}
|
||||
|
||||
/** Unloads one background project at once; one that is not loaded is already unloaded. */
|
||||
export function unloadBackgroundProject(root: string): void {
|
||||
void call(commands.mcpUnloadBackgroundProject(root)).catch(() => undefined);
|
||||
}
|
||||
|
||||
/**
|
||||
* The background projects, current: fetched on mount and when the backend reports a change, and every 30 s
|
||||
* while any is loaded, every 3 s while one answers a request (the end of a request and an idle project's
|
||||
|
||||
@@ -312,6 +312,7 @@ const ICONS = {
|
||||
"page-first": "openidea/general/pageFirst",
|
||||
"page-last": "openidea/general/pageLast",
|
||||
sliders: "openidea/general/sliders",
|
||||
layers: "openidea/general/layers",
|
||||
"graphql-variables": "openidea/general/graphqlVariables",
|
||||
layout: "general/layout",
|
||||
split: "general/splitVertically",
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
<!-- OpenIDEA: Layers (stacked planes) -->
|
||||
<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<path d="M8 2L13.5 4.75L8 7.5L2.5 4.75L8 2Z" stroke="#6C707E" stroke-linejoin="round"/><path d="M2.5 7.5L8 10.25L13.5 7.5M2.5 10.25L8 13L13.5 10.25" stroke="#6C707E" stroke-linecap="round" stroke-linejoin="round"/>
|
||||
</svg>
|
||||
|
Після Ширина: | Висота: | Розмір: 361 B |
@@ -0,0 +1,14 @@
|
||||
.badge {
|
||||
display: flex;
|
||||
flex: none;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 26px;
|
||||
height: 26px;
|
||||
border-radius: var(--radius-selection);
|
||||
background: linear-gradient(135deg, var(--project-color), var(--project-color-end));
|
||||
color: var(--fg-button-primary);
|
||||
font-size: var(--fs-tiny);
|
||||
font-weight: 600;
|
||||
letter-spacing: 0.02em;
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
import { useSyncExternalStore } from "react";
|
||||
import clsx from "clsx";
|
||||
import { projectInitials } from "./projectColor";
|
||||
import { subscribeTabColors, tabColorOverride, tabColorVars, tabColorsVersion } from "./tabColors";
|
||||
import styles from "./ProjectBadge.module.css";
|
||||
|
||||
/** Square project avatar for a two-line row: the title bar widget's colour and initials. */
|
||||
export function ProjectBadge({ name, path, className }: { name: string; path: string; className?: string }) {
|
||||
useSyncExternalStore(subscribeTabColors, tabColorsVersion);
|
||||
return (
|
||||
<span className={clsx(styles.badge, className)} style={tabColorVars(name, tabColorOverride(path))} aria-hidden>
|
||||
{projectInitials(name)}
|
||||
</span>
|
||||
);
|
||||
}
|
||||
@@ -29,11 +29,14 @@
|
||||
min-width: 0;
|
||||
padding: 0 4px;
|
||||
}
|
||||
/* Left items (breadcrumbs…) give way first on narrow windows; right items move into the overflow popup. */
|
||||
/* Left items shrink on narrow windows; right items move into the overflow popup. */
|
||||
.shrink {
|
||||
flex: 0 1 auto;
|
||||
overflow: hidden;
|
||||
}
|
||||
.shrink[data-status-item="editor.breadcrumbs"]:not(:empty) {
|
||||
min-width: min(152px, 28vw);
|
||||
}
|
||||
.shrink > * {
|
||||
min-width: 0;
|
||||
overflow: hidden;
|
||||
|
||||
@@ -112,22 +112,24 @@ export function StatusBar({ lightEdit = false }: { lightEdit?: boolean }) {
|
||||
return () => ro.disconnect();
|
||||
}, []);
|
||||
useLayoutEffect(() => {
|
||||
const leftHosts = [...(barRef.current?.querySelectorAll<HTMLElement>(":scope > [data-status-item]") ?? [])];
|
||||
measure.current = () => {
|
||||
const bar = barRef.current;
|
||||
if (!bar) return;
|
||||
const css = getComputedStyle(bar);
|
||||
const gap = parseFloat(css.columnGap) || 0;
|
||||
const spacer = spacerRef.current;
|
||||
// Left items shrink instead (down to their gap); the spacer keeps its minimum.
|
||||
const leftShown = [...bar.querySelectorAll<HTMLElement>(":scope > [data-status-item]")].filter(
|
||||
(el) => el.getClientRects().length > 0,
|
||||
).length;
|
||||
const leftWidth = leftHosts.reduce(
|
||||
(width, el) =>
|
||||
el.getClientRects().length ? width + (parseFloat(getComputedStyle(el).minWidth) || 0) + gap : width,
|
||||
0,
|
||||
);
|
||||
const available =
|
||||
bar.clientWidth -
|
||||
(parseFloat(css.paddingLeft) || 0) -
|
||||
(parseFloat(css.paddingRight) || 0) -
|
||||
(spacer ? parseFloat(getComputedStyle(spacer).minWidth) || 0 : 0) -
|
||||
leftShown * gap;
|
||||
leftWidth;
|
||||
const items = shownRight.map((i) => ({
|
||||
id: i.id,
|
||||
priority: i.priority,
|
||||
@@ -146,6 +148,7 @@ export function StatusBar({ lightEdit = false }: { lightEdit?: boolean }) {
|
||||
}
|
||||
// The spacer changes width whenever an item comes or goes; the bar, when the window resizes.
|
||||
for (const el of [spacerRef.current, barRef.current, moreRef.current]) if (el) ro?.observe(el);
|
||||
for (const el of leftHosts) ro?.observe(el);
|
||||
});
|
||||
|
||||
const renderLeft = (item: StatusItemContribution) => {
|
||||
|
||||
Reference in new issue
Заблокувати користувача