Reputation: 3626
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?
Upvotes: 6
Views: 21485
Reputation: 1736
I wanted to tell you that why do we get this file generated in our folder,
So the basic reason is that when we run selected code using codeRunner
extention than a file is generated called tempCodeRunnerFile.js
or with some different suffix.
. So at that point of time your selected code is copied into this file and the compiler runs this file as a source.
Upvotes: 0
Reputation: 21
The accepted solution assumes that only saved files will be executed. For unnamed/temporary files, the accepted solution will not resolve the issue per the documentation:
[REPL support] To set whether to run code in Integrated Terminal (only support to run whole file in Integrated Terminal, neither untitled file nor code snippet) (default is false):
Upvotes: 0
Reputation: 671
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.
Upvotes: 5
Reputation: 3626
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
}
Upvotes: 10