Skip to content

Commit

Permalink
Next (#956)
Browse files Browse the repository at this point in the history
20.01.01
  • Loading branch information
DisposaBoy authored Jan 1, 2020
1 parent f890e6a commit f78e351
Show file tree
Hide file tree
Showing 302 changed files with 65,335 additions and 48,399 deletions.
27 changes: 27 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,33 @@ https://margo.sh/b/motd - Get notified when GoSublime has a new release.

## Changes

## 20.01.01

This release mainly focuses on under-the-hood improvements for module support.

- The default auto-completion import mode has been changed to `Kim-Porter`, our solution for auto-completion and package/module going forward.

One side-effect of this change is that unimported-packages support is less reliable but we feel this is a small drawback when compared to the much improved auto-completion support.

We plan to remove support for switching import modes in the future, but if you would like to revert to the previous default (bearing in mind auto-completion might stop working), configure the `MarGocodeCtl` reducer as follows:

```go
&golang.MarGocodeCtl{
ImporterMode: golang.SrcImporterWithFallback,
}
```

- The Go/TypeCheck linter is now more complete and should be able to type-check (without failure) all packages for which auto-completion is available.
This linter offers typechecking (like the gotype tool) but can work on unsaved files and while you type and is faster a full `go install` lint.

To enable add the following reducer to your `margo.go` file:

```go
&golang.TypeCheck{},
```

- Some HTTP handler snippets have been added and are offered in files that `import "net/http"`.

## 19.10.22

- API BREAKAGE:
Expand Down
2 changes: 1 addition & 1 deletion gosubl/about.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import re
import sublime

TAG = '19.10.22-1'
TAG = '20.01.01-1'
ANN = 'a'+TAG
VERSION = 'r'+TAG
VERSION_PAT = re.compile(r'\d{2}[.]\d{2}[.]\d{2}-\d+', re.IGNORECASE)
Expand Down
22 changes: 22 additions & 0 deletions src/margo.sh/.github/workflows/margo-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
on: [push, pull_request]
name: margo-ci
jobs:
margo-ci:
strategy:
matrix:
go-version: [1.12.x, 1.13.x]
platform: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.platform }}
steps:
- name: Setup
uses: actions/setup-go@v1
with:
go-version: ${{ matrix.go-version }}
- name: Checkout
uses: actions/checkout@v2
with:
path: src/margo.sh
- name: CI
env:
GOPATH: ${{ github.workspace }}
run: go run margo.sh ci
18 changes: 0 additions & 18 deletions src/margo.sh/.travis.yml

This file was deleted.

47 changes: 32 additions & 15 deletions src/margo.sh/Gopkg.lock

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

4 changes: 4 additions & 0 deletions src/margo.sh/Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,7 @@ required = [
[[constraint]]
name = "github.com/rogpeppe/go-internal"
version = "1.3.0"

[[override]]
name = "github.com/russross/blackfriday"
version = "1.5.2"
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 @@ -32,7 +32,7 @@ func Main() {
if err != nil {
return mgcli.Error("agent creation failed:", err)
}

mg.SetMemoryLimit(ag.Log, mg.DefaultMemoryLimit)
ag.Store.SetBaseConfig(sublime.DefaultConfig)
if margoExt != nil {
margoExt(ag.Args())
Expand Down
19 changes: 19 additions & 0 deletions src/margo.sh/golang/cursor/curctx.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,25 @@ func (cx *CurCtx) Contains(typ ast.Node) bool {
})
}

func (cx *CurCtx) ImportsMatch(match func(importPath string) bool) bool {
for _, spec := range cx.AstFile.Imports {
p := spec.Path.Value
if len(p) < 3 {
continue
}
if c := p[0]; c == '"' || c == '`' {
p = p[1:]
}
if c := p[len(p)-1]; c == '"' || c == '`' {
p = p[:len(p)-1]
}
if match(p) {
return true
}
}
return false
}

func (cx *CurCtx) Print(x ast.Node) (string, error) {
p := &cx.printer
p.Lock()
Expand Down
5 changes: 5 additions & 0 deletions src/margo.sh/golang/gocode_suggest.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"go/types"
"kuroku.io/margocode/suggest"
"margo.sh/golang/gopkg"
"margo.sh/kimporter"
"margo.sh/mg"
"margo.sh/mgutil"
"runtime/debug"
Expand Down Expand Up @@ -144,6 +145,10 @@ func (gi *gsuImporter) importFromName(pkgName, srcDir string) (pkg *types.Packag
}

func (gi *gsuImporter) ImportFrom(impPath, srcDir string, mode types.ImportMode) (pkg *types.Package, err error) {
if mctl.cfg().ImporterMode == KimPorter {
return kimporter.New(gi.mx, nil).ImportFrom(impPath, srcDir, mode)
}

// TODO: add mode to the key somehow?
// mode is reserved, but currently not used so it's not a problem
// but if it's used in the future, the importer result could depend on it
Expand Down
63 changes: 48 additions & 15 deletions src/margo.sh/golang/gopkg/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,33 +32,57 @@ func ScanFilter(de *vfs.Dirent) bool {
}

func ImportDir(mx *mg.Ctx, dir string) (*Pkg, error) {
if !filepath.IsAbs(dir) {
return nil, fmt.Errorf("ImportDir: %s is not an absolute path", dir)
}
return ImportDirNd(mx, mx.VFS.Poke(dir))
}

func ImportDirNd(mx *mg.Ctx, nd *vfs.Node) (*Pkg, error) {
ls := nd.Ls().Filter(pkgNdFilter).Nodes()
func ImportDirNd(mx *mg.Ctx, dir *vfs.Node) (*Pkg, error) {
return importDirNd(mx, dir, true)
}

func importDirNd(mx *mg.Ctx, nd *vfs.Node, poke bool) (*Pkg, error) {
var cl *vfs.NodeList
if poke {
cl = nd.Ls()
} else {
cl = nd.Children()
}
ls := cl.Filter(pkgNdFilter).Nodes()
if len(ls) == 0 {
return nil, &build.NoGoError{Dir: nd.Path()}
}
memo, err := nd.Memo()
if err != nil {
return nil, err
if poke {
return nil, &build.NoGoError{Dir: nd.Path()}
}
return nil, nil
}

bctx := goutil.BuildContext(mx)
type K struct{ GOROOT, GOPATH string }
type V struct {
p *Pkg
e error
}
k := K{GOROOT: bctx.GOROOT, GOPATH: bctx.GOPATH}
v := memo.Read(k, func() interface{} {
p, err := importDirNd(mx, nd, bctx, ls)
if !poke {
v, _ := nd.PeekMemo(k).(V)
return v.p, v.e
}
v := nd.ReadMemo(k, func() interface{} {
p, err := importDir(mx, nd, bctx, ls)
return V{p: p, e: err}
}).(V)
return v.p, v.e
}

func PeekDir(mx *mg.Ctx, dir string) *Pkg {
return PeekDirNd(mx, mx.VFS.Peek(dir))
}

func PeekDirNd(mx *mg.Ctx, dir *vfs.Node) *Pkg {
p, _ := importDirNd(mx, dir, false)
return p
}

func pkgNdFilter(nd *vfs.Node) bool {
nm := nd.Name()
return nm[0] != '.' && nm[0] != '_' &&
Expand All @@ -67,7 +91,7 @@ func pkgNdFilter(nd *vfs.Node) bool {
!strings.HasSuffix(nm, "_test.go")
}

func importDirNd(mx *mg.Ctx, nd *vfs.Node, bctx *build.Context, ls []*vfs.Node) (*Pkg, error) {
func importDir(mx *mg.Ctx, nd *vfs.Node, bctx *build.Context, ls []*vfs.Node) (*Pkg, error) {
dir := nd.Path()
var errNoGo error = &build.NoGoError{Dir: dir}
bctx.IsDir = func(p string) bool {
Expand Down Expand Up @@ -242,6 +266,8 @@ type modDep struct {
ModPath string
SubPkg string
Version string

oldPath string
}

func (mf *modFile) requireMD(modPath string) (_ modDep, found bool) {
Expand All @@ -259,7 +285,11 @@ func (mf *modFile) require(importPath string) (modDep, error) {
if !found {
return modDep{}, fmt.Errorf("require(%s) not found in %s", importPath, mf.Path)
}
md.SubPkg = strings.TrimPrefix(importPath, md.ModPath)
modPath := md.ModPath
if md.oldPath != "" {
modPath = md.oldPath
}
md.SubPkg = strings.TrimPrefix(importPath, modPath)
md.SubPkg = strings.TrimLeft(md.SubPkg, "/")
return md, nil
}
Expand Down Expand Up @@ -338,7 +368,7 @@ func (mf *modFile) find(mx *mg.Ctx, bctx *build.Context, importPath string, mp *
searchOtherVendors,
searchGrVendor,
}
if !strings.Contains(strings.Split(importPath, "/")[0], ".") {
if !strings.Contains(strings.SplitN(importPath, "/", 2)[0], ".") {
// apparently import paths without dots are reserved for the stdlib
// checking first also avoids the many misses for each stdlib pkg
search = []func() *PkgPath{
Expand All @@ -353,6 +383,9 @@ func (mf *modFile) find(mx *mg.Ctx, bctx *build.Context, importPath string, mp *
return p, nil
}
}
if md.oldPath != "" {
return nil, fmt.Errorf("cannot find `%s` replacement `%s` using `%s`", importPath, md.ModPath, mf.Path)
}
return nil, fmt.Errorf("cannot find `%s` using `%s`", importPath, mf.Path)
}

Expand Down Expand Up @@ -395,11 +428,11 @@ func loadModSum(mx *mg.Ctx, dir string) (*modFile, error) {

for _, r := range mf.File.Replace {
md := modDep{
oldPath: r.Old.Path,
ModPath: r.New.Path,
Version: r.New.Version,
}
// if dir := r.New.Path; modfile.IsDirectoryPath(dir) {
if dir := r.New.Path; dir[0] == '/' || dir[0] == '.' {
if dir := r.New.Path; modfile.IsDirectoryPath(dir) {
if !filepath.IsAbs(dir) {
dir = filepath.Join(mf.Dir, dir)
}
Expand Down
Loading

0 comments on commit f78e351

Please sign in to comment.