-
Notifications
You must be signed in to change notification settings - Fork 646
Conversation
enables the user to upload the current file or selection to the go playground using package goplay - solves #1211
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@m90 This is so cool :)
I have left a few comments, please take a look
src/goPlayground.ts
Outdated
outputChannel.show(); | ||
outputChannel.appendLine('Upload to the Go Playground in progress...\n'); | ||
|
||
return uploader.upload(code, config) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not make the call to goplay
directly from here instead of going through the GoplayUploader
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seeing that it's a common pattern in this extension to make multiple tools available (although maybe not necessarily in that case) for the same task, I thought it'd be a good idea to separate the editor part of the command from the actual uploading. Also, it makes writing tests a lot easier. I think I'd like to keep it that way if possible.
src/goPlayground.ts
Outdated
// it to the given `uploader`, together with the current editor selection | ||
// (or the full content of the editor window if the selection is empty) | ||
export const createCommandWith = (uploader: IPlaygroundUploader) => (): Promise<any> => { | ||
const editor = vscode.window.activeTextEditor; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Show an error message if there is no active editor
src/goPlayground.ts
Outdated
if ((<any>err).missingTool) { | ||
promptForMissingTool(err.missingTool); | ||
} else { | ||
vscode.window.showErrorMessage(err.message); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the absence of the goplay
tool, we end up in the else block here with the error message write EPIPE
. This is because we are passing the code via stdin and the connection gets closed due to ENOENT
error
There are 2 ways to fix this
- Check
BINARY_LOCATION
is a valid absolute path. If not then dont rungoplay
, exit early. OR - Call
goplay
directly from thecreateCommandWith
function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Even after installing goplay
, user will have to reload VSCode for the change to take affect because the location of the binary gets calculated once in the beginning and isnt updated.
Feel free to use getBinPath
for every call
src/goPlayground.ts
Outdated
? editor.document.getText() | ||
: editor.document.getText(selection); | ||
|
||
outputChannel.show(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Clear the output channel before sending any output
@ramya-rao-a Thanks for your review. I think I should have adressed all the open issues, so feel free to take another look when it fits. |
…ility by stat-ing binary location
But the playground doesn't fall into this category. There is only 1 tool that can be used. Features in the Go extension fall into 2 categories
In the interest of keeping similar pattern in the second category here, I'd very much appreciate it if we do not use the OOP like approach for the playground feature. Of course, I am open to consider a refactoring on a bigger scale where we move all the other features (falling in the second category) to a OOP approach. But until then, I'd prefer to keep things similar. |
I see your point re: consistency, yet this would mean that this turns into one untestable monolithic function (correct me if my thinking that capturing channel output in a test is not possible is wrong). I personally would feel a lot more confident shipping such a feature with unit tests, yet this is not my extension. I just wanted to raise awareness for that fact. I'll ping you once I've done the changes. |
@ramya-rao-a As requested I merged all the code into one function for the sake of consistency. |
89e20b7
to
3d8a1f0
Compare
Enables the user to upload the current file or selection to the go playground using package
goplay
.This would solve #1211