-
-
Notifications
You must be signed in to change notification settings - Fork 182
Path mappings #175
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
Path mappings #175
Conversation
…ed multiple paths to test project. Renamed to pathMappings to reflect original issue. Added unix fix
# Conflicts: # package.json # src/paths.ts
src/paths.ts
Outdated
| serverPath = serverPath.substr(1); | ||
| } | ||
|
|
||
| if ( pathMapping !== {} && typeof pathMapping !== 'undefined' ) { |
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.
Object references are never the same thus {} !== {} always is true no?
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.
hm, you're correct.
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.
Just check for own properties by Object.keys maybe?
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.
removed in d005226
Codecov Report
@@ Coverage Diff @@
## master #175 +/- ##
==========================================
+ Coverage 76.34% 79.81% +3.47%
==========================================
Files 2 2
Lines 93 109 +16
Branches 17 22 +5
==========================================
+ Hits 71 87 +16
Misses 14 14
Partials 8 8
Continue to review full report at Codecov.
|
src/paths.ts
Outdated
|
|
||
| /** converts a server-side XDebug file URI to a local path for VS Code with respect to source root settings */ | ||
| export function convertDebuggerPathToClient(fileUri: string|url.Url, localSourceRoot?: string, serverSourceRoot?: string): string { | ||
| export function convertDebuggerPathToClient(fileUri: string|url.Url, localSourceRoot?: string, serverSourceRoot?: string, pathMapping?: { [index: string]: 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.
isn't localSourceRoot and serverSourceRoot obsolete with pathMappings?
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.
Users that update will use "localSourceRoot" and "serverSourceRoot". It was easier to be backwards compatible with an optional extra argument, but I can certainly reformat it to inject localSourceRoot and serverSourceRoot into the config object if they exist.
(this is my first open source node contribution so I apologize for any code style differences)
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.
BC is great, but this function should only take one source of truth for mappings
src/paths.ts
Outdated
|
|
||
| // strip the trailing slash from Windows paths (indicated by a drive letter with a colon) | ||
| const serverIsWindows = /^\/[a-zA-Z]:\//.test(serverPath); | ||
|
|
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 don't try to modify the existing code style.
src/paths.ts
Outdated
| serverPath = serverPath.substr(1); | ||
| } | ||
|
|
||
| if ( typeof pathMapping !== 'undefined' ) { |
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 the existing code style (no spaces inside parens)
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.
No linting!?
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 linting, but this isn't caught.
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.
Maybe turn this on => Whitespace
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.
it is on
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.
@felixfbecker Just a friendly suggestion: tslint now has the space within parens, you may enable it.
src/paths.ts
Outdated
| // normalize slashes for windows-to-unix | ||
| // I thought normalize did this automagically.. | ||
| if ( process.platform !== 'win32' ) { | ||
| mappedServerSource = mappedServerSource.replace(/\\/g, '/'); |
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.
what if the server is Windows?
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 handles the case where local is Linux and server is Windows. This should be the only time backslashes need be converted because local windows will normalize the backslashes in path.relative just fine. Linux just sees the backslashes as part of the filename so path.relative returns the wrong value.
src/test/paths.ts
Outdated
| describe('paths', () => { | ||
| let undef: string; | ||
|
|
||
| const pathMapping = { |
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 prefer to define the test cases through mocha's it DSL over having a config object, it's a lot easier to debug if the values are always inside the test
src/test/paths.ts
Outdated
| // unix to unix | ||
| it('should convert a unix path to a unix URI', () => { | ||
| // site | ||
| assert.equal( convertClientPathToDebugger(sources.unix.site, undef, undef, pathMapping.unixToUnix), results.unix.site ); |
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.
why use undef and not undefined?
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.
... Dunno.
src/test/adapter.ts
Outdated
| describe('PHP Debug Adapter', () => { | ||
|
|
||
| const TEST_PROJECT = path.normalize(__dirname + '/../../testproject'); | ||
| const TEST_PROJECT = path.normalize(__dirname + '/../../testproject/main'); |
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.
why is this needed?
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.
Some tests use /variables.php which has been moved to /testproject/main/variables.php to test multiple source roots.
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 I don't see any new tests that rely on this?
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'm assuming that you're requesting a test that involves /testproject/secondary? Please give me a little direction on this.
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'm fine without a test like that given that tests/paths.ts unit-tests the path mapping, but I don't understand why all these files have to be moved then if they are essentially not used at all.
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.
when testing development of this feature, I had to test that multiple paths were working, so I created multiple paths in testproject. I thought that in the future other developers would also need to test multiple paths, but if you'd like I can move the files back.
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.
The testproject should only contain fixtures used by (automatic) tests
src/paths.ts
Outdated
| let relative: number = localRelative.indexOf('..'); | ||
|
|
||
| // if does not start with .. | ||
| if ( relative !== 0 ) { |
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 not used anywhere else, so no reason to save it in a variable. You can also use .includes() if I'm not mistaken.
src/paths.ts
Outdated
| if ( typeof pathMapping !== 'undefined' ) { | ||
| let mappedServerSource: string; | ||
|
|
||
| for (mappedServerSource of Object.keys(pathMapping) ) { |
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 should declare the let here so it's scoped to the loop body
…path conversion, reverted back to original code styles, various simplifications
|
I believe I've made all requested changes. Let me know if you need anything else. |
src/paths.ts
Outdated
| export function convertDebuggerPathToClient(fileUri: string|url.Url, localSourceRoot?: string, serverSourceRoot?: string): string { | ||
| export function convertDebuggerPathToClient(fileUri: string|url.Url, pathMapping?: { [index: string]: string; }): string { | ||
| let localSourceRoot: string = ''; | ||
| let serverSourceRoot: 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.
why initialize with an empty 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.
if these aren't initialized, then I receive an error testing for serverSourceRoot && localSourceRoot "variable is used before it is assigned"
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 need to type them as string | undefined
src/paths.ts
Outdated
| if (serverIsWindows) { | ||
| serverPath = serverPath.substr(1); | ||
| } | ||
| if (typeof pathMapping !== 'undefined') { |
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.
shorten to if (pathMapping)
src/paths.ts
Outdated
| serverPath = serverPath.substr(1); | ||
| } | ||
| if (typeof pathMapping !== 'undefined') { | ||
| for (let mappedServerSource of Object.keys(pathMapping) ) { |
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, I would name this mappedServerPath
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.
mappedServerSource (or mappedServerPath) is modified by the slash normalization below
src/paths.ts
Outdated
| } | ||
| if (typeof pathMapping !== 'undefined') { | ||
| for (let mappedServerSource of Object.keys(pathMapping) ) { | ||
| let mappedLocalSource: string = pathMapping[mappedServerSource]; |
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.
don't annotate types that can be inferred
src/paths.ts
Outdated
| } | ||
| let localPath: string; | ||
| if (serverSourceRoot && localSourceRoot) { | ||
| if (serverSourceRoot !== '' && localSourceRoot !== '') { |
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 change is unneeded
src/phpDebug.ts
Outdated
| } | ||
|
|
||
| protected async launchRequest(response: VSCodeDebugProtocol.LaunchResponse, args: LaunchRequestArguments) { | ||
| if ( args.hasOwnProperty('localSourceRoot') && typeof args.localSourceRoot !== 'undefined' && args.hasOwnProperty('serverSourceRoot') && typeof args.serverSourceRoot !== 'undefined') { |
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.
shorten to if (args.localSourceRoot && args.serverSourceRoot)
src/phpDebug.ts
Outdated
| protected async launchRequest(response: VSCodeDebugProtocol.LaunchResponse, args: LaunchRequestArguments) { | ||
| if ( args.hasOwnProperty('localSourceRoot') && typeof args.localSourceRoot !== 'undefined' && args.hasOwnProperty('serverSourceRoot') && typeof args.serverSourceRoot !== 'undefined') { | ||
| let pathMappings: {[index: string]: string} = {}; | ||
| if ( args.hasOwnProperty('pathMappings') && typeof args.pathMappings !== 'undefined') { |
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.
same
src/paths.ts
Outdated
| for (let mappedServerSource of Object.keys(pathMapping) ) { | ||
| let mappedLocalSource: string = pathMapping[mappedServerSource]; | ||
| // normalize slashes for windows-to-unix | ||
| if (process.platform !== 'win32') { |
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 think this check is needed, this should be a pure function
src/test/paths.ts
Outdated
| 'file:///C:/Program%20Files/Apache/2.4/htdocs/test.php' | ||
| ); | ||
| // unix to windows | ||
| (process.platform === 'win32' ? it : it.skip)('should convert a unix path to a windows URI', () => { |
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.
if the platform check is removed, these should always run
testproject/.vscode/launch.json
Outdated
| "externalConsole": false, | ||
| "pathMappings": { | ||
| "/var/www/html": "${workspaceRoot}" | ||
| } |
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 setting shouldn't be the default here
…, avoided win32 checks, deprecated options, fixed tests, updated docs
|
FYI, I believe I've made all requested changes here. |
|
FYI, I believe I've made all requested changes here. Let me know if there's anything else, or at least remove the "requested changes" attribute if they have been made properly -- if that's possible. |
|
@johnrom thanks for this. Works a treat with my first attempt at debugging in vscode with docker wordpress/xdebug. It'll be vscode itself but the debugger response into mapped paths is very fast compared to atom. |
Added Path Mapping Support via
pathMappingsoption. Added Tests. Reorganized test project to support path mappings.fixes #54