-
-
Notifications
You must be signed in to change notification settings - Fork 177
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ci: Ability to open a browser when the debug session is created #315
base: main
Are you sure you want to change the base?
Conversation
Adds launch option which allows setting the command to run and the URL to open (to open a browser) with the xdebug query param to start the debugging session
Codecov Report
@@ Coverage Diff @@
## master #315 +/- ##
==========================================
- Coverage 70.05% 69.74% -0.32%
==========================================
Files 5 5
Lines 1012 1028 +16
Branches 161 163 +2
==========================================
+ Hits 709 717 +8
- Misses 303 311 +8
Continue to review full report at Codecov.
|
package.json
Outdated
"type": "object", | ||
"description": "Allows you to open the browser with xdebug start query string", | ||
"properties": { | ||
"cmd": "string", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like that one has to specify a command, can we just use a package like https://www.npmjs.com/package/open?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this valid JSON schema? Should this be "cmd": {"type": "string"}
?
package.json
Outdated
"description": "Allows you to open the browser with xdebug start query string", | ||
"properties": { | ||
"cmd": "string", | ||
"URI": "string" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use camelCase
src/phpDebug.ts
Outdated
@@ -67,6 +67,9 @@ interface LaunchRequestArguments extends VSCodeDebugProtocol.LaunchRequestArgume | |||
/** XDebug configuration */ | |||
xdebugSettings?: { [featureName: string]: string | number } | |||
|
|||
/** Ability to open browser */ | |||
openUrl?: { [key: string]: string } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This says that the object allows arbitrary properties, but the schema clearly says only cmd
and URL
are allowed
src/phpDebug.ts
Outdated
@@ -990,6 +996,11 @@ class PhpDebugSession extends vscode.DebugSession { | |||
await connection.close() | |||
this._connections.delete(id) | |||
this._waitingConnections.delete(connection) | |||
if (this._args.openUrl && this._args.openUrl.cmd && this._args.openUrl.URI) { | |||
childProcess.spawn(this._args.openUrl.cmd, [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no error handling here
Hi, i will implement the other things you menthined, but when i try to add the open module it just wont create the packages-lock.jsosn file (which seems to be neerded for the checking stuff), can you help me with that (tried simple npm install --save open, but as i say, doesn't update the lock file)? |
Are you running at least node 8 and npm 6? |
And of course it does update it now... :-/ so you were probably right and it didn;t work until reboot ... ok will do the other things now... so don't bother :) |
Remove requirement for the cmd, change the config option from object to string and add some logging
Change the launch.json script of the test project to implement the latest changes
Hi, |
src/phpDebug.ts
Outdated
@@ -12,6 +12,9 @@ import { Terminal } from './terminal' | |||
import { isSameUri, convertClientPathToDebugger, convertDebuggerPathToClient } from './paths' | |||
import minimatch = require('minimatch') | |||
|
|||
let open = require('open') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use import open from 'open'
or this is not type safe. You'll need to add npm install --save-dev @types/open
src/phpDebug.ts
Outdated
@@ -12,6 +12,9 @@ import { Terminal } from './terminal' | |||
import { isSameUri, convertClientPathToDebugger, convertDebuggerPathToClient } from './paths' | |||
import minimatch = require('minimatch') | |||
|
|||
let open = require('open') | |||
let appendQuery = require('append-query') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is built into Node, no need for a dependency. Just use import { URL } from 'url'
src/phpDebug.ts
Outdated
@@ -311,6 +317,12 @@ class PhpDebugSession extends vscode.DebugSession { | |||
this.sendErrorResponse(response, <Error>error) | |||
}) | |||
server.listen(args.port || 9000, (error: NodeJS.ErrnoException) => (error ? reject(error) : resolve())) | |||
if (args.openUrl) { | |||
let proc = open(appendQuery(args.openUrl, 'XDEBUG_SESSION_START=vscode')) | |||
proc.stderr.on('data', (data: any) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
data
is not any
, it's either a string or a Buffer, in which case the logged output would be useless (octets). I don't know from the top of my head what it is, but it should not be typed any
.
src/phpDebug.ts
Outdated
if (args.openUrl) { | ||
let proc = open(appendQuery(args.openUrl, 'XDEBUG_SESSION_START=vscode')) | ||
proc.stderr.on('data', (data: any) => { | ||
this.sendEvent(new vscode.OutputEvent('openUrl: ' + util.inspect(data) + '\n')) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You shouldn't use inspect
because it's not a structured object
src/phpDebug.ts
Outdated
proc.stderr.on('data', (data: any) => { | ||
this.sendEvent(new vscode.OutputEvent('openUrl: ' + util.inspect(data) + '\n')) | ||
}) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code is duplicated, it should be in a shared function
src/phpDebug.ts
Outdated
@@ -311,6 +317,12 @@ class PhpDebugSession extends vscode.DebugSession { | |||
this.sendErrorResponse(response, <Error>error) | |||
}) | |||
server.listen(args.port || 9000, (error: NodeJS.ErrnoException) => (error ? reject(error) : resolve())) | |||
if (args.openUrl) { | |||
let proc = open(appendQuery(args.openUrl, 'XDEBUG_SESSION_START=vscode')) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use const
Hi, |
Any news here? :) |
@@ -34,10 +34,12 @@ | |||
"url": "https://github.com/felixfbecker/vscode-php-debug/issues" | |||
}, | |||
"dependencies": { | |||
"append-query": "^2.0.1", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This dependency is now unused
}) | ||
}).catch((reason: any) => { | ||
this.sendEvent(new vscode.OutputEvent('openUrl-error: ' + util.inspect(reason) + '\n')) | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of loggint the error here, it’s better to make this an async function and have the callers await it, so an error is reported as a response to the request
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure what exactly you mean here... so i should remove the .catch and just return the result?
Also should the then be removed too?
The start call would have to be moved to 'connection' callback, but that should be fine
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See my two suggestions above. In addition you'd remove the .catch()
and "unwrap" the .then()
.
} | ||
const myurl = new url.URL(this._args.openUrl) | ||
if (start) { | ||
myurl.searchParams.append('XDEBUG_SESSION_START', 'vscode') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should be set, not append, since append would duplicate the parameter if it’s already set
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would rather keep the append, as a the stop command would be confusing for the xdebug anyway and this may be visible straight away
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand what this has to do with the stop command - what I mean is that append
would potentially add XDEBUG_SESSION_START
twice or more times, like ?XDEBUG_SESSION_START=vscode&XDEBUG_SESSION_START=vscode
, while set()
would just override it so XDEBUG_SESSION_START
appears exactly once
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but what would happen when the stop command should be sent? XDEBUG_SESSION_START=vscode&XDEBUG_SESSION_STOP=vscode (with set or append) as the param is diferrent, so it would be easier to spot such errors.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.set('XDEBUG_SESSION_START', ...)
won't remove the XDEBUG_SESSION_STOP
param.
* Opens the urls specified in configuration, either with start or stop query string | ||
* @param {boolean} start | ||
*/ | ||
private _openUrl(start: boolean) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
private _openUrl(start: boolean) { | |
private async _openUrl(start: boolean): Promise<void> { |
myurl.searchParams.append('XDEBUG_SESSION_STOP', 'vscode') | ||
} | ||
|
||
const proc = opn(myurl.toString()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const proc = opn(myurl.toString()) | |
const proc = await opn(myurl.toString()) |
Hi @letynsoft @felixfbecker Any idea on when you might get this completed, it's a feature I would really like to see. I've just moved back to VSC from NetBeans which had a pretty good config for doing this and I'm missing it already. As an aside, could you also add something along the lines of "program" (very weird choice of parameter name for script) and "args" that does not terminate the debug session which it finishes? Maybe an "init" object with "program" or "script" and "args" that are run when the debugger is started. This would allow platform specific code to run via exec which could open a browser (start http://.... on Windows) or all manner of other funky stuff. |
Adds launch option which allows setting the command to run and the URL to open (to open a browser) with the xdebug query param to start the debugging session