Skip to content
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

Add logic to infer remote path automatically #44

Closed
wants to merge 5 commits into from
Closed

Add logic to infer remote path automatically #44

wants to merge 5 commits into from

Conversation

quoctruong
Copy link
Contributor

@quoctruong quoctruong commented May 14, 2020

Delve has an API to list all the files used by the program. So we can simply get the list of files on the remote machine and map it to the files on the local machine. These include files in the GOROOT and GOPATH on the remote machine as well so we can try to map them to the files in the local machine GOROOT and GOPATH.

Mapping local path to remote path

Since we get all the remote sources, we can retrieve all the remote source files that share the same file name with the local file. We can then do a suffix match to get the best matching remote path.
Mapping remote path to local path
This is more complicated because there are multiple places where we can try to find a match on the local machine.

However, we can use the ListPackagesBuildInfo to help us retrieve all the different Go packages used. Each package item returned comes with a Directory Path and an Import Path. Using Directory Path, we can determine if the remote path is in a particular package or not:

  • If the remote path is in a package, we can try to find whether the package exists on the local machine. We will be searching for it in 3 places:

    • The current user’s workspace folder.
    • The current user’s GOPATH.
    • The current user’s GOMOD folder (%GOMOD%/pkg/mod) if the package name contains pkg/mod.
  • If the remote path is not in any package, then we retrieve the name of the remote path and search for files with that name in the current workspace folder. We find the best matching one using a suffix match.

Updates #45.

@googlebot googlebot added the cla: yes Used by googlebot to label PRs as having a valid CLA. The text of this label should not change. label May 14, 2020
@gopherbot
Copy link
Collaborator

This PR (HEAD: 3d9a114) has been imported to Gerrit for code review.

Please visit https://go-review.googlesource.com/c/vscode-go/+/234020 to see it.

Tip: You can toggle comments from me using the comments slash command (e.g. /comments off)
See the Wiki page for more info

@gopherbot
Copy link
Collaborator

Message from Gobot Gobot:

Patch Set 1:

Congratulations on opening your first change. Thank you for your contribution!

Next steps:
Within the next week or so, a maintainer will review your change and provide
feedback. See https://golang.org/doc/contribute.html#review for more info and
tips to get your patch through code review.

Most changes in the Go project go through a few rounds of revision. This can be
surprising to people new to the project. The careful, iterative review process
is our way of helping mentor contributors and ensuring that their contributions
have a lasting impact.

During May-July and Nov-Jan the Go project is in a code freeze, during which
little code gets reviewed or merged. If a reviewer responds with a comment like
R=go1.11, it means that this CL will be reviewed as part of the next development
cycle. See https://golang.org/s/release for more details.


Please don’t reply on this GitHub thread. Visit golang.org/cl/234020.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link
Collaborator

Message from Hyang-Ah Hana Kim:

Patch Set 1:

(6 comments)

Is it possible to have some unit tests on those local to remote/ remote to local mapping functions?

(Eventually we need integration tests but given the lack of existing tests for debugging, I think that is too much for this cl.)


Please don’t reply on this GitHub thread. Visit golang.org/cl/234020.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link
Collaborator

This PR (HEAD: b06821f) has been imported to Gerrit for code review.

Please visit https://go-review.googlesource.com/c/vscode-go/+/234020 to see it.

Tip: You can toggle comments from me using the comments slash command (e.g. /comments off)
See the Wiki page for more info

@gopherbot
Copy link
Collaborator

Message from Quoc Truong:

Patch Set 2:

Hi Hana,

I've added tests and addressed the comments. PTAL.


Please don’t reply on this GitHub thread. Visit golang.org/cl/234020.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link
Collaborator

Message from Hyang-Ah Hana Kim:

Patch Set 2:

(10 comments)

Thank you for adding tests!


Please don’t reply on this GitHub thread. Visit golang.org/cl/234020.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link
Collaborator

This PR (HEAD: 614a301) has been imported to Gerrit for code review.

Please visit https://go-review.googlesource.com/c/vscode-go/+/234020 to see it.

Tip: You can toggle comments from me using the comments slash command (e.g. /comments off)
See the Wiki page for more info

@gopherbot
Copy link
Collaborator

This PR (HEAD: 409314c) has been imported to Gerrit for code review.

Please visit https://go-review.googlesource.com/c/vscode-go/+/234020 to see it.

Tip: You can toggle comments from me using the comments slash command (e.g. /comments off)
See the Wiki page for more info

@gopherbot
Copy link
Collaborator

Message from Quoc Truong:

Patch Set 3:

(6 comments)

Hi Hana, I've removed typemoq and used sinon now. PTAL.


Please don’t reply on this GitHub thread. Visit golang.org/cl/234020.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link
Collaborator

Message from Hyang-Ah Hana Kim:

Patch Set 4:

(1 comment)

Thanks!


Please don’t reply on this GitHub thread. Visit golang.org/cl/234020.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link
Collaborator

This PR (HEAD: 0383036) has been imported to Gerrit for code review.

Please visit https://go-review.googlesource.com/c/vscode-go/+/234020 to see it.

Tip: You can toggle comments from me using the comments slash command (e.g. /comments off)
See the Wiki page for more info

@gopherbot
Copy link
Collaborator

Message from Quoc Truong:

Patch Set 5:

(1 comment)

Hi Hana, PTAL. I forgot to remove that when testing on my machine.


Please don’t reply on this GitHub thread. Visit golang.org/cl/234020.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link
Collaborator

Message from Hyang-Ah Hana Kim:

Patch Set 5: Code-Review+2


Please don’t reply on this GitHub thread. Visit golang.org/cl/234020.
After addressing review feedback, remember to publish your drafts!

gopherbot pushed a commit that referenced this pull request May 20, 2020
Delve has an [API](https://godoc.org/github.com/go-delve/delve/service/rpc2#ListSourcesOut) to list all the files used by the program. So we can simply get the list of files on the remote machine and map it to the files on the local machine. These include files in the `GOROOT` and `GOPATH` on the remote machine as well so we can try to map them to the files in the local machine `GOROOT` and `GOPATH`.

## Mapping local path to remote path
Since we get all the remote sources, we can retrieve all the remote source files that share the same file name with the local file. We can then do a suffix match to get the best matching remote path.
Mapping remote path to local path
This is more complicated because there are multiple places where we can try to find a match on the local machine.

However, we can use the [`ListPackagesBuildInfo`](https://godoc.org/github.com/go-delve/delve/service/rpc2#ListPackagesBuildInfoOut) to help us retrieve all the different Go packages used. Each package item returned comes with a Directory Path and an Import Path. Using Directory Path, we can determine if the remote path is in a particular package or not:

- If the remote path is in a package, we can try to find whether the package exists on the local machine. We will be searching for it in 3 places:
    - The current user’s workspace folder.
    - The current user’s `GOPATH`.
    - The current user’s `GOMOD` folder (`%GOMOD%/pkg/mod`) if the package name contains `pkg/mod`.

- If the remote path is not in any package, then we retrieve the name of the remote path and search for files with that name in the current workspace folder. We find the best matching one using a suffix match.

Updates #45.

Change-Id: I619c45ea4f79036db944d271169665e72dcffab8
GitHub-Last-Rev: 0383036
GitHub-Pull-Request: #44
Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/234020
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
@gopherbot
Copy link
Collaborator

This PR is being closed because golang.org/cl/234020 has been merged.

@gopherbot gopherbot closed this May 20, 2020
@hyangah hyangah added this to the 0.15.0 milestone Jun 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes Used by googlebot to label PRs as having a valid CLA. The text of this label should not change.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants