Skip to content

Commit

Permalink
Move PackedContext from gbimporter to a new context package
Browse files Browse the repository at this point in the history
Additionally, rename PackedContext => Packed and PackContext => Pack to
prevent the name from stuttering.  This reduces the likelihood of
circular dependencies developing in the future and makes clearer that
Packed is a type shared between packages under the internal directory.
  • Loading branch information
Charlie Vieth committed Sep 8, 2018
1 parent 8351239 commit bbaaca9
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 15 deletions.
4 changes: 2 additions & 2 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (

"runtime/debug"

"github.com/mdempsky/gocode/internal/gbimporter"
"github.com/mdempsky/gocode/internal/context"
"github.com/mdempsky/gocode/internal/suggest"
)

Expand Down Expand Up @@ -126,7 +126,7 @@ func tryToConnect(network, address string) (*rpc.Client, error) {
func cmdAutoComplete(c *rpc.Client) {
var req AutoCompleteRequest
req.Filename, req.Data, req.Cursor = prepareFilenameDataCursor()
req.Context = gbimporter.PackContext(&build.Default)
req.Context = context.Pack(&build.Default)
req.Source = *g_source
req.Builtin = *g_builtin

Expand Down
12 changes: 6 additions & 6 deletions internal/gbimporter/context.go → internal/context/context.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package gbimporter
package context

import "go/build"

// PackedContext is a copy of build.Context without the func fields.
// Packed is a copy of build.Context without the func fields.
//
// TODO(mdempsky): Not sure this belongs here.
type PackedContext struct {
type Packed struct {
GOARCH string
GOOS string
GOROOT string
Expand All @@ -18,8 +18,8 @@ type PackedContext struct {
InstallSuffix string
}

func PackContext(ctx *build.Context) PackedContext {
return PackedContext{
func Pack(ctx *build.Context) Packed {
return Packed{
GOARCH: ctx.GOARCH,
GOOS: ctx.GOOS,
GOROOT: ctx.GOROOT,
Expand All @@ -34,7 +34,7 @@ func PackContext(ctx *build.Context) PackedContext {
}

// Update context ctxt to match PackedContext
func (p *PackedContext) Update(ctxt *build.Context) {
func (p *Packed) Update(ctxt *build.Context) {
ctxt.GOARCH = p.GOARCH
ctxt.GOOS = p.GOOS
ctxt.GOROOT = p.GOROOT
Expand Down
6 changes: 4 additions & 2 deletions internal/gbimporter/gbimporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"path/filepath"
"strings"
"sync"

"github.com/mdempsky/gocode/internal/context"
)

// We need to mangle go/build.Default to make gcimporter work as
Expand All @@ -17,12 +19,12 @@ var buildDefaultLock sync.Mutex
// support for gb-based projects.
type importer struct {
underlying types.ImporterFrom
ctx *PackedContext
ctx *context.Packed
gbroot string
gbpaths []string
}

func New(ctx *PackedContext, filename string, underlying types.ImporterFrom) types.ImporterFrom {
func New(ctx *context.Packed, filename string, underlying types.ImporterFrom) types.ImporterFrom {
imp := &importer{
ctx: ctx,
underlying: underlying,
Expand Down
4 changes: 2 additions & 2 deletions internal/suggest/suggest.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ import (
"sync"

"github.com/mdempsky/gocode/internal/buildutil"
"github.com/mdempsky/gocode/internal/gbimporter"
"github.com/mdempsky/gocode/internal/context"
"github.com/mdempsky/gocode/internal/lookdot"
)

type Config struct {
Importer types.Importer
Context *gbimporter.PackedContext
Context *context.Packed
Logf func(fmt string, args ...interface{})
Builtin bool
}
Expand Down
4 changes: 2 additions & 2 deletions internal/suggest/suggest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"strings"
"testing"

"github.com/mdempsky/gocode/internal/gbimporter"
"github.com/mdempsky/gocode/internal/context"
)

func TestRegress(t *testing.T) {
Expand Down Expand Up @@ -90,7 +90,7 @@ func BenchmarkParseOtherPackageFiles(b *testing.B) {
if _, err := os.Stat(filename); err != nil {
b.Skipf("cannot stat 'os/file.go': %s", err)
}
packed := gbimporter.PackContext(&build.Default)
packed := context.Pack(&build.Default)
conf := Config{Context: &packed}
b.ResetTimer()
for i := 0; i < b.N; i++ {
Expand Down
3 changes: 2 additions & 1 deletion server.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"runtime/debug"
"time"

"github.com/mdempsky/gocode/internal/context"
"github.com/mdempsky/gocode/internal/gbimporter"
"github.com/mdempsky/gocode/internal/suggest"
)
Expand Down Expand Up @@ -55,7 +56,7 @@ type AutoCompleteRequest struct {
Filename string
Data []byte
Cursor int
Context gbimporter.PackedContext
Context context.Packed
Source bool
Builtin bool
}
Expand Down

0 comments on commit bbaaca9

Please sign in to comment.