Skip to content

Commit

Permalink
sync margo
Browse files Browse the repository at this point in the history
  • Loading branch information
DisposaBoy committed May 8, 2018
1 parent e823035 commit 14b1fa0
Show file tree
Hide file tree
Showing 146 changed files with 42,034 additions and 548 deletions.
28 changes: 25 additions & 3 deletions src/margo.sh/Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 11 additions & 3 deletions src/margo.sh/Gopkg.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
required = [
"golang.org/x/tools/cmd/guru"
]

[prune]
go-tests = true
unused-packages = true

[[constraint]]
name = "github.com/ugorji/go"
branch = "master"
Expand All @@ -10,6 +18,6 @@
branch = "master"
name = "golang.org/x/crypto"

[prune]
go-tests = true
unused-packages = true
[[constraint]]
branch = "master"
name = "golang.org/x/tools"
2 changes: 1 addition & 1 deletion src/margo.sh/cmdpkg/margosublime/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func Main() {
return mgcli.Error("agent creation failed:", err)
}

ag.Store.EditorConfig(sublime.DefaultConfig)
ag.Store.SetBaseConfig(sublime.DefaultConfig)
if margoExt != nil {
margoExt(ag.Args())
}
Expand Down
8 changes: 4 additions & 4 deletions src/margo.sh/extension-example/extension-example.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ func Margo(ma mg.Args) {
// they are run in the specified order
// and should ideally not block for more than a couple milliseconds
ma.Store.Use(
// by default, events (e.g. ViewSaved) are triggered in all files
// uncomment the reducer below to restict event to Go(-lang) files
// please note, however, that this mode is not tested
// By default, events (e.g. ViewSaved) are triggered in all files.
// Uncomment the reducer below to restict events to Go(-lang) files.
// Please note, however, that this mode is not tested
// and saving a non-go file will not trigger linters, etc. for that go pkg
//
// mg.Reduce(func(mx *mg.Ctx) *mg.State {
// mg.NewReducer(func(mx *mg.Ctx) *mg.State {
// return mx.SetConfig(mx.Config.EnabledForLangs("go"))
// }),

Expand Down
22 changes: 10 additions & 12 deletions src/margo.sh/format/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,20 @@ type FmtFunc struct {
Fmt func(mx *mg.Ctx, src []byte) ([]byte, error)

// Langs is the list of languages in which the reducer should run
Langs []string
Langs []mg.Lang

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

// ReducerCond returns true if Langs and Actions matches the Ctx
func (ff FmtFunc) ReducerCond(mx *mg.Ctx) bool {
return mx.ActionIs(ff.Actions...) && mx.LangIs(ff.Langs...)
}

// Reduce implements the FmtFunc reducer.
func (ff FmtFunc) Reduce(mx *mg.Ctx) *mg.State {
if !mx.LangIs(ff.Langs...) {
return mx.State
}
if !mx.ActionIs(mg.ViewFmt{}) && !mx.ActionIs(ff.Actions...) {
return mx.State
}

fn := mx.View.Filename()
src, err := mx.View.ReadAll()
if err != nil {
Expand All @@ -48,7 +46,7 @@ func (ff FmtFunc) Reduce(mx *mg.Ctx) *mg.State {
if err != nil {
return mx.AddErrorf("failed to fmt %s: %s\n", fn, err)
}
return mx.SetSrc(src)
return mx.SetViewSrc(src)
}

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

// Langs is the list of languages in which the reducer should run
Langs []string
Langs []mg.Lang

// Actions is a list of additional actions on which the reducer is allowed to run.
// Actions is a list of actions on which the reducer is allowed to run.
// The reducer always runs on the ViewFmt action, even if this list is empty.
Actions []mg.Action
}
Expand Down
10 changes: 5 additions & 5 deletions src/margo.sh/golang/common.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package golang

import (
"margo.sh/mg"
"go/ast"
"go/build"
"go/token"
"margo.sh/mg"
"os"
"path/filepath"
"reflect"
Expand All @@ -14,12 +14,12 @@ import (
"unicode/utf8"
)

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

func BuildContext(mx *mg.Ctx) *build.Context {
c := build.Default
Expand Down
6 changes: 3 additions & 3 deletions src/margo.sh/golang/gocmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func (gc *GoCmd) playTempDir(bx *mg.BultinCmdCtx) (newBx *mg.BultinCmdCtx, tDir
return bx, "", "", fmt.Errorf("cannot MkTempDir: %s", err)
}

if !bx.LangIs("go") {
if !bx.LangIs(mg.Go) {
return bx, tDir, "", nil
}

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

gx.iw = &mg.IssueWriter{
Base: mg.Issue{Label: label},
Patterns: CommonPatterns,
Patterns: bx.CommonPatterns(),
Dir: gx.pkgDir,
}

Expand Down Expand Up @@ -240,6 +240,6 @@ func (gx *goCmdCtx) run(origView *mg.View) error {
ik.Dir = origView.Dir()
}

gx.Store.Dispatch(mg.StoreIssues{Key: ik, Issues: issues})
gx.Store.Dispatch(mg.StoreIssues{IssueKey: ik, Issues: issues})
return err
}
16 changes: 11 additions & 5 deletions src/margo.sh/golang/gocode.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"io"
"margo.sh/golang/internal/gocode"
"margo.sh/mg"
"margo.sh/misc/pf"
"margo.sh/mgpf"
"margo.sh/sublime"
"strings"
"time"
Expand Down Expand Up @@ -71,7 +71,13 @@ func (g *Gocode) ReducerConfig(mx *mg.Ctx) mg.EditorConfig {
return nil
}

// ST might query the GoSublime plugin first, so we must always disable it
cfg = cfg.DisableGsComplete()
// but we don't want to affect editor completions in non-go files
if !g.ReducerCond(mx) {
return cfg
}

if !g.AllowExplicitCompletions {
cfg = cfg.InhibitExplicitCompletions()
}
Expand All @@ -82,7 +88,7 @@ func (g *Gocode) ReducerConfig(mx *mg.Ctx) mg.EditorConfig {
}

func (g *Gocode) ReducerCond(mx *mg.Ctx) bool {
return mx.LangIs("go") && mx.ActionIs(mg.QueryCompletions{})
return mx.ActionIs(mg.QueryCompletions{}) && mx.LangIs(mg.Go)
}

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

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

mx.Log.Println("gocode didn't respond after", pf.D(pTimeout), "taking", pf.Since(start))
mx.Log.Println("gocode didn't respond after", mgpf.D(pTimeout), "taking", mgpf.Since(start))
return st
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/margo.sh/golang/gocode_calltips.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type GocodeCalltips struct {
}

func (gc *GocodeCalltips) ReducerCond(mx *mg.Ctx) bool {
return mx.LangIs("go")
return mx.LangIs(mg.Go)
}

func (gc *GocodeCalltips) ReducerMount(mx *mg.Ctx) {
Expand Down
14 changes: 10 additions & 4 deletions src/margo.sh/golang/gofmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ import (
var (
GoFmt mg.Reducer = mg.NewReducer(goFmt)
GoImports mg.Reducer = mg.NewReducer(goImports)

commonFmtLangs = []mg.Lang{mg.Go}
commonFmtActions = []mg.Action{
mg.ViewFmt{},
mg.ViewPreSave{},
}
)

func disableGsFmt(st *mg.State) *mg.State {
Expand All @@ -24,8 +30,8 @@ type FmtFunc func(mx *mg.Ctx, src []byte) ([]byte, error)
func (ff FmtFunc) Reduce(mx *mg.Ctx) *mg.State {
return disableGsFmt(mgformat.FmtFunc{
Fmt: ff,
Langs: []string{"go"},
Actions: []mg.Action{mg.ViewPreSave{}},
Langs: commonFmtLangs,
Actions: commonFmtActions,
}.Reduce(mx))
}

Expand All @@ -39,7 +45,7 @@ func goImports(mx *mg.Ctx) *mg.State {
return disableGsFmt(mgformat.FmtCmd{
Name: "goimports",
Args: []string{"-srcdir", mx.View.Filename()},
Langs: []string{"go"},
Actions: []mg.Action{mg.ViewPreSave{}},
Langs: commonFmtLangs,
Actions: commonFmtActions,
}.Reduce(mx))
}
Loading

0 comments on commit 14b1fa0

Please sign in to comment.