дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-12-04 17:21:13 +02:00
In a remote (SSH/WSL) window, Generate Request in HTTP Client failed with Permission denied: the scratches folder was resolved on the desktop and its path sent to the remote host. Scratches and generated HTTP requests now live in the data directory of the host that writes them (created on demand, rechecked on later calls), and remote IPC routing is installed before session listeners run. Co-authored-by: bertyhell <[email protected]>
54 рядки
2.1 KiB
TypeScript
54 рядки
2.1 KiB
TypeScript
import { EditorView } from "@codemirror/view";
|
|
import { activeEditor, editorsFor, useEditorRegistry, type TextEditorHandle } from "@/editor/api";
|
|
import { tx } from "@/platform/i18n";
|
|
import { call, commands, emitLocalIdeEvent, IpcError } from "@/platform/ipc";
|
|
import { scratchesDir } from "@/platform/scratchesDir";
|
|
import { editorService } from "@/workbench/contributions";
|
|
import { appendRequests } from "./spring/request";
|
|
|
|
export const GENERATED_REQUESTS = "generated-requests.http";
|
|
|
|
async function scratchFile(): Promise<{ path: string; created: boolean }> {
|
|
const path = `${await scratchesDir()}/${GENERATED_REQUESTS}`;
|
|
let created = true;
|
|
await call(commands.fsCreateFile(path)).catch((e) => {
|
|
if (!(e instanceof IpcError && e.kind === "alreadyExists")) throw e;
|
|
created = false;
|
|
});
|
|
return { path, created };
|
|
}
|
|
|
|
/** The text editor of `path`, once the just opened tab has created it. */
|
|
function editorFor(path: string, timeoutMs = 5000): Promise<TextEditorHandle | null> {
|
|
const find = () => editorsFor(path).find((x) => x === activeEditor()) ?? editorsFor(path)[0] ?? null;
|
|
const now = find();
|
|
if (now) return Promise.resolve(now);
|
|
return new Promise((resolve) => {
|
|
const done = (e: TextEditorHandle | null) => {
|
|
clearTimeout(timer);
|
|
unsubscribe();
|
|
resolve(e);
|
|
};
|
|
const timer = setTimeout(() => done(null), timeoutMs);
|
|
const unsubscribe = useEditorRegistry.subscribe(() => {
|
|
const e = find();
|
|
if (e) done(e);
|
|
});
|
|
});
|
|
}
|
|
|
|
export async function appendGeneratedRequests(blocks: string[]): Promise<void> {
|
|
const file = await scratchFile();
|
|
if (file.created) emitLocalIdeEvent({ type: "fsChanged", created: [file.path], modified: [], removed: [] });
|
|
await editorService().openFile(file.path, { focus: true });
|
|
const e = await editorFor(file.path);
|
|
if (!e) throw new Error(`${tx("Cannot open file")}: ${file.path}`);
|
|
const { insert, from, caret } = appendRequests(e.view.state.doc.toString(), blocks);
|
|
e.view.dispatch({
|
|
changes: { from, insert },
|
|
selection: { anchor: caret },
|
|
effects: EditorView.scrollIntoView(caret, { y: "center" }),
|
|
userEvent: "input",
|
|
});
|
|
}
|