Skip to content

🎥 Make videos programmatically with React

`@remotion/studio-server`: Fix Zed source files opening in new windows

Jonny Burgerf371baa6fef5
diff --git a/packages/studio-server/src/helpers/open-in-editor.ts b/packages/studio-server/src/helpers/open-in-editor.ts
index 61f7f64c63..d1fa325f0c 100644
--- a/packages/studio-server/src/helpers/open-in-editor.ts
+++ b/packages/studio-server/src/helpers/open-in-editor.ts
@@ -277,7 +277,7 @@ function getArgumentsForLineNumber(
const isFolder =
fs.existsSync(fileName) && fs.lstatSync(fileName).isDirectory();
if (isZedEditor) {
- return [fileName + ':' + lineNumber + ':' + colNumber];
+ return ['--existing', fileName + ':' + lineNumber + ':' + colNumber];
}
switch (editorBasename) {
diff --git a/packages/studio-server/src/test/open-in-editor.test.ts b/packages/studio-server/src/test/open-in-editor.test.ts
index ed7c295b0f..e74033cdee 100644
--- a/packages/studio-server/src/test/open-in-editor.test.ts
+++ b/packages/studio-server/src/test/open-in-editor.test.ts
@@ -1,5 +1,11 @@
-import {expect, test} from 'bun:test';
-import {findMacOsEditorsFromProcessOutput} from '../helpers/open-in-editor';
+import {expect, spyOn, test} from 'bun:test';
+import childProcess from 'node:child_process';
+import type {SpawnOptions} from 'node:child_process';
+import {EventEmitter} from 'node:events';
+import {
+ findMacOsEditorsFromProcessOutput,
+ launchEditor,
+} from '../helpers/open-in-editor';
import {findSearchPosition} from '../preview-server/routes/find-in-file';
test('detects current VS Code macOS processes', () => {
@@ -12,6 +18,44 @@ test('detects current VS Code macOS processes', () => {
});
});
+test('opens source locations in an existing Zed window', async () => {
+ const calls: {
+ command: string;
+ args: readonly string[];
+ options: SpawnOptions;
+ }[] = [];
+ const spawnSpy = spyOn(childProcess, 'spawn').mockImplementation(((
+ command: string,
+ args: readonly string[],
+ options: SpawnOptions,
+ ) => {
+ calls.push({command, args, options});
+ return new EventEmitter() as ReturnType<typeof childProcess.spawn>;
+ }) as typeof childProcess.spawn);
+ const sourceFile = __filename;
+
+ try {
+ await launchEditor({
+ colNumber: 4,
+ editor: {command: 'zed', process: 'zed'},
+ fileName: sourceFile,
+ lineNumber: 12,
+ logLevel: 'error',
+ vsCodeNewWindow: false,
+ });
+
+ expect(calls).toEqual([
+ {
+ args: ['--existing', `${sourceFile}:12:4`],
+ command: 'zed',
+ options: {stdio: 'inherit'},
+ },
+ ]);
+ } finally {
+ spawnSpy.mockRestore();
+ }
+});
+
test('finds a property after the component location', () => {
const contents = [
'const MyComp = () => (',