mirror of
https://github.com/golang/go
synced 2024-11-18 16:14:46 -07:00
internal/lsp: return completion item without documentation
Previously, if we failed to find an item's documentation, we would not return the item at all. It seems better to do a best-effort approach, i.e. return the item without documentation. Fixes golang/go#35406 Change-Id: I896ffda2fc79b9210f0d83311808114d0e686820 Reviewed-on: https://go-review.googlesource.com/c/tools/+/205862 Run-TryBot: Rebecca Stambler <rstambler@golang.org> Run-TryBot: Heschi Kreinick <heschi@google.com> Reviewed-by: Heschi Kreinick <heschi@google.com>
This commit is contained in:
parent
a4a09c7216
commit
f7ea15e60b
@ -15,6 +15,7 @@ import (
|
||||
|
||||
"golang.org/x/tools/internal/lsp/protocol"
|
||||
"golang.org/x/tools/internal/lsp/snippet"
|
||||
"golang.org/x/tools/internal/lsp/telemetry"
|
||||
"golang.org/x/tools/internal/span"
|
||||
"golang.org/x/tools/internal/telemetry/log"
|
||||
"golang.org/x/tools/internal/telemetry/tag"
|
||||
@ -154,22 +155,27 @@ func (c *completer) item(cand candidate) (CompletionItem, error) {
|
||||
}
|
||||
ph, pkg, err := c.view.FindFileInPackage(c.ctx, uri, searchPkg)
|
||||
if err != nil {
|
||||
return CompletionItem{}, err
|
||||
log.Error(c.ctx, "error finding file in package", err, telemetry.URI.Of(uri), telemetry.Package.Of(searchPkg.ID()))
|
||||
return item, nil
|
||||
}
|
||||
file, _, _, err := ph.Cached()
|
||||
if err != nil {
|
||||
return CompletionItem{}, err
|
||||
log.Error(c.ctx, "no cached file", err, telemetry.URI.Of(uri))
|
||||
return item, nil
|
||||
}
|
||||
if !(file.Pos() <= obj.Pos() && obj.Pos() <= file.End()) {
|
||||
return CompletionItem{}, errors.Errorf("no file for completion object %s", obj.Name())
|
||||
log.Error(c.ctx, "no file for object", errors.Errorf("no file for completion object %s", obj.Name()), telemetry.URI.Of(uri))
|
||||
return item, nil
|
||||
}
|
||||
ident, err := findIdentifier(c.ctx, c.snapshot, pkg, file, obj.Pos())
|
||||
if err != nil {
|
||||
return CompletionItem{}, err
|
||||
log.Error(c.ctx, "failed to findIdentifier", err, telemetry.URI.Of(uri))
|
||||
return item, nil
|
||||
}
|
||||
hover, err := ident.Hover(c.ctx)
|
||||
if err != nil {
|
||||
return CompletionItem{}, err
|
||||
log.Error(c.ctx, "failed to find Hover", err, telemetry.URI.Of(uri))
|
||||
return item, nil
|
||||
}
|
||||
item.Documentation = hover.Synopsis
|
||||
if c.opts.FullDocumentation {
|
||||
|
Loading…
Reference in New Issue
Block a user