Порівняти коміти

...
Автор SHA1 Повідомлення Дата
l0ng-ai 7af0ff3754 fix(editor): don't indent C++ namespace and extern "C" contents on Enter
Enter inside `namespace x { … }` or `extern "C" { … }` indented the new line
one level, like any brace body. clang-format's built-in styles (LLVM, Google,
Chromium, Mozilla, Microsoft, GNU) keep those contents at the level of the
braces' line (NamespaceIndentation: None), so the editor now does too; other
brace bodies keep their indentation.

Fixes #3993
2026-11-17 22:09:46 +08:00
l0ng-ai d4f6114be1 feat(settings): context menu for the deployment server list (#4017)
Right-clicking a server or server group in Settings › Build, Execution, Deployment › Deployment selects it and offers Add (Server / Server Group), Duplicate and Use as Default for a server, and Remove; the empty part of the list offers Add.

Closes #3910
2026-11-17 22:03:35 +08:00
l0ng-ai ad93e491c9 feat(settings): choose PHP include paths with a folder chooser (#4016)
+ under Settings › Languages & Frameworks › PHP › Include paths opens a folder chooser and adds the picked folder; Edit and double-click still take a typed path, and outside the desktop app + keeps adding a row to type into. Additional stubs are stub names, so that list stays typed.

Closes #3912
2026-11-17 22:00:43 +08:00
9 змінених файлів з 237 додано та 17 видалено

No files matched your search

+23
Переглянути файл
@@ -1,6 +1,7 @@
import { EditorState } from "@codemirror/state";
import { LanguageDescription, type Language } from "@codemirror/language";
import { describe, expect, it } from "vitest";
import { getIndentation } from "@codemirror/language";
import { highlightTree, tagHighlighter, tags as t } from "@lezer/highlight";
import { logWarning } from "./highlight";
import { fencedCodeMode, findLanguageDescription, loadSupport } from "./languages";
@@ -271,6 +272,28 @@ describe("language modes", () => {
}
});
it('keeps C++ namespace and extern "C" contents at the level of their braces', async () => {
const support = await loadSupport(findLanguageDescription("C++", "/p/a.cpp")!);
const doc = [
"namespace foo {",
"class Bar {",
" int x;",
"};",
"namespace inner {",
"void f() {",
" g();",
"}",
"} // namespace inner",
"} // namespace foo",
'extern "C" {',
"int h();",
"}",
].join("\n");
const state = EditorState.create({ doc, extensions: [support!, EditorState.tabSize.of(2)] });
const indent = (line: number) => getIndentation(state, state.doc.line(line).from);
expect([2, 3, 4, 5, 6, 7, 9, 10, 12, 13].map(indent)).toEqual([0, 2, 0, 0, 0, 2, 0, 0, 0, 0]);
});
it("colours `this`, `super` and Rust's `self` as keywords", async () => {
const highlighter = tagHighlighter([
{ tag: t.keyword, class: "keyword" },
+21 -3
Переглянути файл
@@ -11,6 +11,8 @@ import {
LanguageDescription,
LanguageSupport,
StreamLanguage,
delimitedIndent,
indentNodeProp,
indentService,
language as languageFacet,
type StreamParser,
@@ -421,12 +423,28 @@ const EXTRA_TAGS: Record<string, Parameters<typeof styleTags>[0]> = {
YAML: { "Key/Literal Key/QuotedLiteral": t.keyword },
};
const bracedIndent = delimitedIndent({ closing: "}" });
/** Grammar props the stock languages lack: indentation that follows the language's usual style. */
const EXTRA_PROPS: Record<string, NonNullable<Parameters<LRLanguage["configure"]>[0]["props"]>> = {
// clang-format's built-in styles (NamespaceIndentation: None, no extern block indent) keep the
// contents of `namespace x { … }` and `extern "C" { … }` at the level of the braces' line.
"C++": [
indentNodeProp.add({
// The stock rule for every `{ … }` body, except the bodies of these two.
CompoundStatement: (cx) =>
cx.node.parent?.name === "NamespaceDefinition" || cx.node.parent?.name === "LinkageSpecification"
? cx.baseIndent
: bracedIndent(cx),
}),
],
};
function patchSupport(desc: LanguageDescription, support: LanguageSupport): LanguageSupport {
const extra = EXTRA_TAGS[desc.name];
const props = [...(extra ? [styleTags(extra)] : []), ...(EXTRA_PROPS[desc.name] ?? [])];
const language =
extra && support.language instanceof LRLanguage
? support.language.configure({ props: [styleTags(extra)] })
: support.language;
props.length && support.language instanceof LRLanguage ? support.language.configure({ props }) : support.language;
const result = new LanguageSupport(language, [
support.support,
docCommentTags(desc.name),
+70
Переглянути файл
@@ -0,0 +1,70 @@
import { act, cleanup, fireEvent, render, screen } from "@testing-library/react";
import type { ComponentType } from "react";
import { afterEach, beforeEach, expect, it } from "vitest";
import { DEFAULT_DEPLOYMENT_SERVER } from "@/platform/remoteSettings";
import { useContextMenuStore } from "@/ui";
import { PageContext } from "../components/context";
import { DEFAULT_SETTINGS } from "../model/schema";
import { stagedValue, useSettingsDialog } from "../model/staging";
import { DEPLOYMENT_PAGES } from "../pages/deployment";
const server = (id: string, name: string) => ({ ...DEFAULT_DEPLOYMENT_SERVER, id, name });
beforeEach(() => {
const base = structuredClone(DEFAULT_SETTINGS) as typeof DEFAULT_SETTINGS & { deployment: Record<string, unknown> };
base.deployment = { ...base.deployment, servers: [server("a", "Alpha"), server("b", "Beta")], defaultServer: "a" };
useSettingsDialog.setState({ base, globalBase: structuredClone(DEFAULT_SETTINGS), staged: {}, query: "" });
});
afterEach(() => {
act(() => useContextMenuStore.setState({ menu: null }));
cleanup();
});
function renderList() {
const page = DEPLOYMENT_PAGES.find((p) => p.id === "build.deployment")!;
const option = page
.sections!.flatMap((s) => s.options)
.find((o) => o.kind === "custom" && o.label === "Deployment servers");
const Editor = (option as unknown as { component: ComponentType }).component;
render(
<PageContext.Provider value={{ pageId: page.id, scope: "project" }}>
<Editor />
</PageContext.Provider>,
);
}
const menuItem = (label: string) => {
const item = useContextMenuStore.getState().menu!.items.find((i) => "label" in i && i.label === label) as {
run?: () => void;
disabled?: boolean;
};
return item;
};
const staged = (key: string) => stagedValue(useSettingsDialog.getState(), "project", key);
it("offers Add, Duplicate, Use as Default and Remove on a server row", () => {
renderList();
fireEvent.contextMenu(screen.getByRole("option", { name: /Beta/ }));
expect(screen.getByRole("option", { name: /Beta/ })).toHaveAttribute("aria-selected", "true");
expect(menuItem("Add")).toBeDefined();
act(() => menuItem("Use as Default").run!());
expect(staged("deployment.defaultServer")).toBe("b");
fireEvent.contextMenu(screen.getByRole("option", { name: /Beta/ }));
expect(menuItem("Use as Default").disabled).toBe(true);
act(() => menuItem("Duplicate").run!());
expect((staged("deployment.servers") as { name: string }[]).map((s) => s.name)).toEqual([
"Alpha",
"Beta",
"Beta (copy)",
]);
fireEvent.contextMenu(screen.getByRole("option", { name: /Alpha/ }));
act(() => menuItem("Remove").run!());
expect((staged("deployment.servers") as { name: string }[]).map((s) => s.name)).toEqual(["Beta", "Beta (copy)"]);
});
it("only adds from the empty part of the list", () => {
renderList();
fireEvent.contextMenu(screen.getByRole("listbox", { name: "Deployment servers" }));
const labels = useContextMenuStore.getState().menu!.items.map((i) => ("label" in i ? i.label : i.kind));
expect(labels).toEqual(["Add"]);
});
+37
Переглянути файл
@@ -0,0 +1,37 @@
import { beforeEach, expect, it, vi } from "vitest";
import { act, fireEvent, render, screen } from "@testing-library/react";
const { choose, tauri } = vi.hoisted(() => ({ choose: vi.fn(), tauri: { on: true } }));
vi.mock("@/platform/choosePath", () => ({ choosePath: choose }));
vi.mock("@/platform/ipc", async (original) => ({
...(await original<typeof import("@/platform/ipc")>()),
isTauri: () => tauri.on,
}));
import { GlobListEditor } from "../components/Form";
beforeEach(() => {
choose.mockReset();
tauri.on = true;
});
const browse = { directory: true, title: "Choose Include Path" };
it("adds the folder picked in the chooser and leaves the list alone when it is cancelled", async () => {
const onChange = vi.fn();
choose.mockResolvedValueOnce("/opt/platform").mockResolvedValueOnce(null);
render(<GlobListEditor value={["/a"]} onChange={onChange} browse={browse} aria-label="Include paths" />);
await act(async () => fireEvent.click(screen.getByRole("button", { name: "Add" })));
expect(choose).toHaveBeenCalledWith({ directory: true, title: "Choose Include Path" });
expect(onChange).toHaveBeenCalledWith(["/a", "/opt/platform"]);
await act(async () => fireEvent.click(screen.getByRole("button", { name: "Add" })));
expect(onChange).toHaveBeenCalledTimes(1);
expect(screen.queryByRole("textbox")).not.toBeInTheDocument();
});
it("types the path inline without a chooser", async () => {
tauri.on = false;
render(<GlobListEditor value={[]} onChange={vi.fn()} browse={browse} itemLabel="Include path" />);
await act(async () => fireEvent.click(screen.getByRole("button", { name: "Add" })));
expect(choose).not.toHaveBeenCalled();
expect(screen.getByRole("textbox", { name: "Include path" })).toBeInTheDocument();
});
+19 -6
Переглянути файл
@@ -7,6 +7,8 @@ import { useId, useRef, useState, type KeyboardEvent, type ReactNode } from "rea
import clsx from "clsx";
import { Checkbox, IconButton, Input, Select as UiSelect, type SelectOption, T } from "@/ui";
import { tx, useTx } from "@/platform/i18n";
import { choosePath } from "@/platform/choosePath";
import { isTauri } from "@/platform/ipc";
import { highlightIndices } from "../model/pages";
import { HEX_COLOR } from "../model/schema";
import { useLabelMatch, useSearchQuery, useSetting } from "./context";
@@ -303,6 +305,8 @@ export interface GlobListEditorProps {
emptyText?: string;
/** Accessible name of the inline editor. */
itemLabel?: string;
/** Entries are paths: + opens this chooser (Edit still takes typing). */
browse?: { directory: boolean; title: string };
}
/** Editable list of glob patterns (+ / − / edit toolbar, inline editing); also plain string lists. */
@@ -312,6 +316,7 @@ export function GlobListEditor({
placeholder = "**/pattern",
emptyText = "No patterns",
itemLabel = "Pattern",
browse,
...aria
}: GlobListEditorProps) {
const [selected, setSelected] = useState<number | null>(null);
@@ -340,6 +345,19 @@ export function GlobListEditor({
setEditing(null);
};
const add = async () => {
// Outside the desktop app there is no chooser: type the path instead.
if (!browse || !isTauri()) {
setEditing({ index: value.length, text: "" });
return;
}
const picked = await choosePath({ ...browse, title: tx(browse.title) });
if (!picked) return;
const next = [...new Set([...value, picked])];
onChange(next);
setSelected(next.indexOf(picked));
};
const remove = () => {
if (selected === null) return;
const next = value.filter((_, i) => i !== selected);
@@ -380,12 +398,7 @@ export function GlobListEditor({
return (
<div className={styles.globEditor}>
<div className={styles.listToolbar} role="toolbar" aria-controls={listId}>
<IconButton
icon="plus"
title="Add"
size="small"
onClick={() => setEditing({ index: value.length, text: "" })}
/>
<IconButton icon="plus" title="Add" size="small" onClick={() => void add()} />
<IconButton icon="minus" title="Remove" size="small" disabled={selected === null} onClick={remove} />
<IconButton
icon="edit"
+1
Переглянути файл
@@ -221,6 +221,7 @@ export function PhpPage() {
emptyText="No include paths"
itemLabel="Include path"
aria-label="Include paths"
browse={{ directory: true, title: "Choose Include Path" }}
/>
</Row>
<Row
+62 -6
Переглянути файл
@@ -3,7 +3,7 @@
* mappings, excluded remote paths) and the transfer options. Consumed by the
* deployment feature and `ide-remote` (automatic upload, remote delete).
*/
import { useEffect, useId, useState, type KeyboardEvent } from "react";
import { useEffect, useId, useState, type KeyboardEvent, type MouseEvent as ReactMouseEvent } from "react";
import clsx from "clsx";
import { call, commands, IpcError, isTauri, type FsConnection, type RemoteEntry } from "@/platform/ipc";
import { useTx, tx, txTemplate } from "@/platform/i18n";
@@ -30,6 +30,7 @@ import {
Spinner,
T,
Tabs,
type MenuItem,
} from "@/ui";
import { GlobListEditor, Row } from "../components/Form";
import { SshConfigSelect, useSshConfigs } from "../components/SshConfigSelect";
@@ -769,6 +770,26 @@ function DeploymentServersEditor() {
setGroups([...groupList, group]);
setSelected({ kind: "group", id: group.id });
};
const removeTarget = (target: Selection) => {
if (!target) return;
if (target.kind === "group") {
const group = groupList.find((g) => g.id === target.id);
if (!group) return;
const index = groupList.indexOf(group);
const rest = groupList.filter((g) => g.id !== group.id);
setGroups(rest);
const next = rest[Math.min(index, rest.length - 1)] ?? null;
setSelected(next ? { kind: "group", id: next.id } : list[0] ? { kind: "server", id: list[0].id } : null);
return;
}
const server = list.find((s) => s.id === target.id);
if (!server) return;
const index = list.indexOf(server);
const rest = list.filter((s) => s.id !== server.id);
commit(rest);
const next = rest[Math.min(index, rest.length - 1)] ?? null;
setSelected(next ? { kind: "server", id: next.id } : null);
};
const remove = () => {
if (currentGroup) {
const index = groupList.indexOf(currentGroup);
@@ -786,6 +807,34 @@ function DeploymentServersEditor() {
setSelected(next ? { kind: "server", id: next.id } : null);
};
const isSelected = (kind: "server" | "group", id: string) => selected?.kind === kind && selected.id === id;
const addItems: MenuItem[] = [
{ label: "Server", icon: "web", run: () => add() },
{ label: "Server Group", icon: "folder", run: addGroup },
];
// Right-click on a row works on that row (it is selected first); on the empty list it only adds.
const rowMenu = (e: ReactMouseEvent, target: Selection) => {
e.preventDefault();
e.stopPropagation();
setSelected(target);
const server = target?.kind === "server" ? list.find((s) => s.id === target.id) : undefined;
showContextMenu(e, [
{ label: "Add", icon: "plus", submenu: addItems },
...(server
? [
{ label: "Duplicate", icon: "copy", run: () => add(server) } as MenuItem,
{
label: "Use as Default",
icon: "check",
disabled: server.id === effectiveDefault,
run: () => setDefaultServer(server.id),
} as MenuItem,
]
: []),
{ kind: "separator" },
// `remove` acts on the selection, which the state update above has not applied yet.
{ label: "Remove", icon: "minus", run: () => removeTarget(target) },
]);
};
return (
<div className={styles.layout}>
@@ -797,10 +846,7 @@ function DeploymentServersEditor() {
size="small"
onClick={(e) => {
const r = e.currentTarget.getBoundingClientRect();
showContextMenu({ x: r.left, y: r.bottom }, [
{ label: "Server", icon: "web", run: () => add() },
{ label: "Server Group", icon: "folder", run: addGroup },
]);
showContextMenu({ x: r.left, y: r.bottom }, addItems);
}}
/>
<IconButton icon="minus" title="Remove" size="small" disabled={!current && !currentGroup} onClick={remove} />
@@ -819,7 +865,15 @@ function DeploymentServersEditor() {
onClick={() => current && setDefaultServer(current.id)}
/>
</div>
<div className={styles.serverList} role="listbox" aria-label={tx("Deployment servers")}>
<div
className={styles.serverList}
role="listbox"
aria-label={tx("Deployment servers")}
onContextMenu={(e) => {
e.preventDefault();
showContextMenu(e, [{ label: "Add", icon: "plus", submenu: addItems }]);
}}
>
{list.length === 0 && groupList.length === 0 && (
<div className={styles.empty}>
<T>No servers. Click + to add one.</T>
@@ -832,6 +886,7 @@ function DeploymentServersEditor() {
aria-selected={isSelected("group", g.id)}
className={clsx(styles.serverRow, isSelected("group", g.id) && styles.serverSelected)}
onMouseDown={() => setSelected({ kind: "group", id: g.id })}
onContextMenu={(e) => rowMenu(e, { kind: "group", id: g.id })}
>
<Icon name="folder" />
<span className={styles.serverName}>{g.name || g.id}</span>
@@ -845,6 +900,7 @@ function DeploymentServersEditor() {
aria-selected={isSelected("server", s.id)}
className={clsx(styles.serverRow, isSelected("server", s.id) && styles.serverSelected)}
onMouseDown={() => setSelected({ kind: "server", id: s.id })}
onContextMenu={(e) => rowMenu(e, { kind: "server", id: s.id })}
>
<Icon name="web" />
<span className={clsx(styles.serverName, s.id === effectiveDefault && styles.default)}>
+2 -1
Переглянути файл
@@ -2381,5 +2381,6 @@
"Commit Message Generation": "Commit Message Generation",
"Instructions for Generate Commit Message with Agent": "Instructions for Generate Commit Message with Agent",
"Added to the agent's prompt, e.g. a commit format, issue key prefixes or the language to write in.": "Added to the agent's prompt, e.g. a commit format, issue key prefixes or the language to write in.",
"Use Conventional Commits (feat:, fix:, …) and start with the issue key if the branch has one.": "Use Conventional Commits (feat:, fix:, …) and start with the issue key if the branch has one."
"Use Conventional Commits (feat:, fix:, …) and start with the issue key if the branch has one.": "Use Conventional Commits (feat:, fix:, …) and start with the issue key if the branch has one.",
"Choose Include Path": "Choose Include Path"
}
+2 -1
Переглянути файл
@@ -8759,5 +8759,6 @@
"Commit Message Generation": "提交信息生成",
"Instructions for Generate Commit Message with Agent": "用 Agent 生成提交信息时的要求",
"Added to the agent's prompt, e.g. a commit format, issue key prefixes or the language to write in.": "会加到 Agent 的提示词里,例如提交格式、问题编号前缀或使用的语言。",
"Use Conventional Commits (feat:, fix:, …) and start with the issue key if the branch has one.": "使用 Conventional Commits(feat:、fix: 等),分支带问题编号时以它开头。"
"Use Conventional Commits (feat:, fix:, …) and start with the issue key if the branch has one.": "使用 Conventional Commits(feat:、fix: 等),分支带问题编号时以它开头。",
"Choose Include Path": "选择包含路径"
}