用过不少Golang Ide 工具最后感觉还是VSCode好用,只是VSCode针对Golang Build 和 Install 任务执行没有LiteIDE方便,特地整理了Task.json任务并且绑定好了快捷键,现在给大家分享下。
项目整体结构如下
task.json
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "Make Lib",
"command":"go",
"options": {
"cwd": "${workspaceRoot}\\src",
"env": {
"GOPATH": "E:\\tygo;C:\\Users\\Administrator\\go"
}
},
"args": [
"install", //build
"-x",
"ty",
"tx",
],
},
{
"type": "shell",
"label": "Gate Build",
"command":"go",
"options": {
"cwd": "${workspaceRoot}\\src\\gate",
"env": {
"GOPATH": "E:\\tygo;C:\\Users\\Administrator\\go"
}
},
"args": [
"build",
"-o",
"${workspaceRoot}\\bin\\gate.exe",
],
},
{
"type": "shell",
"label": "Main Build",
"command":"go",
"options": {
"cwd": "${workspaceRoot}\\src",
"env": {
"GOPATH": "E:\\tygo;C:\\Users\\Administrator\\go"
}
},
"args": [
"build",
"-o",
"${workspaceRoot}\\bin\\main.exe",
],
},
{
"label": "Build",
"dependsOn": ["Gate Build", "Main Build"],
// "group": {
// // 从这里
// "kind": "build",
// "isDefault": true
// }, // 到这里,设置为默认构建任务,按Ctrl+Shift+B立即执行,不必选择
"presentation": {
//shell命令输出的内容并不弹出来提醒
// "reveal": "silent"
},
"problemMatcher": []
}
]
}
绑定好快捷键Ctrl+F7 编译项目包含的gate.exe 和main.exe 两个可执行文件到bin目录,Ctrl+F8 编译动态库到pkg目录。
keybingings.json
// 将键绑定放在此文件中以覆盖默认值
[{
"key": "CTRL+F7",
"command": "workbench.action.tasks.runTask",
"args": "Build",
"when": "editorTextFocus"
},
{
"key": "CTRL+F8",
"command": "workbench.action.tasks.runTask",
"args": "Make Lib",
"when": "editorTextFocus"
}]
注意:如果项目包含自己编写的库文件,需要在gopath 在制定对应的目录,编译才能成功。
settings.json
{
"go.buildOnSave": "package",
"go.buildFlags": ["-o","E:\\tygo"],
// "go.lintOnSave": true,
// "go.vetOnSave": true,
"go.buildTags": "",
"go.lintFlags": [],
"go.vetFlags": [],
"go.coverOnSave": false,
"go.useCodeSnippetsOnFunctionSuggest": false,
// "go.formatOnSave": true,
"go.lintTool": "golint",
"go.formatTool": "goreturns",
"go.goroot": "C:\\Go",
"go.gopath": "E:\\tygo;C:\\Users\\Administrator\\go",
"go.gocodeAutoBuild": true,
"go.inferGopath": true,
}
第一次写没什么经验,写的不好欢迎大家指正,感谢大家!
有疑问加站长微信联系(非本文作者)