fix(tui): fall back to local cwd when editor spawns in attach mode (#30583)
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
import { defer } from "@/util/defer"
|
import { defer } from "@/util/defer"
|
||||||
|
import { existsSync } from "node:fs"
|
||||||
import { rm } from "node:fs/promises"
|
import { rm } from "node:fs/promises"
|
||||||
import { tmpdir } from "node:os"
|
import { tmpdir } from "node:os"
|
||||||
import { join } from "node:path"
|
import { join } from "node:path"
|
||||||
@@ -13,13 +14,17 @@ export async function open(opts: { value: string; renderer: CliRenderer; cwd?: s
|
|||||||
const filepath = join(tmpdir(), `${Date.now()}.md`)
|
const filepath = join(tmpdir(), `${Date.now()}.md`)
|
||||||
await using _ = defer(async () => rm(filepath, { force: true }))
|
await using _ = defer(async () => rm(filepath, { force: true }))
|
||||||
|
|
||||||
|
// In attach mode the server's project directory may not exist locally.
|
||||||
|
// Fall back to the local process cwd so the editor can still spawn.
|
||||||
|
const cwd = opts.cwd && existsSync(opts.cwd) ? opts.cwd : process.cwd()
|
||||||
|
|
||||||
await Filesystem.write(filepath, opts.value)
|
await Filesystem.write(filepath, opts.value)
|
||||||
opts.renderer.suspend()
|
opts.renderer.suspend()
|
||||||
opts.renderer.currentRenderBuffer.clear()
|
opts.renderer.currentRenderBuffer.clear()
|
||||||
try {
|
try {
|
||||||
const parts = editor.split(" ")
|
const parts = editor.split(" ")
|
||||||
const proc = Process.spawn([...parts, filepath], {
|
const proc = Process.spawn([...parts, filepath], {
|
||||||
cwd: opts.cwd,
|
cwd,
|
||||||
stdin: "inherit",
|
stdin: "inherit",
|
||||||
stdout: "inherit",
|
stdout: "inherit",
|
||||||
stderr: "inherit",
|
stderr: "inherit",
|
||||||
|
|||||||
Reference in New Issue
Block a user