Skip to content

Commit e34a3da

Browse files
committed
[gopls-release-branch.0.5] all: merge master into gopls-release-branch.0.5
8a9a893 internal/lsp/cache: don't set tempModFile is view's modURI is empty 0f1c539 internal/lsp: show orphaned file warnings as diagnostics 7b6ac5b internal/lsp/cache: slightly more useful comment 24570c0 internal/lsp: handle initial workspace load failure per module 04afef3 internal/lsp: don't search for workspace modules by default 7bb30d1 internal/lsp: fix go generate command for subdirs 06f3a46 gopls/internal/regtest: add benchmarks for completions 463111b internal/lsp: add a command to generate the gopls.mod file 03f0cc1 internal/lsp: interpolate variables in the sandbox ba800b1 internal/lsp: ignore errors when finding workspace modules f5e916c internal/lsp/source/completion: move search path to candidate a1f7ab6 internal/lsp/source/completion: move deep search to end of completion 82fe25c gopls/doc: improve enum value documentation aeb8e36 internal/lsp: remove multi-module support in tests fa01252 all: replace 'the the ' with 'the ' a20a5e7 internal/lsp: rewrite createView to populate fields independently 4aa5c68 internal/lsp: remove multi-module test cases 0f52b63 internal/lsp/tests: use NeedsGo1Point ccabf82 internal/lsp/cache: populate URI on files with errors d647fc2 cmd/benchcmp: mention deprecation in docs 78fed78 internal/lsp: handle modifications to the workspace module e94ab72 internal/lsp/source/completion: improve import suggestion labels d56e4e4 internal/lsp/cache: set GO111MODULE=auto in 1.16 3791637 all: fix tests in preparation for GO111MODULE=on by default d148ae1 internal/lsp/source/completion: convert deep completion to bfs 0511c4c internal/imports: use ProcessEnv to filter files 75ebdcb gopls/internal/regtest: add expected ranges in completion tests 60aba8a internal/lsp: always show errors from running commands 63098cc internal/imports: don't set Context.WorkingDir, which was renamed 655488c internal/lsp: fix concurrency issues in view initialization c537a34 internal/lsp: pass options by reference instead of by value c9a70fc internal/lsp/cache: fix release tag parsing f128e62 internal/memoize: show key type in panics 587cf23 internal/lsp/mod: handle nil pointers in code lenses 56d9a0c cover: fix sorting of profile segment boundaries c8d9e05 gopls/internal/regtest: simplify expectation return values 6ec2cde internal/lsp/source: add some additional symbol downranking e20053b gopls/internal/regtest: remove ExpectNow 797bd0f gopls/internal/regtest: simplify regtest EditorConfig cbbbe62 gopls/internal/regtest: add an InitialWorkspaceLoad expectation bf5c620 gopls/internal/regtest: move expectations to their own file f4cefd1 internal/lsp: enable multi-module workspace mode by default in tests 2db8f0f internal/lsp/cache: fix -mod=mod for workspace module setups 6498648 internal/lsp: check file kind before showing warning 3c2036f go/packages: support overlays for replaced modules 2b477fa tools, gopls: update Go versions in go.mod files to 1.12 8f9ed77 go/packages: add roots for overlaid packages for all query types 17fc728 internal/lsp: handle staticcheck in code actions 2350fe8 internal/lsp/source: fix panic in addFieldItems 97363e2 internal/lsp: handle staticcheck in didChangeConfiguration 6422fca report cycle when visiting a grey analyzer b43031a internal/lsp/cache: fix for default -mod=readonly 7ad463c gopls/internal/regtest: add a test for new symbols in test variants d49a6cb internal/lsp/protocol: add support for upcoming LSP 3.16 d179df3 internal/lsp/cache: automatically construct the workspace module 571a207 internal/lsp/source: fix duplicates in workspaceSymbols 53e29e9 internal/lsp: show a warning message when opening an "orphaned" file d6107fe gopls/internal/regtest: skip failing test for go1.13 and below b484961 x/gools/gopls: document settings for working on source distribution 44a2922 internal/lsp, go/packages: fix Go 1.15-related overlay bug 6a8222e gopls/doc: generate settings JSON, docs 201d438 internal/lsp: add more tests for package completion Change-Id: I9e52247c70e94cbedf2ebc47a6e9b2f6dabdb8c6
2 parents c9b80dc + 8a9a893 commit e34a3da

File tree

406 files changed

+5044
-2609
lines changed

Some content is hidden

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

406 files changed

+5044
-2609
lines changed

cmd/benchcmp/doc.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
/*
66
7+
Deprecated: benchcmp is deprecated in favor of benchstat: golang.org/x/perf/cmd/benchstat
8+
79
The benchcmp command displays performance changes between benchmarks.
810
911
Benchcmp parses the output of two 'go test' benchmark runs,

cmd/callgraph/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ func init() {
6363
flag.Var((*buildutil.TagsFlag)(&build.Default.BuildTags), "tags", buildutil.TagsFlagDoc)
6464
}
6565

66-
const Usage = `callgraph: display the the call graph of a Go program.
66+
const Usage = `callgraph: display the call graph of a Go program.
6767
6868
Usage:
6969

cmd/fiximports/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ func fiximports(packages ...string) bool {
266266

267267
// TODO(adonovan): should we make an HTTP request to
268268
// see if there's an HTTP redirect, a "go-import" meta tag,
269-
// or an import comment in the the latest revision?
269+
// or an import comment in the latest revision?
270270
// It would duplicate a lot of logic from "go get".
271271
}
272272
break

cmd/guru/referrers.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ func referrers(q *Query) error {
9595
if pkglevel {
9696
return globalReferrersPkgLevel(q, obj, fset)
9797
}
98-
// We'll use the the object's position to identify it in the larger program.
98+
// We'll use the object's position to identify it in the larger program.
9999
objposn := fset.Position(obj.Pos())
100100
defpkg := obj.Pkg().Path() // defining package
101101
return globalReferrers(q, qpos.info.Pkg.Path(), defpkg, objposn)

cover/profile.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ type Boundary struct {
194194
Start bool // Is this the start of a block?
195195
Count int // Event count from the cover profile.
196196
Norm float64 // Count normalized to [0..1].
197+
Index int // Order in input file.
197198
}
198199

199200
// Boundaries returns a Profile as a set of Boundary objects within the provided src.
@@ -209,8 +210,10 @@ func (p *Profile) Boundaries(src []byte) (boundaries []Boundary) {
209210
divisor := math.Log(float64(max))
210211

211212
// boundary returns a Boundary, populating the Norm field with a normalized Count.
213+
index := 0
212214
boundary := func(offset int, start bool, count int) Boundary {
213-
b := Boundary{Offset: offset, Start: start, Count: count}
215+
b := Boundary{Offset: offset, Start: start, Count: count, Index: index}
216+
index++
214217
if !start || count == 0 {
215218
return b
216219
}
@@ -250,7 +253,9 @@ func (b boundariesByPos) Len() int { return len(b) }
250253
func (b boundariesByPos) Swap(i, j int) { b[i], b[j] = b[j], b[i] }
251254
func (b boundariesByPos) Less(i, j int) bool {
252255
if b[i].Offset == b[j].Offset {
253-
return !b[i].Start && b[j].Start
256+
// Boundaries at the same offset should be ordered according to
257+
// their original position.
258+
return b[i].Index < b[j].Index
254259
}
255260
return b[i].Offset < b[j].Offset
256261
}

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module golang.org/x/tools
22

3-
go 1.11
3+
go 1.12
44

55
require (
66
github.com/yuin/goldmark v1.2.1

go/analysis/validate.go

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package analysis
33
import (
44
"fmt"
55
"reflect"
6+
"strings"
67
"unicode"
78
)
89

@@ -58,14 +59,28 @@ func Validate(analyzers []*Analyzer) error {
5859
}
5960

6061
// recursion
61-
for i, req := range a.Requires {
62+
for _, req := range a.Requires {
6263
if err := visit(req); err != nil {
63-
return fmt.Errorf("%s.Requires[%d]: %v", a.Name, i, err)
64+
return err
6465
}
6566
}
6667
color[a] = black
6768
}
6869

70+
if color[a] == grey {
71+
stack := []*Analyzer{a}
72+
inCycle := map[string]bool{}
73+
for len(stack) > 0 {
74+
current := stack[len(stack)-1]
75+
stack = stack[:len(stack)-1]
76+
if color[current] == grey && !inCycle[current.Name] {
77+
inCycle[current.Name] = true
78+
stack = append(stack, current.Requires...)
79+
}
80+
}
81+
return &CycleInRequiresGraphError{AnalyzerNames: inCycle}
82+
}
83+
6984
return nil
7085
}
7186
for _, a := range analyzers {
@@ -95,3 +110,17 @@ func validIdent(name string) bool {
95110
}
96111
return name != ""
97112
}
113+
114+
type CycleInRequiresGraphError struct {
115+
AnalyzerNames map[string]bool
116+
}
117+
118+
func (e *CycleInRequiresGraphError) Error() string {
119+
var b strings.Builder
120+
b.WriteString("cycle detected involving the following analyzers:")
121+
for n := range e.AnalyzerNames {
122+
b.WriteByte(' ')
123+
b.WriteString(n)
124+
}
125+
return b.String()
126+
}

go/analysis/validate_test.go

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
// Copyright 2020 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
package analysis
6+
7+
import (
8+
"strings"
9+
"testing"
10+
)
11+
12+
func TestValidate(t *testing.T) {
13+
var (
14+
dependsOnSelf = &Analyzer{
15+
Name: "dependsOnSelf",
16+
Doc: "this analyzer depends on itself",
17+
}
18+
inCycleA = &Analyzer{
19+
Name: "inCycleA",
20+
Doc: "this analyzer depends on inCycleB",
21+
}
22+
inCycleB = &Analyzer{
23+
Name: "inCycleB",
24+
Doc: "this analyzer depends on inCycleA and notInCycleA",
25+
}
26+
pointsToCycle = &Analyzer{
27+
Name: "pointsToCycle",
28+
Doc: "this analyzer depends on inCycleA",
29+
}
30+
notInCycleA = &Analyzer{
31+
Name: "notInCycleA",
32+
Doc: "this analyzer depends on notInCycleB and notInCycleC",
33+
}
34+
notInCycleB = &Analyzer{
35+
Name: "notInCycleB",
36+
Doc: "this analyzer depends on notInCycleC",
37+
}
38+
notInCycleC = &Analyzer{
39+
Name: "notInCycleC",
40+
Doc: "this analyzer has no dependencies",
41+
}
42+
)
43+
44+
dependsOnSelf.Requires = append(dependsOnSelf.Requires, dependsOnSelf)
45+
inCycleA.Requires = append(inCycleA.Requires, inCycleB)
46+
inCycleB.Requires = append(inCycleB.Requires, inCycleA, notInCycleA)
47+
pointsToCycle.Requires = append(pointsToCycle.Requires, inCycleA)
48+
notInCycleA.Requires = append(notInCycleA.Requires, notInCycleB, notInCycleC)
49+
notInCycleB.Requires = append(notInCycleB.Requires, notInCycleC)
50+
notInCycleC.Requires = []*Analyzer{}
51+
52+
cases := []struct {
53+
analyzers []*Analyzer
54+
wantErr bool
55+
analyzersInCycle map[string]bool
56+
}{
57+
{
58+
[]*Analyzer{dependsOnSelf},
59+
true,
60+
map[string]bool{"dependsOnSelf": true},
61+
},
62+
{
63+
[]*Analyzer{inCycleA, inCycleB},
64+
true,
65+
map[string]bool{"inCycleA": true, "inCycleB": true},
66+
},
67+
{
68+
[]*Analyzer{pointsToCycle},
69+
true,
70+
map[string]bool{"inCycleA": true, "inCycleB": true},
71+
},
72+
{
73+
[]*Analyzer{notInCycleA},
74+
false,
75+
map[string]bool{},
76+
},
77+
}
78+
79+
for _, c := range cases {
80+
got := Validate(c.analyzers)
81+
82+
if !c.wantErr {
83+
if got == nil {
84+
continue
85+
}
86+
t.Errorf("got unexpected error while validating analyzers %v: %v", c.analyzers, got)
87+
}
88+
89+
if got == nil {
90+
t.Errorf("expected error while validating analyzers %v, but got nil", c.analyzers)
91+
}
92+
93+
err, ok := got.(*CycleInRequiresGraphError)
94+
if !ok {
95+
t.Errorf("want CycleInRequiresGraphError, got %T", err)
96+
}
97+
98+
for a := range c.analyzersInCycle {
99+
if !err.AnalyzerNames[a] {
100+
t.Errorf("analyzer %s should be in cycle", a)
101+
}
102+
}
103+
for a := range err.AnalyzerNames {
104+
if !c.analyzersInCycle[a] {
105+
t.Errorf("analyzer %s should not be in cycle", a)
106+
}
107+
}
108+
}
109+
}
110+
111+
func TestCycleInRequiresGraphErrorMessage(t *testing.T) {
112+
err := CycleInRequiresGraphError{}
113+
errMsg := err.Error()
114+
wantSubstring := "cycle detected"
115+
if !strings.Contains(errMsg, wantSubstring) {
116+
t.Errorf("error string %s does not contain expected substring %q", errMsg, wantSubstring)
117+
}
118+
}

go/internal/gcimporter/gcimporter.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,7 @@ func (p *parser) parseMapType(parent *types.Package) types.Type {
491491
//
492492
// For unqualified and anonymous names, the returned package is the parent
493493
// package unless parent == nil, in which case the returned package is the
494-
// package being imported. (The parent package is not nil if the the name
494+
// package being imported. (The parent package is not nil if the name
495495
// is an unqualified struct field or interface method name belonging to a
496496
// type declared in another package.)
497497
//

go/packages/golist.go

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,21 @@ extractQueries:
246246
}
247247
}
248248
}
249+
// Add root for any package that matches a pattern. This applies only to
250+
// packages that are modified by overlays, since they are not added as
251+
// roots automatically.
252+
for _, pattern := range restPatterns {
253+
match := matchPattern(pattern)
254+
for _, pkgID := range modifiedPkgs {
255+
pkg, ok := response.seenPackages[pkgID]
256+
if !ok {
257+
continue
258+
}
259+
if match(pkg.PkgPath) {
260+
response.addRoot(pkg.ID)
261+
}
262+
}
263+
}
249264

250265
sizeswg.Wait()
251266
if sizeserr != nil {
@@ -753,7 +768,8 @@ func (state *golistState) getGoVersion() (string, error) {
753768
return state.goVersion, state.goVersionError
754769
}
755770

756-
// getPkgPath finds the package path of a directory if it's relative to a root directory.
771+
// getPkgPath finds the package path of a directory if it's relative to a root
772+
// directory.
757773
func (state *golistState) getPkgPath(dir string) (string, bool, error) {
758774
absDir, err := filepath.Abs(dir)
759775
if err != nil {

0 commit comments

Comments
 (0)