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:
parent
afc68fbc60
commit
f6abc2cac8
|
@ -150,9 +150,12 @@ func (app *Application) connect(ctx context.Context, client cmdClient) (protocol
|
||||||
}
|
}
|
||||||
go jc.Run(ctx)
|
go jc.Run(ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
params := &protocol.InitializeParams{}
|
params := &protocol.InitializeParams{}
|
||||||
params.RootURI = string(span.FileURI(app.Config.Dir))
|
params.RootURI = string(span.FileURI(app.Config.Dir))
|
||||||
params.Capabilities.Workspace.Configuration = true
|
params.Capabilities.Workspace.Configuration = true
|
||||||
|
params.Capabilities.TextDocument.Hover.ContentFormat = []protocol.MarkupKind{protocol.PlainText}
|
||||||
|
|
||||||
client.prepare(app, server)
|
client.prepare(app, server)
|
||||||
if _, err := server.Initialize(ctx, params); err != nil {
|
if _, err := server.Initialize(ctx, params); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
|
@ -100,13 +100,7 @@ func (d *definition) Run(ctx context.Context, args ...string) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("%v: %v", from, err)
|
return fmt.Errorf("%v: %v", from, err)
|
||||||
}
|
}
|
||||||
//TODO: either work out how to request plain text, or
|
description := strings.TrimSpace(hover.Contents.Value)
|
||||||
//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)
|
|
||||||
var result interface{}
|
var result interface{}
|
||||||
switch d.query.Emulate {
|
switch d.query.Emulate {
|
||||||
case "":
|
case "":
|
||||||
|
|
|
@ -105,6 +105,12 @@ func (s *Server) setClientCapabilities(caps protocol.ClientCapabilities) {
|
||||||
// Check if the client supports configuration messages.
|
// Check if the client supports configuration messages.
|
||||||
s.configurationSupported = caps.Workspace.Configuration
|
s.configurationSupported = caps.Workspace.Configuration
|
||||||
s.dynamicConfigurationSupported = caps.Workspace.DidChangeConfiguration.DynamicRegistration
|
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 {
|
func (s *Server) initialized(ctx context.Context, params *protocol.InitializedParams) error {
|
||||||
|
|
|
@ -35,7 +35,6 @@ func (s *Server) hover(ctx context.Context, params *protocol.TextDocumentPositio
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
markdown := "```go\n" + content + "\n```"
|
|
||||||
identSpan, err := ident.Range.Span()
|
identSpan, err := ident.Range.Span()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -45,10 +44,20 @@ func (s *Server) hover(ctx context.Context, params *protocol.TextDocumentPositio
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return &protocol.Hover{
|
return &protocol.Hover{
|
||||||
Contents: protocol.MarkupContent{
|
Contents: markupContent(content, s.preferredContentFormat),
|
||||||
Kind: protocol.Markdown,
|
|
||||||
Value: markdown,
|
|
||||||
},
|
|
||||||
Range: &rng,
|
Range: &rng,
|
||||||
}, nil
|
}, 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
|
||||||
|
}
|
||||||
|
|
|
@ -77,6 +77,7 @@ type Server struct {
|
||||||
insertTextFormat protocol.InsertTextFormat
|
insertTextFormat protocol.InsertTextFormat
|
||||||
configurationSupported bool
|
configurationSupported bool
|
||||||
dynamicConfigurationSupported bool
|
dynamicConfigurationSupported bool
|
||||||
|
preferredContentFormat protocol.MarkupKind
|
||||||
|
|
||||||
textDocumentSyncKind protocol.TextDocumentSyncKind
|
textDocumentSyncKind protocol.TextDocumentSyncKind
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue