From a829fd27971affc77cd7ce09bac42df8d29afe31 Mon Sep 17 00:00:00 2001 From: Ryan Welcher Date: Fri, 13 Nov 2026 14:05:28 -0500 Subject: [PATCH] Open the Xdebug setup for the editor chosen in Settings When the Code editor setting names VS Code, Cursor, PhpStorm or Zed and that editor is detected, the Debugging row's button is named for it and opens its setup directly, as "Open in" opens the chosen editor. Otherwise the menu stays as it was. --- docs/guide/step-debugging.md | 4 +- src/renderer/components/settings-dialog.jsx | 2 +- src/renderer/components/site-details.jsx | 12 +++++- src/renderer/index.jsx | 5 ++- src/renderer/xdebug.cjs | 20 +++++++++- tests/e2e/journeys/xdebug.spec.js | 41 +++++++++++++++++++++ tests/unit/xdebug.test.cjs | 19 +++++++++- 7 files changed, 96 insertions(+), 7 deletions(-) diff --git a/docs/guide/step-debugging.md b/docs/guide/step-debugging.md index 5d4b75ae..232f40c5 100644 --- a/docs/guide/step-debugging.md +++ b/docs/guide/step-debugging.md @@ -14,6 +14,8 @@ The **Debugging** row of the site's details then names *Xdebug*, and while the s The menu lists the editors the app finds on your computer that it has setup for. If it finds none of them, there is no menu. The app looks in each editor's usual install location, so it can miss one installed elsewhere, such as PhpStorm from JetBrains' own installer on Windows. Sublime Text has no setup: its PHP debugger needs Node.js installed on your computer. +If you chose one of these editors as your **Code editor** on the **General** tab of **Settings**, and the app finds it, the button is named for it instead, such as **Set up Xdebug for Zed**, and opens that editor's setup without the menu. In the steps below, select that button where they say to choose your editor from the menu. To set up a different editor, change the **Code editor** setting, or set it to **Ask each time** to have the menu back. + ## Connect VS Code or Cursor Cursor uses the same setup as VS Code: choose **Cursor** in the menu, and follow the same steps in Cursor. @@ -71,7 +73,7 @@ A site you start while another site's server has Xdebug starts without it. Its * ## If your editor does not stop -- Check that the site's details show **Set up Xdebug for your editor** under **Debugging**. If they do not, restart the server. If they still do not, the app found no editor it has setup for. +- Check that the site's details show **Set up Xdebug for your editor**, or **Set up Xdebug for** and your code editor's name, under **Debugging**. If they do not, restart the server. If they still do not, the app found no editor it has setup for. - Check that **Listen for Xdebug** is running in VS Code, Cursor or Zed, or that PhpStorm is listening for debug connections, and that no other program uses port 9003. - On a Core site, check that the breakpoint is in `src/`, not `build/`, and not in one of the three files above. - On a Gutenberg site, check that the breakpoint is in one of the checkout's own PHP files. diff --git a/src/renderer/components/settings-dialog.jsx b/src/renderer/components/settings-dialog.jsx index 0385e2a6..a7a80354 100644 --- a/src/renderer/components/settings-dialog.jsx +++ b/src/renderer/components/settings-dialog.jsx @@ -300,7 +300,7 @@ function EditorControl({ settings, onChange }) { @@ -387,7 +388,14 @@ export function SiteDetails({ id, open, siteName, facts, pathCopied, onCopyPath, {notice.text} ))} - {row.setup && xdebugEditors.length ? ( + {row.setup && xdebugSetupEditor ? ( + // The editor chosen in Settings opens its setup + // directly, as "Open in" opens that editor (#767). + + ) : null} + {row.setup && !xdebugSetupEditor && xdebugEditors.length ? ( { if (xdebugOn) loadDetected(); }, [xdebugOn, loadDetected]); const setupEditors = useMemo(() => xdebugEditors(detectedEditors), [detectedEditors]); + // The editor chosen in Settings opens its setup without the menu (#767). + const setupEditor = xdebugSetupEditor({ editors: setupEditors, preferred: settings?.editor ?? null }); // A copy that failed says so on its button, and why in the log. const copyXdebugConfig = useCallback(async (text) => { try { @@ -2581,6 +2583,7 @@ function SiteRow({ sitePath, initialized, createdAt, label, projectType = null, pathCopied={pathCopied} onCopyPath={copyPath} xdebugEditors={setupEditors} + xdebugSetupEditor={setupEditor} onOpenXdebugSetup={setXdebugEditor} server={skipInit ? { process: serverState, section: serverSectionState, onToggle: toggleDevServer, onOpen: openSiteLink } : null} watch={skipInit ? { process: watchProcessState, onToggle: toggleWatch } : null} diff --git a/src/renderer/xdebug.cjs b/src/renderer/xdebug.cjs index 6dedcbf1..30c7ab21 100644 --- a/src/renderer/xdebug.cjs +++ b/src/renderer/xdebug.cjs @@ -211,4 +211,22 @@ function xdebugEditors(detected) { return editors.filter((editor) => ids.has(editor.id)); } -module.exports = { XDEBUG_PORT, xdebugLaunchConfig, phpStormSettings, xdebugStatus, xdebugSection, xdebugHolder, xdebugEditors, zedDebugConfig }; +/** + * The editor whose setup the button opens directly (#767): the one chosen in + * Settings, when it is among those the menu offers. "Open in" is that editor + * and nothing else, and so is this. With none chosen, one that has no setup, + * or one no longer found, there is none, and the button is the menu. + * + * @param {Object} root0 + * @param {Array} [root0.editors] From `xdebugEditors`. + * @param {?string} [root0.preferred] The id of the editor chosen in Settings, or null for none. + * @return {?{id: string, name: string, setup: string, label: string}} The editor, with the button's label. + */ +function xdebugSetupEditor({ editors = [], preferred = null } = {}) { + const chosen = preferred ? (editors || []).find((editor) => editor.id === preferred) : null; + if (!chosen) return null; + // translators: %s: the name of an editor, for example "VS Code". + return { ...chosen, label: sprintf(__('Set up Xdebug for %s'), chosen.name) }; +} + +module.exports = { XDEBUG_PORT, xdebugLaunchConfig, phpStormSettings, xdebugStatus, xdebugSection, xdebugHolder, xdebugEditors, xdebugSetupEditor, zedDebugConfig }; diff --git a/tests/e2e/journeys/xdebug.spec.js b/tests/e2e/journeys/xdebug.spec.js index fc9f3237..7f19a5fe 100644 --- a/tests/e2e/journeys/xdebug.spec.js +++ b/tests/e2e/journeys/xdebug.spec.js @@ -372,3 +372,44 @@ test( 'the setup menu offers the detected editors that have a setup, and no setu await page.evaluate( () => window.api.listEditors() ); await expect( setup ).toHaveCount( 0 ); } ); + +// With an editor chosen in Settings that has a setup and is found, the button +// names it and opens its setup without the menu, as "Open in" opens that +// editor (#767). Once detection no longer finds it, the button is the menu +// again. +test( 'the editor chosen in Settings opens its setup directly, and the menu returns once it is not found', async ( { session } ) => { + const site = await makeSite( session ); + const { app, page } = await session.start( { ...site.settings, preferences: { editor: 'zed' } } ); + const followSetting = await stubServer( app, session, [ 'vscode', 'zed' ] ); + const direct = page.getByRole( 'button', { name: 'Set up Xdebug for Zed', exact: true } ); + const menu = page.getByRole( 'button', { name: 'Set up Xdebug for your editor', exact: true } ); + + await setXdebug( page, true ); + await expect.poll( () => session.readSettings().preferences?.xdebug ).toBe( true ); + await followSetting(); + await ui.startDevServerButton( page ).click(); + + // INVARIANT — the button names the chosen editor, and opens its setup + // with no menu in between. + await expect( direct ).toBeVisible( { timeout: 30_000 } ); + await expect( menu ).toHaveCount( 0 ); + await direct.click(); + await expect( page.getByRole( 'menuitem' ) ).toHaveCount( 0 ); + const zed = page.getByRole( 'dialog', { name: 'Set up Zed', exact: true } ); + await expect( zed ).toBeVisible(); + await expect( zed.getByText( '.zed/debug.json', { exact: true } ) ).toBeVisible(); + await page.keyboard.press( 'Escape' ); + await expect( zed ).toHaveCount( 0 ); + + // INVARIANT — once the chosen editor is not found, the button is the menu + // of those that are, and the setting is left as it was. + await app.evaluate( () => { global.e2eEditors = [ 'vscode' ]; } ); + await ui.stopDevServerButton( page ).click(); + await followSetting(); + await ui.startDevServerButton( page ).click(); + await expect( menu ).toBeVisible( { timeout: 30_000 } ); + await expect( direct ).toHaveCount( 0 ); + await menu.click(); + await expect.poll( () => page.getByRole( 'menuitem' ).allTextContents() ).toEqual( [ 'VS Code' ] ); + expect( session.readSettings().preferences?.editor ).toBe( 'zed' ); +} ); diff --git a/tests/unit/xdebug.test.cjs b/tests/unit/xdebug.test.cjs index c7c94bb0..db208a62 100644 --- a/tests/unit/xdebug.test.cjs +++ b/tests/unit/xdebug.test.cjs @@ -1,7 +1,7 @@ const test = require('node:test'); const assert = require('node:assert/strict'); -const { xdebugLaunchConfig, phpStormSettings, xdebugStatus, xdebugSection, xdebugHolder, xdebugEditors, zedDebugConfig } = require('../../src/renderer/xdebug.cjs'); +const { xdebugLaunchConfig, phpStormSettings, xdebugStatus, xdebugSection, xdebugHolder, xdebugEditors, xdebugSetupEditor, zedDebugConfig } = require('../../src/renderer/xdebug.cjs'); const mappings = (text) => JSON.parse(text).configurations[0].pathMappings; @@ -187,6 +187,23 @@ test('with no detected editor that has a setup, the menu offers nothing', () => assert.deepEqual(xdebugEditors(undefined), []); }); +// With the editor chosen in Settings among those with a setup (#767), the +// button opens that editor's setup and nothing else, as "Open in" opens that +// editor; otherwise it is the menu. +test('the setup opens the editor chosen in Settings directly when it has a setup and was found', () => { + const editors = xdebugEditors(found('vscode', 'zed')); + assert.deepEqual(xdebugSetupEditor({ editors, preferred: 'zed' }), { id: 'zed', name: 'Zed', setup: 'zed', label: 'Set up Xdebug for Zed' }); + assert.deepEqual(xdebugSetupEditor({ editors: xdebugEditors(found('cursor')), preferred: 'cursor' }), { id: 'cursor', name: 'Cursor', setup: 'vscode', label: 'Set up Xdebug for Cursor' }); +}); + +test('the setup is the menu with no editor chosen, one with no setup, or one no longer found', () => { + const editors = xdebugEditors(found('vscode', 'sublime')); + assert.equal(xdebugSetupEditor({ editors, preferred: null }), null); + assert.equal(xdebugSetupEditor({ editors, preferred: 'sublime' }), null); + assert.equal(xdebugSetupEditor({ editors, preferred: 'zed' }), null); + assert.equal(xdebugSetupEditor({ editors: undefined, preferred: 'vscode' }), null); +}); + // Zed reads its debug setup from .zed/debug.json, a list of scenarios, and // runs the same Xdebug adapter VS Code's PHP Debug is, under the name // "Xdebug", with the same listener and mapping keys.