1// Copyright 2022 The Go Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style
3// license that can be found in the LICENSE file.
12// DocumentChange is a union of various file edit operations.
14// Exactly one field of this struct is non-nil; see [DocumentChange.Valid].
16// See https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#resourceChanges
17type DocumentChange struct {
18 TextDocumentEdit *TextDocumentEdit
19 CreateFile *CreateFile
20 RenameFile *RenameFile
21 DeleteFile *DeleteFile
24// Valid reports whether the DocumentChange sum-type value is valid,
25// that is, exactly one of create, delete, edit, or rename.
26func (ch DocumentChange) Valid() bool {
28 if ch.TextDocumentEdit != nil {
31 if ch.CreateFile != nil {
34 if ch.RenameFile != nil {
37 if ch.DeleteFile != nil {
43func (d *DocumentChange) UnmarshalJSON(data []byte) error {
45 if err := json.Unmarshal(data, &m); err != nil {
49 if _, ok := m["textDocument"]; ok {
50 d.TextDocumentEdit = new(TextDocumentEdit)
51 return json.Unmarshal(data, d.TextDocumentEdit)
54 // The {Create,Rename,Delete}File types all share a 'kind' field.
58 d.CreateFile = new(CreateFile)
59 return json.Unmarshal(data, d.CreateFile)
61 d.RenameFile = new(RenameFile)
62 return json.Unmarshal(data, d.RenameFile)
64 d.DeleteFile = new(DeleteFile)
65 return json.Unmarshal(data, d.DeleteFile)
67 return fmt.Errorf("DocumentChanges: unexpected kind: %q", kind)
70func (d *DocumentChange) MarshalJSON() ([]byte, error) {
71 if d.TextDocumentEdit != nil {
72 return json.Marshal(d.TextDocumentEdit)
73 } else if d.CreateFile != nil {
74 return json.Marshal(d.CreateFile)
75 } else if d.RenameFile != nil {
76 return json.Marshal(d.RenameFile)
77 } else if d.DeleteFile != nil {
78 return json.Marshal(d.DeleteFile)
80 return nil, fmt.Errorf("empty DocumentChanges union value")
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list