File tree Expand file tree Collapse file tree 2 files changed +23
-0
lines changed
Expand file tree Collapse file tree 2 files changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -264,6 +264,9 @@ func (entry *DocumentSymbolArrayOrSymbolInformationArray) UnmarshalJSON(raw []by
264264 if err := json .Unmarshal (raw , & intermediate ); err != nil {
265265 return err
266266 }
267+ if len (intermediate ) == 0 {
268+ return nil
269+ }
267270 discriminator := struct {
268271 Range * Range `json:"range,omitempty"`
269272 Location * Location `json:"location,omitempty"`
@@ -292,6 +295,16 @@ func (entry *DocumentSymbolArrayOrSymbolInformationArray) UnmarshalJSON(raw []by
292295 return nil
293296}
294297
298+ func (entry DocumentSymbolArrayOrSymbolInformationArray ) MarshalJSON () ([]byte , error ) {
299+ if entry .DocumentSymbolArray != nil {
300+ return json .Marshal (entry .DocumentSymbolArray )
301+ }
302+ if entry .SymbolInformationArray != nil {
303+ return json .Marshal (entry .SymbolInformationArray )
304+ }
305+ return []byte ("[]" ), nil
306+ }
307+
295308// ApplyWorkspaceEditParams structure according to LSP
296309type ApplyWorkspaceEditParams struct {
297310 Label string `json:"label,omitempty"`
Original file line number Diff line number Diff line change @@ -159,4 +159,14 @@ func TestVariousMessages(t *testing.T) {
159159 err := json .Unmarshal ([]byte (msg ), & symbol )
160160 require .NoError (t , err )
161161 })
162+
163+ t .Run ("EmptyDocumentSymbolMarshalUnmarshal" , func (t * testing.T ) {
164+ var symbol DocumentSymbolArrayOrSymbolInformationArray
165+ err := json .Unmarshal ([]byte (`[]` ), & symbol )
166+ require .NoError (t , err )
167+ data , err := json .Marshal (symbol )
168+ require .Equal (t , "[]" , string (data ))
169+ data , err = json .Marshal (& symbol )
170+ require .Equal (t , "[]" , string (data ))
171+ })
162172}
You can’t perform that action at this time.
0 commit comments