【发布时间】:2020-07-26 08:08:24
【问题描述】:
【问题讨论】:
标签: go vscode-code-runner
【问题讨论】:
标签: go vscode-code-runner
我终于意识到有一个code-runner.ignoreSelection 设置可以忽略选择以始终运行整个文件。默认值为false。我必须在我的用户设置中手动打开它。在 Go 中,总是运行整个文件。
{
"code-runner.ignoreSelection": true
}
【讨论】:
这个临时文件“tempCodeRunnerFile”表明你已经选择了部分代码sn-p并运行它。如果你不幸的是在终端中运行代码,默认情况下它不会被删除。
但这种情况下的解决方案可能是自定义 code-runner.executorMap 以在运行后自动删除临时文件。
作为go 和其他一些语言的示例(在Windows 上,使用GitBash 并在终端上运行),使用&& 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 在运行实际文件时(没有选择)。$dirWithoutTrailingSlash,因为路径被引号包围,Windows 上的最后一个斜杠将转义引号。\\\\),否则会以 \tempCodeRunnerFile 结尾,\t 表示转义 t。它可以工作,但手动操作时需要注意一些事项。
更多信息请参见github issue。并特别感谢 github.com/filipesilva 在此解决方案中的帮助。
【讨论】: