1
0
mirror of https://github.com/golang/go synced 2024-11-18 10:04:43 -07:00

internal/lsp: check content format instead of assuming markdown

Fixes golang/go#31078

Change-Id: I2227f64d839d65d7b46d43e1b90f5b1dc298bf6f
Reviewed-on: https://go-review.googlesource.com/c/tools/+/172601
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
This commit is contained in:
Rebecca Stambler 2019-04-17 14:47:10 -04:00
parent afc68fbc60
commit f6abc2cac8
5 changed files with 26 additions and 13 deletions

View File

@ -150,9 +150,12 @@ func (app *Application) connect(ctx context.Context, client cmdClient) (protocol
}
go jc.Run(ctx)
}
params := &protocol.InitializeParams{}
params.RootURI = string(span.FileURI(app.Config.Dir))
params.Capabilities.Workspace.Configuration = true
params.Capabilities.TextDocument.Hover.ContentFormat = []protocol.MarkupKind{protocol.PlainText}
client.prepare(app, server)
if _, err := server.Initialize(ctx, params); err != nil {
return nil, err

View File

@ -100,13 +100,7 @@ func (d *definition) Run(ctx context.Context, args ...string) error {
if err != nil {
return fmt.Errorf("%v: %v", from, err)
}
//TODO: either work out how to request plain text, or
//use a less kludgy way of cleaning the markdown
description := hover.Contents.Value
if v := strings.TrimPrefix(description, "```go"); v != description {
description = strings.TrimSuffix(v, "```")
}
description = strings.TrimSpace(description)
description := strings.TrimSpace(hover.Contents.Value)
var result interface{}
switch d.query.Emulate {
case "":

View File

@ -105,6 +105,12 @@ func (s *Server) setClientCapabilities(caps protocol.ClientCapabilities) {
// Check if the client supports configuration messages.
s.configurationSupported = caps.Workspace.Configuration
s.dynamicConfigurationSupported = caps.Workspace.DidChangeConfiguration.DynamicRegistration
// Check which types of content format are supported by this client.
s.preferredContentFormat = protocol.PlainText
if len(caps.TextDocument.Hover.ContentFormat) > 0 {
s.preferredContentFormat = caps.TextDocument.Hover.ContentFormat[0]
}
}
func (s *Server) initialized(ctx context.Context, params *protocol.InitializedParams) error {

View File

@ -35,7 +35,6 @@ func (s *Server) hover(ctx context.Context, params *protocol.TextDocumentPositio
if err != nil {
return nil, err
}
markdown := "```go\n" + content + "\n```"
identSpan, err := ident.Range.Span()
if err != nil {
return nil, err
@ -45,10 +44,20 @@ func (s *Server) hover(ctx context.Context, params *protocol.TextDocumentPositio
return nil, err
}
return &protocol.Hover{
Contents: protocol.MarkupContent{
Kind: protocol.Markdown,
Value: markdown,
},
Range: &rng,
Contents: markupContent(content, s.preferredContentFormat),
Range: &rng,
}, nil
}
func markupContent(content string, kind protocol.MarkupKind) protocol.MarkupContent {
result := protocol.MarkupContent{
Kind: kind,
}
switch kind {
case protocol.PlainText:
result.Value = content
case protocol.Markdown:
result.Value = "```go\n" + content + "\n```"
}
return result
}

View File

@ -77,6 +77,7 @@ type Server struct {
insertTextFormat protocol.InsertTextFormat
configurationSupported bool
dynamicConfigurationSupported bool
preferredContentFormat protocol.MarkupKind
textDocumentSyncKind protocol.TextDocumentSyncKind