diff --git a/README.md b/README.md index 475bbf7b..d7654dd7 100644 --- a/README.md +++ b/README.md @@ -32,7 +32,7 @@ Each of these has a page in the user guide. - **[Link a Trac ticket](https://wordpress.github.io/contributor-toolkit/guide/trac-tickets)** to a Core site and read its facts in the app: summary, status and resolution, type, milestone, component, keywords, age. A ticket can also arrive from a browser: the app answers `wpct://ticket/62281` links and offers the ticket to the site you have open. On a Gutenberg site, **[link a GitHub issue](https://wordpress.github.io/contributor-toolkit/guide/gutenberg-issues)** instead, and the app lists the pull requests that cite it. - **[Try the work that already exists on it](https://wordpress.github.io/contributor-toolkit/guide/applying-patches)**: pull requests are checked out on their own branches with the author's commits, on both projects, while on Core `.diff` and `.patch` files are previewed and applied to the current ticket as removable layers. When a patch file will not apply, the app says which regions failed and why, and leaves the checkout untouched. - **[Hold work for several tickets or issues in one site](https://wordpress.github.io/contributor-toolkit/guide/ticket-branches)**. Each one gets its own branch inside the site, so moving between them is a file swap of seconds instead of another clone and another install. -- **[Run the site](https://wordpress.github.io/contributor-toolkit/guide/running-the-site)** and debug it: a [debug log tab](https://wordpress.github.io/contributor-toolkit/guide/logs-and-debugging) with fatals surfaced instead of hidden behind the recovery screen, [the database](https://wordpress.github.io/contributor-toolkit/guide/database), [captured mail](https://wordpress.github.io/contributor-toolkit/guide/mail), [a terminal](https://wordpress.github.io/contributor-toolkit/guide/terminal) using the Node.js runtime the app bundles, and [step debugging with Xdebug](https://wordpress.github.io/contributor-toolkit/guide/step-debugging) in VS Code, Cursor, PhpStorm or Zed. +- **[Run the site](https://wordpress.github.io/contributor-toolkit/guide/running-the-site)** and debug it: a [debug log tab](https://wordpress.github.io/contributor-toolkit/guide/logs-and-debugging) with fatals surfaced instead of hidden behind the recovery screen, [the database](https://wordpress.github.io/contributor-toolkit/guide/database), [captured mail](https://wordpress.github.io/contributor-toolkit/guide/mail), [a terminal](https://wordpress.github.io/contributor-toolkit/guide/terminal) using the Node.js runtime the app bundles, and [step debugging with Xdebug](https://wordpress.github.io/contributor-toolkit/guide/step-debugging) in VS Code, Cursor, PhpStorm, Zed or Sublime Text. - **[Send the change back](https://wordpress.github.io/contributor-toolkit/guide/submitting-changes)**: [a GitHub pull request](https://wordpress.github.io/contributor-toolkit/guide/submit-github-pr) to `wordpress-develop` or `WordPress/gutenberg`, opened through device sign-in with no credential on disk, [a patch attached to Trac](https://wordpress.github.io/contributor-toolkit/guide/submit-trac) (Core only), or [a patch handed to a mentor](https://wordpress.github.io/contributor-toolkit/guide/submit-mentor) that keeps your name on the work. - **[Keep the site current with trunk](https://wordpress.github.io/contributor-toolkit/guide/trunk-updates)** without recreating it, fetching only what changed. diff --git a/docs/guide/editors.md b/docs/guide/editors.md index 8918e4fb..3ce904a3 100644 --- a/docs/guide/editors.md +++ b/docs/guide/editors.md @@ -32,7 +32,7 @@ The **Changed files** section of the site's details lists, as folder trees, the - With **Ask each time**, a menu labelled **Open in** opens next to the file, with the same editors and **Other application…**. Press Escape to close it without opening anything. - If the app found no editor, the file is shown in your file manager. -Folders that editors create for their own settings are not listed: `.idea`, `.vscode`, `.vs`, `.fleet`, `.zed` and `.nova`. The app adds them to the site's local Git excludes (`.git/info/exclude`), so they also stay out of your patch. If you remove a rule from that file, the app does not add it again. A file that the project itself tracks in one of these folders, such as Gutenberg's own `.vscode` files, is still listed when you change it. +Folders that editors create for their own settings are not listed: `.idea`, `.vscode`, `.vs`, `.fleet`, `.zed` and `.nova`. The app adds them to the site's local Git excludes (`.git/info/exclude`), so they also stay out of your patch. If you remove a rule from that file, the app does not add it again. A file that the project itself tracks in one of these folders, such as Gutenberg's own `.vscode` files, is still listed when you change it. Sublime Text project files at the top of the site's folder, `*.sublime-project` and the `*.sublime-workspace` beside each, are left out the same way, in a block of their own. ## How detection works diff --git a/docs/guide/step-debugging.md b/docs/guide/step-debugging.md index cd3fae7c..18517e01 100644 --- a/docs/guide/step-debugging.md +++ b/docs/guide/step-debugging.md @@ -2,7 +2,7 @@ A site's PHP can run with Xdebug, so you can stop on a breakpoint in your editor and step through Core one line at a time. It is off unless you turn it on, because it slows every request. -This is a proof of concept. It has setup for VS Code, Cursor, PhpStorm and Zed, and one running site has Xdebug at a time. +This is a proof of concept. It has setup for VS Code, Cursor, PhpStorm, Zed and Sublime Text, and one running site has Xdebug at a time. ## Turn it on @@ -14,7 +14,7 @@ The **Debugging** row of the site's details then names *Xdebug*, and while the s ![The site's details with the Debugging row reading WP_DEBUG · SCRIPT_DEBUG · Xdebug, and the Set up Xdebug for your editor menu open under it, listing VS Code and PhpStorm](/screenshots/xdebug-setup-menu.png) -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. +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. 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. @@ -56,6 +56,17 @@ Like the launch.json, the debug.json listens on `127.0.0.1` only. If Zed says no debug tasks were found, the PHP extension is not installed: Zed leaves out a debug task whose adapter it does not have. +## Connect Sublime Text + +Sublime Text debugs PHP with the **Debugger** package and its PHP adapter, which needs [Node.js](https://nodejs.org/) installed on your computer. If you have not set them up, follow the [Debugger package's setup guide](https://github.com/daveleroy/SublimeDebugger). The app does not install Node.js or check for it. + +1. In the site's details, select **Set up Xdebug for your editor**, choose **Sublime Text**, then select **Copy project file**. +2. Save it in the site's folder as `xdebug.sublime-project`, and open it with **Project → Open Project**. The app keeps it out of your patch. +3. Press the Debugger's play button, choose **Listen for Xdebug**, then press play again. +4. Set a breakpoint, and load a page of the site in the browser. + +Like the launch.json, the project file listens on `127.0.0.1` only. + ## Where to set breakpoints On a Core site, set breakpoints in `src/`, the files you edit. The server runs WordPress from `build/`, but the build copies the PHP from `src/` line for line, and the launch.json maps one to the other. @@ -76,7 +87,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**, 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. +- Check that **Listen for Xdebug** is running in VS Code, Cursor, Zed or Sublime Text, 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. - Check that no other site's server is running with Xdebug. diff --git a/src/exclude-file.cjs b/src/exclude-file.cjs index f4501a83..63c42948 100644 --- a/src/exclude-file.cjs +++ b/src/exclude-file.cjs @@ -3,7 +3,8 @@ /** * The one writer of the app's blocks in a site's `.git/info/exclude` (#523): * the machine-local excludes and the generated Gutenberg download main.js - * seeds (#19), the editor folders (#737), and the files another branch + * seeds (#19), the editor folders (#737), the link Xdebug leaves (#723), + * Sublime Text's project files (#758), and the files another branch * ignored that a switch leaves behind (#521). No Electron, so * ticket-branches.js can use it too. * diff --git a/src/main.js b/src/main.js index 8bf29cd4..a78dee41 100644 --- a/src/main.js +++ b/src/main.js @@ -128,6 +128,16 @@ const EDITOR_EXCLUDES = [ '/.nova/' ]; +// Sublime Text keeps a project in a file rather than a folder, and writes a +// .sublime-workspace beside it. The Xdebug setup asks for one in the site's +// folder (#758). A block of its own for the reason above: a site seeded +// before this has the editor block already. +const SUBLIME_EXCLUDES_MARKER = '# WordPress Contributor Toolkit Sublime Text'; +const SUBLIME_EXCLUDES = [ + '/*.sublime-project', + '/*.sublime-workspace' +]; + /** * Seeds per-site ignores for machine-local files that must never become part * of a contribution. This lives in `.git/info/exclude`, not the repository's @@ -139,8 +149,9 @@ const EDITOR_EXCLUDES = [ * Existing rules above or below the block are never rewritten. * * @param {string} dir Repository working directory. - * @return {Promise} Whether the agent or editor block was appended; - * the Gutenberg block is not counted. + * @return {Promise} Whether the agent, editor or Sublime Text block + * was appended; the Gutenberg and Xdebug blocks + * are not counted. */ async function ensureLocalExcludes(dir) { const gitDir = path.join(dir, '.git'); @@ -157,11 +168,13 @@ async function ensureLocalExcludes(dir) { // Playground CLI links its VFS root into the folder the server runs from, // which for a plugin-mount site is the checkout, and leaves the link behind // when the server stops. The launch.json and debug.json the editor setups - // ask for are under the editor folders excluded below. + // ask for are under the editor folders excluded below, and the Sublime Text + // project file is in a block of its own. await appendExcludeBlock(dir, '# WordPress Contributor Toolkit Xdebug', ['/.playground-xdebug-root'], { once: true }); const agents = await appendExcludeBlock(dir, LOCAL_EXCLUDES_MARKER, LOCAL_EXCLUDES, { once: true }); const editors = await appendExcludeBlock(dir, EDITOR_EXCLUDES_MARKER, EDITOR_EXCLUDES, { once: true }); - return agents || editors; + const sublime = await appendExcludeBlock(dir, SUBLIME_EXCLUDES_MARKER, SUBLIME_EXCLUDES, { once: true }); + return agents || editors || sublime; } // Screenshot harness only (scripts/screenshots/): point userData at a throwaway diff --git a/src/renderer/components/xdebug-setup-dialog.jsx b/src/renderer/components/xdebug-setup-dialog.jsx index dd6a3098..54649438 100644 --- a/src/renderer/components/xdebug-setup-dialog.jsx +++ b/src/renderer/components/xdebug-setup-dialog.jsx @@ -1,5 +1,6 @@ import { useCallback, useEffect, useId, useRef, useState } from 'react'; import { speak } from '@wordpress/a11y'; +import { ExternalLink } from '@wordpress/components'; import { createInterpolateElement } from '@wordpress/element'; import { __, sprintf } from '@wordpress/i18n'; import { check as checkIcon, copy as copyIcon, error as errorIcon } from '@wordpress/icons'; @@ -109,6 +110,45 @@ function ZedSteps({ config, onCopy }) { ); } +// Sublime Text debugs PHP with the Debugger package, a third-party package +// whose setup is its own README's to say (#758). The dialog gives only what +// this site needs, and names the Node.js the PHP adapter needs, which the +// README does not. It deliberately leaves out the fix for a Sublime opened +// from the macOS Dock not finding an nvm or Homebrew Node (the package's +// `node` setting): the README does not cover that either, and the app does +// not troubleshoot a third-party package. +const SUBLIME_DEBUGGER_URL = 'https://github.com/daveleroy/SublimeDebugger'; + +function SublimeSteps({ config, onCopy }) { + // A real link, so it is announced as one and its address can be copied; + // the browser opens it, not the window. + const link = ( + { event.preventDefault(); window.api.openExternal(SUBLIME_DEBUGGER_URL); }} + /> + ); + return ( + <> + {createInterpolateElement( + __('Sublime Text debugs PHP with the Debugger package and its PHP adapter, which needs Node.js. If you haven’t set them up, follow the Debugger package’s setup guide.'), + { ...STEP_MARKUP, link } + )} +
    + xdebug.sublime-project, and open it with Project → Open Project:')}> +
    +
    {config}
    + + + +
    +
    + +
+ + ); +} + // A value for PhpStorm's settings: its field's name over it, and its copy // button at the end, described by that name. function PhpStormValue({ value, onCopy }) { @@ -147,20 +187,21 @@ function PhpStormSteps({ values, onCopy }) { /** * How to stop on breakpoints while the site's server has Xdebug (#723), for * one editor, picked from the Debugging row's menu: VS Code or Cursor, with - * the launch.json they need, Zed, with its debug.json, or PhpStorm, with the - * values its settings need. The - * app shows and copies them, and never writes them into the checkout, where - * they would end up in a patch. + * the launch.json they need, Zed, with its debug.json, Sublime Text, with its + * project file, or PhpStorm, with the values its settings need. The app + * shows and copies them, and never writes them into the checkout, where they + * would end up in a patch. * * @param {Object} props * @param {?Object} props.editor The editor while open, from `xdebugEditors`: `{id, name, setup}`; or null. * @param {string} props.config The launch.json, from `xdebugLaunchConfig`. * @param {string} props.zed The debug.json, from `zedDebugConfig`. + * @param {string} props.sublime The .sublime-project, from `sublimeProjectConfig`. * @param {Array} props.phpStorm The PhpStorm values, from `phpStormSettings`. * @param {Function} props.onCopy Copies a text, resolving to whether it worked. * @param {Function} props.onClose */ -export function XdebugSetupDialog({ editor, config, zed, phpStorm, onCopy, onClose }) { +export function XdebugSetupDialog({ editor, config, zed, sublime, phpStorm, onCopy, onClose }) { // The editor stays drawn while the dialog closes, when `editor` is already // null. const [shown, setShown] = useState(editor); @@ -170,7 +211,8 @@ export function XdebugSetupDialog({ editor, config, zed, phpStorm, onCopy, onClo const phpStormShown = setup === 'phpstorm'; const steps = { phpstorm: , - zed: + zed: , + sublime: }; return ( { if (!next) onClose(); }}> diff --git a/src/renderer/index.jsx b/src/renderer/index.jsx index 182d6b51..8b4327f3 100644 --- a/src/renderer/index.jsx +++ b/src/renderer/index.jsx @@ -2614,7 +2614,7 @@ function SiteRow({ sitePath, initialized, createdAt, label, projectType = null, onClose={() => setDirtyModalOpen(false)} /> ) : null} - entry.id === xdebugEditor) || null : null} config={xdebug ? xdebug.config : ''} zed={xdebug ? xdebug.zed : ''} phpStorm={xdebug ? xdebug.phpStorm : []} onCopy={copyXdebugConfig} onClose={() => setXdebugEditor(null)} /> + entry.id === xdebugEditor) || null : null} config={xdebug ? xdebug.config : ''} zed={xdebug ? xdebug.zed : ''} sublime={xdebug ? xdebug.sublime : ''} phpStorm={xdebug ? xdebug.phpStorm : []} onCopy={copyXdebugConfig} onClose={() => setXdebugEditor(null)} /> asking.action()} onClose={() => setAsking(null)} /> {isPatchOpen && ( diff --git a/src/renderer/xdebug.cjs b/src/renderer/xdebug.cjs index 30c7ab21..0c2c0935 100644 --- a/src/renderer/xdebug.cjs +++ b/src/renderer/xdebug.cjs @@ -66,6 +66,29 @@ function zedDebugConfig({ sitePath, serve }) { ], null, 2); } +/** + * The .sublime-project a contributor saves for Sublime Text's Debugger + * package, which runs the same Xdebug adapter as VS Code's PHP Debug, as + * "php", and reads its setups from `debugger_configurations` in the project + * file. It is saved in the site's folder, like the other editors' files, so + * the folder it opens is that one; the site's `.git/info/exclude` keeps it, + * and the .sublime-workspace Sublime writes beside it, out of a patch. + * + * @param {Object} root0 + * @param {string} root0.sitePath The checkout's folder, in this platform's form. + * @param {Object} root0.serve The project's serve model: `{strategy, pluginSlug}`. + * @return {string} The file's text. + */ +function sublimeProjectConfig({ sitePath, serve }) { + const { server, local } = xdebugMapping({ sitePath, serve }); + return JSON.stringify({ + folders: [{ path: '.' }], + debugger_configurations: [ + { name: 'Listen for Xdebug', type: 'php', request: 'launch', hostname: XDEBUG_HOST, port: XDEBUG_PORT, pathMappings: { [server]: local } } + ] + }, null, 2); +} + /** * The one mapping between the path PHP sees and the folder on this machine, * which every editor needs; see `xdebugLaunchConfig` for why it is this one. @@ -147,9 +170,9 @@ function xdebugStatus({ setting, running, startedWith, holder = '', heldAtStart /** * What the server's details say of Xdebug: null when there is nothing to * say; otherwise whether the server has it, the note from `xdebugStatus`, - * and the launch.json for VS Code, the debug.json for Zed and the values for - * PhpStorm while it has - * it (and nothing when it would not connect). + * and the launch.json for VS Code, the debug.json for Zed, the project file + * for Sublime Text and the values for PhpStorm while it has it (and nothing + * when it would not connect). * * @param {Object} root0 * @param {boolean} root0.setting What the settings hold. @@ -161,7 +184,7 @@ function xdebugStatus({ setting, running, startedWith, holder = '', heldAtStart * @param {Function} [root0.nameFor] A site's name, by its path. * @param {Object} root0.serve The project's serve model. * @param {string} root0.url The running server's address. - * @return {?{on: boolean, note: string, config: string, zed: string, phpStorm: Array}} + * @return {?{on: boolean, note: string, config: string, zed: string, sublime: string, phpStorm: Array}} */ function xdebugSection({ setting, running, startedWith, heldAtStart = false, sitePath, servers = {}, nameFor = (dir) => dir, serve, url }) { const holderPath = xdebugHolder({ sitePath, servers }); @@ -171,6 +194,7 @@ function xdebugSection({ setting, running, startedWith, heldAtStart = false, sit ...status, config: status.on ? xdebugLaunchConfig({ sitePath, serve }) : '', zed: status.on ? zedDebugConfig({ sitePath, serve }) : '', + sublime: status.on ? sublimeProjectConfig({ sitePath, serve }) : '', phpStorm: status.on ? phpStormSettings({ sitePath, serve, url }) : [] }; } @@ -193,19 +217,20 @@ function xdebugHolder({ sitePath, servers }) { /** * The editors the setup menu offers: those found on this machine that have a * setup, in this order. Cursor reads VS Code's launch.json, so it gets that - * setup under its own name. Sublime Text has none: its PHP debugger needs - * Node.js installed, which the toolkit does not ask for. With none found - * that has a setup, there is nothing to set up, and the list is empty. + * setup under its own name. Sublime Text's Debugger package needs Node.js + * on the computer, which its setup says (#758). With none found that has a + * setup, there is nothing to set up, and the list is empty. * * @param {Array<{id: string}>} [detected] From `editor:list`. - * @return {Array<{id: string, name: string, setup: string}>} `setup` is 'vscode', 'phpstorm' or 'zed'. + * @return {Array<{id: string, name: string, setup: string}>} `setup` is 'vscode', 'phpstorm', 'zed' or 'sublime'. */ function xdebugEditors(detected) { const editors = [ { id: 'vscode', name: __('VS Code'), setup: 'vscode' }, { id: 'cursor', name: __('Cursor'), setup: 'vscode' }, { id: 'phpstorm', name: __('PhpStorm'), setup: 'phpstorm' }, - { id: 'zed', name: __('Zed'), setup: 'zed' } + { id: 'zed', name: __('Zed'), setup: 'zed' }, + { id: 'sublime', name: __('Sublime Text'), setup: 'sublime' } ]; const ids = new Set((detected || []).map((editor) => editor.id)); return editors.filter((editor) => ids.has(editor.id)); @@ -229,4 +254,4 @@ function xdebugSetupEditor({ editors = [], preferred = null } = {}) { return { ...chosen, label: sprintf(__('Set up Xdebug for %s'), chosen.name) }; } -module.exports = { XDEBUG_PORT, xdebugLaunchConfig, phpStormSettings, xdebugStatus, xdebugSection, xdebugHolder, xdebugEditors, xdebugSetupEditor, zedDebugConfig }; +module.exports = { XDEBUG_PORT, xdebugLaunchConfig, phpStormSettings, xdebugStatus, xdebugSection, xdebugHolder, xdebugEditors, xdebugSetupEditor, zedDebugConfig, sublimeProjectConfig }; diff --git a/tests/e2e/journeys/xdebug.spec.js b/tests/e2e/journeys/xdebug.spec.js index 7f19a5fe..b77d6023 100644 --- a/tests/e2e/journeys/xdebug.spec.js +++ b/tests/e2e/journeys/xdebug.spec.js @@ -319,8 +319,8 @@ test( 'a setup dialog closed by the server going does not open again by itself a } ); // The menu offers the editors found on this machine that have a setup (#723): -// Cursor gets VS Code's, Zed its own, and Sublime Text none. Finding none of -// them, there is nothing to set up, and no setup is offered. +// Cursor gets VS Code's, and Zed and Sublime Text their own (#758). Finding +// none of them, there is nothing to set up, and no setup is offered. test( 'the setup menu offers the detected editors that have a setup, and no setup when it finds none', async ( { session } ) => { const site = await makeSite( session ); const { app, page } = await session.start( site.settings ); @@ -334,7 +334,7 @@ test( 'the setup menu offers the detected editors that have a setup, and no setu await ui.startDevServerButton( page ).click(); await setup.click(); // INVARIANT — only the detected editors with a setup, in a fixed order. - await expect.poll( items ).toEqual( [ 'Cursor', 'Zed' ] ); + await expect.poll( items ).toEqual( [ 'Cursor', 'Zed', 'Sublime Text' ] ); // INVARIANT — Cursor's is VS Code's launch.json, under Cursor's name. await page.getByRole( 'menuitem', { name: 'Cursor', exact: true } ).click(); @@ -362,9 +362,39 @@ test( 'the setup menu offers the detected editors that have a setup, and no setu await page.keyboard.press( 'Escape' ); await expect( zed ).toHaveCount( 0 ); + // INVARIANT — Sublime Text's is a .sublime-project for the Debugger + // package's PHP adapter, with the same listener and mapping. Setting the + // package up is its own guide's to say; the dialog links to it and names + // the Node.js that guide leaves out. + await setup.click(); + await page.getByRole( 'menuitem', { name: 'Sublime Text', exact: true } ).click(); + const sublime = page.getByRole( 'dialog', { name: 'Set up Sublime Text', exact: true } ); + await expect( sublime ).toBeVisible(); + await expect( sublime ).toContainText( 'Sublime Text debugs PHP with the Debugger package and its PHP adapter, which needs Node.js.' ); + // The link opens the guide in the browser; the function that would open it + // records the address instead. + await app.evaluate( ( { shell } ) => { + global.e2eOpened = []; + shell.openExternal = async ( url ) => { global.e2eOpened.push( url ); }; + } ); + const guide = sublime.getByRole( 'link', { name: /^Debugger package’s setup guide/ } ); + await expect( guide ).toHaveAttribute( 'href', 'https://github.com/daveleroy/SublimeDebugger' ); + await guide.click(); + await expect.poll( () => app.evaluate( () => global.e2eOpened ) ).toEqual( [ 'https://github.com/daveleroy/SublimeDebugger' ] ); + // INVARIANT — the file has a name before its extension: a file named only + // .sublime-project is hidden on macOS, and Open Project cannot choose it. + await expect( sublime.locator( '.xdebug-setup-step' ).first() ).toContainText( 'Save this in the site’s folder as xdebug.sublime-project' ); + const project = JSON.parse( await sublime.locator( '.xdebug-launch-config' ).textContent() ); + expect( project.folders ).toEqual( [ { path: '.' } ] ); + expect( project.debugger_configurations[ 0 ] ).toMatchObject( { type: 'php', request: 'launch', port: 9003, hostname: '127.0.0.1' } ); + expect( project.debugger_configurations[ 0 ].pathMappings ).toEqual( { '/wordpress': path.join( site.dir, 'src' ) } ); + await expect( sublime.getByRole( 'button', { name: 'Copy project file', exact: true } ) ).toBeVisible(); + await page.keyboard.press( 'Escape' ); + await expect( sublime ).toHaveCount( 0 ); + // INVARIANT — with nothing detected that has a setup, the row still names // Xdebug and offers no setup. - await app.evaluate( () => { global.e2eEditors = [ 'sublime' ]; } ); + await app.evaluate( () => { global.e2eEditors = []; } ); await ui.stopDevServerButton( page ).click(); await ui.startDevServerButton( page ).click(); await expect( ui.stopDevServerButton( page ) ).toBeVisible(); diff --git a/tests/unit/ipc-wiring.test.cjs b/tests/unit/ipc-wiring.test.cjs index d8ed6c8b..41720c32 100644 --- a/tests/unit/ipc-wiring.test.cjs +++ b/tests/unit/ipc-wiring.test.cjs @@ -1931,6 +1931,37 @@ test('site:status excludes editor folders from a site seeded before they were ad assert.equal(exclude.split('# WordPress Contributor Toolkit local excludes').length - 1, 1, 'the agent block is not written again'); }); +// The Xdebug setup for Sublime Text asks for a .sublime-project in the site's +// folder (#758). A site seeded before then has the editor block, written only +// once, so the project file arrives in a block of its own. +test('site:status excludes a Sublime Text project from a site seeded before it was added (issue #758)', async (t) => { + const dir = adoptedRepo(t, 'ipc-wiring-sublime-exclude-'); + fs.writeFileSync(path.join(dir, 'README.md'), 'managed wordpress-develop site\n'); + commitFiles(dir, ['README.md'], 'init'); + fs.writeFileSync(path.join(dir, '.git', 'info', 'exclude'), '# WordPress Contributor Toolkit local excludes\n/.claude/\n# WordPress Contributor Toolkit editor folders\n/.vscode/\n'); + fs.writeFileSync(path.join(dir, 'wordpress.sublime-project'), '{}\n'); + fs.writeFileSync(path.join(dir, 'wordpress.sublime-workspace'), '{}\n'); + fs.appendFileSync(path.join(dir, 'README.md'), 'real contributor edit\n'); + + const main = loadMain({ + stubs: { + ...silentLogging(), + ...fakeSettingsStore({ sites: [dir], siteMeta: { [dir]: {} } }).stubs + } + }); + await main.invoke('site:status', dir); + const result = await main.invoke('git:get-patch', dir); + + assert.equal(result.ok, true); + assert.match(result.patch, /README\.md/, 'the contributor\'s WordPress change stays visible'); + assert.doesNotMatch(result.patch, /sublime-project/); + assert.doesNotMatch(result.patch, /sublime-workspace/); + + await main.invoke('site:status', dir); + const exclude = fs.readFileSync(path.join(dir, '.git', 'info', 'exclude'), 'utf8'); + assert.equal(exclude.split('# WordPress Contributor Toolkit Sublime Text').length - 1, 1, 'the Sublime Text block is added only once'); +}); + // --- what the patch says about deletions, additions and binaries (#85) --- // A repository with a committed base, for the generation tests below. Returns diff --git a/tests/unit/xdebug.test.cjs b/tests/unit/xdebug.test.cjs index db208a62..5c5868e9 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, xdebugSetupEditor, zedDebugConfig } = require('../../src/renderer/xdebug.cjs'); +const { xdebugLaunchConfig, phpStormSettings, xdebugStatus, xdebugSection, xdebugHolder, xdebugEditors, xdebugSetupEditor, zedDebugConfig, sublimeProjectConfig } = require('../../src/renderer/xdebug.cjs'); const mappings = (text) => JSON.parse(text).configurations[0].pathMappings; @@ -171,7 +171,8 @@ test('the setup menu lists the detected editors that have a setup, in a fixed or assert.deepEqual(xdebugEditors(found('zed', 'sublime', 'phpstorm', 'vscode')), [ { id: 'vscode', name: 'VS Code', setup: 'vscode' }, { id: 'phpstorm', name: 'PhpStorm', setup: 'phpstorm' }, - { id: 'zed', name: 'Zed', setup: 'zed' } + { id: 'zed', name: 'Zed', setup: 'zed' }, + { id: 'sublime', name: 'Sublime Text', setup: 'sublime' } ]); }); @@ -183,7 +184,7 @@ test('Cursor gets the VS Code setup, under its own name', () => { // menu has no entries, and the Debugging row offers no setup. test('with no detected editor that has a setup, the menu offers nothing', () => { assert.deepEqual(xdebugEditors([]), []); - assert.deepEqual(xdebugEditors(found('sublime')), []); + assert.deepEqual(xdebugEditors(found('notepad')), []); assert.deepEqual(xdebugEditors(undefined), []); }); @@ -197,9 +198,9 @@ test('the setup opens the editor chosen in Settings directly when it has a setup }); 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')); + const editors = xdebugEditors(found('vscode', 'notepad')); assert.equal(xdebugSetupEditor({ editors, preferred: null }), null); - assert.equal(xdebugSetupEditor({ editors, preferred: 'sublime' }), null); + assert.equal(xdebugSetupEditor({ editors, preferred: 'notepad' }), null); assert.equal(xdebugSetupEditor({ editors, preferred: 'zed' }), null); assert.equal(xdebugSetupEditor({ editors: undefined, preferred: 'vscode' }), null); }); @@ -226,3 +227,29 @@ test('a server with Xdebug gets its Zed config', () => { assert.equal(section.zed, zedDebugConfig({ sitePath: '/sites/wp', serve: { strategy: 'docroot' } })); assert.equal(xdebugSection({ sitePath: '/sites/wp', serve: { strategy: 'docroot' }, setting: true, running: true, startedWith: false }).zed, ''); }); + +// Sublime Text's Debugger package reads `debugger_configurations` from a +// .sublime-project and runs the same Xdebug adapter as VS Code, as "php" +// (#758). The file is saved in the site's folder, so it opens that folder. +test('the Sublime Text project file opens the site and listens on 127.0.0.1:9003 with the launch.json mapping', () => { + for (const sitePath of ['/sites/wp', 'C:\\sites\\wp']) { + for (const serve of [{ strategy: 'docroot' }, { strategy: 'plugin-mount', pluginSlug: 'gutenberg' }]) { + const project = JSON.parse(sublimeProjectConfig({ sitePath, serve })); + assert.deepEqual(project.folders, [{ path: '.' }]); + assert.equal(project.debugger_configurations.length, 1); + const [listen] = project.debugger_configurations; + assert.equal(listen.type, 'php'); + assert.equal(listen.request, 'launch'); + assert.equal(listen.port, 9003); + assert.equal(listen.hostname, '127.0.0.1'); + assert.equal(listen.name, 'Listen for Xdebug'); + assert.deepEqual(listen.pathMappings, mappings(xdebugLaunchConfig({ sitePath, serve }))); + } + } +}); + +test('a server with Xdebug gets its Sublime Text project file', () => { + const section = xdebugSection({ sitePath: '/sites/wp', serve: { strategy: 'docroot' }, url: 'http://127.0.0.1:9400/', setting: true, running: true, startedWith: true }); + assert.equal(section.sublime, sublimeProjectConfig({ sitePath: '/sites/wp', serve: { strategy: 'docroot' } })); + assert.equal(xdebugSection({ sitePath: '/sites/wp', serve: { strategy: 'docroot' }, setting: true, running: true, startedWith: false }).sublime, ''); +});