Skip to content
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

Open
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

letynsoft
Copy link

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

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
Copy link

codecov bot commented Oct 12, 2018

Codecov Report

Merging #315 into master will decrease coverage by 0.31%.
The diff coverage is 37.5%.

Impacted file tree graph

@@            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
Impacted Files Coverage Δ
src/phpDebug.ts 66.26% <37.5%> (-0.54%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 047777b...af056c8. Read the comment docs.

package.json Outdated
"type": "object",
"description": "Allows you to open the browser with xdebug start query string",
"properties": {
"cmd": "string",
Copy link
Contributor

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?

Copy link
Contributor

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"
Copy link
Contributor

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 }
Copy link
Contributor

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, [
Copy link
Contributor

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

@letynsoft
Copy link
Author

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)?
Also not sure what you mean with the camel case one, but i guess, once i figure out the open package, it will only need a string URL there

@felixfbecker
Copy link
Contributor

Are you running at least node 8 and npm 6?

@letynsoft
Copy link
Author

letynsoft commented Oct 17, 2018

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
@letynsoft
Copy link
Author

letynsoft commented Oct 17, 2018

Hi,
So i have updated the feature.
Let me know your thoughts :)

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')
Copy link
Contributor

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')
Copy link
Contributor

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) => {
Copy link
Contributor

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'))
Copy link
Contributor

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'))
})
}
Copy link
Contributor

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'))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use const

@letynsoft
Copy link
Author

Hi,
Another update...
Seems i didn't notice the first open should have been opn in the commit title :-/

@letynsoft
Copy link
Author

Any news here? :)

@@ -34,10 +34,12 @@
"url": "https://github.com/felixfbecker/vscode-php-debug/issues"
},
"dependencies": {
"append-query": "^2.0.1",
Copy link
Contributor

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'))
})
Copy link
Contributor

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

Copy link
Author

@letynsoft letynsoft Dec 22, 2018

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

Copy link
Contributor

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')
Copy link
Contributor

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

Copy link
Author

@letynsoft letynsoft Dec 22, 2018

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

Copy link
Contributor

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

Copy link
Author

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.

Copy link
Contributor

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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
private _openUrl(start: boolean) {
private async _openUrl(start: boolean): Promise<void> {

myurl.searchParams.append('XDEBUG_SESSION_STOP', 'vscode')
}

const proc = opn(myurl.toString())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const proc = opn(myurl.toString())
const proc = await opn(myurl.toString())

@ianef
Copy link

ianef commented Mar 8, 2019

Hi @letynsoft @felixfbecker
This is an excellent step forward. I've just tried to implement a simple solution using the "program" and "args" properties but it stops debugging when the "program" script ends.

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.

@felixfbecker felixfbecker changed the base branch from master to main December 21, 2020 20:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants