Skip to content

Commit

Permalink
deps: update x/tools and gopls to 65435275
Browse files Browse the repository at this point in the history
Note that this change also includes two other updates:
 - updates error message in test "scenario_modreadonly/config_set_env_goflags_mod_readonly" due to CL 274119.
 - gopls.go now explicitly sets "allowModfileModifications" to true, see CL 268597, 274532 & 275442.

* gopls/internal/regtest: eliminate unneeded executions and reduce delay 65435275
* internal/lsp: move the background context onto the snapshot ab685790
* internal/lsp/source: allow users to set new options for network access 9a0e0bbb
* internal/lsp: fix handling of //-style comments in CRLF files 73cf035b
* internal/lsp/source: default experimentalDiagnosticsDelay to 250ms 6607ba8a
* internal/lsp: force LANG setting while difftest a679dec0
* internal/lsp: separate the environment's value of GO111MODULE out 54578894
* internal/lsp: update diagnostic snapshotID even if not published 214da9f3
* tools, gopls: add pkg.go.dev badges to READMEs 39497347
* internal/lsp: move generated file check out of didModifyFiles fe8bd3ca
* go/analysis/passes/fieldalignment: suggest fix for multi-named fields 090fee60
* gopls/doc: generate JSON too, store as composite literal a1a1cbea
* internal/lsp/source: allow opt-out from -mod=readonly, GOPROXY=off fa6651ed
* internal/lsp: add go get quick fix on failing imports bd5d160b
* internal/lsp: disable network access for some go commands 43adb69d
* internal/lsp: set -mod=readonly in most contexts 9bc6a978
* internal/lsp: add READMEs that describe tests, how to run tests bdde1628
* gopls/doc: fix link to lsp-go.el 8b44681d
* internal/lsp: don't reload invalid build configurations unconditionally 2ecf2a5d
* gopls/doc: add fieldalignment to analyzers.md bef1c476
* cmd/toolstash: drop 387, use softfloat instead 7534955a
* gopls/internal/regtest: TestRenamePackage passes with go 1.16 92771a23
* internal/lsp: improve errors in multi-module workspaces (GO111MODULE=on) 7beb506c
* internal/lsp: track all go.mod changes no matter the workspace mode a1b87a1c
* internal/lsp/cache: include missing dependencies in mod tidy key 5fbf2908
* internal/lsp/cache: fix race on snapshot.workspaceDirHandle 182cd11f
* internal/lsp: limit all findModules calls to search 1 million files ae829c33
* internal/lsp: run analyses on changed files before full diagnostics ac6f37ff
* internal/lsp: use mode (GOPATH/modules) oriented error messages fd09bd90
* internal/lsp: check the value of GO111MODULE before collecting modules f0400ba2
* Change require 'nvim_lsp' to 'lspconfig' in vim.md 02d27ecf
* internal/lsp: disable support for symlinks pending decision 1937afe4
* internal/lsp: only show gc_details diagnostics on saved buffers dcde6b0e
* internal/lsp/lsprpc: prefer XDG_RUNTIME_DIR for the daemon socket 74704816
* internal/lsp: update modifications to directories at the LSP level 7e522c86
* internal/lsp: restore snapshot ID guard for published diagnostics bd313628
* Revert "internal/lsp/source: simplify workspace symbol package collection" bf23c547
* internal/lsp/source: simplify workspace symbol package collection 852eb642
* go/analysis: avoid panic in ifaceassert fd5f2936
* gopls, internal/lsp: support fillstruct for partially-filled structs 0e8b1ee1
* internal/lsp: offer type converted completion candidates ca1c1492
* Revert "internal/lsp: use mode (GOPATH/modules) oriented error messages" c5a73c30
* internal/lsp: use mode (GOPATH/modules) oriented error messages ccae4fb3
* internal/lsp: fix misspelling in Codelens option e7a54586
* internal/lsp: move options to correct sections b5590dee
* internal/lsp: explicitly watch all known directories 2e53cd67
* go/analysis/passes/fieldalignment: add fieldalignment analyser 299f270d
* internal/lsp: extract filenames from go command errors d890b968
* internal/lsp: switch the default symbol style to dynamic 208275ba
* internal/lsp: rewrite the workspace symbol marker tests 325b08a5
* internal/lsp/tests: factor normalization logic out of cmd tests ed677e9d
* internal/lsp: track diagnostics by reporting source a3098589
* internal/lsp: revise some semantic token details a9663296
* internal/lsp: fix some incorrect spelling 2c860bdd
* gopls/internal/regtest: skip regtests for openbsd-amd64-64 on TryBots 911501bf
* internal/lsp: fix title for vendor suggested fix 4aa1a224
* internal/lsp: only show command errors once a83918f9
* gopls/internal/regtest: convert circular import tests to regtests b5535b15
* internal/lsp: use pointers to source.Error, and not to ErrorList db3e1ec2
* internal/lsp: refactor code action go command calls a9763abb
* internal/lsp: fix godef for embedded type aliases 5bad4594
* internal/lsp: nest the workspace root if there is only one module 45586ddb
* internal/lsp: fix go.mod parse error parsing to show diagnostics 780cb80b
* internal/lsp: remove workspace packages as needed 20be4ac4
* internal/lsp/cache: only invalidate metadata for go.mod files on save 6d151481
* internal/lsp: pass a parsed module to go mod tidy a7380940
* internal/lsp/fake: hold the mutex for all of SaveBufferWithoutActions c0d5e891
* gopls/internal/regtest: handle flake in TestCRLF be796f87
* internal/lsp/source: set experimentalPackageCacheKey to true by default 0557df36
* Handle BareInits option in ssa.BuilderMode 4783bc9b
* internal/lsp: handle deletion of a directory on disk 25dc3e1c
* internal/lsp/mod: speed up and simplify go.mod code lenses 4d9c4f8a
* internal/lsp/cache: fix a staticcheck warning by handling error 1727ee11
* internal/lsp: support unimported completions in multi-module mode 6ed8ff9a
  • Loading branch information
leitzler committed Dec 4, 2020
1 parent a0d49d2 commit 4602fc0
Show file tree
Hide file tree
Showing 61 changed files with 2,915 additions and 2,157 deletions.
7 changes: 7 additions & 0 deletions cmd/govim/gopls.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,13 @@ func (g *govimplugin) startGopls() error {
if conf.SymbolStyle != nil {
goplsConfig[goplsSymbolStyle] = *conf.SymbolStyle
}

// TODO: This option was introduced as a way to opt-out from the changes introduced in CL 268597.
// According to CL 274532 (that added this opt-out), it is intended to be removed - "Ideally
// we'll be able to remove them in a few months after things stabilize.". We need to handle that
// case before it is removed.
goplsConfig["allowModfileModifications"] = true

initParams.InitializationOptions = goplsConfig

if _, err := g.server.Initialize(context.Background(), initParams); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion cmd/govim/internal/golang_org_x_tools/event/core/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/govim/govim/cmd/govim/internal/golang_org_x_tools/event/label"
)

// Event holds the information about an event of note that ocurred.
// Event holds the information about an event of note that occurred.
type Event struct {
at time.Time

Expand Down
7 changes: 7 additions & 0 deletions cmd/govim/internal/golang_org_x_tools/lsp/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# lsp

internal/lsp provides much of the Language Server Protocol (lsp) implementation
for gopls.

Documentation for users and contributors can be found in the
[`gopls/doc`](../../gopls/doc) directory.
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,6 @@ func run(pass *analysis.Pass) (interface{}, error) {
}
expr := n.(*ast.CompositeLit)

// TODO: Handle partially-filled structs as well.
if len(expr.Elts) != 0 {
return
}

var file *ast.File
for _, f := range pass.Files {
if f.Pos() <= expr.Pos() && expr.Pos() <= f.End() {
Expand Down Expand Up @@ -90,10 +85,10 @@ func run(pass *analysis.Pass) (interface{}, error) {
if fieldCount == 0 || fieldCount == len(expr.Elts) {
return
}

var fillable bool
for i := 0; i < fieldCount; i++ {
field := obj.Field(i)

// Ignore fields that are not accessible in the current package.
if field.Pkg() != nil && field.Pkg() != pass.Pkg && !field.Exported() {
continue
Expand Down Expand Up @@ -137,6 +132,7 @@ func SuggestedFix(fset *token.FileSet, rng span.Range, content []byte, file *ast
break
}
}

if info == nil {
return nil, fmt.Errorf("nil types.Info")
}
Expand All @@ -161,6 +157,17 @@ func SuggestedFix(fset *token.FileSet, rng span.Range, content []byte, file *ast
}
fieldCount := obj.NumFields()

// Check which types have already been filled in. (we only want to fill in
// the unfilled types, or else we'll blat user-supplied details)
prefilledTypes := map[string]ast.Expr{}
for _, e := range expr.Elts {
if kv, ok := e.(*ast.KeyValueExpr); ok {
if key, ok := kv.Key.(*ast.Ident); ok {
prefilledTypes[key.Name] = kv.Value
}
}
}

// Use a new fileset to build up a token.File for the new composite
// literal. We need one line for foo{, one line for }, and one line for
// each field we're going to set. format.Node only cares about line
Expand All @@ -186,21 +193,6 @@ func SuggestedFix(fset *token.FileSet, rng span.Range, content []byte, file *ast
if fieldTyp == nil {
continue
}
idents, ok := matches[fieldTyp]
if !ok {
return nil, fmt.Errorf("invalid struct field type: %v", fieldTyp)
}

// Find the identifer whose name is most similar to the name of the field's key.
// If we do not find any identifer that matches the pattern, generate a new value.
// NOTE: We currently match on the name of the field key rather than the field type.
value := analysisinternal.FindBestMatch(obj.Field(i).Name(), idents)
if value == nil {
value = populateValue(fset, file, pkg, fieldTyp)
}
if value == nil {
return nil, nil
}

tok.AddLine(line - 1) // add 1 byte per line
if line > tok.LineCount() {
Expand All @@ -214,7 +206,27 @@ func SuggestedFix(fset *token.FileSet, rng span.Range, content []byte, file *ast
Name: obj.Field(i).Name(),
},
Colon: pos,
Value: value,
}
if expr, ok := prefilledTypes[obj.Field(i).Name()]; ok {
kv.Value = expr
} else {
idents, ok := matches[fieldTyp]
if !ok {
return nil, fmt.Errorf("invalid struct field type: %v", fieldTyp)
}

// Find the identifer whose name is most similar to the name of the field's key.
// If we do not find any identifer that matches the pattern, generate a new value.
// NOTE: We currently match on the name of the field key rather than the field type.
value := analysisinternal.FindBestMatch(obj.Field(i).Name(), idents)
if value == nil {
value = populateValue(fset, file, pkg, fieldTyp)
}
if value == nil {
return nil, nil
}

kv.Value = value
}
elts = append(elts, kv)
line++
Expand Down Expand Up @@ -251,33 +263,53 @@ func SuggestedFix(fset *token.FileSet, rng span.Range, content []byte, file *ast
index := bytes.Index(firstLine, trimmed)
whitespace := firstLine[:index]

var newExpr bytes.Buffer
if err := format.Node(&newExpr, fakeFset, cl); err != nil {
return nil, fmt.Errorf("failed to format %s: %v", cl.Type, err)
// First pass through the formatter: turn the expr into a string.
var formatBuf bytes.Buffer
if err := format.Node(&formatBuf, fakeFset, cl); err != nil {
return nil, fmt.Errorf("failed to run first format on:\n%s\ngot err: %v", cl.Type, err)
}
split = bytes.Split(newExpr.Bytes(), []byte("\n"))
newText := bytes.NewBuffer(nil)
for i, s := range split {
// Don't add the extra indentation to the first line.
if i != 0 {
newText.Write(whitespace)
}
newText.Write(s)
if i < len(split)-1 {
newText.WriteByte('\n')
sug := indent(formatBuf.Bytes(), whitespace)

if len(prefilledTypes) > 0 {
// Attempt a second pass through the formatter to line up columns.
sourced, err := format.Source(sug)
if err == nil {
sug = indent(sourced, whitespace)
}
}

return &analysis.SuggestedFix{
TextEdits: []analysis.TextEdit{
{
Pos: expr.Pos(),
End: expr.End(),
NewText: newText.Bytes(),
NewText: sug,
},
},
}, nil
}

// indent works line by line through str, indenting (prefixing) each line with
// ind.
func indent(str, ind []byte) []byte {
split := bytes.Split(str, []byte("\n"))
newText := bytes.NewBuffer(nil)
for i, s := range split {
if len(s) == 0 {
continue
}
// Don't add the extra indentation to the first line.
if i != 0 {
newText.Write(ind)
}
newText.Write(s)
if i < len(split)-1 {
newText.WriteByte('\n')
}
}
return newText.Bytes()
}

// populateValue constructs an expression to fill the value of a struct field.
//
// When the type of a struct field is a basic literal or interface, we return
Expand Down
4 changes: 4 additions & 0 deletions cmd/govim/internal/golang_org_x_tools/lsp/cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ type fileHandle struct {
err error
}

func (h *fileHandle) Saved() bool {
return true
}

func (c *Cache) GetFile(ctx context.Context, uri span.URI) (source.FileHandle, error) {
return c.getFile(ctx, uri)
}
Expand Down
21 changes: 20 additions & 1 deletion cmd/govim/internal/golang_org_x_tools/lsp/cache/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"go/ast"
"go/types"
"path"
"path/filepath"
"sort"
"strings"
"sync"
Expand Down Expand Up @@ -407,7 +408,7 @@ func typeCheck(ctx context.Context, snapshot *snapshot, m *metadata, mode source
}
dep := resolveImportPath(pkgPath, pkg, deps)
if dep == nil {
return nil, errors.Errorf("no package for import %s", pkgPath)
return nil, snapshot.missingPkgError(pkgPath)
}
if !isValidImport(m.pkgPath, dep.m.pkgPath) {
return nil, errors.Errorf("invalid use of internal package %s", pkgPath)
Expand Down Expand Up @@ -453,6 +454,24 @@ func typeCheck(ctx context.Context, snapshot *snapshot, m *metadata, mode source
return pkg, nil
}

// missingPkgError returns an error message for a missing package that varies
// based on the user's workspace mode.
func (s *snapshot) missingPkgError(pkgPath string) error {
if s.workspaceMode()&moduleMode != 0 {
return fmt.Errorf("no required module provides package %q", pkgPath)
}
gorootSrcPkg := filepath.FromSlash(filepath.Join(s.view.goroot, "src", pkgPath))

var b strings.Builder
b.WriteString(fmt.Sprintf("cannot find package %q in any of \n\t%s (from $GOROOT)", pkgPath, gorootSrcPkg))

for _, gopath := range strings.Split(s.view.gopath, ":") {
gopathSrcPkg := filepath.FromSlash(filepath.Join(gopath, "src", pkgPath))
b.WriteString(fmt.Sprintf("\n\t%s (from $GOPATH)", gopathSrcPkg))
}
return errors.New(b.String())
}

type extendedError struct {
primary types.Error
secondaries []types.Error
Expand Down
4 changes: 2 additions & 2 deletions cmd/govim/internal/golang_org_x_tools/lsp/cache/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ func sourceError(ctx context.Context, snapshot *snapshot, pkg *pkg, e interface{
msg = e.Message
kind = source.Analysis
category = e.Category
fixes, err = suggestedFixes(snapshot, pkg, e)
fixes, err = suggestedAnalysisFixes(snapshot, pkg, e)
if err != nil {
return nil, err
}
Expand All @@ -154,7 +154,7 @@ func sourceError(ctx context.Context, snapshot *snapshot, pkg *pkg, e interface{
}, nil
}

func suggestedFixes(snapshot *snapshot, pkg *pkg, diag *analysis.Diagnostic) ([]source.SuggestedFix, error) {
func suggestedAnalysisFixes(snapshot *snapshot, pkg *pkg, diag *analysis.Diagnostic) ([]source.SuggestedFix, error) {
var fixes []source.SuggestedFix
for _, fix := range diag.SuggestedFixes {
edits := make(map[span.URI][]protocol.TextEdit)
Expand Down
Loading

0 comments on commit 4602fc0

Please sign in to comment.