When I execute Run Code in selection mode, there is a temp file called tempCodeRunnerFile.go will appear in the folder. How can I avoid this file appear in the project?
When I execute Run Code in selection mode, there is a temp file called tempCodeRunnerFile.go will appear in the folder. How can I avoid this file appear in the project?
I finally realized that there is a code-runner.ignoreSelection setting can ignore selection to always run entire file. The default is false. I have to turn it on manually in my User Settings. In Go, there is always run entire file.
{
"code-runner.ignoreSelection": true
}
This temp file "tempCodeRunnerFile" indicates that you have selected part of the code snippet and run it. And if you are running code in terminal unfortunately it will not be deleted by default.
But the solution in this case could be customizing the code-runner.executorMap to remove the temporary file automatically after running it.
As example (on Windows, using GitBash and running on terminal) for go and some other languages, using && rm tempCodeRunnerFile:
"code-runner.executorMap": {
"go": "go run $fullFileName && rm -f $dirWithoutTrailingSlash\\\\tempCodeRunnerFile.go",
"javascript": "node $fullFileName && rm -f $dirWithoutTrailingSlash\\\\tempCodeRunnerFile.js",
"typescript": "ts-node $fullFileName && rm -f $dirWithoutTrailingSlash\\\\tempCodeRunnerFile.cljs",
"clojure": "lumo $fullFileName && rm -f $dirWithoutTrailingSlash\\\\tempCodeRunnerFile.cljs",
},
Notes:
-f flag is needed to prevent rm: cannot remove 'path/here': No such file or directory when running the real file (without a selection).$dirWithoutTrailingSlash is needed because the path is surrounded by quotes and the final slash on windows will escape the quote.\\\\) are needed otherwise it will end up as \tempCodeRunnerFile, and \t means escape t.It works but there are a few things to keep in mind when doing it manually.
More information in this github issue. And special thanks for github.com/filipesilva for helping in this solution.