Skip to content
Merged
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
4 changes: 3 additions & 1 deletion docs/guide/step-debugging.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/components/settings-dialog.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ function EditorControl({ settings, onChange }) {
<Stack direction="column" gap="md">
<SelectControl
label={__('Code editor')}
description={__('What “Open in” in the site’s menu and the files under “Changed files” open in. With “Ask each time”, or an editor that is no longer installed, the app asks which to use.')}
description={__('What “Open in” in the site’s menu and the files under “Changed files” open in, and which editor’s Xdebug setup the site’s details offer. With “Ask each time”, or an editor that is no longer installed, the app asks which to use.')}
items={items}
value={editor || ASK_FOR_EDITOR}
disabled={!settings || !editors}
Expand Down
12 changes: 10 additions & 2 deletions src/renderer/components/site-details.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -346,12 +346,13 @@ function useStickyWhileItFits(active) {
* @param {boolean} props.pathCopied The path has just been copied with the button here.
* @param {Function} props.onCopyPath
* @param {Array} [props.xdebugEditors] The editors the Debugging row's setup menu offers, from `xdebugEditors`.
* @param {?Object} [props.xdebugSetupEditor] The editor chosen in Settings, from `xdebugSetupEditor`, whose setup the button opens instead of the menu; or null.
* @param {Function} [props.onOpenXdebugSetup] Opens an editor's setup, given its id, for the Debugging row while the server has Xdebug.
* @param {Object} [props.server] The server's section, or null while the site's setup is not done: `{ process, section, onToggle, onOpen }`, the first two from site-processes.cjs.
* @param {Object} [props.watch] The build watch's section, or null likewise: `{ process, onToggle }`.
* @param {Object} [props.changed] The changed files, from `changedFileGroups`, with what the rows do: `{ change, yours, onOpenFile, onRevertFile, revertReason, revertError }`. No files, no section.
*/
export function SiteDetails({ id, open, siteName, facts, pathCopied, onCopyPath, xdebugEditors = [], onOpenXdebugSetup = null, server = null, watch = null, changed = null }) {
export function SiteDetails({ id, open, siteName, facts, pathCopied, onCopyPath, xdebugEditors = [], xdebugSetupEditor = null, onOpenXdebugSetup = null, server = null, watch = null, changed = null }) {
const { sidebarRef, unstuck } = useStickyWhileItFits(open);
return (
<div id={id} className="dashboard-sidebar-slot" inert={open ? undefined : ''}>
Expand Down Expand Up @@ -387,7 +388,14 @@ export function SiteDetails({ id, open, siteName, facts, pathCopied, onCopyPath,
<Notice.Description>{notice.text}</Notice.Description>
</Notice.Root>
))}
{row.setup && xdebugEditors.length ? (
{row.setup && xdebugSetupEditor ? (
// The editor chosen in Settings opens its setup
// directly, as "Open in" opens that editor (#767).
<Button variant="outline" tone="neutral" size="compact" onClick={() => onOpenXdebugSetup(xdebugSetupEditor.id)}>
{xdebugSetupEditor.label}
</Button>
) : null}
{row.setup && !xdebugSetupEditor && xdebugEditors.length ? (
<Menu.Root>
<Menu.Trigger
render={
Expand Down
5 changes: 4 additions & 1 deletion src/renderer/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import { deleteSiteQuestion } from './site-dialogs.cjs';
import { serverProcess, watchProcess, buildHoldsStarts, serverSection } from './site-processes.cjs';
import { applyLocale, textDirection } from './locale-setup.cjs';
import { getProjectType } from '../project-type.cjs';
import { xdebugEditors, xdebugSection } from './xdebug.cjs';
import { xdebugEditors, xdebugSection, xdebugSetupEditor } from './xdebug.cjs';
import { sanitizeSiteFolder, resolveTargetDir } from './site-folder.cjs';
import { noticeForOpenResult } from './open-failure.cjs';
import { describeAppliedLayer, attributeConflicts, layerExitFailure } from './applied-layer.cjs';
Expand Down Expand Up @@ -1429,6 +1429,8 @@ function SiteRow({ sitePath, initialized, createdAt, label, projectType = null,
// again each time the server has Xdebug.
useEffect(() => { 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 {
Expand Down Expand Up @@ -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}
Expand Down
20 changes: 19 additions & 1 deletion src/renderer/xdebug.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
41 changes: 41 additions & 0 deletions tests/e2e/journeys/xdebug.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' );
} );
19 changes: 18 additions & 1 deletion tests/unit/xdebug.test.cjs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -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.
Expand Down
Loading