Skip to content

Commit f8dd8b3

Browse files
committed
update for latest GoSublime
1 parent 02a5407 commit f8dd8b3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

95 files changed

+567
-6707
lines changed

broker.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ type Job struct {
3030
}
3131

3232
type Broker struct {
33+
sync.Mutex
34+
3335
tag string
34-
served uint
36+
served counter
3537
start time.Time
36-
rLck sync.Mutex
37-
wLck sync.Mutex
3838
r io.Reader
3939
w io.Writer
4040
in *bufio.Reader
@@ -60,8 +60,8 @@ func (b *Broker) Send(resp Response) error {
6060
}
6161

6262
func (b *Broker) SendNoLog(resp Response) error {
63-
b.wLck.Lock()
64-
defer b.wLck.Unlock()
63+
b.Lock()
64+
defer b.Unlock()
6565

6666
if resp.Data == nil {
6767
resp.Data = M{}
@@ -95,7 +95,7 @@ func (b *Broker) SendNoLog(resp Response) error {
9595
}
9696

9797
func (b *Broker) call(req *Request, cl Caller) {
98-
b.served++
98+
b.served.next()
9999

100100
defer func() {
101101
err := recover()
@@ -226,7 +226,7 @@ func (b *Broker) Loop(decorate bool, wait bool) {
226226
b.SendNoLog(Response{
227227
Token: "margo.bye-ni",
228228
Data: M{
229-
"served": b.served,
229+
"served": b.served.val(),
230230
"uptime": time.Now().Sub(b.start).String(),
231231
},
232232
})

common.go

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"bytes"
55
"encoding/base64"
66
"encoding/json"
7+
"fmt"
78
"go/ast"
89
"go/parser"
910
"go/printer"
@@ -19,6 +20,8 @@ var (
1920
sRuneError = eRune()
2021
)
2122

23+
type void struct{}
24+
2225
type jString string
2326

2427
func (s jString) String() string {
@@ -223,3 +226,61 @@ func tempDir(env map[string]string, subDirs ...string) string {
223226

224227
return dir
225228
}
229+
230+
func post(r Response) {
231+
sendCh <- r
232+
}
233+
234+
func postMessage(format string, a ...interface{}) {
235+
post(Response{
236+
Token: "margo.message",
237+
Data: M{
238+
"message": fmt.Sprintf(format, a...),
239+
},
240+
})
241+
}
242+
243+
func fileImportPaths(af *ast.File) []string {
244+
l := []string{}
245+
246+
if af != nil {
247+
for _, decl := range af.Decls {
248+
if gdecl, ok := decl.(*ast.GenDecl); ok {
249+
for _, spec := range gdecl.Specs {
250+
if ispec, ok := spec.(*ast.ImportSpec); ok {
251+
ipath := unquote(ispec.Path.Value)
252+
if ipath != "C" {
253+
l = append(l, ipath)
254+
}
255+
}
256+
}
257+
}
258+
}
259+
}
260+
261+
return l
262+
}
263+
264+
func pathList(p, pathSep string) []string {
265+
if pathSep == "" {
266+
pathSep = string(filepath.ListSeparator)
267+
}
268+
l := strings.Split(p, pathSep)
269+
270+
i := 0
271+
for _, s := range l {
272+
if s != "" {
273+
l[i] = s
274+
i += 1
275+
}
276+
}
277+
278+
return l[:i]
279+
}
280+
281+
func envRootList(env map[string]string) (string, []string) {
282+
if env == nil {
283+
return "", []string{}
284+
}
285+
return env["GOROOT"], pathList(env["GOPATH"], env["_pathsep"])
286+
}

fx.go

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
package main
2+
3+
import (
4+
"path/filepath"
5+
"strings"
6+
)
7+
8+
var (
9+
fileExts = map[string]void{}
10+
)
11+
12+
func init() {
13+
exts := []string{
14+
".c",
15+
".h",
16+
".go",
17+
".goc",
18+
".md",
19+
".txt",
20+
".git",
21+
".bzr",
22+
".tmp",
23+
".swig",
24+
".swigcxx",
25+
".a",
26+
".s",
27+
".S",
28+
".syso",
29+
".so",
30+
".dll",
31+
".o",
32+
".5",
33+
".6",
34+
".8",
35+
".out",
36+
".cc",
37+
".hh",
38+
".dat",
39+
".py",
40+
".pyc",
41+
".zip",
42+
".z",
43+
".7z",
44+
".gz",
45+
".tar",
46+
".bz2",
47+
".tgz",
48+
".rar",
49+
".pro",
50+
".occ",
51+
".asc",
52+
".conf",
53+
".html",
54+
".jpg",
55+
".png",
56+
".js",
57+
".json",
58+
".src",
59+
".log",
60+
".patch",
61+
".diff",
62+
".php",
63+
".rit",
64+
".css",
65+
".lua",
66+
".less",
67+
".ttf",
68+
".expected",
69+
".ps",
70+
".bak",
71+
".cix",
72+
".d",
73+
".hac",
74+
".hrb",
75+
".java",
76+
".lexres",
77+
".lst",
78+
".pan",
79+
".phpt",
80+
".prof",
81+
".set",
82+
".sol",
83+
".vrs",
84+
".exe",
85+
".bat",
86+
".sh",
87+
".rc",
88+
".bash",
89+
}
90+
91+
for _, ext := range exts {
92+
fileExts[ext] = void{}
93+
}
94+
}
95+
96+
func fx(nm string) (isFileExt, isGoFileExt bool) {
97+
nm = strings.ToLower(nm)
98+
ext := filepath.Ext(nm)
99+
100+
if ext == ".go" {
101+
return true, true
102+
}
103+
104+
if !strings.HasPrefix(nm, "go.") {
105+
if _, ok := fileExts[ext]; ok {
106+
return true, false
107+
}
108+
}
109+
110+
return false, false
111+
}

g_autoinst.go

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
package main
2+
3+
import (
4+
"go/parser"
5+
"io/ioutil"
6+
"os"
7+
"os/exec"
8+
"path/filepath"
9+
"runtime"
10+
"strings"
11+
)
12+
13+
var (
14+
autoInstCh = make(chan AutoInstOptions, 10)
15+
)
16+
17+
func autoInstall(ao AutoInstOptions) {
18+
select {
19+
case autoInstCh <- ao:
20+
default:
21+
}
22+
}
23+
24+
type AutoInstOptions struct {
25+
// if ImportPaths is empty, Src is parsed in order to populate it
26+
ImportPaths []string
27+
Src string
28+
29+
// the environment variables as passed by the client - they should not be merged with os.Environ(...)
30+
// GOPATH is be valid
31+
Env map[string]string
32+
}
33+
34+
func (a *AutoInstOptions) imports() map[string]string {
35+
m := map[string]string{}
36+
37+
if len(a.ImportPaths) == 0 {
38+
_, af, _ := parseAstFile("a.go", a.Src, parser.ImportsOnly)
39+
a.ImportPaths = fileImportPaths(af)
40+
}
41+
42+
for _, p := range a.ImportPaths {
43+
m[p] = filepath.FromSlash(p) + ".a"
44+
}
45+
46+
return m
47+
}
48+
49+
func (a *AutoInstOptions) install() {
50+
if a.Env == nil {
51+
a.Env = map[string]string{}
52+
}
53+
54+
osArch := runtime.GOOS + "_" + runtime.GOARCH
55+
roots := []string{}
56+
57+
if p := a.Env["GOROOT"]; p != "" {
58+
roots = append(roots, filepath.Join(p, "pkg", osArch))
59+
}
60+
61+
psep := string(filepath.ListSeparator)
62+
if s := a.Env["_pathsep"]; s != "" {
63+
psep = s
64+
}
65+
66+
for _, p := range strings.Split(a.Env["GOPATH"], psep) {
67+
if p != "" {
68+
roots = append(roots, filepath.Join(p, "pkg", osArch))
69+
}
70+
}
71+
72+
if len(roots) == 0 {
73+
return
74+
}
75+
76+
archiveOk := func(fn string) bool {
77+
for _, root := range roots {
78+
_, err := os.Stat(filepath.Join(root, fn))
79+
if err == nil {
80+
return true
81+
}
82+
}
83+
return false
84+
}
85+
86+
el := envSlice(a.Env)
87+
installed := []string{}
88+
89+
for path, fn := range a.imports() {
90+
if !archiveOk(fn) {
91+
cmd := exec.Command("go", "install", path)
92+
cmd.Env = el
93+
cmd.Stderr = ioutil.Discard
94+
cmd.Stdout = ioutil.Discard
95+
cmd.Run()
96+
97+
if archiveOk(fn) {
98+
installed = append(installed, path)
99+
}
100+
}
101+
}
102+
103+
if len(installed) > 0 {
104+
postMessage("auto-installed: %v", strings.Join(installed, ", "))
105+
}
106+
}
107+
108+
func init() {
109+
go func() {
110+
for ao := range autoInstCh {
111+
ao.install()
112+
}
113+
}()
114+
}

gosublime.org/fsnotify.head

Lines changed: 0 additions & 1 deletion
This file was deleted.

gosublime.org/fsnotify/.travis.yml

Lines changed: 0 additions & 1 deletion
This file was deleted.

gosublime.org/fsnotify/LICENSE

Lines changed: 0 additions & 27 deletions
This file was deleted.

0 commit comments

Comments
 (0)