Skip to content

Commit 7a6cbdc

Browse files
committed
all: merge master into gopls-release-branch.0.4
Figured it was easier to just merge to master instead of cherry-picking. Change-Id: Ia78e95bd1dc4e6b07bd5f9be73118f99f9827091
2 parents 2a1e5b5 + ca5866b commit 7a6cbdc

40 files changed

+586
-352
lines changed

godoc/vfs/mapfs/mapfs.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
package mapfs // import "golang.org/x/tools/godoc/vfs/mapfs"
88

99
import (
10+
"fmt"
1011
"io"
1112
"os"
1213
pathpkg "path"
@@ -18,9 +19,21 @@ import (
1819
)
1920

2021
// New returns a new FileSystem from the provided map.
21-
// Map keys should be forward slash-separated pathnames
22-
// and not contain a leading slash.
22+
// Map keys must be forward slash-separated paths with
23+
// no leading slash, such as "file1.txt" or "dir/file2.txt".
24+
// New panics if any of the paths contain a leading slash.
2325
func New(m map[string]string) vfs.FileSystem {
26+
// Verify all provided paths are relative before proceeding.
27+
var pathsWithLeadingSlash []string
28+
for p := range m {
29+
if strings.HasPrefix(p, "/") {
30+
pathsWithLeadingSlash = append(pathsWithLeadingSlash, p)
31+
}
32+
}
33+
if len(pathsWithLeadingSlash) > 0 {
34+
panic(fmt.Errorf("mapfs.New: invalid paths with a leading slash: %q", pathsWithLeadingSlash))
35+
}
36+
2437
return mapFS(m)
2538
}
2639

gopls/doc/settings.md

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,15 @@ Example Usage:
8383
...
8484
```
8585

86-
### **staticcheck** *boolean*
86+
### **codelens** *map[string]bool*
8787

88-
If true, it enables the use of the staticcheck.io analyzers.
88+
Overrides the enabled/disabled state of various code lenses. Currently, we
89+
support two code lenses:
90+
91+
* `generate`: run `go generate` as specified by a `//go:generate` directive.
92+
* `upgrade.dependency`: upgrade a dependency listed in a `go.mod` file.
93+
94+
By default, both of these code lenses are enabled.
8995

9096
### **completionDocumentation** *boolean*
9197

@@ -129,3 +135,27 @@ At the location of the `<>` in this program, deep completion would suggest the r
129135
If true, this enables server side fuzzy matching of completion candidates.
130136

131137
Default: `true`.
138+
139+
### **staticcheck** *boolean*
140+
141+
If true, it enables the use of the staticcheck.io analyzers.
142+
143+
### **matcher** *string*
144+
145+
Defines the algorithm that is used when calculating completion candidates. Must be one of:
146+
147+
* `"fuzzy"`
148+
* `"caseSensitive"`
149+
* `"caseInsensitive"`
150+
151+
Default: `"caseInsensitive"`.
152+
153+
### **symbolMatcher** *string*
154+
155+
Defines the algorithm that is used when calculating workspace symbol results. Must be one of:
156+
157+
* `"fuzzy"`
158+
* `"caseSensitive"`
159+
* `"caseInsensitive"`
160+
161+
Default: `"caseInsensitive"`.

gopls/doc/vscode.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,16 @@ See the section on [command line](command-line.md) arguments for more informatio
5252

5353
You can disable features through the `"go.languageServerExperimentalFeatures"` section of the config. An example of a feature you may want to disable is `"documentLink"`, which opens [`pkg.go.dev`](https://pkg.go.dev) links when you click on import statements in your file.
5454

55+
### Build tags
56+
57+
build tags will not be picked from `go.buildTags` configuration section, instead they should be specified as part of the`GOFLAGS` environment variable:
58+
59+
```json5
60+
"go.toolsEnvVars": {
61+
"GOFLAGS": "-tags=<yourtag>"
62+
}
63+
```
64+
5565

5666
[VSCode-Go]: https://github.com/microsoft/vscode-go
5767

internal/event/export/log.go

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import (
1212

1313
"golang.org/x/tools/internal/event"
1414
"golang.org/x/tools/internal/event/core"
15-
"golang.org/x/tools/internal/event/keys"
1615
"golang.org/x/tools/internal/event/label"
1716
)
1817

@@ -27,7 +26,7 @@ func LogWriter(w io.Writer, onlyErrors bool) event.Exporter {
2726

2827
type logWriter struct {
2928
mu sync.Mutex
30-
buffer [128]byte
29+
printer Printer
3130
writer io.Writer
3231
onlyErrors bool
3332
}
@@ -40,28 +39,7 @@ func (w *logWriter) ProcessEvent(ctx context.Context, ev core.Event, lm label.Ma
4039
}
4140
w.mu.Lock()
4241
defer w.mu.Unlock()
43-
44-
buf := w.buffer[:0]
45-
if !ev.At().IsZero() {
46-
w.writer.Write(ev.At().AppendFormat(buf, "2006/01/02 15:04:05 "))
47-
}
48-
msg := keys.Msg.Get(lm)
49-
io.WriteString(w.writer, msg)
50-
if err := keys.Err.Get(lm); err != nil {
51-
io.WriteString(w.writer, ": ")
52-
io.WriteString(w.writer, err.Error())
53-
}
54-
for index := 0; ev.Valid(index); index++ {
55-
l := ev.Label(index)
56-
if !l.Valid() || l.Key() == keys.Msg || l.Key() == keys.Err {
57-
continue
58-
}
59-
io.WriteString(w.writer, "\n\t")
60-
io.WriteString(w.writer, l.Key().Name())
61-
io.WriteString(w.writer, "=")
62-
l.Key().Format(w.writer, buf, l)
63-
}
64-
io.WriteString(w.writer, "\n")
42+
w.printer.WriteEvent(w.writer, ev, lm)
6543

6644
case event.IsStart(ev):
6745
if span := GetSpan(ctx); span != nil {

internal/event/export/printer.go

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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 export
6+
7+
import (
8+
"io"
9+
10+
"golang.org/x/tools/internal/event/core"
11+
"golang.org/x/tools/internal/event/keys"
12+
"golang.org/x/tools/internal/event/label"
13+
)
14+
15+
type Printer struct {
16+
buffer [128]byte
17+
}
18+
19+
func (p *Printer) WriteEvent(w io.Writer, ev core.Event, lm label.Map) {
20+
buf := p.buffer[:0]
21+
if !ev.At().IsZero() {
22+
w.Write(ev.At().AppendFormat(buf, "2006/01/02 15:04:05 "))
23+
}
24+
msg := keys.Msg.Get(lm)
25+
io.WriteString(w, msg)
26+
if err := keys.Err.Get(lm); err != nil {
27+
if msg != "" {
28+
io.WriteString(w, ": ")
29+
}
30+
io.WriteString(w, err.Error())
31+
}
32+
for index := 0; ev.Valid(index); index++ {
33+
l := ev.Label(index)
34+
if !l.Valid() || l.Key() == keys.Msg || l.Key() == keys.Err {
35+
continue
36+
}
37+
io.WriteString(w, "\n\t")
38+
io.WriteString(w, l.Key().Name())
39+
io.WriteString(w, "=")
40+
l.Key().Format(w, buf, l)
41+
}
42+
io.WriteString(w, "\n")
43+
}

internal/lsp/cache/analysis.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ func (s *snapshot) actionHandle(ctx context.Context, id packageID, a *analysis.A
147147
})
148148
act.handle = h
149149

150-
s.addActionHandle(act)
150+
act = s.addActionHandle(act)
151151
return act, nil
152152
}
153153

internal/lsp/cache/check.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,11 @@ func (s *snapshot) buildPackageHandle(ctx context.Context, id packageID, mode so
9797
})
9898
ph.handle = h
9999

100-
// Cache the PackageHandle in the snapshot.
101-
s.addPackage(ph)
100+
// Cache the PackageHandle in the snapshot. If a package handle has already
101+
// been cached, addPackage will return the cached value. This is fine,
102+
// since the original package handle above will have no references and be
103+
// garbage collected.
104+
ph = s.addPackageHandle(ph)
102105

103106
return ph, nil
104107
}

internal/lsp/cache/session.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,7 @@ func (s *Session) updateOverlays(ctx context.Context, changes []source.FileModif
419419
return overlays, nil
420420
}
421421

422+
// GetFile implements the source.FileSystem interface.
422423
func (s *Session) GetFile(uri span.URI) source.FileHandle {
423424
if overlay := s.readOverlay(uri); overlay != nil {
424425
return overlay
@@ -436,3 +437,16 @@ func (s *Session) readOverlay(uri span.URI) *overlay {
436437
}
437438
return nil
438439
}
440+
441+
func (s *Session) UnsavedFiles() []span.URI {
442+
s.overlayMu.Lock()
443+
defer s.overlayMu.Unlock()
444+
445+
var unsaved []span.URI
446+
for uri, overlay := range s.overlays {
447+
if !overlay.saved {
448+
unsaved = append(unsaved, uri)
449+
}
450+
}
451+
return unsaved
452+
}

internal/lsp/cache/snapshot.go

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -291,17 +291,17 @@ func (s *snapshot) rebuildImportGraph() {
291291
}
292292
}
293293

294-
func (s *snapshot) addPackage(ph *packageHandle) {
294+
func (s *snapshot) addPackageHandle(ph *packageHandle) *packageHandle {
295295
s.mu.Lock()
296296
defer s.mu.Unlock()
297297

298-
// TODO: We should make sure not to compute duplicate packageHandles,
299-
// and instead panic here. This will be hard to do because we may encounter
300-
// the same package multiple times in the dependency tree.
301-
if _, ok := s.packages[ph.packageKey()]; ok {
302-
return
298+
// If the package handle has already been cached,
299+
// return the cached handle instead of overriding it.
300+
if ph, ok := s.packages[ph.packageKey()]; ok {
301+
return ph
303302
}
304303
s.packages[ph.packageKey()] = ph
304+
return ph
305305
}
306306

307307
func (s *snapshot) workspacePackageIDs() (ids []packageID) {
@@ -427,7 +427,7 @@ func (s *snapshot) getActionHandle(id packageID, m source.ParseMode, a *analysis
427427
return s.actions[key]
428428
}
429429

430-
func (s *snapshot) addActionHandle(ah *actionHandle) {
430+
func (s *snapshot) addActionHandle(ah *actionHandle) *actionHandle {
431431
s.mu.Lock()
432432
defer s.mu.Unlock()
433433

@@ -438,10 +438,11 @@ func (s *snapshot) addActionHandle(ah *actionHandle) {
438438
mode: ah.pkg.mode,
439439
},
440440
}
441-
if _, ok := s.actions[key]; ok {
442-
return
441+
if ah, ok := s.actions[key]; ok {
442+
return ah
443443
}
444444
s.actions[key] = ah
445+
return ah
445446
}
446447

447448
func (s *snapshot) getIDsForURI(uri span.URI) []packageID {

internal/lsp/cmd/cmd.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -241,10 +241,10 @@ func (app *Application) connectRemote(ctx context.Context, remote string) (*conn
241241
return connection, connection.initialize(ctx, app.options)
242242
}
243243

244-
var matcherString = map[source.Matcher]string{
245-
source.Fuzzy: "fuzzy",
246-
source.CaseSensitive: "caseSensitive",
247-
source.CaseInsensitive: "default",
244+
var matcherString = map[source.SymbolMatcher]string{
245+
source.SymbolFuzzy: "fuzzy",
246+
source.SymbolCaseSensitive: "caseSensitive",
247+
source.SymbolCaseInsensitive: "default",
248248
}
249249

250250
func (c *connection) initialize(ctx context.Context, options func(*source.Options)) error {
@@ -262,7 +262,7 @@ func (c *connection) initialize(ctx context.Context, options func(*source.Option
262262
}
263263
params.Capabilities.TextDocument.DocumentSymbol.HierarchicalDocumentSymbolSupport = opts.HierarchicalDocumentSymbolSupport
264264
params.InitializationOptions = map[string]interface{}{
265-
"matcher": matcherString[opts.Matcher],
265+
"symbolMatcher": matcherString[opts.SymbolMatcher],
266266
}
267267
if _, err := c.Server.Initialize(ctx, params); err != nil {
268268
return err

0 commit comments

Comments
 (0)