|
| 1 | +namespace FsAutoComplete |
| 2 | +open LSP.Types |
| 3 | +open LSP.BaseTypes |
| 4 | +open FSharp.Compiler.Text |
| 5 | +open FSharp.Compiler.Tokenization |
| 6 | +open FSharp.Compiler.EditorServices |
| 7 | +open FSharp.Compiler.Symbols |
| 8 | + |
| 9 | +module KeywordList = |
| 10 | + open FSharp.Data |
| 11 | + |
| 12 | + let keywordDescriptions = FSharpKeywords.KeywordsWithDescription |> dict |
| 13 | + |
| 14 | + let keywordTooltips = |
| 15 | + keywordDescriptions |
| 16 | + |> Seq.map (fun kv -> |
| 17 | + let lines = kv.Value.Replace("\r\n", "\n").Split('\n') |
| 18 | + |
| 19 | + let allLines = |
| 20 | + Array.concat [| [| "<summary>" |] |
| 21 | + lines |
| 22 | + [| "</summary>" |] |] |
| 23 | + |
| 24 | + let tip = |
| 25 | + ToolTipText [ ToolTipElement.Single( |
| 26 | + [| TaggedText.tagText kv.Key |], |
| 27 | + FSharpXmlDoc.FromXmlText(FSharp.Compiler.Xml.XmlDoc(allLines, Range.Zero)) |
| 28 | + ) ] |
| 29 | + |
| 30 | + kv.Key, tip) |
| 31 | + |> dict |
| 32 | + |
| 33 | + let hashDirectives = |
| 34 | + [ |
| 35 | + "r", "References an assembly" |
| 36 | + "load", "Reads a source file, compiles it, and runs it." |
| 37 | + "I", "Specifies an assembly search path in quotation marks." |
| 38 | + "light", "Enables or disables lightweight syntax, for compatibility with other versions of ML" |
| 39 | + "if", "Supports conditional compilation" |
| 40 | + "else", "Supports conditional compilation" |
| 41 | + "endif", "Supports conditional compilation" |
| 42 | + "nowarn", "Disables a compiler warning or warnings" |
| 43 | + "line", "Indicates the original source code line" |
| 44 | + ] |
| 45 | + |> dict |
| 46 | + |
| 47 | + let hashSymbolCompletionItems = |
| 48 | + hashDirectives |
| 49 | + |> Seq.map (fun kv -> |
| 50 | + { defaultCompletionItem with |
| 51 | + detail=Some kv.Key |
| 52 | + kind = Some CompletionItemKind.Keyword |
| 53 | + insertText = Some kv.Key |
| 54 | + filterText = Some kv.Key |
| 55 | + sortText = Some kv.Key |
| 56 | + documentation = Some( {kind=MarkupKind.Markdown;value=kv.Value}) |
| 57 | + label = "#" + kv.Key }) |
| 58 | + |> Seq.toArray |
| 59 | + |
| 60 | + let allKeywords: string list = |
| 61 | + keywordDescriptions |
| 62 | + |> Seq.map ((|KeyValue|) >> fst) |
| 63 | + |> Seq.toList |
| 64 | + |
| 65 | + let keywordCompletionItems = |
| 66 | + allKeywords |
| 67 | + |> List.mapi (fun id k -> |
| 68 | + {defaultCompletionItem with |
| 69 | + label = k |
| 70 | + detail= Some k |
| 71 | + data= JsonValue.Record [|"FullName", JsonValue.String(k)|] |
| 72 | + CompletionItem.kind = Some CompletionItemKind.Keyword |
| 73 | + documentation =Some ({kind=MarkupKind.Markdown;value=keywordDescriptions[k]}) |
| 74 | + sortText = None//Some(sprintf "1000000%d" id) |
| 75 | + filterText = Some k |
| 76 | + insertText = Some k |
| 77 | + }) |
| 78 | + |
0 commit comments