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

Can clicking "run tests" automatically save the file? #1225

Closed
skybrian opened this issue Sep 19, 2017 · 6 comments
Closed

Can clicking "run tests" automatically save the file? #1225

skybrian opened this issue Sep 19, 2017 · 6 comments

Comments

@skybrian
Copy link

If I edit a test and click "run test", there is a dialog:

File has unsaved changes. Save and try again.

It seems like it would be better to automatically save the file?

@skybrian
Copy link
Author

In case it matters, I have file.autoSave on. Here are my preferences:

{
    "[plaintext]": {
        "editor.quickSuggestions": false,
        "editor.wordWrap": "bounded"
    },

    "editor.stablePeek": true,
    "files.autoSave": "onFocusChange",
    "go.coverageDecorator": "gutter",
    "go.coverageOptions": "showUncoveredCodeOnly",
    "go.inferGopath": true,
    "go.lintOnSave": "off",
    "go.toolsGopath": "/Users/skybrian/go/tools",
    "go.useCodeSnippetsOnFunctionSuggest": true
}

@ramya-rao-a
Copy link
Contributor

Sure that is doable and is pretty simple.
PRs are welcome.

The change should be done here: https://github.com/Microsoft/vscode-go/blob/0.6.65/src/goTest.ts#L34

You can use editor.document.save() to save the document

@curiouslychase
Copy link
Contributor

curiouslychase commented Sep 23, 2017

would it make sense to have this disabled by default and have a flag to enable? something like go.saveTestFileOnRun (alternatively to check if files.autoSave is onFocusChange)?

@ramya-rao-a
Copy link
Contributor

ramya-rao-a commented Sep 24, 2017

@chaseadamsio Why so? When you explicitly click on the Run test code lens or use one of the test commands from the command palet, you are making a conscious decision to run the test and so saving the file makes sense. Am I missing something?

Is it so as to not race with the Auto Save feature?

@curiouslychase
Copy link
Contributor

If the expected behavior is always save the file when you run the tests I think it makes sense. Personally I like having flags for anything I might want to disable, so that was the only reason I suggested it. I'll pick this up and submit a PR.

ramya-rao-a pushed a commit that referenced this issue Sep 25, 2017
* add auto save to tests on test run or debug. Fixes #1225

* goTest: remove flag for saving test file on run or debug

* goTest: add document save to testCurrentFile

* goTest: fix indentation in testCurrentFile

* goTest: add return for document.save in testCurrentFile
@ramya-rao-a
Copy link
Contributor

In the latest update to the Go extension, the files get saved when test is triggered.
Thanks @chaseadamsio for the fix!

@vscodebot vscodebot bot locked and limited conversation to collaborators Jan 24, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants