Skip to content

Conversation

@johnrom
Copy link
Contributor

@johnrom johnrom commented Jun 25, 2017

Added Path Mapping Support via pathMappings option. Added Tests. Reorganized test project to support path mappings.

fixes #54

src/paths.ts Outdated
serverPath = serverPath.substr(1);
}

if ( pathMapping !== {} && typeof pathMapping !== 'undefined' ) {
Copy link

@aminpaks aminpaks Jun 25, 2017

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

hm, you're correct.

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed in d005226

@codecov
Copy link

codecov bot commented Jun 25, 2017

Codecov Report

Merging #175 into master will increase coverage by 3.47%.
The diff coverage is 100%.

Impacted file tree graph

@@            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
Impacted Files Coverage Δ
src/paths.ts 94.11% <100%> (+2.68%) ⬆️

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 6253d4f...043adbf. Read the comment docs.

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

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?

Copy link
Contributor Author

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)

Copy link
Contributor

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);

Copy link
Contributor

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' ) {
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 the existing code style (no spaces inside parens)

Choose a reason for hiding this comment

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

No linting!?

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 linting, but this isn't caught.

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

Copy link
Contributor

Choose a reason for hiding this comment

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

it is on

Copy link

@aminpaks aminpaks Jul 22, 2017

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

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?

Copy link
Contributor Author

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.

describe('paths', () => {
let undef: string;

const pathMapping = {
Copy link
Contributor

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

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

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

... Dunno.

describe('PHP Debug Adapter', () => {

const TEST_PROJECT = path.normalize(__dirname + '/../../testproject');
const TEST_PROJECT = path.normalize(__dirname + '/../../testproject/main');
Copy link
Contributor

Choose a reason for hiding this comment

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

why is this needed?

Copy link
Contributor Author

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.

Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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

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

@johnrom
Copy link
Contributor Author

johnrom commented Jun 26, 2017

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

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?

Copy link
Contributor Author

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"

Copy link
Contributor

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

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

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

Copy link
Contributor Author

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];
Copy link
Contributor

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

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

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

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') {
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 think this check is needed, this should be a pure function

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

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

"externalConsole": false,
"pathMappings": {
"/var/www/html": "${workspaceRoot}"
}
Copy link
Contributor

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

johnrom commented Jul 10, 2017

FYI, I believe I've made all requested changes here.

@felixfbecker felixfbecker changed the title 54 path mappings Path mappings Jul 15, 2017
@johnrom
Copy link
Contributor Author

johnrom commented Sep 14, 2017

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.

@felixfbecker felixfbecker merged commit 24eafe9 into xdebug:master Nov 21, 2017
@lbod
Copy link

lbod commented Nov 21, 2017

@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.

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.

Mapping more than one path for source code

4 participants