崇高构建配置

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?

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

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

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.

I got by with

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

In ST3: it is changed to be:

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

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