go-langserver icon indicating copy to clipboard operation
go-langserver copied to clipboard

Added MarkdownString type, Deprecated MarkedString #216

Open BugDiver opened this issue 6 years ago • 4 comments

Added interface MarkupContent for backword compatibility

BugDiver avatar Feb 15 '18 14:02 BugDiver

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?

BugDiver avatar Feb 27 '18 09:02 BugDiver

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.

keegancsmith avatar Feb 27 '18 10:02 keegancsmith

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.

keegancsmith avatar Feb 27 '18 12:02 keegancsmith

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()
	}
}

ianlopshire avatar Oct 04 '18 17:10 ianlopshire