Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions apps/server/src/open.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@ describe("resolveEditorLaunch", () => {
args: ["/tmp/workspace"],
});

const traeLaunch = yield* resolveEditorLaunch(
{ cwd: "/tmp/workspace", editor: "trae" },
"darwin",
);
assert.deepEqual(traeLaunch, {
command: "trae",
args: ["/tmp/workspace"],
});

const zedLaunch = yield* resolveEditorLaunch(
{ cwd: "/tmp/workspace", editor: "zed" },
"darwin",
Expand Down Expand Up @@ -74,6 +83,15 @@ describe("resolveEditorLaunch", () => {
args: ["--goto", "/tmp/workspace/src/open.ts:71:5"],
});

const traeLineAndColumn = yield* resolveEditorLaunch(
{ cwd: "/tmp/workspace/src/open.ts:71:5", editor: "trae" },
"darwin",
);
assert.deepEqual(traeLineAndColumn, {
command: "trae",
args: ["/tmp/workspace/src/open.ts:71:5"],
});

const zedLineAndColumn = yield* resolveEditorLaunch(
{ cwd: "/tmp/workspace/src/open.ts:71:5", editor: "zed" },
"darwin",
Expand Down
24 changes: 22 additions & 2 deletions apps/web/src/components/ChatView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ import {
Icon,
OpenAI,
OpenCodeIcon,
TraeIcon,
VisualStudioCode,
Zed,
} from "./Icons";
Expand Down Expand Up @@ -6056,6 +6057,11 @@ const OpenInPicker = memo(function OpenInPicker({
Icon: CursorIcon,
value: "cursor",
},
{
label: "Trae",
Icon: TraeIcon,
value: "trae",
},
{
label: "VS Code",
Icon: VisualStudioCode,
Expand Down Expand Up @@ -6087,6 +6093,15 @@ const OpenInPicker = memo(function OpenInPicker({
? lastEditor
: (options[0]?.value ?? null);
const primaryOption = options.find(({ value }) => value === effectiveEditor) ?? null;
const getEditorIconClassName = useCallback(
(editor: EditorId, surface: "button" | "menu") => {
if (surface === "button") {
return editor === "trae" ? "size-4" : "size-3.5";
}
return cn("text-muted-foreground", editor === "trae" && "size-5 sm:size-4.5");
},
[],
);

const openInEditor = useCallback(
(editorId: EditorId | null) => {
Expand Down Expand Up @@ -6128,7 +6143,12 @@ const OpenInPicker = memo(function OpenInPicker({
disabled={!effectiveEditor || !openInCwd}
onClick={() => openInEditor(effectiveEditor)}
>
{primaryOption?.Icon && <primaryOption.Icon aria-hidden="true" className="size-3.5" />}
{primaryOption?.Icon && (
<primaryOption.Icon
aria-hidden="true"
className={getEditorIconClassName(primaryOption.value, "button")}
/>
)}
<span className="sr-only @sm/header-actions:not-sr-only @sm/header-actions:ml-0.5">
Open
</span>
Expand All @@ -6142,7 +6162,7 @@ const OpenInPicker = memo(function OpenInPicker({
{options.length === 0 && <MenuItem disabled>No installed editors found</MenuItem>}
{options.map(({ label, Icon, value }) => (
<MenuItem key={value} onClick={() => openInEditor(value)}>
<Icon aria-hidden="true" className="text-muted-foreground" />
<Icon aria-hidden="true" className={getEditorIconClassName(value, "menu")} />
{label}
{value === effectiveEditor && openFavoriteEditorShortcutLabel && (
<MenuShortcut>{openFavoriteEditorShortcutLabel}</MenuShortcut>
Expand Down
10 changes: 10 additions & 0 deletions apps/web/src/components/Icons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@ export const CursorIcon: Icon = (props) => (
</svg>
);

export const TraeIcon: Icon = (props) => (
<svg {...props} viewBox="0 0 24 24" fill="currentColor">
<path
fillRule="evenodd"
clipRule="evenodd"
d="M24 20.541H3.428v-3.426H0V3.4h24V20.54zM3.428 17.115h17.144V6.827H3.428v10.288zm8.573-5.196-2.425 2.424-2.424-2.424 2.424-2.424 2.425 2.424zm6.857-.001-2.424 2.423-2.425-2.423 2.425-2.425 2.424 2.425z"
/>
</svg>
);

export const VisualStudioCode: Icon = (props) => {
const id = useId();
const maskId = `${id}-vscode-a`;
Expand Down
43 changes: 43 additions & 0 deletions apps/web/src/test/setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
class MemoryStorage implements Storage {
readonly #values = new Map<string, string>();

get length(): number {
return this.#values.size;
}

clear(): void {
this.#values.clear();
}

getItem(key: string): string | null {
return this.#values.get(key) ?? null;
}

key(index: number): string | null {
return Array.from(this.#values.keys())[index] ?? null;
}

removeItem(key: string): void {
this.#values.delete(key);
}

setItem(key: string, value: string): void {
this.#values.set(key, String(value));
}
}

const storageLike = globalThis.localStorage;
const hasCompleteStorageApi =
typeof storageLike?.getItem === "function" &&
typeof storageLike.setItem === "function" &&
typeof storageLike.removeItem === "function" &&
typeof storageLike.clear === "function" &&
typeof storageLike.key === "function";

if (!hasCompleteStorageApi) {
Object.defineProperty(globalThis, "localStorage", {
configurable: true,
writable: true,
value: new MemoryStorage(),
});
}
12 changes: 12 additions & 0 deletions apps/web/vitest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { defineConfig, mergeConfig } from "vitest/config";

import viteConfig from "./vite.config";

export default mergeConfig(
viteConfig,
defineConfig({
test: {
setupFiles: ["./src/test/setup.ts"],
},
}),
);
1 change: 0 additions & 1 deletion bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/contracts/src/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { TrimmedNonEmptyString } from "./baseSchemas";

export const EDITORS = [
{ id: "cursor", label: "Cursor", command: "cursor" },
{ id: "trae", label: "Trae", command: "trae" },
{ id: "vscode", label: "VS Code", command: "code" },
{ id: "zed", label: "Zed", command: "zed" },
{ id: "file-manager", label: "File Manager", command: null },
Expand Down
28 changes: 22 additions & 6 deletions scripts/build-desktop-artifact.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,14 @@ import { BRAND_ASSET_PATHS } from "./lib/brand-assets.ts";
import { resolveCatalogDependencies } from "./lib/resolve-catalog.ts";

import * as NodeRuntime from "@effect/platform-node/NodeRuntime";
import * as NodeServices from "@effect/platform-node/NodeServices";
import * as NodeChildProcessSpawner from "@effect/platform-node/NodeChildProcessSpawner";
import * as NodeFileSystem from "@effect/platform-node/NodeFileSystem";
import * as NodePath from "@effect/platform-node/NodePath";
import * as NodeStdio from "@effect/platform-node/NodeStdio";
import * as NodeTerminal from "@effect/platform-node/NodeTerminal";
import { Config, Data, Effect, FileSystem, Layer, Logger, Option, Path, Schema } from "effect";
import { Command, Flag } from "effect/unstable/cli";
import type { Environment as CliEnvironment } from "effect/unstable/cli/Command";
import { ChildProcess, ChildProcessSpawner } from "effect/unstable/process";

const BuildPlatform = Schema.Literals(["mac", "linux", "win"]);
Expand Down Expand Up @@ -771,10 +776,21 @@ const buildDesktopArtifactCli = Command.make("build-desktop-artifact", {
Command.withHandler((input) => Effect.flatMap(resolveBuildOptions(input), buildDesktopArtifact)),
);

const cliRuntimeLayer = Layer.mergeAll(Logger.layer([Logger.consolePretty()]), NodeServices.layer);
const childProcessRuntimeLayer = NodeChildProcessSpawner.layer.pipe(
Layer.provideMerge(NodeFileSystem.layer),
Layer.provideMerge(NodePath.layer),
);

const cliRuntimeLayer = Layer.mergeAll(
childProcessRuntimeLayer,
NodeStdio.layer,
NodeTerminal.layer,
Logger.layer([Logger.consolePretty()]),
);

Command.run(buildDesktopArtifactCli, { version: "0.0.0" }).pipe(
Effect.scoped,
Effect.provide(cliRuntimeLayer),
NodeRuntime.runMain,
const runtimeProgram = Effect.provide(
Effect.scoped(Command.run(buildDesktopArtifactCli, { version: "0.0.0" })),
cliRuntimeLayer as Layer.Layer<CliEnvironment>,
);

NodeRuntime.runMain(runtimeProgram);
24 changes: 18 additions & 6 deletions scripts/dev-runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,15 @@
import { homedir } from "node:os";

import * as NodeRuntime from "@effect/platform-node/NodeRuntime";
import * as NodeServices from "@effect/platform-node/NodeServices";
import * as NodeChildProcessSpawner from "@effect/platform-node/NodeChildProcessSpawner";
import * as NodeFileSystem from "@effect/platform-node/NodeFileSystem";
import * as NodePath from "@effect/platform-node/NodePath";
import * as NodeStdio from "@effect/platform-node/NodeStdio";
import * as NodeTerminal from "@effect/platform-node/NodeTerminal";
import { NetService } from "@t3tools/shared/Net";
import { Config, Data, Effect, Hash, Layer, Logger, Option, Path, Schema } from "effect";
import { Argument, Command, Flag } from "effect/unstable/cli";
import type { Environment as CliEnvironment } from "effect/unstable/cli/Command";
import { ChildProcess } from "effect/unstable/process";

const BASE_SERVER_PORT = 3773;
Expand Down Expand Up @@ -536,15 +541,22 @@ const devRunnerCli = Command.make("dev-runner", {
Command.withHandler((input) => runDevRunnerWithInput(input)),
);

const childProcessRuntimeLayer = NodeChildProcessSpawner.layer.pipe(
Layer.provideMerge(NodeFileSystem.layer),
Layer.provideMerge(NodePath.layer),
);

const cliRuntimeLayer = Layer.mergeAll(
Logger.layer([Logger.consolePretty()]),
NodeServices.layer,
childProcessRuntimeLayer,
NodeStdio.layer,
NodeTerminal.layer,
NetService.layer,
Logger.layer([Logger.consolePretty()]),
);

const runtimeProgram = Command.run(devRunnerCli, { version: "0.0.0" }).pipe(
Effect.scoped,
Effect.provide(cliRuntimeLayer),
const runtimeProgram = Effect.provide(
Effect.scoped(Command.run(devRunnerCli, { version: "0.0.0" })),
cliRuntimeLayer as Layer.Layer<CliEnvironment | NetService>,
);

if (import.meta.main) {
Expand Down