mirror of
https://github.com/golang/go.git
synced 2025-05-05 23:53:05 +00:00
internal/lsp: turn on completion documentation by default
This feature has been in an experimental state for a long enough time that I think we can enable it by default at master. Change-Id: I9bbb8b41377719f0e97f608f6e5163a883a176b3 Reviewed-on: https://go-review.googlesource.com/c/tools/+/192259 Run-TryBot: Rebecca Stambler <rstambler@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Cottrell <iancottrell@google.com>
This commit is contained in:
parent
df305b82d2
commit
adb45749da
@ -26,7 +26,7 @@ func (s *Server) completion(ctx context.Context, params *protocol.CompletionPara
|
||||
candidates, surrounding, err := source.Completion(ctx, view, f, params.Position, source.CompletionOptions{
|
||||
WantDeepCompletion: !s.disableDeepCompletion,
|
||||
WantFuzzyMatching: !s.disableFuzzyMatching,
|
||||
WantDocumentaton: s.wantCompletionDocumentation,
|
||||
NoDocumentation: !s.wantCompletionDocumentation,
|
||||
WantFullDocumentation: s.hoverKind == fullDocumentation,
|
||||
WantUnimported: s.wantUnimportedCompletions,
|
||||
})
|
||||
|
@ -273,9 +273,12 @@ func (s *Server) processConfig(ctx context.Context, view source.View, config int
|
||||
}
|
||||
|
||||
// Check if the user wants documentation in completion items.
|
||||
// This defaults to true.
|
||||
s.wantCompletionDocumentation = true
|
||||
if wantCompletionDocumentation, ok := c["wantCompletionDocumentation"].(bool); ok {
|
||||
s.wantCompletionDocumentation = wantCompletionDocumentation
|
||||
}
|
||||
|
||||
// Check if placeholders are enabled.
|
||||
if usePlaceholders, ok := c["usePlaceholders"].(bool); ok {
|
||||
s.usePlaceholders = usePlaceholders
|
||||
|
@ -110,9 +110,9 @@ func (r *runner) Completion(t *testing.T, data tests.Completions, snippets tests
|
||||
r.server.disableDeepCompletion = true
|
||||
r.server.disableFuzzyMatching = true
|
||||
r.server.wantUnimportedCompletions = false
|
||||
r.server.wantCompletionDocumentation = false
|
||||
}()
|
||||
|
||||
// Set this as a default.
|
||||
r.server.wantCompletionDocumentation = true
|
||||
|
||||
for src, itemList := range data {
|
||||
|
@ -381,10 +381,12 @@ type candidate struct {
|
||||
|
||||
type CompletionOptions struct {
|
||||
WantDeepCompletion bool
|
||||
WantDocumentaton bool
|
||||
WantFullDocumentation bool
|
||||
WantUnimported bool
|
||||
WantFuzzyMatching bool
|
||||
|
||||
WantUnimported bool
|
||||
|
||||
NoDocumentation bool
|
||||
WantFullDocumentation bool
|
||||
}
|
||||
|
||||
// Completion returns a list of possible candidates for completion, given a
|
||||
|
@ -113,28 +113,30 @@ func (c *completer) item(cand candidate) (CompletionItem, error) {
|
||||
plainSnippet: plainSnippet,
|
||||
placeholderSnippet: placeholderSnippet,
|
||||
}
|
||||
// TODO(rstambler): Log errors when this feature is enabled.
|
||||
if c.opts.WantDocumentaton {
|
||||
// If the user doesn't want documentation for completion items.
|
||||
if c.opts.NoDocumentation {
|
||||
return item, nil
|
||||
}
|
||||
declRange, err := objToRange(c.ctx, c.view, obj)
|
||||
if err != nil {
|
||||
goto Return
|
||||
return item, nil
|
||||
}
|
||||
pos := c.view.Session().Cache().FileSet().Position(declRange.spanRange.Start)
|
||||
if !pos.IsValid() {
|
||||
goto Return
|
||||
return item, nil
|
||||
}
|
||||
uri := span.FileURI(pos.Filename)
|
||||
f, err := c.view.GetFile(c.ctx, uri)
|
||||
if err != nil {
|
||||
goto Return
|
||||
return item, nil
|
||||
}
|
||||
gof, ok := f.(GoFile)
|
||||
if !ok {
|
||||
goto Return
|
||||
return item, nil
|
||||
}
|
||||
pkg, err := gof.GetCachedPackage(c.ctx)
|
||||
if err != nil {
|
||||
goto Return
|
||||
return item, nil
|
||||
}
|
||||
var ph ParseGoHandle
|
||||
for _, h := range pkg.GetHandles() {
|
||||
@ -143,26 +145,24 @@ func (c *completer) item(cand candidate) (CompletionItem, error) {
|
||||
}
|
||||
}
|
||||
if ph == nil {
|
||||
goto Return
|
||||
return item, nil
|
||||
}
|
||||
file, _ := ph.Cached(c.ctx)
|
||||
if file == nil {
|
||||
goto Return
|
||||
return item, nil
|
||||
}
|
||||
ident, err := findIdentifier(c.ctx, c.view, gof, pkg, file, declRange.spanRange.Start)
|
||||
if err != nil {
|
||||
goto Return
|
||||
return item, nil
|
||||
}
|
||||
hover, err := ident.Hover(c.ctx)
|
||||
if err != nil {
|
||||
goto Return
|
||||
return item, nil
|
||||
}
|
||||
item.Documentation = hover.Synopsis
|
||||
if c.opts.WantFullDocumentation {
|
||||
item.Documentation = hover.FullDocumentation
|
||||
}
|
||||
}
|
||||
Return:
|
||||
return item, nil
|
||||
}
|
||||
|
||||
|
@ -104,7 +104,6 @@ func (r *runner) Completion(t *testing.T, data tests.Completions, snippets tests
|
||||
}, source.CompletionOptions{
|
||||
WantDeepCompletion: deepComplete,
|
||||
WantFuzzyMatching: fuzzyMatch,
|
||||
WantDocumentaton: true,
|
||||
WantUnimported: unimported,
|
||||
})
|
||||
if err != nil {
|
||||
|
Loading…
x
Reference in New Issue
Block a user