internal/lsp/source: respect user's hover kind in signature help

I had originally wanted to create a shared code path for hover in all
cases, but hover has a lot more differences from the documentation in
signature help and completion than I expected. You can't use markdown,
and you probably don't want links--it would take a bigger refactor to
extract something that worked for each feature.

Handling the Structured and SingleLine hover setting also doesn't seem
necessary--those settings are really specific to the way the client
presents the hover, which isn't related to signature help or completion.

For completion, all we need is an extra check on the hover kind for the
NoDocumentation option.

Fixes golang/go#38577

Change-Id: Ib2037906c13f5be26813fcd2c20989e4d1b6c9bd
Reviewed-on: https://go-review.googlesource.com/c/tools/+/266139
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
Trust: Rebecca Stambler <rstambler@golang.org>
This commit is contained in:
Rebecca Stambler 2020-10-28 23:51:50 -04:00
Родитель 061905c3e8
Коммит 186a7436c9
3 изменённых файлов: 25 добавлений и 12 удалений

Просмотреть файл

@ -510,7 +510,7 @@ func Completion(ctx context.Context, snapshot source.Snapshot, fh source.FileHan
opts: &completionOptions{
matcher: opts.Matcher,
unimported: opts.CompleteUnimported,
documentation: opts.CompletionDocumentation,
documentation: opts.CompletionDocumentation && opts.HoverKind != source.NoDocumentation,
fullDocumentation: opts.HoverKind == source.FullDocumentation,
placeholders: opts.UsePlaceholders,
literal: opts.LiteralCompletions && opts.InsertTextFormat == protocol.SnippetTextFormat,

Просмотреть файл

@ -7,7 +7,6 @@ package source
import (
"context"
"go/ast"
"go/doc"
"go/token"
"go/types"
@ -123,7 +122,7 @@ FindCall:
}
return &protocol.SignatureInformation{
Label: name + s.Format(),
Documentation: doc.Synopsis(s.doc),
Documentation: s.doc,
Parameters: paramInfo,
}, activeParam, nil
}
@ -140,7 +139,7 @@ func builtinSignature(ctx context.Context, snapshot Snapshot, callExpr *ast.Call
activeParam := activeParameter(callExpr, len(sig.params), sig.variadic, pos)
return &protocol.SignatureInformation{
Label: sig.name + sig.Format(),
Documentation: doc.Synopsis(sig.doc),
Documentation: sig.doc,
Parameters: paramInfo,
}, activeParam, nil

Просмотреть файл

@ -9,6 +9,7 @@ import (
"context"
"fmt"
"go/ast"
"go/doc"
"go/printer"
"go/token"
"go/types"
@ -79,8 +80,8 @@ func (s *signature) Params() []string {
// NewBuiltinSignature returns signature for the builtin object with a given
// name, if a builtin object with the name exists.
func NewBuiltinSignature(ctx context.Context, snapshot Snapshot, name string) (*signature, error) {
builtin, err := snapshot.BuiltinPackage(ctx)
func NewBuiltinSignature(ctx context.Context, s Snapshot, name string) (*signature, error) {
builtin, err := s.BuiltinPackage(ctx)
if err != nil {
return nil, err
}
@ -103,10 +104,17 @@ func NewBuiltinSignature(ctx context.Context, snapshot Snapshot, name string) (*
variadic = true
}
}
params, _ := formatFieldList(ctx, snapshot, decl.Type.Params, variadic)
results, needResultParens := formatFieldList(ctx, snapshot, decl.Type.Results, false)
params, _ := formatFieldList(ctx, s, decl.Type.Params, variadic)
results, needResultParens := formatFieldList(ctx, s, decl.Type.Results, false)
d := decl.Doc.Text()
switch s.View().Options().HoverKind {
case SynopsisDocumentation:
d = doc.Synopsis(d)
case NoDocumentation:
d = ""
}
return &signature{
doc: decl.Doc.Text(),
doc: d,
name: name,
needResultParens: needResultParens,
params: params,
@ -188,12 +196,18 @@ func NewSignature(ctx context.Context, s Snapshot, pkg Package, sig *types.Signa
results = append(results, el.Name()+" "+typ)
}
}
var doc string
var d string
if comment != nil {
doc = comment.Text()
d = comment.Text()
}
switch s.View().Options().HoverKind {
case SynopsisDocumentation:
d = doc.Synopsis(d)
case NoDocumentation:
d = ""
}
return &signature{
doc: doc,
doc: d,
params: params,
results: results,
variadic: sig.Variadic(),