Wil*_*ang 5 go vscode-code-runner
当我在选择模式下执行时,文件夹中会出现Run Code一个名为的临时文件。tempCodeRunnerFile.go如何避免该文件出现在项目中?
Wil*_*ang 10
我终于意识到有一个code-runner.ignoreSelection设置可以忽略选择以始终运行整个文件。默认为false. 我必须在我的用户设置中手动打开它。在 Go 中,总是运行整个文件。
{
"code-runner.ignoreSelection": true
}
Run Code Online (Sandbox Code Playgroud)
此临时文件“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",
},
Run Code Online (Sandbox Code Playgroud)
笔记:
-f需要该标志来防止rm: cannot remove 'path/here': No such file or directory运行真实文件(没有选择)。$dirWithoutTrailingSlash,因为路径被引号包围,并且 Windows 上的最后一个斜杠将转义引号。\\\\),否则最终会变成\tempCodeRunnerFile, ,\t表示转义t。它有效,但手动执行时需要记住一些事项。
更多信息请参见此github 问题。特别感谢github.com/filipesilva在此解决方案中提供的帮助。