go-langserver
go-langserver copied to clipboard
Added MarkdownString type, Deprecated MarkedString #216
Added interface MarkupContent for backword compatibility
Can someone please check why the build is broken. It's passing for appveyor
. Two out of three builds are passing for travis
as well. Maybe retriggering fixes that.
Any other comments/feedback?
It triggered a data race which I haven't seen before! I filed https://github.com/sourcegraph/go-langserver/issues/244 but it looks very much unrelated to your code. Restarted the CI job. Thanks for the ping.
Thanks, I just read the spec for MarkupContent
. It seems a hover can now return
contents: MarkedString | MarkedString[] | MarkupContent
and that MarkupContent
is somewhat equivalent to
type MarkupContent struct {
Kind string // 'plaintext' | 'markdown'
Value string
}
I'm almost tempted to drop support for the deprecated MarkedString
to simplify. But that would likely be painful in practice. So we should adjust this PR so there is a clear path forward for deprecating. There isn't a nice way to convert MarkedString[]
into MarkupContent
while still remaining correct, so I think a type with an awful name like MarkedStringOrMarkupContent
is unfortunately the way forward, then we can fully remove MarkedString
support at some point.
Also your PR supports raw strings being converted into MarkupContent
which isn't needed. It also has a field called IsTrusted
which I don't see in the spec.
What is preventing MarkedString[]
from being converted to MarkupContent
?
The MarkedString
spec doesn't differentiate between markdown
and plaintext
so we can just default to markdown
when converting.
// untested example
func MarkedStringsToMarkupContent(ms []MarkedString) (MarkupContent) {
var b strings.Builder
for i := range ms {
if ms[i].isRawString {
b.WriteString(ms[i].Value)
continue
}
b.WriteString("```")
b.WriteString(ms[i].Language)
b.WriteString("\n")
b.WriteString(ms[i].Value)
b.WriteString("\n")
b.WriteString("```")
if i != len(ms) -1 {
b.WriteString("\n")
}
}
return MarkupContent{
Kind: "markdown",
Value: b.String()
}
}