Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deps: update x/tools and gopls to d1954cc86c82 #935

Merged
merged 1 commit into from Sep 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/docker-based_tests.yml
Expand Up @@ -26,6 +26,7 @@ env:
GH_USER: "x-access-token"
GH_TOKEN: ${{ github.token }}
GOVIM_TEST_RACE_SLOWDOWN: "1.5"
GOVIM_ERRLOGMATCH_WAIT: "25s"

name: Docker-based tests
jobs:
Expand Down
Expand Up @@ -198,8 +198,12 @@ func TypeExpr(fset *token.FileSet, f *ast.File, pkg *types.Package, typ types.Ty
X: ast.NewIdent(pkgName),
Sel: ast.NewIdent(t.Obj().Name()),
}
case *types.Struct:
return ast.NewIdent(t.String())
case *types.Interface:
return ast.NewIdent(t.String())
default:
return nil // TODO: anonymous structs, but who does that
return nil
}
}

Expand Down Expand Up @@ -398,14 +402,14 @@ func equivalentTypes(want, got types.Type) bool {
func FindBestMatch(pattern string, idents []*ast.Ident) ast.Expr {
fuzz := fuzzy.NewMatcher(pattern)
var bestFuzz ast.Expr
highScore := float32(-1) // minimum score is -1 (no match)
highScore := float32(0) // minimum score is 0 (no match)
for _, ident := range idents {
// TODO: Improve scoring algorithm.
score := fuzz.Score(ident.Name)
if score > highScore {
highScore = score
bestFuzz = ident
} else if score == -1 {
} else if score == 0 {
// Order matters in the fuzzy matching algorithm. If we find no match
// when matching the target to the identifier, try matching the identifier
// to the target.
Expand Down
2 changes: 1 addition & 1 deletion cmd/govim/internal/golang_org_x_tools/imports/fix.go
Expand Up @@ -615,7 +615,7 @@ func getCandidatePkgs(ctx context.Context, wrappedCallback *scanCallback, filena
packageName: path.Base(importPath),
relevance: MaxRelevance,
}
if notSelf(p) && wrappedCallback.packageNameLoaded(p) {
if notSelf(p) && wrappedCallback.dirFound(p) && wrappedCallback.packageNameLoaded(p) {
wrappedCallback.exportsLoaded(p, exports)
}
}
Expand Down
Expand Up @@ -13,7 +13,6 @@ import (
"go/format"
"go/token"
"go/types"
"log"
"unicode"

"golang.org/x/tools/go/analysis"
Expand Down Expand Up @@ -254,8 +253,7 @@ func SuggestedFix(fset *token.FileSet, rng span.Range, content []byte, file *ast

var newExpr bytes.Buffer
if err := format.Node(&newExpr, fakeFset, cl); err != nil {
log.Printf("failed to format %s: %v", cl.Type, err)
return nil, err
return nil, fmt.Errorf("failed to format %s: %v", cl.Type, err)
}
split = bytes.Split(newExpr.Bytes(), []byte("\n"))
newText := bytes.NewBuffer(nil)
Expand Down
1 change: 1 addition & 0 deletions cmd/govim/internal/golang_org_x_tools/lsp/cache/load.go
Expand Up @@ -121,6 +121,7 @@ func (s *snapshot) load(ctx context.Context, scopes ...interface{}) error {
}
event.Error(ctx, "go/packages.Load", err, tag.Snapshot.Of(s.ID()), tag.Directory.Of(cfg.Dir), tag.Query.Of(query), tag.PackageCount.Of(len(pkgs)))
} else {
err = fmt.Errorf("no packages returned")
event.Log(ctx, "go/packages.Load", tag.Snapshot.Of(s.ID()), tag.Directory.Of(cfg.Dir), tag.Query.Of(query), tag.PackageCount.Of(len(pkgs)))
}
if len(pkgs) == 0 {
Expand Down
47 changes: 28 additions & 19 deletions cmd/govim/internal/golang_org_x_tools/lsp/cache/mod.go
Expand Up @@ -6,7 +6,9 @@ package cache

import (
"context"
"encoding/json"
"fmt"
"io"
"os"
"path/filepath"
"regexp"
Expand Down Expand Up @@ -273,6 +275,15 @@ func (muh *modUpgradeHandle) upgrades(ctx context.Context, snapshot *snapshot) (
return data.upgrades, data.err
}

// moduleUpgrade describes a module that can be upgraded to a particular
// version.
type moduleUpgrade struct {
Path string
Update struct {
Version string
}
}

func (s *snapshot) ModUpgrade(ctx context.Context, fh source.FileHandle) (map[string]string, error) {
if err := s.awaitLoaded(ctx); err != nil {
return nil, err
Expand Down Expand Up @@ -306,7 +317,7 @@ func (s *snapshot) ModUpgrade(ctx context.Context, fh source.FileHandle) (map[st
}
// Run "go list -mod readonly -u -m all" to be able to see which deps can be
// upgraded without modifying mod file.
args := []string{"-u", "-m", "all"}
args := []string{"-u", "-m", "-json", "all"}
if !snapshot.view.tmpMod || containsVendor(fh.URI()) {
// Use -mod=readonly if the module contains a vendor directory
// (see golang/go#38711).
Expand All @@ -316,28 +327,26 @@ func (s *snapshot) ModUpgrade(ctx context.Context, fh source.FileHandle) (map[st
if err != nil {
return &modUpgradeData{err: err}
}
upgradesList := strings.Split(stdout.String(), "\n")
if len(upgradesList) <= 1 {
return nil
var upgradeList []moduleUpgrade
dec := json.NewDecoder(stdout)
for {
var m moduleUpgrade
if err := dec.Decode(&m); err == io.EOF {
break
} else if err != nil {
return &modUpgradeData{err: err}
}
upgradeList = append(upgradeList, m)
}
if len(upgradeList) <= 1 {
return &modUpgradeData{}
}
upgrades := make(map[string]string)
for _, upgrade := range upgradesList[1:] {
// Example: "github.com/x/tools v1.1.0 [v1.2.0]"
info := strings.Split(upgrade, " ")
if len(info) != 3 {
continue
}
dep, version := info[0], info[2]

// Make sure that the format matches our expectation.
if len(version) < 2 {
continue
}
if version[0] != '[' || version[len(version)-1] != ']' {
for _, upgrade := range upgradeList[1:] {
if upgrade.Update.Version == "" {
continue
}
latest := version[1 : len(version)-1] // remove the "[" and "]"
upgrades[dep] = latest
upgrades[upgrade.Path] = upgrade.Update.Version
}
return &modUpgradeData{
upgrades: upgrades,
Expand Down
23 changes: 17 additions & 6 deletions cmd/govim/internal/golang_org_x_tools/lsp/cache/snapshot.go
Expand Up @@ -16,6 +16,7 @@ import (
"os"
"path/filepath"
"sort"
"strconv"
"strings"
"sync"

Expand Down Expand Up @@ -1120,19 +1121,29 @@ func (s *snapshot) shouldInvalidateMetadata(ctx context.Context, originalFH, cur
if original.Name.Name != current.Name.Name {
return true
}
// If the package's imports have increased, definitely re-run `go list`.
if len(original.Imports) < len(current.Imports) {
return true
}
importSet := make(map[string]struct{})
for _, importSpec := range original.Imports {
importSet[importSpec.Path.Value] = struct{}{}
}
// If any of the current imports were not in the original imports.
for _, importSpec := range current.Imports {
if _, ok := importSet[importSpec.Path.Value]; !ok {
return true
if _, ok := importSet[importSpec.Path.Value]; ok {
continue
}
// If the import path is obviously not valid, we can skip reloading
// metadata. For now, valid means properly quoted and without a
// terminal slash.
path, err := strconv.Unquote(importSpec.Path.Value)
if err != nil {
continue
}
if path == "" {
continue
}
if path[len(path)-1] == '/' {
continue
}
return true
}
return false
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/govim/internal/golang_org_x_tools/lsp/cache/view.go
Expand Up @@ -717,7 +717,7 @@ func (v *View) maybeReinitialize() {

func (v *View) setBuildInformation(ctx context.Context, folder span.URI, options source.Options) error {
if err := checkPathCase(folder.Filename()); err != nil {
return fmt.Errorf("invalid workspace configuration: %w", err)
return errors.Errorf("invalid workspace configuration: %w", err)
}
// Make sure to get the `go env` before continuing with initialization.
modFile, err := v.setGoEnv(ctx, options.Env)
Expand Down
Expand Up @@ -6,13 +6,13 @@ package cmd

import (
"context"
"errors"
"flag"
"fmt"

"github.com/govim/govim/cmd/govim/internal/golang_org_x_tools/lsp/protocol"
"github.com/govim/govim/cmd/govim/internal/golang_org_x_tools/span"
"github.com/govim/govim/cmd/govim/internal/golang_org_x_tools/tool"
errors "golang.org/x/xerrors"
)

// prepareRename implements the prepare_rename verb for gopls.
Expand Down Expand Up @@ -68,7 +68,7 @@ func (r *prepareRename) Run(ctx context.Context, args ...string) error {
}
result, err := conn.PrepareRename(ctx, &p)
if err != nil {
return fmt.Errorf("prepare_rename failed: %w", err)
return errors.Errorf("prepare_rename failed: %w", err)
}
if result == nil {
return ErrInvalidRenamePosition
Expand Down
2 changes: 1 addition & 1 deletion cmd/govim/internal/golang_org_x_tools/lsp/cmd/serve.go
Expand Up @@ -6,7 +6,6 @@ package cmd

import (
"context"
"errors"
"flag"
"fmt"
"io"
Expand All @@ -22,6 +21,7 @@ import (
"github.com/govim/govim/cmd/govim/internal/golang_org_x_tools/lsp/lsprpc"
"github.com/govim/govim/cmd/govim/internal/golang_org_x_tools/lsp/protocol"
"github.com/govim/govim/cmd/govim/internal/golang_org_x_tools/tool"
errors "golang.org/x/xerrors"
)

// Serve is a struct that exposes the configurable parts of the LSP server as
Expand Down