| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
package main |
| 6 |
|
| 7 |
import ( |
| 8 |
"fmt" |
| 9 |
"sort" |
| 10 |
) |
| 11 |
|
| 12 |
|
| 13 |
type Model struct { |
| 14 |
Version Metadata `json:"metaData"` |
| 15 |
Requests []*Request `json:"requests"` |
| 16 |
Notifications []*Notification `json:"notifications"` |
| 17 |
Structures []*Structure `json:"structures"` |
| 18 |
Enumerations []*Enumeration `json:"enumerations"` |
| 19 |
TypeAliases []*TypeAlias `json:"typeAliases"` |
| 20 |
Line int `json:"line"` |
| 21 |
} |
| 22 |
|
| 23 |
|
| 24 |
type Metadata struct { |
| 25 |
Version string `json:"version"` |
| 26 |
Line int `json:"line"` |
| 27 |
} |
| 28 |
|
| 29 |
|
| 30 |
type Request struct { |
| 31 |
Documentation string `json:"documentation"` |
| 32 |
ErrorData *Type `json:"errorData"` |
| 33 |
Direction string `json:"messageDirection"` |
| 34 |
Method string `json:"method"` |
| 35 |
Params *Type `json:"params"` |
| 36 |
PartialResult *Type `json:"partialResult"` |
| 37 |
Proposed bool `json:"proposed"` |
| 38 |
RegistrationMethod string `json:"registrationMethod"` |
| 39 |
RegistrationOptions *Type `json:"registrationOptions"` |
| 40 |
Result *Type `json:"result"` |
| 41 |
Since string `json:"since"` |
| 42 |
Line int `json:"line"` |
| 43 |
} |
| 44 |
|
| 45 |
|
| 46 |
type Notification struct { |
| 47 |
Documentation string `json:"documentation"` |
| 48 |
Direction string `json:"messageDirection"` |
| 49 |
Method string `json:"method"` |
| 50 |
Params *Type `json:"params"` |
| 51 |
Proposed bool `json:"proposed"` |
| 52 |
RegistrationMethod string `json:"registrationMethod"` |
| 53 |
RegistrationOptions *Type `json:"registrationOptions"` |
| 54 |
Since string `json:"since"` |
| 55 |
Line int `json:"line"` |
| 56 |
} |
| 57 |
|
| 58 |
|
| 59 |
type Structure struct { |
| 60 |
Documentation string `json:"documentation"` |
| 61 |
Extends []*Type `json:"extends"` |
| 62 |
Mixins []*Type `json:"mixins"` |
| 63 |
Name string `json:"name"` |
| 64 |
Properties []NameType `json:"properties"` |
| 65 |
Proposed bool `json:"proposed"` |
| 66 |
Since string `json:"since"` |
| 67 |
Line int `json:"line"` |
| 68 |
} |
| 69 |
|
| 70 |
|
| 71 |
type Enumeration struct { |
| 72 |
Documentation string `json:"documentation"` |
| 73 |
Name string `json:"name"` |
| 74 |
Proposed bool `json:"proposed"` |
| 75 |
Since string `json:"since"` |
| 76 |
SupportsCustomValues bool `json:"supportsCustomValues"` |
| 77 |
Type *Type `json:"type"` |
| 78 |
Values []NameValue `json:"values"` |
| 79 |
Line int `json:"line"` |
| 80 |
} |
| 81 |
|
| 82 |
|
| 83 |
type TypeAlias struct { |
| 84 |
Documentation string `json:"documentation"` |
| 85 |
Deprecated string `json:"deprecated"` |
| 86 |
Name string `json:"name"` |
| 87 |
Proposed bool `json:"proposed"` |
| 88 |
Since string `json:"since"` |
| 89 |
Type *Type `json:"type"` |
| 90 |
Line int `json:"line"` |
| 91 |
} |
| 92 |
|
| 93 |
|
| 94 |
type NameValue struct { |
| 95 |
Documentation string `json:"documentation"` |
| 96 |
Name string `json:"name"` |
| 97 |
Proposed bool `json:"proposed"` |
| 98 |
Since string `json:"since"` |
| 99 |
Value any `json:"value"` |
| 100 |
Line int `json:"line"` |
| 101 |
} |
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
type Type struct { |
| 106 |
Kind string `json:"kind"` |
| 107 |
Items []*Type `json:"items"` |
| 108 |
Element *Type `json:"element"` |
| 109 |
Name string `json:"name"` |
| 110 |
Key *Type `json:"key"` |
| 111 |
Value any `json:"value"` |
| 112 |
Line int `json:"line"` |
| 113 |
} |
| 114 |
|
| 115 |
|
| 116 |
type ParseLiteral struct { |
| 117 |
Properties `json:"properties"` |
| 118 |
} |
| 119 |
|
| 120 |
|
| 121 |
type NameType struct { |
| 122 |
Name string `json:"name"` |
| 123 |
Type *Type `json:"type"` |
| 124 |
Optional bool `json:"optional"` |
| 125 |
Documentation string `json:"documentation"` |
| 126 |
Deprecated string `json:"deprecated"` |
| 127 |
Since string `json:"since"` |
| 128 |
Proposed bool `json:"proposed"` |
| 129 |
Line int `json:"line"` |
| 130 |
} |
| 131 |
|
| 132 |
|
| 133 |
type Properties []NameType |
| 134 |
|
| 135 |
|
| 136 |
func addLineNumbers(buf []byte) []byte { |
| 137 |
var ans []byte |
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
for linecnt, i := 1, 0; i < len(buf); i++ { |
| 143 |
ans = append(ans, buf[i]) |
| 144 |
switch buf[i] { |
| 145 |
case '{': |
| 146 |
if buf[i+1] == '\n' { |
| 147 |
ans = append(ans, fmt.Sprintf(`"line": %d, `, linecnt)...) |
| 148 |
|
| 149 |
|
| 150 |
} |
| 151 |
case '\n': |
| 152 |
linecnt++ |
| 153 |
} |
| 154 |
} |
| 155 |
return ans |
| 156 |
} |
| 157 |
|
| 158 |
type sortedMap[T any] map[string]T |
| 159 |
|
| 160 |
func (s sortedMap[T]) keys() []string { |
| 161 |
var keys []string |
| 162 |
for k := range s { |
| 163 |
keys = append(keys, k) |
| 164 |
} |
| 165 |
sort.Strings(keys) |
| 166 |
return keys |
| 167 |
} |