-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathDocumentation.fs
127 lines (104 loc) · 3.88 KB
/
Documentation.fs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
module Glutinum.Converter.Reader.Documentation
open Glutinum.Converter.GlueAST
open Glutinum.Converter.Reader.Utils
open Glutinum.Converter.Reader.Types
open TypeScript
open Fable.Core.JsInterop
open System
let private readDocumentation
(summary: ResizeArray<Ts.SymbolDisplayPart>)
(jsDocTags: ResizeArray<Ts.JSDocTag>)
=
let summary =
let content =
summary |> (Some >> ts.displayPartsToString) |> String.splitLines
if List.forall String.IsNullOrWhiteSpace content then
None
else
Some(GlueComment.Summary content)
let jsDocTags =
jsDocTags
|> Seq.choose (fun tag ->
match tag.kind with
| Ts.SyntaxKind.JSDocReturnTag ->
match tag.comment with
| Some comment ->
ts.getTextOfJSDocComment comment
|> Option.defaultValue ""
|> GlueComment.Returns
|> Some
| None -> None
| Ts.SyntaxKind.JSDocParameterTag ->
let parameterTag = tag :?> Ts.JSDocParameterTag
let identifier = unbox<Ts.Identifier> parameterTag.name
let content =
match parameterTag.comment with
| Some comment -> ts.getTextOfJSDocComment comment
| None -> None
{
Name = identifier.getText ()
Content = content
}
|> GlueComment.Param
|> Some
| Ts.SyntaxKind.JSDocDeprecatedTag ->
match tag.comment with
| Some comment ->
ts.getTextOfJSDocComment comment
|> GlueComment.Deprecated
|> Some
// We want to keep the deprecated tag even if there is no comment
// as it is still useful information
| None -> GlueComment.Deprecated None |> Some
| Ts.SyntaxKind.JSDocTag ->
match tag.tagName.getText () with
| "remarks" ->
match tag.comment with
| Some comment ->
ts.getTextOfJSDocComment comment
|> Option.defaultValue ""
|> GlueComment.Remarks
|> Some
| None -> None
| "defaultValue" ->
match tag.comment with
| Some comment ->
ts.getTextOfJSDocComment comment
|> Option.defaultValue ""
|> GlueComment.DefaultValue
|> Some
| None -> None
| "example" ->
match tag.comment with
| Some comment ->
ts.getTextOfJSDocComment comment
|> Option.defaultValue ""
|> GlueComment.Example
|> Some
| None -> None
| _ -> None
)
|> Seq.toList
[
match summary with
| Some summary -> summary
| None -> ()
yield! jsDocTags
]
let readDocumentationForSignature
(reader: ITypeScriptReader)
(declaration: Ts.Declaration)
=
match reader.checker.getSignatureFromDeclaration declaration with
| Some signature ->
readDocumentation
(signature.getDocumentationComment (Some reader.checker))
(ts.getJSDocTags declaration)
| None -> []
let readDocumentationForNode (reader: ITypeScriptReader) (node: Ts.Node) =
match reader.checker.getSymbolAtLocation node with
| Some symbol ->
readDocumentation
(symbol.getDocumentationComment (Some reader.checker))
(ts.getJSDocTags node.parent)
| None -> []