当我在选择模式下执行时,文件夹中会出现Run Code
一个名为的临时文件。tempCodeRunnerFile.go
如何避免此文件出现在项目中?
问问题
4441 次
2 回答
5
我终于意识到有一个code-runner.ignoreSelection
设置可以忽略选择以始终运行整个文件。默认值为false
. 我必须在我的用户设置中手动打开它。在 Go 中,总是运行整个文件。
{
"code-runner.ignoreSelection": true
}
于 2020-07-26T08:15:47.207 回答
0
此临时文件“tempCodeRunnerFile”表示您已选择部分代码片段并运行它。如果不幸的是您在终端中运行代码,默认情况下它不会被删除。
但在这种情况下,解决方案可能是自定义code-runner.executorMap
运行临时文件后自动删除它。
例如(在 Windows 上,使用 GitBash 并在终端上运行)go
和其他一些语言,使用&& 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",
},
笔记:
- 运行真实文件时需要该
-f
标志来防止rm: cannot remove 'path/here': No such file or directory
(没有选择)。 - using
$dirWithoutTrailingSlash
是必需的,因为路径被引号包围,并且 Windows 上的最后一个斜杠将转义引号。 - 需要双转义斜杠 (
\\\\
) 否则它将以\tempCodeRunnerFile
, 和\t
表示 escape结束t
。 - 如果代码执行失败,将不会删除文件。
它可以工作,但在手动操作时需要记住一些事项。
此github 问题中的更多信息。特别感谢github.com/filipesilva帮助解决这个问题。
于 2021-02-09T12:34:18.763 回答