@@ -37,6 +37,19 @@ public struct TextDocumentRegistrationOptions: RegistrationOptions, Hashable {
37
37
self . documentSelector = documentSelector
38
38
}
39
39
40
+ public init ( fromLSPAny value: LSPAny ) {
41
+ guard case let . dictionary( dict) = value else {
42
+ return
43
+ }
44
+
45
+ var documentSelector : DocumentSelector ?
46
+ if let value = dict [ " documentSelector " ] {
47
+ documentSelector = DocumentSelector ( fromLSPArray: value)
48
+ }
49
+
50
+ self . documentSelector = documentSelector
51
+ }
52
+
40
53
public func encodeIntoLSPAny( dict: inout [ String : LSPAny ] ) {
41
54
guard let documentSelector = documentSelector else { return }
42
55
dict [ " documentSelector " ] = documentSelector. encodeToLSPAny ( )
@@ -106,6 +119,80 @@ public struct SemanticTokensRegistrationOptions: RegistrationOptions, TextDocume
106
119
self . semanticTokenOptions = semanticTokenOptions
107
120
}
108
121
122
+ public init ? ( fromLSPAny value: LSPAny ) {
123
+ guard case let . dictionary( dict) = value else {
124
+ return nil
125
+ }
126
+
127
+ textDocumentRegistrationOptions = TextDocumentRegistrationOptions ( fromLSPAny: value)
128
+
129
+ var range : ValueOrBool < SemanticTokensOptions . SemanticTokensRangeOptions > ?
130
+ if let rangeLSPAny = dict [ " range " ] {
131
+ switch rangeLSPAny {
132
+ case let . bool( value) :
133
+ range = . bool( value)
134
+ case . dictionary:
135
+ range = . value( SemanticTokensOptions . SemanticTokensRangeOptions ( ) )
136
+ default :
137
+ break
138
+ }
139
+ }
140
+
141
+ var full : ValueOrBool < SemanticTokensOptions . SemanticTokensFullOptions > ?
142
+ if let fullLSPAny = dict [ " full " ] {
143
+ switch fullLSPAny {
144
+ case let . bool( value) :
145
+ full = . bool( value)
146
+ case let . dictionary( optionsDict) :
147
+ var delta : Bool ?
148
+ if let value = optionsDict [ " delta " ] ,
149
+ case let . bool( deltaValue) = value
150
+ {
151
+ delta = deltaValue
152
+ }
153
+
154
+ full = . value( SemanticTokensOptions . SemanticTokensFullOptions ( delta: delta) )
155
+ default :
156
+ break
157
+ }
158
+ }
159
+
160
+ guard case let . dictionary( legendDict) = dict [ " legend " ] else {
161
+ return nil
162
+ }
163
+
164
+ var tokenTypes : [ String ] = [ ]
165
+ if case let . array( types) = legendDict [ " tokenTypes " ] {
166
+ tokenTypes = types. compactMap {
167
+ if case let . string( string) = $0 {
168
+ return string
169
+ }
170
+ return nil
171
+ }
172
+ }
173
+
174
+ var tokenModifiers : [ String ] = [ ]
175
+ if case let . array( types) = legendDict [ " tokenModifiers " ] {
176
+ tokenModifiers = types. compactMap {
177
+ if case let . string( string) = $0 {
178
+ return string
179
+ }
180
+ return nil
181
+ }
182
+ }
183
+
184
+ let legend = SemanticTokensLegend (
185
+ tokenTypes: tokenTypes,
186
+ tokenModifiers: tokenModifiers
187
+ )
188
+
189
+ semanticTokenOptions = SemanticTokensOptions (
190
+ legend: legend,
191
+ range: range,
192
+ full: full
193
+ )
194
+ }
195
+
109
196
public func encodeIntoLSPAny( dict: inout [ String : LSPAny ] ) {
110
197
textDocumentRegistrationOptions. encodeIntoLSPAny ( dict: & dict)
111
198
let legend = semanticTokenOptions. legend
0 commit comments