Skip to content
Draft
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
113 changes: 113 additions & 0 deletions apps/server/src/process/externalLauncher.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1313,3 +1313,116 @@ it.effect("starts a Windows command shim for unicode paths with cmd metacharacte
);
}),
);

// Windows drive letters cannot resolve the POSIX editor stub.
it.effect.skipIf(windowsHost)("neovide roots folders and positions files", () =>
Effect.gen(function* () {
const fs = yield* FileSystem.FileSystem;
const path = yield* Path.Path;
const binDir = yield* fs.makeTempDirectoryScoped({ prefix: "t3-editor-neovide-" });
const executable = path.join(binDir, "neovide");
yield* fs.writeFileString(executable, "#!/bin/sh\n");
yield* fs.chmod(executable, 0o755);

const spawnFor = (cwd: string) =>
Effect.gen(function* () {
let spawned: ChildProcess.StandardCommand | undefined;
yield* Effect.gen(function* () {
const launcher = yield* ExternalLauncher.ExternalLauncher;
yield* launcher.launchEditor({ editor: "neovide", cwd });
}).pipe(
Effect.provide(
layerTest({
platform: "darwin",
env: { PATH: binDir },
onSpawn: (command) => {
spawned = command;
},
}),
),
);
return spawned;
});

const folderSpawn = yield* spawnFor(binDir);
assert.deepEqual(folderSpawn?.args, [binDir]);
assert.equal(folderSpawn?.options.cwd, binDir);
const fileSpawn = yield* spawnFor(executable);
assert.deepEqual(fileSpawn?.args, [executable]);
assert.equal(fileSpawn?.options.cwd, undefined);
assert.deepEqual((yield* spawnFor(`${executable}:12`))?.args, [
executable,
"--",
"+call cursor(12,1)",
]);
}).pipe(Effect.scoped, Effect.provide(NodeServices.layer)),
);

// Windows drive letters cannot resolve the POSIX editor stub.
it.effect.skipIf(windowsHost)("neovim is offered on POSIX but never spawned by the server", () =>
Effect.gen(function* () {
const fs = yield* FileSystem.FileSystem;
const path = yield* Path.Path;
const binDir = yield* fs.makeTempDirectoryScoped({ prefix: "t3-editor-neovim-" });
const executable = path.join(binDir, "nvim");
yield* fs.writeFileString(executable, "#!/bin/sh\n");
yield* fs.chmod(executable, 0o755);

const editorsOn = (platform: NodeJS.Platform) =>
Effect.gen(function* () {
const launcher = yield* ExternalLauncher.ExternalLauncher;
return yield* launcher.resolveAvailableEditors();
}).pipe(Effect.provide(layerTest({ platform, env: { PATH: binDir } })));

assert.include(yield* editorsOn("linux"), "neovim");
assert.notInclude(yield* editorsOn("win32"), "neovim");

let spawned = false;
const exit = yield* Effect.gen(function* () {
const launcher = yield* ExternalLauncher.ExternalLauncher;
return yield* launcher.launchEditor({ editor: "neovim", cwd: "/workspace" });
}).pipe(
Effect.provide(
layerTest({
platform: "linux",
env: { PATH: binDir },
onSpawn: () => {
spawned = true;
},
}),
),
Effect.exit,
);
assert.isTrue(Exit.isFailure(exit));
assert.isFalse(spawned);
}).pipe(Effect.scoped, Effect.provide(NodeServices.layer)),
);

it.effect("discovers Neovide from its Windows install directory", () =>
Effect.gen(function* () {
const fs = yield* FileSystem.FileSystem;
const path = yield* Path.Path;
const programFiles = yield* fs.makeTempDirectoryScoped({ prefix: "t3-neovide-win-" });
const executable = path.join(programFiles, "Neovide", "neovide.exe");
yield* fs.makeDirectory(path.dirname(executable), { recursive: true });
yield* fs.writeFileString(executable, "");
yield* fs.chmod(executable, 0o755);

const editors = yield* Effect.gen(function* () {
const launcher = yield* ExternalLauncher.ExternalLauncher;
return yield* launcher.resolveAvailableEditors();
}).pipe(
Effect.provide(
layerTest({
platform: "win32",
env: {
ProgramFiles: programFiles,
PATH: path.join(programFiles, "empty"),
PATHEXT: ".COM;.EXE;.BAT;.CMD",
},
}),
),
);
assert.include(editors, "neovide");
}).pipe(Effect.scoped, Effect.provide(NodeServices.layer)),
);
30 changes: 26 additions & 4 deletions apps/server/src/process/externalLauncher.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { expandHomePath } from "@t3tools/provider-core/server/pathExpansion";
import * as NodePath from "@effect/platform-node/NodePath";
import {
EDITOR_TARGET_WITH_POSITION_PATTERN,
EDITORS,
ExternalLauncherError,
ExternalLauncherBrowserSpawnError,
Expand Down Expand Up @@ -51,6 +52,8 @@ interface EditorLaunch {
readonly command: string;
readonly args: ReadonlyArray<string>;
readonly detached?: boolean;
/** Process cwd when args alone would not root the editor (Neovide <0.16 lacks `--chdir`). */
readonly cwd?: string;
}

interface ProcessLaunch {
Expand All @@ -67,7 +70,6 @@ interface TargetPathAndPosition {

// cmd shims reparse %* after escaping is gone; newlines and quotes can expose shell operators.
const WINDOWS_SHIM_UNSAFE_ARG_PATTERN = /[\u0000-\u001f\u007f"]/;
const TARGET_WITH_POSITION_PATTERN = /^(.*?):(\d+)(?::(\d+))?$/;
const POWERSHELL_ARGUMENTS_PREFIX = [
"-NoProfile",
"-NonInteractive",
Expand Down Expand Up @@ -125,7 +127,7 @@ const readBrowserLaunchEnv = BrowserLaunchEnvConfig.pipe(Effect.orElseSucceed(()
const readCommandLookupEnv = CommandLookupEnvConfig.pipe(Effect.orElseSucceed(() => ({})));

function parseTargetPathAndPosition(target: string): Option.Option<TargetPathAndPosition> {
const match = TARGET_WITH_POSITION_PATTERN.exec(target);
const match = EDITOR_TARGET_WITH_POSITION_PATTERN.exec(target);
if (!match?.[1] || !match[2]) {
return Option.none();
}
Expand All @@ -138,7 +140,7 @@ function parseTargetPathAndPosition(target: string): Option.Option<TargetPathAnd
}

function resolveCommandEditorArgs(
editor: (typeof EDITORS)[number],
editor: Exclude<(typeof EDITORS)[number], { launchStyle: "terminal" }>,
target: string,
isDirectory: boolean,
projectRoot: string | undefined,
Expand Down Expand Up @@ -169,6 +171,16 @@ function resolveCommandEditorArgs(
path,
],
});
case "neovim":
return Option.match(parsedTarget, {
// Folder opens set EditorLaunch.cwd; --chdir would break Neovide before 0.16.
onNone: () => [target],
onSome: ({ path, line, column }) => [
path,
"--",
`+call cursor(${line},${Option.getOrElse(column, () => "1")})`,
],
});
}
}

Expand Down Expand Up @@ -419,6 +431,9 @@ const buildAvailableEditors = Effect.fn("externalLauncher.buildAvailableEditors"
const available: EditorId[] = [];

for (const editor of EDITORS) {
// Clients type terminal editors into a POSIX shell; Windows shells quote differently.
if (editor.launchStyle === "terminal" && platform === "win32") continue;

if (editor.commands === null) {
if ((yield* resolveUsableFileManagerCommand(platform, env)) !== undefined) {
available.push(editor.id);
Expand Down Expand Up @@ -489,6 +504,11 @@ const resolveEditorLaunch = Effect.fn("resolveEditorLaunch")(function* (
return yield* new ExternalLauncherUnknownEditorError({ editor: input.editor });
}

// Clients run these in the thread's terminal; a detached spawn has no TTY.
if (editorDef.launchStyle === "terminal") {
return yield* new ExternalLauncherUnsupportedEditorError({ editor: input.editor });
}

if (editorDef.commands) {
const resolved = yield* resolveEditorCommand(editorDef, env);
if (Option.isNone(resolved)) {
Expand All @@ -499,7 +519,7 @@ const resolveEditorLaunch = Effect.fn("resolveEditorLaunch")(function* (
}
const { command, baseArgs } = resolved.value;
const isDirectory =
editorDef.launchStyle === "goto" &&
(editorDef.launchStyle === "goto" || editorDef.launchStyle === "neovim") &&
(yield* (yield* FileSystem.FileSystem).stat(input.cwd).pipe(
Effect.map((info) => info.type === "Directory"),
Effect.orElseSucceed(() => false),
Expand All @@ -512,6 +532,7 @@ const resolveEditorLaunch = Effect.fn("resolveEditorLaunch")(function* (
...baseArgs,
...resolveCommandEditorArgs(editorDef, input.cwd, isDirectory, input.projectRoot),
],
...(isDirectory && editorDef.launchStyle === "neovim" ? { cwd: input.cwd } : {}),
};
}

Expand Down Expand Up @@ -865,6 +886,7 @@ const launchEditorProcess = Effect.fn("externalLauncher.launchEditorProcess")(fu
stdin: "ignore",
stdout: "ignore",
stderr: "ignore",
...(launch.cwd !== undefined ? { cwd: launch.cwd } : {}),
},
},
(cause) =>
Expand Down
25 changes: 25 additions & 0 deletions apps/web/src/components/ChatView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@ import { resolveScrollToEndClearance } from "./composerFooterLayout";
import { ChatHeader } from "./chat/ChatHeader";
import { useSideChat } from "./chat/useSideChat";
import { useRemoteOpenState } from "~/remoteOpen";
import { registerTerminalEditorHost } from "../terminalEditorHost";
import { shouldShowOpenInPicker } from "./chat/OpenInPicker.logic";
import { useOpenFavoriteEditorShortcut } from "./chat/OpenInPickerShortcut";
import {
Expand Down Expand Up @@ -1949,6 +1950,30 @@ export default function ChatView(props: ChatViewProps) {
setTerminalUiLaunchContext,
setThreadError,
});
const openTerminalEditorStable = useStableCallback((command: string) => {
if (activeThreadRef) {
const panels = useRightPanelStore.getState();
panels.setMaximized(activeThreadRef, false);
// At this width the panel is a modal sheet that would cover the drawer.
if (prefersPlanSidebarSheet) panels.close(activeThreadRef);
}
return runProjectScriptStable(
{ id: "terminal-editor", name: "editor", command },
{ rememberAsLastInvoked: false, preferNewTerminal: true },
);
});
const terminalEditorEnvironmentId =
!backgroundThread && !embedded && activeThread && activeProject
? activeThread.environmentId
: null;
// oxlint-disable-next-line t3code/no-unreasoned-state-sync -- publishes this thread's terminal to openers outside its tree, such as the persistent drawer
useEffect(() => {
if (terminalEditorEnvironmentId === null) return;
return registerTerminalEditorHost({
environmentId: terminalEditorEnvironmentId,
open: openTerminalEditorStable,
});
}, [terminalEditorEnvironmentId, openTerminalEditorStable]);
const {
saveProjectScript: saveProjectScriptStable,
updateProjectScript: updateProjectScriptStable,
Expand Down
75 changes: 75 additions & 0 deletions apps/web/src/components/Icons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,81 @@ export const VSCodium: Icon = (props) => {
);
};

export const NeovideIcon: Icon = (props) => {
const id = useId();
const leftGradientId = `${id}-neovide-left`;
const rightGradientId = `${id}-neovide-right`;
const crossGradientId = `${id}-neovide-cross`;

return (
<svg {...props} viewBox="0 0 256 256" fill="none">
<defs>
<linearGradient
id={leftGradientId}
x1="49.021549"
y1="-0.079835393"
x2="49.021549"
y2="97.845657"
gradientTransform="matrix(0.49500848,0,0,2.3234666,34.367657,9.4880553)"
gradientUnits="userSpaceOnUse"
>
<stop offset="0" stopColor="#16B0ED" stopOpacity="0.800235524" />
<stop offset="1" stopColor="#0F59B2" stopOpacity="0.83700023" />
</linearGradient>
<linearGradient
id={rightGradientId}
x1="326.17365"
y1="-0.069164939"
x2="326.17365"
y2="98.851547"
gradientTransform="matrix(-0.50009738,0,0,2.2998234,360.41234,9.4880553)"
gradientUnits="userSpaceOnUse"
>
<stop offset="0" stopColor="#7DB643" />
<stop offset="1" stopColor="#367533" />
</linearGradient>
<linearGradient
id={crossGradientId}
x1="103.88479"
y1="-0.11508822"
x2="103.88479"
y2="178.55785"
gradientTransform="matrix(0.90309898,0,0,1.2735433,34.367657,9.4880553)"
gradientUnits="userSpaceOnUse"
>
<stop offset="0" stopColor="#88C649" stopOpacity="0.8" />
<stop offset="1" stopColor="#439240" stopOpacity="0.84" />
</linearGradient>
</defs>
<path
fill="currentColor"
d="m 128.00953,0 c -1.23772,0 -2.47582,0.5458718 -3.14671,1.6353058 l -6.66166,10.7585922 -3.13714,0.306022 -8.62716,-9.2523891 C 104.68863,1.5771234 101.15915,2.2721764 100.263,4.6811826 L 95.844214,16.501288 92.79793,17.424136 82.5496,10.050915 C 80.468371,8.5477344 77.140969,9.9343306 76.72962,12.46084 l -2.032449,12.465622 -2.797608,1.501421 -11.491712,-5.240629 c -2.335875,-1.067406 -5.334488,0.939333 -5.236548,3.500127 L 55.61127,37.334704 53.181894,39.328629 40.867638,36.4262 c -2.502369,-0.582666 -5.044685,1.954419 -4.457042,4.456449 l 2.902817,12.317392 -1.994191,2.424268 -12.649013,-0.439908 c -2.551342,-0.07344 -4.563244,2.895391 -3.500596,5.235848 l 5.241331,11.494959 -1.501624,2.797234 -12.462504,2.027396 c -2.5317515,0.411294 -3.9038394,3.738252 -2.410247,5.819203 l 7.374206,10.237398 -0.927753,3.050659 -11.8216851,4.422972 c -2.3995342,0.89604 -3.0998065,4.42015 -1.2242521,6.17304 l 9.2488422,8.626 -0.306063,3.13195 -10.7600286,6.66076 c -1.43423441,0.88621 -1.90746247,2.74036 -1.45379942,4.29388 H 34.320759 c -0.08286,-4.01467 0.09103,-8.03393 0.526046,-12.04006 l 16.388721,-7.28237 c 3.501359,-1.5546 5.084092,-5.65809 3.529289,-9.16632 l -1.133391,-2.562941 h 0.01445 L 46.199935,81.349296 c 3.674449,-6.542835 8.114221,-12.639009 13.256354,-18.136594 l 0.06694,0.06216 C 73.117902,48.700827 91.008237,38.81379 110.62619,35.106478 l 11.71648,12.293483 c 2.64928,2.773785 7.03665,2.876089 9.80836,0.224743 l 13.11289,-12.537346 c 27.05125,5.066539 50.5064,21.769043 64.13934,45.673807 L 200.427,101.03035 c -1.5499,3.50824 0.0304,7.61173 3.52929,9.16632 l 17.283,7.67446 c 0.30792,3.09848 0.46112,6.21038 0.45909,9.32412 h 0.0956 c 2e-5,0.65521 -0.0294,1.30658 -0.043,1.96045 h 34.08298 c 0.45368,-1.55351 -0.0196,-3.40767 -1.4538,-4.29387 l -10.75523,-6.66077 -0.30606,-3.13194 9.24406,-8.626 c 1.88045,-1.7529 1.17538,-5.27701 -1.22905,-6.17304 l -11.8121,-4.422977 -0.93254,-3.050659 7.37419,-10.237398 c 1.50338,-2.080951 0.12144,-5.403013 -2.41024,-5.819203 l -12.45772,-2.027397 -1.50163,-2.797233 5.23655,-11.494959 c 1.07245,-2.340457 -0.9152,-5.333773 -3.49103,-5.235848 l -12.6538,0.439908 -1.99419,-2.424268 2.9076,-12.317392 c 0.58764,-2.502035 -1.95467,-5.044012 -4.45704,-4.456449 l -12.31904,2.902429 -2.42937,-1.993925 0.44474,-12.647323 c 0.0979,-2.560794 -2.90067,-4.562636 -5.23654,-3.500127 l -11.49171,5.240629 -2.79761,-1.501421 -2.03245,-12.465622 C 178.8686,9.9343208 175.5412,8.552643 173.45997,10.05092 l -10.24363,7.373216 -3.04628,-0.922848 -4.41879,-11.8201054 C 154.85512,2.2721764 151.32086,1.5771234 149.57262,3.4475309 L 140.95025,12.69992 137.81789,12.393898 131.15624,1.6353058 C 130.4829,0.54586691 129.24724,0 128.00953,0 Z m -0.38258,22.554791 c 4.19241,0.01395 7.58386,3.41564 7.58462,7.607517 0,10.146542 -15.22185,10.146542 -15.22185,0 7.6e-4,-4.212419 3.42427,-7.622615 7.63723,-7.607517 z M 36.840997,91.443246 c 4.196149,0.01126 7.591277,3.416698 7.589408,7.612301 0,10.146543 -15.221854,10.146543 -15.221854,0 -0.0019,-4.212412 3.419488,-7.624752 7.632446,-7.612301 z m 181.567113,0.358621 c 4.19243,0.01395 7.58387,3.415641 7.58463,7.60752 0,10.146553 -15.22185,10.146553 -15.22185,0 7.5e-4,-4.212419 3.42428,-7.622618 7.63722,-7.60752 z"
/>
<path
fill={`url(#${leftGradientId})`}
d="M 34.39677,58.236531 82.870719,9.302562 V 236.88696 L 34.39677,188.51815 Z"
/>
<path
fill={`url(#${rightGradientId})`}
d="M 221.69673,58.610128 172.55877,9.2405879 173.5548,236.82916 222.02875,188.46037 Z"
/>
<path
fill={`url(#${crossGradientId})`}
d="M 82.838401,9.3414878 208.86559,201.62861 173.59939,236.88922 47.506234,45.027731 Z"
/>
<path
fill="#000"
fillOpacity="0.13"
d="m 82.881769,98.529378 -0.06706,7.573632 -38.911476,-57.438942 3.602976,-3.669847 z"
/>
<path
fill="currentColor"
d="m 0.00822228,128.23763 c 0.06381047,1.15772 0.5900871,2.28788 1.61161312,2.91677 l 10.7600286,6.66077 0.306063,3.13194 -9.2488422,8.626 c -1.8755544,1.748 -1.1752821,5.27211 1.2242521,6.17304 l 11.8216851,4.4182 0.927753,3.05066 -7.374206,10.24218 c -1.4984845,2.08584 -0.1215167,5.40802 2.410247,5.81442 l 12.462504,2.02739 1.501624,2.80202 -5.241331,11.49018 c -1.067543,2.33556 0.949256,5.33867 3.500596,5.23584 l 12.644231,-0.4399 1.998973,2.42905 -2.902817,12.32217 c -0.587641,2.49714 1.954671,5.02967 4.457042,4.4421 l 12.314256,-2.89764 2.429376,1.98914 -0.439967,12.6521 c -0.09794,2.56082 2.900675,4.56277 5.236548,3.49535 l 11.491712,-5.23585 2.797608,1.50142 2.032449,12.45606 c 0.411349,2.5363 3.738751,3.90809 5.81998,2.4147 l 10.243548,-7.37799 3.051066,0.92764 4.418786,11.81531 c 0.89615,2.39921 4.42563,3.10429 6.17386,1.22409 l 8.62716,-9.24282 3.13714,0.3108 6.65687,10.75858 c 1.34179,2.16908 4.95153,2.17398 6.29821,0 l 6.65687,-10.75858 3.13714,-0.3108 8.62237,9.24282 c 1.74824,1.8802 5.27772,1.17512 6.17387,-1.22409 l 4.41878,-11.81531 3.05107,-0.92764 10.24355,7.37799 c 2.08122,1.49339 5.40384,0.11678 5.81519,-2.4147 l 2.03245,-12.45606 2.8024,-1.50142 11.49171,5.23585 c 2.33587,1.06742 5.32959,-0.92958 5.23654,-3.49535 l -0.44475,-12.6521 2.42938,-1.98914 12.31904,2.89764 c 2.50237,0.58757 5.03988,-1.94496 4.45226,-4.4421 l -2.90282,-12.32217 1.99419,-2.42905 12.64902,0.4399 c 2.55134,0.10283 4.56826,-2.90028 3.49581,-5.23584 l -5.23655,-11.49018 1.49684,-2.80202 12.45773,-2.02739 c 2.53666,-0.4064 3.9184,-3.72858 2.41502,-5.81442 l -7.37419,-10.24218 0.92296,-3.05066 11.82168,-4.4182 c 2.40443,-0.90093 3.10471,-4.42504 1.22426,-6.17304 l -9.23927,-8.626 0.30606,-3.13194 10.75524,-6.66077 c 1.02154,-0.62889 1.54782,-1.75905 1.61163,-2.91677 h -34.22169 c -0.23905,21.49027 -7.84793,42.2603 -21.60136,58.81364 l -0.0335,-0.0287 c -1.69183,2.01195 -3.46762,3.95181 -5.32263,5.81442 l -16.097,-3.46187 c -3.74866,-0.80301 -7.43669,1.58076 -8.2398,5.33626 l -3.81622,17.82579 c -24.85712,11.25919 -53.38847,11.12301 -78.136936,-0.37296 l -3.816225,-17.8258 c -0.803109,-3.7506 -4.488796,-6.13693 -8.235008,-5.33147 l -15.738304,3.3758 c -2.418569,-2.49028 -4.696831,-5.11304 -6.824254,-7.85616 l -0.07652,0.0574 C 45.774957,174.19336 39.995633,162.22571 36.869691,149.45836 l 0.09564,-0.024 c -1.696247,-6.95139 -2.567307,-14.06598 -2.644577,-21.19682 z M 71.244395,198.66576 h 0.0049 c 4.194281,0.014 7.586507,3.41855 7.584624,7.6123 0,10.14655 -15.221854,10.14655 -15.221854,0 -0.0019,-4.21241 3.419483,-7.62475 7.632446,-7.6123 z m 112.760325,0.35862 c 4.19241,0.0147 7.58386,3.41566 7.58462,7.60752 0,10.14655 -15.22185,10.14655 -15.22185,0 7.5e-4,-4.21241 3.42427,-7.62262 7.63723,-7.60752 z"
/>
</svg>
);
};

export const Zed: Icon = (props) => {
const id = useId();
const clipPathId = `${id}-zed-logo-a`;
Expand Down
Loading
Loading