Skip to content

Commit f8adbc8

Browse files
committed
sync margo
1 parent d7aa237 commit f8adbc8

Some content is hidden

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

64 files changed

+5933
-456
lines changed

src/margo.sh/.travis.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
go_import_path: margo.sh
22
language: go
33
go:
4-
- 1.9
4+
- '1.10'
55
- 1.x
6+
- master
67

78
script:
89
- go test -race -v ./...
10+
- go vet ./...

src/margo.sh/Gopkg.lock

Lines changed: 16 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/margo.sh/Gopkg.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,7 @@ required = [
2121
[[constraint]]
2222
branch = "master"
2323
name = "golang.org/x/tools"
24+
25+
[[constraint]]
26+
branch = "master"
27+
name = "github.com/mdempsky/gocode"

src/margo.sh/cmdpkg/margosublime/main.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,17 @@ import (
99
)
1010

1111
var (
12-
margoExt mg.MargoFunc = sublime.Margo
12+
margoExt mg.MargoFunc = sublime.Margo
13+
agentConfig = mg.AgentConfig{AgentName: sublime.AgentName}
1314
)
1415

1516
func Main() {
16-
cfg := mg.AgentConfig{AgentName: sublime.AgentName}
1717
app := mgcli.NewApp()
1818
app.Flags = []cli.Flag{
1919
cli.StringFlag{
2020
Name: "codec",
21-
Value: cfg.Codec,
22-
Destination: &cfg.Codec,
21+
Value: agentConfig.Codec,
22+
Destination: &agentConfig.Codec,
2323
Usage: fmt.Sprintf("The IPC codec: %s (default %s)", mg.CodecNamesStr, mg.DefaultCodec),
2424
},
2525
}
@@ -28,7 +28,7 @@ func Main() {
2828
return cli.ShowAppHelp(ctx)
2929
}
3030

31-
ag, err := mg.NewAgent(cfg)
31+
ag, err := mg.NewAgent(agentConfig)
3232
if err != nil {
3333
return mgcli.Error("agent creation failed:", err)
3434
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package margosublime
2+
3+
import (
4+
"margo.sh/mg"
5+
"margo.sh/mgutil"
6+
"margo.sh/sublime"
7+
"testing"
8+
)
9+
10+
func TestConfig(t *testing.T) {
11+
ac := agentConfig
12+
ac.Stdin = &mgutil.IOWrapper{}
13+
ac.Stdout = &mgutil.IOWrapper{}
14+
ac.Stderr = &mgutil.IOWrapper{}
15+
ag, err := mg.NewAgent(ac)
16+
if err != nil {
17+
t.Fatalf("agent creation failed: %v", err)
18+
}
19+
20+
ag.Store.SetBaseConfig(sublime.DefaultConfig)
21+
mxc := make(chan *mg.Ctx)
22+
ag.Store.Subscribe(func(mx *mg.Ctx) {
23+
mxc <- mx
24+
})
25+
ag.Store.Dispatch(mg.Render)
26+
go ag.Run()
27+
mx := <-mxc
28+
29+
if _, ok := mx.Config.(sublime.Config); !ok {
30+
t.Fatalf("mx.Config is %T, not %T", mx.Config, sublime.Config{})
31+
}
32+
33+
ec := mx.Config.EditorConfig()
34+
cv, ok := ec.(sublime.ConfigValues)
35+
if !ok {
36+
t.Fatalf("mx.Config.EditorConfig() is %T, not %T", ec, sublime.ConfigValues{})
37+
}
38+
39+
if len(cv.EnabledForLangs) == 0 {
40+
t.Fatal("EditorConfig().Values.EnabledForLangs in empty")
41+
}
42+
}

src/margo.sh/extension-example/extension-example.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ func Margo(ma mg.Args) {
1818
// and saving a non-go file will not trigger linters, etc. for that go pkg
1919
//
2020
// mg.NewReducer(func(mx *mg.Ctx) *mg.State {
21-
// return mx.SetConfig(mx.Config.EnabledForLangs("go"))
21+
// return mx.SetConfig(mx.Config.EnabledForLangs(mg.Go))
2222
// }),
2323

2424
// add the day and time to the status bar
25-
// DayTimeStatus,
25+
&DayTimeStatus{},
2626

2727
// both GoFmt and GoImports will automatically disable the GoSublime version
2828
// you will need to install the `goimports` tool manually
@@ -51,8 +51,6 @@ func Margo(ma mg.Args) {
5151
// add some default context aware-ish snippets
5252
golang.Snippets,
5353

54-
// add our own snippets
55-
5654
// check the file for syntax errors
5755
&golang.SyntaxCheck{},
5856

@@ -71,8 +69,7 @@ func Margo(ma mg.Args) {
7169
// golang.GoVet(),
7270

7371
// run `go test -race` on save
74-
// in go1.10, go vet is ran automatically
75-
golang.GoTest("-race"),
72+
// golang.GoTest("-race"),
7673

7774
// run `golint` on save
7875
// &golang.Linter{Name: "golint", Label: "Go/Lint"},

src/margo.sh/golang/common.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"go/build"
66
"go/token"
77
"margo.sh/mg"
8+
"margo.sh/why_would_you_make_yotsuba_cry"
89
"os"
910
"path/filepath"
1011
"reflect"
@@ -51,11 +52,7 @@ func PathList(p string) []string {
5152
}
5253

5354
func NodeEnclosesPos(node ast.Node, pos token.Pos) bool {
54-
if node == nil {
55-
return false
56-
}
57-
// apparently node can be (*T)(nil)
58-
if reflect.ValueOf(node).IsNil() {
55+
if why_would_you_make_yotsuba_cry.IsNil(node) {
5956
return false
6057
}
6158
if np := node.Pos(); !np.IsValid() || pos <= np {

src/margo.sh/golang/gocmd.go

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -55,17 +55,17 @@ func (gc *GoCmd) runCmd(mx *mg.Ctx, rc mg.RunCmd) *mg.State {
5555
)
5656
}
5757

58-
func (gc *GoCmd) goBuiltin(bx *mg.BultinCmdCtx) *mg.State {
58+
func (gc *GoCmd) goBuiltin(bx *mg.CmdCtx) *mg.State {
5959
go gc.goTool(bx)
6060
return bx.State
6161
}
6262

63-
func (gc *GoCmd) playBuiltin(bx *mg.BultinCmdCtx) *mg.State {
63+
func (gc *GoCmd) playBuiltin(bx *mg.CmdCtx) *mg.State {
6464
go gc.playTool(bx, "")
6565
return bx.State
6666
}
6767

68-
func (gc *GoCmd) replayBuiltin(bx *mg.BultinCmdCtx) *mg.State {
68+
func (gc *GoCmd) replayBuiltin(bx *mg.CmdCtx) *mg.State {
6969
v := bx.View
7070
cid := ""
7171
if v.Path == "" {
@@ -77,13 +77,13 @@ func (gc *GoCmd) replayBuiltin(bx *mg.BultinCmdCtx) *mg.State {
7777
return bx.State
7878
}
7979

80-
func (gc *GoCmd) goTool(bx *mg.BultinCmdCtx) {
80+
func (gc *GoCmd) goTool(bx *mg.CmdCtx) {
8181
gx := newGoCmdCtx(bx, "go.builtin", "", "", "")
8282
defer gx.Output.Close()
8383
gx.run(gx.View)
8484
}
8585

86-
func (gc *GoCmd) playTool(bx *mg.BultinCmdCtx, cancelID string) {
86+
func (gc *GoCmd) playTool(bx *mg.CmdCtx, cancelID string) {
8787
origView := bx.View
8888
bx, tDir, tFn, err := gc.playTempDir(bx)
8989
gx := newGoCmdCtx(bx, "go.play", cancelID, tDir, tFn)
@@ -109,7 +109,7 @@ func (gc *GoCmd) playTool(bx *mg.BultinCmdCtx, cancelID string) {
109109
}
110110
}
111111

112-
func (gc *GoCmd) playTempDir(bx *mg.BultinCmdCtx) (newBx *mg.BultinCmdCtx, tDir string, tFn string, err error) {
112+
func (gc *GoCmd) playTempDir(bx *mg.CmdCtx) (newBx *mg.CmdCtx, tDir string, tFn string, err error) {
113113
tDir, err = mg.MkTempDir("go.play")
114114
if err != nil {
115115
return bx, "", "", fmt.Errorf("cannot MkTempDir: %s", err)
@@ -133,7 +133,7 @@ func (gc *GoCmd) playTempDir(bx *mg.BultinCmdCtx) (newBx *mg.BultinCmdCtx, tDir
133133
return bx, tDir, "", fmt.Errorf("cannot create temp file: %s", err)
134134
}
135135

136-
bx = bx.Copy(func(bx *mg.BultinCmdCtx) {
136+
bx = bx.Copy(func(bx *mg.CmdCtx) {
137137
bx.Ctx = bx.Ctx.Copy(func(mx *mg.Ctx) {
138138
mx.State = mx.State.Copy(func(st *mg.State) {
139139
st.View = st.View.Copy(func(v *mg.View) {
@@ -159,7 +159,7 @@ func (gc *GoCmd) playToolRun(gx *goCmdCtx, bld *build.Context, origView *mg.View
159159

160160
args := gx.Args
161161
exe := filepath.Join(gx.tDir, "margo.play~~"+nm+".exe")
162-
gx.BultinCmdCtx = gx.BultinCmdCtx.Copy(func(bx *mg.BultinCmdCtx) {
162+
gx.CmdCtx = gx.CmdCtx.Copy(func(bx *mg.CmdCtx) {
163163
bx.Name = "go"
164164
bx.Args = []string{"build", "-o", exe}
165165
bx.Ctx = bx.Ctx.Copy(func(mx *mg.Ctx) {
@@ -174,7 +174,7 @@ func (gc *GoCmd) playToolRun(gx *goCmdCtx, bld *build.Context, origView *mg.View
174174
return
175175
}
176176

177-
gx.BultinCmdCtx = gx.BultinCmdCtx.Copy(func(bx *mg.BultinCmdCtx) {
177+
gx.CmdCtx = gx.CmdCtx.Copy(func(bx *mg.CmdCtx) {
178178
bx.Name = exe
179179
bx.Args = args
180180
bx.Ctx = bx.Ctx.Copy(func(mx *mg.Ctx) {
@@ -187,15 +187,15 @@ func (gc *GoCmd) playToolRun(gx *goCmdCtx, bld *build.Context, origView *mg.View
187187
}
188188

189189
type goCmdCtx struct {
190-
*mg.BultinCmdCtx
190+
*mg.CmdCtx
191191
pkgDir string
192192
key interface{}
193-
iw *mg.IssueWriter
193+
iw *mg.IssueOut
194194
tDir string
195195
tFn string
196196
}
197197

198-
func newGoCmdCtx(bx *mg.BultinCmdCtx, label, cancelID string, tDir, tFn string) *goCmdCtx {
198+
func newGoCmdCtx(bx *mg.CmdCtx, label, cancelID string, tDir, tFn string) *goCmdCtx {
199199
gx := &goCmdCtx{
200200
pkgDir: bx.View.Dir(),
201201
tDir: tDir,
@@ -205,18 +205,19 @@ func newGoCmdCtx(bx *mg.BultinCmdCtx, label, cancelID string, tDir, tFn string)
205205
type Key struct{ label string }
206206
gx.key = Key{label}
207207

208-
gx.iw = &mg.IssueWriter{
208+
gx.iw = &mg.IssueOut{
209209
Base: mg.Issue{Label: label},
210210
Patterns: bx.CommonPatterns(),
211211
Dir: gx.pkgDir,
212212
}
213213

214-
gx.BultinCmdCtx = bx.Copy(func(bx *mg.BultinCmdCtx) {
214+
gx.CmdCtx = bx.Copy(func(bx *mg.CmdCtx) {
215215
bx.Name = "go"
216216
bx.CancelID = cancelID
217-
bx.Output = bx.Output.Copy(func(w *mg.CmdOutputWriter) {
218-
w.Writer = gx.iw
219-
})
217+
bx.Output = mg.OutputStreams{
218+
bx.Output,
219+
gx.iw,
220+
}
220221
})
221222

222223
return gx

0 commit comments

Comments
 (0)