Go-Sublime-build配置

huangapple go评论86阅读模式
英文:

Go-Sublime-build configuration

问题

我在尝试在Sublime Text 2中设置go运行当前文件时遇到了问题。这是我在go.sublime-build文件中的内容:

{
"cmd": [ "go", "run", "${file}" ]
}

当我尝试在go源文件上运行构建时,我得到了错误:

[Error 6] The handle is invalid
[cmd: [u'go run', u'C:\Users\gprasant\Documents\GitHub\programming_pearls\src\go\quicksort.go']]
[dir: C:\Users\gprasant\Documents\GitHub\programming_pearls\src\go]

有没有办法解决这个问题?或者Sublime Text中是否有其他用于Go开发的插件?

英文:

Im having issues trying to set up go to run the current file from Sublime text 2.
Here's what I have in my go.sublime-build file

{
	"cmd": [ "go", "run", "${file}" ]
}

When I try to run build on a go source file, I get the error

[Error 6] The handle is invalid
[cmd:  [u'go run', u'C:\\Users\\gprasant\\Documents\\GitHub\\programming_pearls\\src\\go\\quicksort.go']]
[dir:  C:\Users\gprasant\Documents\GitHub\programming_pearls\src\go]

Is there any way to get this fixed ? Or is there another plugin in Sublime text for Go development?

答案1

得分: 10

安装GoSublime应该可以让这个工作正常运行。安装并重新启动ST2后:按下ctrl-B,输入"run"并按回车。

英文:

Installing GoSublime should get this working for you. After installing and restarting ST2: do ctrl-B, type "run" and hit enter.

答案2

得分: 8

我用以下方式解决了问题:

{
    "cmd": "go run $file",
    "shell": true
}
英文:

I got by with

{
    "cmd": "go run $file",
    "shell" : true
}

答案3

得分: 5

{
"shell_cmd": "go run ${file}"
}

英文:

In ST3: it is changed to be:

{
    "shell_cmd": "go run ${file}"
}

答案4

得分: 4

{
"cmd": ["go run '${file}'"],
"selector": "source.go",
"path": "/usr/local/go/bin",
"shell": true
}

英文:

On my mac, I needed the following code in:

/Users/your_user_name/Library/Application Support/Sublime Text 2/Packages/User/go.sublime-build

go.sublime-build

{
    "cmd": ["go run '${file}'"],
    "selector": "source.go",
    "path": "/usr/local/go/bin",
    "shell": true
}  
  • "cmd" line quoting is to correctly handle file paths with spaces.
  • "shell" line is needed since commenting it out breaks it.
  • "path" line is needed because the basic shell, doesn't have access to my .zshrc file include the export GOPATH statement defining the go path.

After that any .go file should build and run with command+B, leaving the stdout message in a console built into sublime text 2.

答案5

得分: 1

{
"cmd": ["go", "run", "${file}"],
"path": "/user/local/go/bin"
}

我喜欢GoSublime,只是讨厌每次点击Command + B时都要输入run。

英文:

what about:

{
    "cmd": ["go", "run", "${file}"],
    "path": "/user/local/go/bin"
}  

I like GoSublime, just hate to type run each time when click Command + B

答案6

得分: 0

SublimeText 2
为golang创建构建系统,使F4/shift-F4 工作(下一个错误/上一个错误)

首先,创建一个文件:~/gosublime_build.sh

GOPATH=~/go
export GOPATH 
echo "GOPATH:$GOPATH"

if [ "$3." = "RUN." ]
  then 
     EXENAME=${1##*/}
     EXENAME=$GOPATH/bin/$EXENAME
     echo $EXENAME
     $($EXENAME)
     echo "code: $?"
     exit
fi

echo "go build $2"
cd /usr/local/go/bin
./go build -o ~/temp.go.compiled $2
if [ $? -eq 0 ]
 then
   cd $1
   echo "Project: " $1
   /usr/local/go/bin/go install
   echo "go install exit code: $?"
 else
   echo "go build exit code: $?"
fi

第二步:

chmod 777 ~/gosublime_build.sh

第三步:为"go"创建一个新的sublime2构建系统(Tools/Build System/New)

{
"cmd": ["~/gosublime_build.sh $file_path $file"]
,"shell": true
,"selector": "source.go"
,"file_regex": "([\\w/_-]+[.]{1}[\\w./_-]+?):([0-9]+):?([0-9]+)?(.*)?"
}  

第四步:选择你的新构建系统(Tools/Build System)

第五步:使用Ctrl-B进行构建,使用F4/Shift-F4进行下一个/上一个错误

如果有人知道如何指示go编译器为每个错误提供文件和行的完整路径,这个过程可以简化。

英文:

SublimeText 2
build-system for golang, making F4/shift-F4 work (next error/prev error)

1st, create a file: ~/gosublime_build.sh

GOPATH=~/go
export GOPATH 
echo "GOPATH:$GOPATH"

if [ "$3." = "RUN." ]
  then 
     EXENAME=${1##*/}
     EXENAME=$GOPATH/bin/$EXENAME
     echo $EXENAME
     $($EXENAME)
     echo "code: $?"
     exit
fi

echo "go build $2"
cd /usr/local/go/bin
./go build -o ~/temp.go.compiled $2
if [ $? -eq 0 ]
 then
   cd $1
   echo "Project: " $1
   /usr/local/go/bin/go install
   echo "go install exit code: $?"
 else
   echo "go build exit code: $?"
fi

2nd:

chmod 777 ~/gosublime_build.sh

3rd: create a new sublime2 build-system for "go" (Tools/Build System/New)

{
"cmd": ["~/gosublime_build.sh $file_path $file"]
,"shell": true
,"selector": "source.go"
,"file_regex": "([\\w/_-]+[.]{1}[\\w./_-]+?):([0-9]+):?([0-9]+)?(.*)?"
}  

4th: select your new build-system (Tools/Build System)

5th: build with Ctrl-B, F4/Shift-F4: next/prev error

If anybody knows how to instruct the go compiler to inform FULL PATH of file and line for each error, this process can be simplified

huangapple
  • 本文由 发表于 2012年12月11日 17:43:41
  • 转载请务必保留本文链接:https://go.coder-hub.com/13817467.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定