Conversation
d8b025e to
8856b90
Compare
f531331 to
5a46aa6
Compare
| } | ||
|
|
||
| foreach (glob($mapPath.'/*.map') as $mapFile) { | ||
| xdebug_set_source_map($mapFile); |
There was a problem hiding this comment.
This function is not available yet but this is the cleaneast way to do it IMHO.
There was a problem hiding this comment.
is there any public discussion on the Xdebug side about this function ?
Btw, the verb set in the name is confusing if it registers a new source map without removing the previous one, as that's not the usual meaning of set in function names.
There was a problem hiding this comment.
As this is a feature that I haven't added yet, I am more than happy to discuss how it should work. I agree that using xdebug_add_source_map is probably a better choice. Right now, the internals will reject a new source map if it touches the same files though, and that seems not so easy to change.
Alternatively, I could add a new function xdebug_add_source_map_directory, which you would only have to call once before the compiled template files are loaded into PHP's memory through include.
Then Xdebug can (additionally) scan this directory to pick up any source maps that exist.
There was a problem hiding this comment.
xdebug_add_source_map_directory might be better for the Twig use case indeed (and might maybe have less overhead for requests not using breakpoints by skipping the filesystem scanning, depending on when xdebug actually traverses those directories)
There was a problem hiding this comment.
It currently scans the files (if path mapping is enabled) at the start of every request. Although for now, it only works with the step debugger, in the future I want to extend the support to maps to other features too: https://xdebug.org/funding/001-native-path-mapping#future-scope
|
@derickr I would love to get your feedback on how I've integrated the source map feature with Twig. |
5a46aa6 to
e717cb6
Compare
src/Cache/ChainCache.php
Outdated
| $directories = []; | ||
| foreach ($this->caches as $cache) { | ||
| if ($cache instanceof DirectoryCacheInterface) { | ||
| $directories []= $cache->getDirectories(); |
There was a problem hiding this comment.
| $directories []= $cache->getDirectories(); | |
| $directories[] = $cache->getDirectories(); |
e717cb6 to
64a7bf9
Compare
derickr
left a comment
There was a problem hiding this comment.
Thanks for looking into this!
I left some comments and questions to ask how things can be improved.
I'm also still waiting on https://youtrack.jetbrains.com/issue/WI-81344/Cant-Set-Breakpoints-in-Template-Files-Even-Though-I-Added-The-File-Name-Pattern-to-PHP to make it into a release of PhpStorm (it's already fine with VS Code's Plugin)
| } | ||
|
|
||
| foreach (glob($mapPath.'/*.map') as $mapFile) { | ||
| xdebug_set_source_map($mapFile); |
There was a problem hiding this comment.
As this is a feature that I haven't added yet, I am more than happy to discuss how it should work. I agree that using xdebug_add_source_map is probably a better choice. Right now, the internals will reject a new source map if it touches the same files though, and that seems not so easy to change.
Alternatively, I could add a new function xdebug_add_source_map_directory, which you would only have to call once before the compiled template files are loaded into PHP's memory through include.
Then Xdebug can (additionally) scan this directory to pick up any source maps that exist.
| $endLine, | ||
| basename($templatePath), | ||
| $debugInfo[$startLine], | ||
| ); |
There was a problem hiding this comment.
I imagine, this gets large, as there is a separate entry in the source file for each line.
I am planning on optimising this, using how JavaScript source maps approach the line-to-line mappings, if possible.
I would also recommend that if $startLine and $endline are the same, you should not include the $endLine in the mapping. It saves some processing on the Xdebug side (runs many times), where doing the test here needs to be done once per map-write.
| $startLine = $compiledLines[$i]; | ||
| // End line is exclusive, so use next start line minus 1 | ||
| // Use a reasonable max for last range (Xdebug can't handle PHP_INT_MAX) | ||
| $endLine = isset($compiledLines[$i + 1]) ? $compiledLines[$i + 1] - 1 : 999999; |
There was a problem hiding this comment.
I don't like it that you need to use a random largish constant (999999) here. Perhaps it would make sense if I add an EOF marker to the parser, so that you can do:
compiled_file.php:5-EOF = orig_file.twig:4
Would that be helpful?
There was a problem hiding this comment.
it would definitely be helpful here.
Closes #4697