Skip to content

Commit 0197bed

Browse files
committed
fix: Keep virtual source reference consistent (#574)
* Keep virtual source reference consistent. * Changelog.
1 parent 81dd7f4 commit 0197bed

File tree

2 files changed

+30
-7
lines changed

2 files changed

+30
-7
lines changed

CHANGELOG.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,21 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
1010

1111
- Option to start PHP built-in web server without router script.
1212

13+
### Fixed
14+
15+
- Internal Source Reference for virtual source files fixed - when stepping into eval()
16+
1317
## [1.15.1]
1418

1519
### Changed
1620

17-
- Defined under packages.json this extension should be prefered for PHP debugging.
21+
- Defined under packages.json this extension should be preferred for PHP debugging.
1822

1923
## [1.15.0]
2024

2125
### Added
2226

23-
- Support for terminateDebuggee option letting the user choose to keep the debugee running. Press Alt when hovering over stop action.
27+
- Support for terminateDebuggee option letting the user choose to keep the debuggee running. Press Alt when hovering over stop action.
2428
- Handle breakpoints in a async manner.
2529

2630
### Changed

src/phpDebug.ts

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -586,8 +586,16 @@ class PhpDebugSession extends vscode.DebugSession {
586586
let source: VSCodeDebugProtocol.Source
587587
const urlObject = url.parse(status.fileUri)
588588
if (urlObject.protocol === 'dbgp:') {
589-
const sourceReference = this._sourceIdCounter++
590-
this._sources.set(sourceReference, { connection, url: status.fileUri })
589+
let sourceReference
590+
const src = Array.from(this._sources).find(
591+
([, v]) => v.url === status.fileUri && v.connection === connection
592+
)
593+
if (src) {
594+
sourceReference = src[0]
595+
} else {
596+
sourceReference = this._sourceIdCounter++
597+
this._sources.set(sourceReference, { connection, url: status.fileUri })
598+
}
591599
// for eval code, we need to include .php extension to get syntax highlighting
592600
source = { name: status.exception.name + '.php', sourceReference, origin: status.exception.name }
593601
// for eval code, we add a "<?php" line at the beginning to get syntax highlighting (see sourceRequest)
@@ -608,11 +616,22 @@ class PhpDebugSession extends vscode.DebugSession {
608616
let line = stackFrame.line
609617
const urlObject = url.parse(stackFrame.fileUri)
610618
if (urlObject.protocol === 'dbgp:') {
611-
const sourceReference = this._sourceIdCounter++
612-
this._sources.set(sourceReference, { connection, url: stackFrame.fileUri })
619+
let sourceReference
620+
const src = Array.from(this._sources).find(
621+
([, v]) => v.url === stackFrame.fileUri && v.connection === connection
622+
)
623+
if (src) {
624+
sourceReference = src[0]
625+
} else {
626+
sourceReference = this._sourceIdCounter++
627+
this._sources.set(sourceReference, { connection, url: stackFrame.fileUri })
628+
}
613629
// for eval code, we need to include .php extension to get syntax highlighting
614630
source = {
615-
name: stackFrame.type === 'eval' ? 'eval.php' : stackFrame.name,
631+
name:
632+
stackFrame.type === 'eval'
633+
? `eval ${stackFrame.fileUri.substr(7)}.php`
634+
: stackFrame.name,
616635
sourceReference,
617636
origin: stackFrame.type,
618637
}

0 commit comments

Comments
 (0)