Skip to content

Commit 0299452

Browse files
committed
feat(Handler/Completion): Support markdown description in resolve
Signed-off-by: Adam Tao <[email protected]>
1 parent 60fa62f commit 0299452

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

src/Common/Conversions.fs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ namespace CSharpLanguageServer.Common
22

33
open System
44
open Microsoft.CodeAnalysis
5+
open Microsoft.CodeAnalysis.Completion
56
open Microsoft.CodeAnalysis.Text
67
open Ionide.LanguageServerProtocol.Types
78
open FSharpPlus
@@ -205,3 +206,25 @@ module CompletionContext =
205206
| CompletionTriggerKind.TriggerCharacter -> Option.map Completion.CompletionTrigger.CreateInsertionTrigger ctx.TriggerCharacter
206207
| _ -> None)
207208
|> Option.defaultValue (Completion.CompletionTrigger.Invoke)
209+
210+
211+
module CompletionDescription =
212+
let toMarkdownString (description: CompletionDescription) : string =
213+
description.TaggedParts
214+
|> Seq.map (fun taggedText ->
215+
// WTF, if the developers of Roslyn don't want users to use TaggedText, why they set TaggedText to public?
216+
// If they indeed want users to use it, why they set lots of imported fields to internal?
217+
match taggedText.Tag with
218+
// TODO: Support code block?
219+
| "CodeBlockStart" -> "`` " + taggedText.Text
220+
| "CodeBlockEnd" -> " ``" + taggedText.Text
221+
| TextTags.LineBreak -> "\n\n"
222+
| _ -> taggedText.Text)
223+
|> String.concat ""
224+
225+
let toDocumentation (description: CompletionDescription) : Documentation =
226+
Documentation.Markup { Kind = MarkupKind.Markdown; Value = toMarkdownString description }
227+
228+
229+
module Documentation =
230+
let fromCompletionDescription = CompletionDescription.toDocumentation

src/Handlers/Completion.fs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,5 @@ module Completion =
136136
completionService.GetDescriptionAsync(doc, cachedItem, ct)
137137
|> map Option.ofObj
138138
|> Async.AwaitTask
139-
// TODO: make the doc as a markdown string instead of a plain text
140-
return { item with Documentation = description |> map (fun x -> Documentation.String x.Text) } |> success
139+
return { item with Documentation = description |> map Documentation.fromCompletionDescription } |> success
141140
}

0 commit comments

Comments
 (0)