Skip to content

Commit 14b1fa0

Browse files
committed
sync margo
1 parent e823035 commit 14b1fa0

File tree

146 files changed

+42034
-548
lines changed

Some content is hidden

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

146 files changed

+42034
-548
lines changed

src/margo.sh/Gopkg.lock

Lines changed: 25 additions & 3 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: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
required = [
2+
"golang.org/x/tools/cmd/guru"
3+
]
4+
5+
[prune]
6+
go-tests = true
7+
unused-packages = true
8+
19
[[constraint]]
210
name = "github.com/ugorji/go"
311
branch = "master"
@@ -10,6 +18,6 @@
1018
branch = "master"
1119
name = "golang.org/x/crypto"
1220

13-
[prune]
14-
go-tests = true
15-
unused-packages = true
21+
[[constraint]]
22+
branch = "master"
23+
name = "golang.org/x/tools"

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ func Main() {
3333
return mgcli.Error("agent creation failed:", err)
3434
}
3535

36-
ag.Store.EditorConfig(sublime.DefaultConfig)
36+
ag.Store.SetBaseConfig(sublime.DefaultConfig)
3737
if margoExt != nil {
3838
margoExt(ag.Args())
3939
}

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ func Margo(ma mg.Args) {
1212
// they are run in the specified order
1313
// and should ideally not block for more than a couple milliseconds
1414
ma.Store.Use(
15-
// by default, events (e.g. ViewSaved) are triggered in all files
16-
// uncomment the reducer below to restict event to Go(-lang) files
17-
// please note, however, that this mode is not tested
15+
// By default, events (e.g. ViewSaved) are triggered in all files.
16+
// Uncomment the reducer below to restict events to Go(-lang) files.
17+
// Please note, however, that this mode is not tested
1818
// and saving a non-go file will not trigger linters, etc. for that go pkg
1919
//
20-
// mg.Reduce(func(mx *mg.Ctx) *mg.State {
20+
// mg.NewReducer(func(mx *mg.Ctx) *mg.State {
2121
// return mx.SetConfig(mx.Config.EnabledForLangs("go"))
2222
// }),
2323

src/margo.sh/format/format.go

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,20 @@ type FmtFunc struct {
1919
Fmt func(mx *mg.Ctx, src []byte) ([]byte, error)
2020

2121
// Langs is the list of languages in which the reducer should run
22-
Langs []string
22+
Langs []mg.Lang
2323

24-
// Actions is a list of additional actions on which the reducer is allowed to run.
24+
// Actions is a list of actions on which the reducer is allowed to run.
2525
// The reducer always runs on the ViewFmt action, even if this list is empty.
2626
Actions []mg.Action
2727
}
2828

29+
// ReducerCond returns true if Langs and Actions matches the Ctx
30+
func (ff FmtFunc) ReducerCond(mx *mg.Ctx) bool {
31+
return mx.ActionIs(ff.Actions...) && mx.LangIs(ff.Langs...)
32+
}
33+
2934
// Reduce implements the FmtFunc reducer.
3035
func (ff FmtFunc) Reduce(mx *mg.Ctx) *mg.State {
31-
if !mx.LangIs(ff.Langs...) {
32-
return mx.State
33-
}
34-
if !mx.ActionIs(mg.ViewFmt{}) && !mx.ActionIs(ff.Actions...) {
35-
return mx.State
36-
}
37-
3836
fn := mx.View.Filename()
3937
src, err := mx.View.ReadAll()
4038
if err != nil {
@@ -48,7 +46,7 @@ func (ff FmtFunc) Reduce(mx *mg.Ctx) *mg.State {
4846
if err != nil {
4947
return mx.AddErrorf("failed to fmt %s: %s\n", fn, err)
5048
}
51-
return mx.SetSrc(src)
49+
return mx.SetViewSrc(src)
5250
}
5351

5452
// FmtCmd is wrapper around FmtFunc for generic fmt commands.
@@ -66,9 +64,9 @@ type FmtCmd struct {
6664
Env mg.EnvMap
6765

6866
// Langs is the list of languages in which the reducer should run
69-
Langs []string
67+
Langs []mg.Lang
7068

71-
// Actions is a list of additional actions on which the reducer is allowed to run.
69+
// Actions is a list of actions on which the reducer is allowed to run.
7270
// The reducer always runs on the ViewFmt action, even if this list is empty.
7371
Actions []mg.Action
7472
}

src/margo.sh/golang/common.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
package golang
22

33
import (
4-
"margo.sh/mg"
54
"go/ast"
65
"go/build"
76
"go/token"
7+
"margo.sh/mg"
88
"os"
99
"path/filepath"
1010
"reflect"
@@ -14,12 +14,12 @@ import (
1414
"unicode/utf8"
1515
)
1616

17-
var (
18-
CommonPatterns = append([]*regexp.Regexp{
17+
func init() {
18+
mg.AddCommonPatterns(mg.Go,
1919
regexp.MustCompile(`^\s*(?P<path>.+?\.\w+):(?P<line>\d+:)(?P<column>\d+:?)?(?:(?P<tag>warning|error)[:])?(?P<message>.+?)(?: [(](?P<label>[-\w]+)[)])?$`),
2020
regexp.MustCompile(`(?P<message>can't load package: package .+: found packages .+ \((?P<path>.+?\.go)\).+)`),
21-
}, mg.CommonPatterns...)
22-
)
21+
)
22+
}
2323

2424
func BuildContext(mx *mg.Ctx) *build.Context {
2525
c := build.Default

src/margo.sh/golang/gocmd.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ func (gc *GoCmd) playTempDir(bx *mg.BultinCmdCtx) (newBx *mg.BultinCmdCtx, tDir
115115
return bx, "", "", fmt.Errorf("cannot MkTempDir: %s", err)
116116
}
117117

118-
if !bx.LangIs("go") {
118+
if !bx.LangIs(mg.Go) {
119119
return bx, tDir, "", nil
120120
}
121121

@@ -202,7 +202,7 @@ func newGoCmdCtx(bx *mg.BultinCmdCtx, label, cancelID string, tDir, tFn string)
202202

203203
gx.iw = &mg.IssueWriter{
204204
Base: mg.Issue{Label: label},
205-
Patterns: CommonPatterns,
205+
Patterns: bx.CommonPatterns(),
206206
Dir: gx.pkgDir,
207207
}
208208

@@ -240,6 +240,6 @@ func (gx *goCmdCtx) run(origView *mg.View) error {
240240
ik.Dir = origView.Dir()
241241
}
242242

243-
gx.Store.Dispatch(mg.StoreIssues{Key: ik, Issues: issues})
243+
gx.Store.Dispatch(mg.StoreIssues{IssueKey: ik, Issues: issues})
244244
return err
245245
}

src/margo.sh/golang/gocode.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
"io"
1212
"margo.sh/golang/internal/gocode"
1313
"margo.sh/mg"
14-
"margo.sh/misc/pf"
14+
"margo.sh/mgpf"
1515
"margo.sh/sublime"
1616
"strings"
1717
"time"
@@ -71,7 +71,13 @@ func (g *Gocode) ReducerConfig(mx *mg.Ctx) mg.EditorConfig {
7171
return nil
7272
}
7373

74+
// ST might query the GoSublime plugin first, so we must always disable it
7475
cfg = cfg.DisableGsComplete()
76+
// but we don't want to affect editor completions in non-go files
77+
if !g.ReducerCond(mx) {
78+
return cfg
79+
}
80+
7581
if !g.AllowExplicitCompletions {
7682
cfg = cfg.InhibitExplicitCompletions()
7783
}
@@ -82,7 +88,7 @@ func (g *Gocode) ReducerConfig(mx *mg.Ctx) mg.EditorConfig {
8288
}
8389

8490
func (g *Gocode) ReducerCond(mx *mg.Ctx) bool {
85-
return mx.LangIs("go") && mx.ActionIs(mg.QueryCompletions{})
91+
return mx.ActionIs(mg.QueryCompletions{}) && mx.LangIs(mg.Go)
8692
}
8793

8894
func (g *Gocode) ReducerMount(mx *mg.Ctx) {
@@ -116,7 +122,7 @@ func (g *Gocode) Reduce(mx *mg.Ctx) *mg.State {
116122
select {
117123
case g.reqs <- gr:
118124
case <-time.After(qTimeout):
119-
mx.Log.Println("gocode didn't accept the request after", pf.D(time.Since(start)))
125+
mx.Log.Println("gocode didn't accept the request after", mgpf.D(time.Since(start)))
120126
return st
121127
}
122128

@@ -131,10 +137,10 @@ func (g *Gocode) Reduce(mx *mg.Ctx) *mg.State {
131137
case <-time.After(pTimeout):
132138
go func() {
133139
<-gr.res
134-
mx.Log.Println("gocode eventually responded after", pf.Since(start))
140+
mx.Log.Println("gocode eventually responded after", mgpf.Since(start))
135141
}()
136142

137-
mx.Log.Println("gocode didn't respond after", pf.D(pTimeout), "taking", pf.Since(start))
143+
mx.Log.Println("gocode didn't respond after", mgpf.D(pTimeout), "taking", mgpf.Since(start))
138144
return st
139145
}
140146
}

src/margo.sh/golang/gocode_calltips.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ type GocodeCalltips struct {
2727
}
2828

2929
func (gc *GocodeCalltips) ReducerCond(mx *mg.Ctx) bool {
30-
return mx.LangIs("go")
30+
return mx.LangIs(mg.Go)
3131
}
3232

3333
func (gc *GocodeCalltips) ReducerMount(mx *mg.Ctx) {

src/margo.sh/golang/gofmt.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ import (
1010
var (
1111
GoFmt mg.Reducer = mg.NewReducer(goFmt)
1212
GoImports mg.Reducer = mg.NewReducer(goImports)
13+
14+
commonFmtLangs = []mg.Lang{mg.Go}
15+
commonFmtActions = []mg.Action{
16+
mg.ViewFmt{},
17+
mg.ViewPreSave{},
18+
}
1319
)
1420

1521
func disableGsFmt(st *mg.State) *mg.State {
@@ -24,8 +30,8 @@ type FmtFunc func(mx *mg.Ctx, src []byte) ([]byte, error)
2430
func (ff FmtFunc) Reduce(mx *mg.Ctx) *mg.State {
2531
return disableGsFmt(mgformat.FmtFunc{
2632
Fmt: ff,
27-
Langs: []string{"go"},
28-
Actions: []mg.Action{mg.ViewPreSave{}},
33+
Langs: commonFmtLangs,
34+
Actions: commonFmtActions,
2935
}.Reduce(mx))
3036
}
3137

@@ -39,7 +45,7 @@ func goImports(mx *mg.Ctx) *mg.State {
3945
return disableGsFmt(mgformat.FmtCmd{
4046
Name: "goimports",
4147
Args: []string{"-srcdir", mx.View.Filename()},
42-
Langs: []string{"go"},
43-
Actions: []mg.Action{mg.ViewPreSave{}},
48+
Langs: commonFmtLangs,
49+
Actions: commonFmtActions,
4450
}.Reduce(mx))
4551
}

0 commit comments

Comments
 (0)