Add command to fetch import on current line#1222
Add command to fetch import on current line#1222ramya-rao-a merged 11 commits intomicrosoft:masterfrom
Conversation
|
I see that Travis is failing but I don't know why. @ramya-rao-a can you see why? I have very little experience with Travis. |
|
@juicemia Its just the linter failing Run |
77f9f7f to
cb9d11c
Compare
package.json
Outdated
| }, | ||
| { | ||
| "command": "go.get.import", | ||
| "title": "Go: Get Import on Curent Line", |
There was a problem hiding this comment.
How about Go: Import Package? Go: Install Package ? Go: Get Package ? Go: Install Imported Package
(naming is seriously the hardest thing to do)
And the command would be more intuitive if it had the word "package" like go.get.package or go.import.package
Also update the description. It should be clear that we run a go get -u on the package
There was a problem hiding this comment.
I think Go: Get Package is the best one out of all of them, because it follows the semantics of using go get. I'll change that now.
src/goGetImport.ts
Outdated
| return vscode.window.showErrorMessage('Could not locate Go binaries. Make sure you have Go installed'); | ||
| } | ||
|
|
||
| fs.exists(path.join(getCurrentGoPath(), 'src', importPath), (exists) => { |
There was a problem hiding this comment.
we can skip this check and run go get -u regardless
If the package already exists then it will be updated.
Thoughts?
There was a problem hiding this comment.
I think it's a good idea, if we make sure to let the user know that their package will be updated. They might not want that for whatever reason.
EDIT: We can ask them to confirm if they want to update.
src/goGetImport.ts
Outdated
| return; | ||
| } | ||
|
|
||
| vscode.window.showInformationMessage(`Successfully fetched package ${importPath}`); |
There was a problem hiding this comment.
What do you think of showing the progress/success/failure messages in the output pane just like the current command Go: Install/Update Tools
There was a problem hiding this comment.
I think that's a great idea.
There was a problem hiding this comment.
One thing I just thought of: go get -u doesn't output anything by default unless it fails. For this to be useful, we would have to run go get -u -v. We could also show the output pane only if the command fails. Thoughts?
src/goGetImport.ts
Outdated
| const selection = editor.selection; | ||
| const selectedText = editor.document.lineAt(selection.active.line).text; | ||
|
|
||
| const importPath = getImportPath(selectedText); |
There was a problem hiding this comment.
If user runs this command on a line thats not an import statement, shouldnt we exit earlier? We know go get would fail then.
There was a problem hiding this comment.
Yup absolutely. Forgot that check.
| }).then(() => done(), done); | ||
| }); | ||
|
|
||
| test('getImportPath()', () => { |
There was a problem hiding this comment.
may I just say that I absolutely love it that you have added tests 🥇
This will allow users to easily fetch a dependency without having to take their attention away from the code they're editing. microsoft#1189
The plugin only fetches one import so having the file name plural is misleading to anybody reading the code. microsoft#1189
This consolidates the functionality found in two commands into one place so that if it ever needs to be changed or removed it can be done more easily.
Anybody else who comes along later and reads this is gonna have an easier time if they only have to keep one name in their head vs. having to keep two (goGetImport and goGetPackage). microsoft#1189
If there's no import path to pass to `go get` then there's no point in spinning up a child process and waiting for it to finish to error out. This also fixes a bug in `getImportPath` that would cause it to return invalid input paths for things like comments and function definitions. microsoft#1189
9ac522f to
8473a3d
Compare
src/goGetPackage.ts
Outdated
| return vscode.window.showErrorMessage('Could not locate Go binaries. Make sure you have Go installed'); | ||
| } | ||
|
|
||
| fs.exists(path.join(getCurrentGoPath(), 'src', importPath), (exists) => { |
There was a problem hiding this comment.
getCurrentGoPath() can return : or ; separated paths as well. This would fail then
There was a problem hiding this comment.
Instead you can run go list and pass the importpath to see if the package exists.
Or skip this check altogether.
I really feel that if a user has explicitly run this Go: Get Package command then they would know that this would get the package using go get
There was a problem hiding this comment.
I'm checking there because it runs go get -u. I can remove the check and make it just run go get without passing -u so that if the package already exists, nothing happens. It's basically the same behavior but it offloads the check to the go tooling.
|
@juicemia I went ahead and rebased your branch from master as there were some conflicts. You might have to delete your local branch and checkout from the remote again. Sorry for the trouble, I usually work alone, so didnt think of the troubles rebasing might cause others :( |
|
It's okay. I'll figure it out, no worries. |
`go get` won't download a package if it's already in `$GOPATH/src`. There's no point in checking for the package to exist and then downloading with `-u` because `go get -u` and `go get` are effectively the same when a package hasn't been downloaded yet. microsoft#1189
`go get -v` gives users more information on what's going on with the command. This way a user can tell if the package was even downloaded, because by default `go get` won't output anything. `go get -v` will output nothing if the package isn't downloaded because it already exists. To get around this, an information message is shown saying that the package wasn't downloaded. This keeps the user informed because they will be expecting feedback from the command. In the event of an error (like if there's no internet connection), the error gets shown to the output pane so the user knows what happened. microsoft#1189
|
Thanks @juicemia! |

This command allows users to just fetch a dependency from their editor. Under the hood, all it does is run
go getfor the import path on the current line.NOTE: This is not a replacement for dependency management tools like dep.