Skip to content
This repository has been archived by the owner on Jul 15, 2023. It is now read-only.

Map remote go module cache to local module cache #3079

Merged
merged 2 commits into from
Apr 22, 2020

Conversation

fnmunhoz
Copy link
Contributor

This is similar to another scenario: #1179

When using the remote debug feature, the paths to remote go module cache might not match the paths to local go module cache.

The idea here is to check if the remote path includes the go module cache sub string, for example:

/go/pkg/mod/github.com/account/package

In this case, it would be a match for the go module cache substring:

/pkg/mod/

And in this case, the path would be replaced by:

/Users/someuser/go/pkg/mod/github.com/account/package

Considering a local gopath like this:

$GOPATH="/Users/someuser/go".

By doing that, vscode-go can find all source files during debug, including cached modules.

I've made the minimal required changes to make it work for the scenario that I was facing, but I'm happy to make improvements based on feedback.

If I missed any guidelines, please let me know.

Also, I'm curious to know if this is the right approach to deal with this, or there is a better alternative.

@ramya-rao-a
Copy link
Contributor

Thanks for the PR @fnmunhoz

@quoctruong, Can you verify the fix here?

@quoctruong
Copy link
Contributor

LGTM


if (gopath && indexGoModCache > 0) {
return path.join(
gopath,
Copy link
Contributor

Choose a reason for hiding this comment

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

gopath can potentially have multiple paths with the path separator specific to the OS platform. In that case, we can't use it in path.join directly this way.

Copy link
Contributor

Choose a reason for hiding this comment

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

Does /pkg/mod apply to the first path in the gopath? Is there a rule around this?
Also, we need to ensure the right path separators are being used like we did in #3108

cc @quoctruong

Copy link
Contributor

Choose a reason for hiding this comment

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

Does /pkg/mod apply to the first path in the gopath? Is there a rule around this?

Yes. I'm not sure where this is specified, but you can see goimports relying on this fact here.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks @stamblerre

@fnmunhoz, @quoctruong I have pushed a commit to use the first go path, can either of you test this one more time?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ramya-rao-a sure I'll try to do it today and let you know. Thanks.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hey @ramya-rao-a I just double checked the extension after the change you made and it works fine for me, I was able to debug all files, including libraries inside go mod cache.

Thanks!

@msftclas
Copy link

msftclas commented Mar 23, 2020

CLA assistant check
All CLA requirements met.

@ramya-rao-a
Copy link
Contributor

@fnmunhoz Thanks for your first PR contribution to this project. Can you please sign the CLA as requested in the above comment?

pathToConvert
.substr(indexGoModCache)
.split(this.remotePathSeparator)
.join(this.localPathSeparator)
Copy link
Contributor

Choose a reason for hiding this comment

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

I just thought of one problem with this logic. Even if you are replacing the local path separator by the remote path separator, path.join will normalize the path according to the platform. This means that you probably have to do the replacing part AFTER joining the path?

Copy link
Contributor

Choose a reason for hiding this comment

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

We will have to do similar changes like you did to toDebuggerPath here as well. I was hoping to do that outside of this PR and have this PR focus only on the module cache part. Because the change has to applied to the goroot workaround and to the return statement a few lines below

Copy link
Contributor

Choose a reason for hiding this comment

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

That sounds good.

Copy link
Contributor

@ramya-rao-a ramya-rao-a left a comment

Choose a reason for hiding this comment

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

Setting review status to Request changes until the CLA is signed

@fnmunhoz
Copy link
Contributor Author

Hey @ramya-rao-a sorry for the really long delay.

I've signed the CLA. Not sure if this PR is still valid based on the comments above, but feel free to go ahead with it if that's the case.

Thanks!

@ramya-rao-a ramya-rao-a merged commit d3c0757 into microsoft:master Apr 22, 2020
@ramya-rao-a
Copy link
Contributor

Thanks @fnmunhoz!

@fnmunhoz
Copy link
Contributor Author

Yay! Thank you @ramya-rao-a

@fnmunhoz fnmunhoz deleted the handle-gomodcache branch April 22, 2020 17:39
@ramya-rao-a
Copy link
Contributor

The latest update 0.14.2 has this change, thanks @fnmunhoz!

@fnmunhoz
Copy link
Contributor Author

Good to know! Thanks @ramya-rao-a 😃

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants