mirror of
https://github.com/golang/go
synced 2024-11-18 14:54:40 -07:00
internal/lsp: convert all logging calls to the context version
Change-Id: I20e3acee4272f05a9f31a7bb4219fc2fe751e6b3 Reviewed-on: https://go-review.googlesource.com/c/tools/+/185988 Run-TryBot: Ian Cottrell <iancottrell@google.com> Reviewed-by: Rebecca Stambler <rstambler@golang.org>
This commit is contained in:
parent
c8ecc7589e
commit
1b7e409d2c
13
internal/lsp/cache/gofile.go
vendored
13
internal/lsp/cache/gofile.go
vendored
@ -11,6 +11,7 @@ import (
|
||||
"sync"
|
||||
|
||||
"golang.org/x/tools/internal/lsp/source"
|
||||
"golang.org/x/tools/internal/lsp/xlog"
|
||||
"golang.org/x/tools/internal/span"
|
||||
)
|
||||
|
||||
@ -52,7 +53,7 @@ func (f *goFile) GetToken(ctx context.Context) *token.File {
|
||||
|
||||
if f.isDirty() || f.astIsTrimmed() {
|
||||
if _, err := f.view.loadParseTypecheck(ctx, f); err != nil {
|
||||
f.View().Session().Logger().Errorf(ctx, "unable to check package for %s: %v", f.URI(), err)
|
||||
xlog.Errorf(ctx, "unable to check package for %s: %v", f.URI(), err)
|
||||
return nil
|
||||
}
|
||||
}
|
||||
@ -71,7 +72,7 @@ func (f *goFile) GetAnyAST(ctx context.Context) *ast.File {
|
||||
|
||||
if f.isDirty() {
|
||||
if _, err := f.view.loadParseTypecheck(ctx, f); err != nil {
|
||||
f.View().Session().Logger().Errorf(ctx, "unable to check package for %s: %v", f.URI(), err)
|
||||
xlog.Errorf(ctx, "unable to check package for %s: %v", f.URI(), err)
|
||||
return nil
|
||||
}
|
||||
}
|
||||
@ -91,7 +92,7 @@ func (f *goFile) GetAST(ctx context.Context) *ast.File {
|
||||
|
||||
if f.isDirty() || f.astIsTrimmed() {
|
||||
if _, err := f.view.loadParseTypecheck(ctx, f); err != nil {
|
||||
f.View().Session().Logger().Errorf(ctx, "unable to check package for %s: %v", f.URI(), err)
|
||||
xlog.Errorf(ctx, "unable to check package for %s: %v", f.URI(), err)
|
||||
return nil
|
||||
}
|
||||
}
|
||||
@ -110,7 +111,7 @@ func (f *goFile) GetPackages(ctx context.Context) []source.Package {
|
||||
|
||||
if f.isDirty() || f.astIsTrimmed() {
|
||||
if errs, err := f.view.loadParseTypecheck(ctx, f); err != nil {
|
||||
f.View().Session().Logger().Errorf(ctx, "unable to check package for %s: %v", f.URI(), err)
|
||||
xlog.Errorf(ctx, "unable to check package for %s: %v", f.URI(), err)
|
||||
|
||||
// Create diagnostics for errors if we are able to.
|
||||
if len(errs) > 0 {
|
||||
@ -151,12 +152,12 @@ func (f *goFile) GetPackage(ctx context.Context) source.Package {
|
||||
func unexpectedAST(ctx context.Context, f *goFile) bool {
|
||||
// If the AST comes back nil, something has gone wrong.
|
||||
if f.ast == nil {
|
||||
f.View().Session().Logger().Errorf(ctx, "expected full AST for %s, returned nil", f.URI())
|
||||
xlog.Errorf(ctx, "expected full AST for %s, returned nil", f.URI())
|
||||
return true
|
||||
}
|
||||
// If the AST comes back trimmed, something has gone wrong.
|
||||
if f.ast.isTrimmed {
|
||||
f.View().Session().Logger().Errorf(ctx, "expected full AST for %s, returned trimmed", f.URI())
|
||||
xlog.Errorf(ctx, "expected full AST for %s, returned trimmed", f.URI())
|
||||
return true
|
||||
}
|
||||
return false
|
||||
|
7
internal/lsp/cache/load.go
vendored
7
internal/lsp/cache/load.go
vendored
@ -10,6 +10,7 @@ import (
|
||||
|
||||
"golang.org/x/tools/go/packages"
|
||||
"golang.org/x/tools/internal/lsp/source"
|
||||
"golang.org/x/tools/internal/lsp/xlog"
|
||||
"golang.org/x/tools/internal/span"
|
||||
)
|
||||
|
||||
@ -224,11 +225,11 @@ func (v *view) link(ctx context.Context, pkgPath packagePath, pkg *packages.Pack
|
||||
for _, filename := range m.files {
|
||||
f, err := v.getFile(ctx, span.FileURI(filename))
|
||||
if err != nil {
|
||||
v.session.log.Errorf(ctx, "no file %s: %v", filename, err)
|
||||
xlog.Errorf(ctx, "no file %s: %v", filename, err)
|
||||
}
|
||||
gof, ok := f.(*goFile)
|
||||
if !ok {
|
||||
v.session.log.Errorf(ctx, "not a Go file: %s", f.URI())
|
||||
xlog.Errorf(ctx, "not a Go file: %s", f.URI())
|
||||
}
|
||||
if gof.meta == nil {
|
||||
gof.meta = make(map[packageID]*metadata)
|
||||
@ -252,7 +253,7 @@ func (v *view) link(ctx context.Context, pkgPath packagePath, pkg *packages.Pack
|
||||
}
|
||||
if _, ok := m.children[packageID(importPkg.ID)]; !ok {
|
||||
if err := v.link(ctx, importPkgPath, importPkg, m, missingImports); err != nil {
|
||||
v.session.log.Errorf(ctx, "error in dependency %s: %v", importPkgPath, err)
|
||||
xlog.Errorf(ctx, "error in dependency %s: %v", importPkgPath, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
6
internal/lsp/cache/session.go
vendored
6
internal/lsp/cache/session.go
vendored
@ -199,12 +199,12 @@ func (s *session) DidOpen(ctx context.Context, uri span.URI, _ source.FileKind,
|
||||
if strings.HasPrefix(string(uri), string(view.Folder())) {
|
||||
f, err := view.GetFile(ctx, uri)
|
||||
if err != nil {
|
||||
s.log.Errorf(ctx, "error getting file for %s", uri)
|
||||
xlog.Errorf(ctx, "error getting file for %s", uri)
|
||||
return
|
||||
}
|
||||
gof, ok := f.(*goFile)
|
||||
if !ok {
|
||||
s.log.Errorf(ctx, "%s is not a Go file", uri)
|
||||
xlog.Errorf(ctx, "%s is not a Go file", uri)
|
||||
return
|
||||
}
|
||||
// Mark file as open.
|
||||
@ -276,7 +276,7 @@ func (s *session) openOverlay(ctx context.Context, uri span.URI, data []byte) {
|
||||
}
|
||||
_, hash, err := s.cache.GetFile(uri).Read(ctx)
|
||||
if err != nil {
|
||||
s.log.Errorf(ctx, "failed to read %s: %v", uri, err)
|
||||
xlog.Errorf(ctx, "failed to read %s: %v", uri, err)
|
||||
return
|
||||
}
|
||||
if hash == s.overlays[uri].hash {
|
||||
|
5
internal/lsp/cache/view.go
vendored
5
internal/lsp/cache/view.go
vendored
@ -17,6 +17,7 @@ import (
|
||||
"golang.org/x/tools/go/packages"
|
||||
"golang.org/x/tools/internal/lsp/debug"
|
||||
"golang.org/x/tools/internal/lsp/source"
|
||||
"golang.org/x/tools/internal/lsp/xlog"
|
||||
"golang.org/x/tools/internal/span"
|
||||
)
|
||||
|
||||
@ -277,12 +278,12 @@ func (v *view) remove(ctx context.Context, id packageID, seen map[packageID]stru
|
||||
for _, filename := range m.files {
|
||||
f, err := v.findFile(span.FileURI(filename))
|
||||
if err != nil {
|
||||
v.session.log.Errorf(ctx, "cannot find file %s: %v", f.URI(), err)
|
||||
xlog.Errorf(ctx, "cannot find file %s: %v", f.URI(), err)
|
||||
continue
|
||||
}
|
||||
gof, ok := f.(*goFile)
|
||||
if !ok {
|
||||
v.session.log.Errorf(ctx, "non-Go file %v", f.URI())
|
||||
xlog.Errorf(ctx, "non-Go file %v", f.URI())
|
||||
continue
|
||||
}
|
||||
gof.mu.Lock()
|
||||
|
@ -11,6 +11,7 @@ import (
|
||||
|
||||
"golang.org/x/tools/internal/lsp/protocol"
|
||||
"golang.org/x/tools/internal/lsp/source"
|
||||
"golang.org/x/tools/internal/lsp/xlog"
|
||||
"golang.org/x/tools/internal/span"
|
||||
)
|
||||
|
||||
@ -57,7 +58,7 @@ func (s *Server) codeAction(ctx context.Context, params *protocol.CodeActionPara
|
||||
if s.wantSuggestedFixes {
|
||||
qf, err := quickFixes(ctx, view, gof)
|
||||
if err != nil {
|
||||
view.Session().Logger().Errorf(ctx, "quick fixes failed for %s: %v", uri, err)
|
||||
xlog.Errorf(ctx, "quick fixes failed for %s: %v", uri, err)
|
||||
}
|
||||
codeActions = append(codeActions, qf...)
|
||||
}
|
||||
|
@ -12,6 +12,7 @@ import (
|
||||
|
||||
"golang.org/x/tools/internal/lsp/protocol"
|
||||
"golang.org/x/tools/internal/lsp/source"
|
||||
"golang.org/x/tools/internal/lsp/xlog"
|
||||
"golang.org/x/tools/internal/span"
|
||||
)
|
||||
|
||||
@ -35,7 +36,7 @@ func (s *Server) completion(ctx context.Context, params *protocol.CompletionPara
|
||||
WantDocumentaton: s.wantCompletionDocumentation,
|
||||
})
|
||||
if err != nil {
|
||||
s.session.Logger().Infof(ctx, "no completions found for %s:%v:%v: %v", uri, int(params.Position.Line), int(params.Position.Character), err)
|
||||
xlog.Infof(ctx, "no completions found for %s:%v:%v: %v", uri, int(params.Position.Line), int(params.Position.Character), err)
|
||||
}
|
||||
return &protocol.CompletionList{
|
||||
IsIncomplete: false,
|
||||
@ -62,11 +63,11 @@ func (s *Server) toProtocolCompletionItems(ctx context.Context, view source.View
|
||||
prefix = strings.ToLower(surrounding.Prefix())
|
||||
spn, err := surrounding.Range.Span()
|
||||
if err != nil {
|
||||
s.session.Logger().Infof(ctx, "failed to get span for surrounding position: %s:%v:%v: %v", m.URI, int(pos.Line), int(pos.Character), err)
|
||||
xlog.Infof(ctx, "failed to get span for surrounding position: %s:%v:%v: %v", m.URI, int(pos.Line), int(pos.Character), err)
|
||||
} else {
|
||||
rng, err := m.Range(spn)
|
||||
if err != nil {
|
||||
s.session.Logger().Infof(ctx, "failed to convert surrounding position: %s:%v:%v: %v", m.URI, int(pos.Line), int(pos.Character), err)
|
||||
xlog.Infof(ctx, "failed to convert surrounding position: %s:%v:%v: %v", m.URI, int(pos.Line), int(pos.Character), err)
|
||||
} else {
|
||||
insertionRange = rng
|
||||
}
|
||||
|
@ -10,13 +10,14 @@ import (
|
||||
|
||||
"golang.org/x/tools/internal/lsp/protocol"
|
||||
"golang.org/x/tools/internal/lsp/source"
|
||||
"golang.org/x/tools/internal/lsp/xlog"
|
||||
"golang.org/x/tools/internal/span"
|
||||
)
|
||||
|
||||
func (s *Server) Diagnostics(ctx context.Context, view source.View, uri span.URI) {
|
||||
f, err := view.GetFile(ctx, uri)
|
||||
if err != nil {
|
||||
s.session.Logger().Errorf(ctx, "no file for %s: %v", uri, err)
|
||||
xlog.Errorf(ctx, "no file for %s: %v", uri, err)
|
||||
return
|
||||
}
|
||||
// For non-Go files, don't return any diagnostics.
|
||||
@ -26,7 +27,7 @@ func (s *Server) Diagnostics(ctx context.Context, view source.View, uri span.URI
|
||||
}
|
||||
reports, err := source.Diagnostics(ctx, view, gof, s.disabledAnalyses)
|
||||
if err != nil {
|
||||
s.session.Logger().Errorf(ctx, "failed to compute diagnostics for %s: %v", gof.URI(), err)
|
||||
xlog.Errorf(ctx, "failed to compute diagnostics for %s: %v", gof.URI(), err)
|
||||
return
|
||||
}
|
||||
|
||||
@ -38,7 +39,7 @@ func (s *Server) Diagnostics(ctx context.Context, view source.View, uri span.URI
|
||||
if s.undelivered == nil {
|
||||
s.undelivered = make(map[span.URI][]source.Diagnostic)
|
||||
}
|
||||
s.session.Logger().Errorf(ctx, "failed to deliver diagnostic for %s (will retry): %v", uri, err)
|
||||
xlog.Errorf(ctx, "failed to deliver diagnostic for %s (will retry): %v", uri, err)
|
||||
s.undelivered[uri] = diagnostics
|
||||
continue
|
||||
}
|
||||
@ -49,7 +50,7 @@ func (s *Server) Diagnostics(ctx context.Context, view source.View, uri span.URI
|
||||
// undelivered ones (only for remaining URIs).
|
||||
for uri, diagnostics := range s.undelivered {
|
||||
if err := s.publishDiagnostics(ctx, view, uri, diagnostics); err != nil {
|
||||
s.session.Logger().Errorf(ctx, "failed to deliver diagnostic for %s (will not retry): %v", uri, err)
|
||||
xlog.Errorf(ctx, "failed to deliver diagnostic for %s (will not retry): %v", uri, err)
|
||||
}
|
||||
// If we fail to deliver the same diagnostics twice, just give up.
|
||||
delete(s.undelivered, uri)
|
||||
|
@ -15,6 +15,7 @@ import (
|
||||
"golang.org/x/tools/internal/lsp/debug"
|
||||
"golang.org/x/tools/internal/lsp/protocol"
|
||||
"golang.org/x/tools/internal/lsp/source"
|
||||
"golang.org/x/tools/internal/lsp/xlog"
|
||||
"golang.org/x/tools/internal/span"
|
||||
)
|
||||
|
||||
@ -154,7 +155,7 @@ func (s *Server) initialized(ctx context.Context, params *protocol.InitializedPa
|
||||
}
|
||||
buf := &bytes.Buffer{}
|
||||
debug.PrintVersionInfo(buf, true, debug.PlainText)
|
||||
s.session.Logger().Infof(ctx, "%s", buf)
|
||||
xlog.Infof(ctx, "%s", buf)
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -209,7 +210,7 @@ func (s *Server) processConfig(ctx context.Context, view source.View, config int
|
||||
case "FullDocumentation":
|
||||
s.hoverKind = source.FullDocumentation
|
||||
default:
|
||||
view.Session().Logger().Errorf(ctx, "unsupported hover kind %s", hoverKind)
|
||||
xlog.Errorf(ctx, "unsupported hover kind %s", hoverKind)
|
||||
// The default value is already be set to synopsis.
|
||||
}
|
||||
}
|
||||
|
@ -9,6 +9,7 @@ import (
|
||||
|
||||
"golang.org/x/tools/internal/lsp/protocol"
|
||||
"golang.org/x/tools/internal/lsp/source"
|
||||
"golang.org/x/tools/internal/lsp/xlog"
|
||||
"golang.org/x/tools/internal/span"
|
||||
)
|
||||
|
||||
@ -29,7 +30,7 @@ func (s *Server) documentHighlight(ctx context.Context, params *protocol.TextDoc
|
||||
}
|
||||
spans, err := source.Highlight(ctx, f, rng.Start)
|
||||
if err != nil {
|
||||
view.Session().Logger().Errorf(ctx, "no highlight for %s: %v", spn, err)
|
||||
xlog.Errorf(ctx, "no highlight for %s: %v", spn, err)
|
||||
}
|
||||
return toProtocolHighlight(m, spans), nil
|
||||
}
|
||||
|
@ -15,6 +15,7 @@ import (
|
||||
|
||||
"golang.org/x/tools/internal/lsp/protocol"
|
||||
"golang.org/x/tools/internal/lsp/source"
|
||||
"golang.org/x/tools/internal/lsp/xlog"
|
||||
"golang.org/x/tools/internal/span"
|
||||
)
|
||||
|
||||
@ -37,13 +38,13 @@ func (s *Server) documentLink(ctx context.Context, params *protocol.DocumentLink
|
||||
case *ast.ImportSpec:
|
||||
target, err := strconv.Unquote(n.Path.Value)
|
||||
if err != nil {
|
||||
view.Session().Logger().Errorf(ctx, "cannot unquote import path %s: %v", n.Path.Value, err)
|
||||
xlog.Errorf(ctx, "cannot unquote import path %s: %v", n.Path.Value, err)
|
||||
return false
|
||||
}
|
||||
target = "https://godoc.org/" + target
|
||||
l, err := toProtocolLink(view, m, target, n.Pos(), n.End())
|
||||
if err != nil {
|
||||
view.Session().Logger().Errorf(ctx, "cannot initialize DocumentLink %s: %v", n.Path.Value, err)
|
||||
xlog.Errorf(ctx, "cannot initialize DocumentLink %s: %v", n.Path.Value, err)
|
||||
return false
|
||||
}
|
||||
links = append(links, l)
|
||||
@ -54,7 +55,7 @@ func (s *Server) documentLink(ctx context.Context, params *protocol.DocumentLink
|
||||
}
|
||||
l, err := findLinksInString(n.Value, n.Pos(), view, m)
|
||||
if err != nil {
|
||||
view.Session().Logger().Errorf(ctx, "cannot find links in string: %v", err)
|
||||
xlog.Errorf(ctx, "cannot find links in string: %v", err)
|
||||
return false
|
||||
}
|
||||
links = append(links, l...)
|
||||
@ -67,7 +68,7 @@ func (s *Server) documentLink(ctx context.Context, params *protocol.DocumentLink
|
||||
for _, comment := range commentGroup.List {
|
||||
l, err := findLinksInString(comment.Text, comment.Pos(), view, m)
|
||||
if err != nil {
|
||||
view.Session().Logger().Errorf(ctx, "cannot find links in comment: %v", err)
|
||||
xlog.Errorf(ctx, "cannot find links in comment: %v", err)
|
||||
continue
|
||||
}
|
||||
links = append(links, l...)
|
||||
|
@ -60,6 +60,6 @@ func sendParseError(ctx context.Context, log xlog.Logger, req *jsonrpc2.Request,
|
||||
err = jsonrpc2.NewErrorf(jsonrpc2.CodeParseError, "%v", err)
|
||||
}
|
||||
if err := req.Reply(ctx, nil, err); err != nil {
|
||||
log.Errorf(ctx, "%v", err)
|
||||
xlog.Errorf(ctx, "%v", err)
|
||||
}
|
||||
}
|
||||
|
@ -9,6 +9,7 @@ import (
|
||||
|
||||
"golang.org/x/tools/internal/lsp/protocol"
|
||||
"golang.org/x/tools/internal/lsp/source"
|
||||
"golang.org/x/tools/internal/lsp/xlog"
|
||||
"golang.org/x/tools/internal/span"
|
||||
)
|
||||
|
||||
@ -34,7 +35,7 @@ func (s *Server) references(ctx context.Context, params *protocol.ReferenceParam
|
||||
}
|
||||
references, err := ident.References(ctx)
|
||||
if err != nil {
|
||||
view.Session().Logger().Errorf(ctx, "no references for %s: %v", ident.Name, err)
|
||||
xlog.Errorf(ctx, "no references for %s: %v", ident.Name, err)
|
||||
}
|
||||
if params.Context.IncludeDeclaration {
|
||||
// The declaration of this identifier may not be in the
|
||||
|
@ -9,6 +9,7 @@ import (
|
||||
|
||||
"golang.org/x/tools/internal/lsp/protocol"
|
||||
"golang.org/x/tools/internal/lsp/source"
|
||||
"golang.org/x/tools/internal/lsp/xlog"
|
||||
"golang.org/x/tools/internal/span"
|
||||
)
|
||||
|
||||
@ -29,7 +30,7 @@ func (s *Server) signatureHelp(ctx context.Context, params *protocol.TextDocumen
|
||||
}
|
||||
info, err := source.SignatureHelp(ctx, f, rng.Start)
|
||||
if err != nil {
|
||||
s.session.Logger().Infof(ctx, "no signature help for %s:%v:%v : %s", uri, int(params.Position.Line), int(params.Position.Character), err)
|
||||
xlog.Infof(ctx, "no signature help for %s:%v:%v : %s", uri, int(params.Position.Line), int(params.Position.Character), err)
|
||||
return nil, nil
|
||||
}
|
||||
return toProtocolSignatureHelp(info), nil
|
||||
|
@ -14,6 +14,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"golang.org/x/tools/internal/lsp/snippet"
|
||||
"golang.org/x/tools/internal/lsp/xlog"
|
||||
"golang.org/x/tools/internal/span"
|
||||
)
|
||||
|
||||
@ -192,7 +193,7 @@ func formatFieldList(ctx context.Context, v View, list *ast.FieldList) ([]string
|
||||
cfg := printer.Config{Mode: printer.UseSpaces | printer.TabIndent, Tabwidth: 4}
|
||||
b := &bytes.Buffer{}
|
||||
if err := cfg.Fprint(b, v.Session().Cache().FileSet(), p.Type); err != nil {
|
||||
v.Session().Logger().Errorf(ctx, "unable to print type %v", p.Type)
|
||||
xlog.Errorf(ctx, "unable to print type %v", p.Type)
|
||||
continue
|
||||
}
|
||||
typ := replacer.Replace(b.String())
|
||||
|
@ -34,6 +34,7 @@ import (
|
||||
"golang.org/x/tools/go/analysis/passes/unsafeptr"
|
||||
"golang.org/x/tools/go/analysis/passes/unusedresult"
|
||||
"golang.org/x/tools/go/packages"
|
||||
"golang.org/x/tools/internal/lsp/xlog"
|
||||
"golang.org/x/tools/internal/span"
|
||||
)
|
||||
|
||||
@ -81,7 +82,7 @@ func Diagnostics(ctx context.Context, view View, f GoFile, disabledAnalyses map[
|
||||
if !diagnostics(ctx, view, pkg, reports) {
|
||||
// If we don't have any list, parse, or type errors, run analyses.
|
||||
if err := analyses(ctx, view, pkg, disabledAnalyses, reports); err != nil {
|
||||
view.Session().Logger().Errorf(ctx, "failed to run analyses for %s: %v", f.URI(), err)
|
||||
xlog.Errorf(ctx, "failed to run analyses for %s: %v", f.URI(), err)
|
||||
}
|
||||
}
|
||||
// Updates to the diagnostics for this package may need to be propagated.
|
||||
@ -230,29 +231,29 @@ func parseDiagnosticMessage(input string) span.Span {
|
||||
func pointToSpan(ctx context.Context, view View, spn span.Span) span.Span {
|
||||
f, err := view.GetFile(ctx, spn.URI())
|
||||
if err != nil {
|
||||
view.Session().Logger().Errorf(ctx, "could not find file for diagnostic: %v", spn.URI())
|
||||
xlog.Errorf(ctx, "could not find file for diagnostic: %v", spn.URI())
|
||||
return spn
|
||||
}
|
||||
diagFile, ok := f.(GoFile)
|
||||
if !ok {
|
||||
view.Session().Logger().Errorf(ctx, "%s is not a Go file", spn.URI())
|
||||
xlog.Errorf(ctx, "%s is not a Go file", spn.URI())
|
||||
return spn
|
||||
}
|
||||
tok := diagFile.GetToken(ctx)
|
||||
if tok == nil {
|
||||
view.Session().Logger().Errorf(ctx, "could not find token.File for diagnostic: %v", spn.URI())
|
||||
xlog.Errorf(ctx, "could not find token.File for diagnostic: %v", spn.URI())
|
||||
return spn
|
||||
}
|
||||
data, _, err := diagFile.Handle(ctx).Read(ctx)
|
||||
if err != nil {
|
||||
view.Session().Logger().Errorf(ctx, "could not find content for diagnostic: %v", spn.URI())
|
||||
xlog.Errorf(ctx, "could not find content for diagnostic: %v", spn.URI())
|
||||
return spn
|
||||
}
|
||||
c := span.NewTokenConverter(diagFile.FileSet(), tok)
|
||||
s, err := spn.WithOffset(c)
|
||||
//we just don't bother producing an error if this failed
|
||||
if err != nil {
|
||||
view.Session().Logger().Errorf(ctx, "invalid span for diagnostic: %v: %v", spn.URI(), err)
|
||||
xlog.Errorf(ctx, "invalid span for diagnostic: %v: %v", spn.URI(), err)
|
||||
return spn
|
||||
}
|
||||
start := s.Start()
|
||||
|
@ -17,6 +17,7 @@ import (
|
||||
"golang.org/x/tools/internal/imports"
|
||||
"golang.org/x/tools/internal/lsp/diff"
|
||||
"golang.org/x/tools/internal/lsp/telemetry/trace"
|
||||
"golang.org/x/tools/internal/lsp/xlog"
|
||||
"golang.org/x/tools/internal/span"
|
||||
)
|
||||
|
||||
@ -106,7 +107,7 @@ func buildProcessEnv(ctx context.Context, view View) *imports.ProcessEnv {
|
||||
env := &imports.ProcessEnv{
|
||||
WorkingDir: cfg.Dir,
|
||||
Logf: func(format string, v ...interface{}) {
|
||||
view.Session().Logger().Infof(ctx, format, v...)
|
||||
xlog.Infof(ctx, format, v...)
|
||||
},
|
||||
}
|
||||
for _, kv := range cfg.Env {
|
||||
@ -137,7 +138,7 @@ func computeTextEdits(ctx context.Context, file File, formatted string) (edits [
|
||||
defer done()
|
||||
data, _, err := file.Handle(ctx).Read(ctx)
|
||||
if err != nil {
|
||||
file.View().Session().Logger().Errorf(ctx, "Cannot compute text edits: %v", err)
|
||||
xlog.Errorf(ctx, "Cannot compute text edits: %v", err)
|
||||
return nil
|
||||
}
|
||||
u := diff.SplitLines(string(data))
|
||||
|
@ -13,6 +13,7 @@ import (
|
||||
"golang.org/x/tools/internal/lsp/protocol"
|
||||
"golang.org/x/tools/internal/lsp/source"
|
||||
"golang.org/x/tools/internal/lsp/telemetry/trace"
|
||||
"golang.org/x/tools/internal/lsp/xlog"
|
||||
"golang.org/x/tools/internal/span"
|
||||
)
|
||||
|
||||
@ -133,7 +134,7 @@ func (s *Server) didClose(ctx context.Context, params *protocol.DidCloseTextDocu
|
||||
defer func() {
|
||||
for _, uri := range clear {
|
||||
if err := s.publishDiagnostics(ctx, view, uri, []source.Diagnostic{}); err != nil {
|
||||
s.session.Logger().Errorf(ctx, "failed to clear diagnostics for %s: %v", uri, err)
|
||||
xlog.Errorf(ctx, "failed to clear diagnostics for %s: %v", uri, err)
|
||||
}
|
||||
}
|
||||
}()
|
||||
@ -141,18 +142,18 @@ func (s *Server) didClose(ctx context.Context, params *protocol.DidCloseTextDocu
|
||||
// clear out all diagnostics for the package.
|
||||
f, err := view.GetFile(ctx, uri)
|
||||
if err != nil {
|
||||
s.session.Logger().Errorf(ctx, "no file for %s: %v", uri, err)
|
||||
xlog.Errorf(ctx, "no file for %s: %v", uri, err)
|
||||
return nil
|
||||
}
|
||||
// For non-Go files, don't return any diagnostics.
|
||||
gof, ok := f.(source.GoFile)
|
||||
if !ok {
|
||||
s.session.Logger().Errorf(ctx, "closing a non-Go file, no diagnostics to clear")
|
||||
xlog.Errorf(ctx, "closing a non-Go file, no diagnostics to clear")
|
||||
return nil
|
||||
}
|
||||
pkg := gof.GetPackage(ctx)
|
||||
if pkg == nil {
|
||||
s.session.Logger().Errorf(ctx, "no package available for %s", uri)
|
||||
xlog.Errorf(ctx, "no package available for %s", uri)
|
||||
return nil
|
||||
}
|
||||
for _, filename := range pkg.GetFilenames() {
|
||||
|
Loading…
Reference in New Issue
Block a user