Skip to content

Commit

Permalink
deps: update x/tools and gopls to acefd226
Browse files Browse the repository at this point in the history
* internal/lsp/source: move completion to its own package acefd226
* internal/lsp/source: support some fzf-like tokens in symbol matching ea3a2cdb
* internal/lsp/analysis: update fillreturns title 242af255
* internal/lsp/source: fix go1.12 build (again) 9786fa37
* internal/lsp: add support for RelatedInformation in diagnostics 39188db5
* internal/lsp: support for package completion in all files 93eecc35
* gopls/internal/regtest: use gopls hooks and add a test for staticcheck af4cc2cd
* gopls/integration/regtest: move regtests to the gopls module e2cc5a11
* present: fix newline parsing for go present 76a6aac6
* playground/socket: remove the os cleanup from start method of process 2364a5e8
* internal/lsp: reproduce and fix golang/go#41057 cf788077
* internal/lsp/cache: use the right snapshot in ModUpgrade 36b1a880
* internal/lsp: clean up some of the mod code lens code 5d67d6c6
* go/ssa: implement missing testing.testDeps SetPanicOnExit0 method 5b9ef244
  • Loading branch information
myitcv committed Sep 8, 2020
1 parent bab59a6 commit 2157eb7
Show file tree
Hide file tree
Showing 50 changed files with 1,218 additions and 2,316 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ outer:
End: typeErrEndPos,
Message: typeErr.Msg,
SuggestedFixes: []analysis.SuggestedFix{{
Message: "Fill with empty values",
Message: "Fill in return values",
TextEdits: []analysis.TextEdit{{
Pos: ret.Pos(),
End: ret.End(),
Expand Down
47 changes: 45 additions & 2 deletions cmd/govim/internal/golang_org_x_tools/lsp/cache/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -405,22 +405,65 @@ func typeCheck(ctx context.Context, snapshot *snapshot, m *metadata, mode source

// We don't care about a package's errors unless we have parsed it in full.
if mode == source.ParseFull {
expandErrors(rawErrors)
for _, e := range rawErrors {
srcErr, err := sourceError(ctx, snapshot, pkg, e)
if err != nil {
event.Error(ctx, "unable to compute error positions", err, tag.Package.Of(pkg.ID()))
continue
}
pkg.errors = append(pkg.errors, srcErr)
if err, ok := e.(types.Error); ok {
pkg.typeErrors = append(pkg.typeErrors, err)
if err, ok := e.(extendedError); ok {
pkg.typeErrors = append(pkg.typeErrors, err.primary)
}
}
}

return pkg, nil
}

type extendedError struct {
primary types.Error
secondaries []types.Error
}

func (e extendedError) Error() string {
return e.primary.Error()
}

// expandErrors duplicates "secondary" errors by mapping them to their main
// error. Some errors returned by the type checker are followed by secondary
// errors which give more information about the error. These are errors in
// their own right, and they are marked by starting with \t. For instance, when
// there is a multiply-defined function, the secondary error points back to the
// definition first noticed.
//
// This code associates the secondary error with its primary error, which can
// then be used as RelatedInformation when the error becomes a diagnostic.
func expandErrors(errs []error) []error {
for i := 0; i < len(errs); {
e, ok := errs[i].(types.Error)
if !ok {
i++
continue
}
enew := extendedError{
primary: e,
}
j := i + 1
for ; j < len(errs); j++ {
spl, ok := errs[j].(types.Error)
if !ok || len(spl.Msg) == 0 || spl.Msg[0] != '\t' {
break
}
enew.secondaries = append(enew.secondaries, spl)
}
errs[i] = enew
i = j
}
return errs
}

// resolveImportPath resolves an import path in pkg to a package from deps.
// It should produce the same results as resolveImportPath:
// https://cs.opensource.google/go/go/+/master:src/cmd/go/internal/load/pkg.go;drc=641918ee09cb44d282a30ee8b66f99a0b63eaef9;l=990.
Expand Down
29 changes: 28 additions & 1 deletion cmd/govim/internal/golang_org_x_tools/lsp/cache/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,32 @@ func sourceError(ctx context.Context, snapshot *snapshot, pkg *pkg, e interface{
if err != nil {
return nil, err
}

case extendedError:
perr := e.primary
msg = perr.Msg
kind = source.TypeError
if !perr.Pos.IsValid() {
return nil, fmt.Errorf("invalid position for type error %v", e)
}
spn, err = typeErrorRange(snapshot, fset, pkg, perr.Pos)
if err != nil {
return nil, err
}
for _, s := range e.secondaries {
var x source.RelatedInformation
x.Message = s.Msg
xspn, err := typeErrorRange(snapshot, fset, pkg, s.Pos)
if err != nil {
return nil, fmt.Errorf("invalid position for type error %v", s)
}
x.URI = xspn.URI()
rng, err := spanToRange(snapshot, pkg, xspn)
if err != nil {
return nil, err
}
x.Range = rng
related = append(related, x)
}
case *analysis.Diagnostic:
spn, err = span.NewRange(fset, e.Pos, e.End).Span()
if err != nil {
Expand All @@ -111,6 +136,8 @@ func sourceError(ctx context.Context, snapshot *snapshot, pkg *pkg, e interface{
if err != nil {
return nil, err
}
default:
panic(fmt.Sprintf("%T unexpected", e))
}
rng, err := spanToRange(snapshot, pkg, spn)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion cmd/govim/internal/golang_org_x_tools/lsp/cache/mod.go
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ func (s *snapshot) ModUpgrade(ctx context.Context, fh source.FileHandle) (map[st

snapshot := arg.(*snapshot)

pm, err := s.ParseMod(ctx, fh)
pm, err := snapshot.ParseMod(ctx, fh)
if err != nil {
return &modUpgradeData{err: err}
}
Expand Down
27 changes: 23 additions & 4 deletions cmd/govim/internal/golang_org_x_tools/lsp/code_lens.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ package lsp

import (
"context"
"fmt"

"github.com/govim/govim/cmd/govim/internal/golang_org_x_tools/event"
"github.com/govim/govim/cmd/govim/internal/golang_org_x_tools/lsp/mod"
"github.com/govim/govim/cmd/govim/internal/golang_org_x_tools/lsp/protocol"
"github.com/govim/govim/cmd/govim/internal/golang_org_x_tools/lsp/source"
Expand All @@ -18,12 +20,29 @@ func (s *Server) codeLens(ctx context.Context, params *protocol.CodeLensParams)
if !ok {
return nil, err
}
var lensFuncs map[string]source.LensFunc
switch fh.Kind() {
case source.Mod:
return mod.CodeLens(ctx, snapshot, fh.URI())
lensFuncs = mod.LensFuncs()
case source.Go:
return source.CodeLens(ctx, snapshot, fh)
lensFuncs = source.LensFuncs()
default:
// Unsupported file kind for a code lens.
return nil, nil
}
// Unsupported file kind for a code action.
return nil, nil
var result []protocol.CodeLens
for lens, lf := range lensFuncs {
if !snapshot.View().Options().EnabledCodeLens[lens] {
continue
}
added, err := lf(ctx, snapshot, fh)
// Code lens is called on every keystroke, so we should just operate in
// a best-effort mode, ignoring errors.
if err != nil {
event.Error(ctx, fmt.Sprintf("code lens %s failed", lens), err)
continue
}
result = append(result, added...)
}
return result, nil
}
65 changes: 51 additions & 14 deletions cmd/govim/internal/golang_org_x_tools/lsp/completion.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import (
"github.com/govim/govim/cmd/govim/internal/golang_org_x_tools/lsp/debug/tag"
"github.com/govim/govim/cmd/govim/internal/golang_org_x_tools/lsp/protocol"
"github.com/govim/govim/cmd/govim/internal/golang_org_x_tools/lsp/source"
"github.com/govim/govim/cmd/govim/internal/golang_org_x_tools/lsp/source/completion"
"github.com/govim/govim/cmd/govim/internal/golang_org_x_tools/span"
)

func (s *Server) completion(ctx context.Context, params *protocol.CompletionParams) (*protocol.CompletionList, error) {
Expand All @@ -21,11 +23,11 @@ func (s *Server) completion(ctx context.Context, params *protocol.CompletionPara
if !ok {
return nil, err
}
var candidates []source.CompletionItem
var surrounding *source.Selection
var candidates []completion.CompletionItem
var surrounding *completion.Selection
switch fh.Kind() {
case source.Go:
candidates, surrounding, err = source.Completion(ctx, snapshot, fh, params.Position, params.Context.TriggerCharacter)
candidates, surrounding, err = completion.Completion(ctx, snapshot, fh, params.Position, params.Context.TriggerCharacter)
case source.Mod:
candidates, surrounding = nil, nil
}
Expand All @@ -42,15 +44,50 @@ func (s *Server) completion(ctx context.Context, params *protocol.CompletionPara
if err != nil {
return nil, err
}
// Span treats an end of file as the beginning of the next line, which for
// a final line ending without a newline is incorrect and leads to
// completions being ignored. We adjust the ending in case ange end is on a
// different line here.
// This should be removed after the resolution of golang/go#41029
if rng.Start.Line != rng.End.Line {
rng.End = protocol.Position{
Character: rng.Start.Character + float64(len(surrounding.Content())),
Line: rng.Start.Line,

// internal/span treats end of file as the beginning of the next line, even
// when it's not newline-terminated. We correct for that behaviour here if
// end of file is not newline-terminated. See golang/go#41029.
src, err := fh.Read()
if err != nil {
return nil, err
}

// Get the actual number of lines in source.
numLines := len(strings.Split(string(src), "\n"))

tok := snapshot.FileSet().File(surrounding.Start())
endOfFile := tok.Pos(tok.Size())

// For newline-terminated files, the line count reported by go/token should
// be lower than the actual number of lines we see when splitting by \n. If
// they're the same, the file isn't newline-terminated.
if numLines == tok.LineCount() && tok.Size() != 0 {
// Get span for character before end of file to bypass span's treatment of end
// of file. We correct for this later.
spn, err := span.NewRange(snapshot.FileSet(), endOfFile-1, endOfFile-1).Span()
if err != nil {
return nil, err
}
m := &protocol.ColumnMapper{
URI: fh.URI(),
Converter: span.NewContentConverter(fh.URI().Filename(), []byte(src)),
Content: []byte(src),
}
eofRng, err := m.Range(spn)
if err != nil {
return nil, err
}
eofPosition := protocol.Position{
Line: eofRng.Start.Line,
// Correct for using endOfFile - 1 earlier.
Character: eofRng.Start.Character + 1,
}
if surrounding.Start() == endOfFile {
rng.Start = eofPosition
}
if surrounding.End() == endOfFile {
rng.End = eofPosition
}
}

Expand All @@ -67,7 +104,7 @@ func (s *Server) completion(ctx context.Context, params *protocol.CompletionPara
}, nil
}

func toProtocolCompletionItems(candidates []source.CompletionItem, rng protocol.Range, options source.Options) []protocol.CompletionItem {
func toProtocolCompletionItems(candidates []completion.CompletionItem, rng protocol.Range, options source.Options) []protocol.CompletionItem {
var (
items = make([]protocol.CompletionItem, 0, len(candidates))
numDeepCompletionsSeen int
Expand All @@ -79,7 +116,7 @@ func toProtocolCompletionItems(candidates []source.CompletionItem, rng protocol.
if !options.DeepCompletion {
continue
}
if numDeepCompletionsSeen >= source.MaxDeepCompletions {
if numDeepCompletionsSeen >= completion.MaxDeepCompletions {
continue
}
numDeepCompletionsSeen++
Expand Down
5 changes: 3 additions & 2 deletions cmd/govim/internal/golang_org_x_tools/lsp/diagnostics.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ If you believe this is a mistake, please file an issue: https://github.com/golan
return
}

// Add all reports to the global map, checking for duplciates.
// Add all reports to the global map, checking for duplicates.
reportsMu.Lock()
for id, diags := range pkgReports {
key := idWithAnalysis{
Expand Down Expand Up @@ -307,7 +307,8 @@ func toProtocolDiagnostics(diagnostics []*source.Diagnostic) []protocol.Diagnost
})
}
reports = append(reports, protocol.Diagnostic{
Message: strings.TrimSpace(diag.Message), // go list returns errors prefixed by newline
// diag.Message might start with \n or \t
Message: strings.TrimSpace(diag.Message),
Range: diag.Range,
Severity: diag.Severity,
Source: diag.Source,
Expand Down
8 changes: 6 additions & 2 deletions cmd/govim/internal/golang_org_x_tools/lsp/fake/editor.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ type EditorConfig struct {
// EditorRootPath specifies the root path of the workspace folder used when
// initializing gopls in the sandbox. If empty, the Workdir is used.
EditorRootPath string

// EnableStaticcheck enables staticcheck analyzers.
EnableStaticcheck bool
}

// NewEditor Creates a new Editor.
Expand Down Expand Up @@ -180,14 +183,15 @@ func (e *Editor) configuration() map[string]interface{} {
if e.Config.CodeLens != nil {
config["codelens"] = e.Config.CodeLens
}

if e.Config.SymbolMatcher != nil {
config["symbolMatcher"] = *e.Config.SymbolMatcher
}

if e.Config.SymbolStyle != nil {
config["symbolStyle"] = *e.Config.SymbolStyle
}
if e.Config.EnableStaticcheck {
config["staticcheck"] = true
}

return config
}
Expand Down
Loading

0 comments on commit 2157eb7

Please sign in to comment.