Skip to content

Commit

Permalink
Add logic to infer remote path automatically
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
quoctruong authored and hyangah committed May 20, 2020
1 parent e2aa002 commit c574518
Show file tree
Hide file tree
Showing 2 changed files with 610 additions and 11 deletions.
Loading

0 comments on commit c574518

Please sign in to comment.