Skip to content

Commit 8a7080e

Browse files
committed
text: remove unnecessary TextDocumentWillSaveEvent type
1 parent 840bdb8 commit 8a7080e

File tree

5 files changed

+13
-155
lines changed

5 files changed

+13
-155
lines changed

text.go

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -90,28 +90,6 @@ func (t TextDocumentSaveReason) String() string {
9090
}
9191
}
9292

93-
// TextDocumentWillSaveEvent is.
94-
type TextDocumentWillSaveEvent struct {
95-
// Document is the document that will be saved.
96-
Document TextDocument `json:"document"`
97-
98-
// Reason is the reason why save was triggered.
99-
Reason TextDocumentSaveReason `json:"reason"`
100-
}
101-
102-
// TextDocumentContentChangeEvent an event describing a change to a text document. If range and rangeLength are omitted
103-
// the new text is considered to be the full content of the document.
104-
type TextDocumentContentChangeEvent struct {
105-
// Range is the range of the document that changed.
106-
Range *Range `json:"range,omitempty"`
107-
108-
// RangeLength is the length of the range that got replaced.
109-
RangeLength float64 `json:"rangeLength,omitempty"`
110-
111-
// Text is the new text of the document.
112-
Text string `json:"text"`
113-
}
114-
11593
// TextDocumentChangeRegistrationOptions describe options to be used when registering for text document change events.
11694
type TextDocumentChangeRegistrationOptions struct {
11795
TextDocumentRegistrationOptions
@@ -140,6 +118,19 @@ type DidSaveTextDocumentParams struct {
140118
TextDocument TextDocumentIdentifier `json:"textDocument"`
141119
}
142120

121+
// TextDocumentContentChangeEvent an event describing a change to a text document. If range and rangeLength are omitted
122+
// the new text is considered to be the full content of the document.
123+
type TextDocumentContentChangeEvent struct {
124+
// Range is the range of the document that changed.
125+
Range *Range `json:"range,omitempty"`
126+
127+
// RangeLength is the length of the range that got replaced.
128+
RangeLength float64 `json:"rangeLength,omitempty"`
129+
130+
// Text is the new text of the document.
131+
Text string `json:"text"`
132+
}
133+
143134
// TextDocumentSaveRegistrationOptions TextDocumentSave Registration options.
144135
type TextDocumentSaveRegistrationOptions struct {
145136
TextDocumentRegistrationOptions

text_gojay.go

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -151,35 +151,6 @@ var (
151151
_ gojay.UnmarshalerJSONObject = (*TextDocumentChangeEvent)(nil)
152152
)
153153

154-
// MarshalJSONObject implements gojay.MarshalerJSONObject.
155-
func (v *TextDocumentWillSaveEvent) MarshalJSONObject(enc *gojay.Encoder) {
156-
enc.ObjectKey(keyDocument, &v.Document)
157-
enc.Float64Key(keyReason, float64(v.Reason))
158-
}
159-
160-
// IsNil returns wether the structure is nil value or not.
161-
func (v *TextDocumentWillSaveEvent) IsNil() bool { return v == nil }
162-
163-
// UnmarshalJSONObject implements gojay's UnmarshalerJSONObject.
164-
func (v *TextDocumentWillSaveEvent) UnmarshalJSONObject(dec *gojay.Decoder, k string) error {
165-
switch k {
166-
case keyDocument:
167-
return dec.Object(&v.Document)
168-
case keyReason:
169-
return dec.Float64((*float64)(&v.Reason))
170-
}
171-
return nil
172-
}
173-
174-
// NKeys returns the number of keys to unmarshal.
175-
func (v *TextDocumentWillSaveEvent) NKeys() int { return 2 }
176-
177-
// compile time check whether the TextDocumentWillSaveEvent implements a gojay.MarshalerJSONObject and gojay.UnmarshalerJSONObject interfaces.
178-
var (
179-
_ gojay.MarshalerJSONObject = (*TextDocumentWillSaveEvent)(nil)
180-
_ gojay.UnmarshalerJSONObject = (*TextDocumentWillSaveEvent)(nil)
181-
)
182-
183154
// MarshalJSONObject implements gojay.MarshalerJSONObject.
184155
func (v *TextDocumentContentChangeEvent) MarshalJSONObject(enc *gojay.Encoder) {
185156
enc.ObjectKeyOmitEmpty(keyRange, v.Range)

text_gojay_test.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,6 @@ func TestTextDocumentChangeEvent(t *testing.T) {
2828
testTextDocumentChangeEvent(t, gojay.Marshal, gojay.Unsafe.Unmarshal)
2929
}
3030

31-
func TestTextDocumentWillSaveEvent(t *testing.T) {
32-
testTextDocumentWillSaveEvent(t, gojay.Marshal, gojay.Unsafe.Unmarshal)
33-
}
34-
3531
func TestTextDocumentContentChangeEvent(t *testing.T) {
3632
testTextDocumentContentChangeEvent(t, gojay.Marshal, gojay.Unsafe.Unmarshal)
3733
}

text_json_test.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,6 @@ func TestTextDocumentChangeEvent(t *testing.T) {
2727
testTextDocumentChangeEvent(t, json.Marshal, json.Unmarshal)
2828
}
2929

30-
func TestTextDocumentWillSaveEvent(t *testing.T) {
31-
testTextDocumentWillSaveEvent(t, json.Marshal, json.Unmarshal)
32-
}
33-
3430
func TestTextDocumentContentChangeEvent(t *testing.T) {
3531
testTextDocumentContentChangeEvent(t, json.Marshal, json.Unmarshal)
3632
}

text_test.go

Lines changed: 0 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -445,102 +445,6 @@ func TestTextDocumentSaveReason_String(t *testing.T) {
445445
}
446446
}
447447

448-
func testTextDocumentWillSaveEvent(t *testing.T, marshal marshalFunc, unmarshal unmarshalFunc) {
449-
const (
450-
want = `{"document":{"uri":"file:///path/to/test.go","languageId":"go","version":1,"lineCount":50},"reason":2}`
451-
wantInvalid = `{"document":{"uri":"file:///path/to/invalid.go","languageId":"typescript","version":2,"lineCount":100},"reason":1}`
452-
)
453-
wantType := TextDocumentWillSaveEvent{
454-
Document: TextDocument{
455-
URI: uri.File("/path/to/test.go"),
456-
LanguageID: "go",
457-
Version: 1,
458-
LineCount: 50,
459-
},
460-
Reason: AfterDelay,
461-
}
462-
463-
t.Run("Marshal", func(t *testing.T) {
464-
tests := []struct {
465-
name string
466-
field TextDocumentWillSaveEvent
467-
want string
468-
wantMarshalErr bool
469-
wantErr bool
470-
}{
471-
{
472-
name: "Valid",
473-
field: wantType,
474-
want: want,
475-
wantMarshalErr: false,
476-
wantErr: false,
477-
},
478-
{
479-
name: "Invalid",
480-
field: wantType,
481-
want: wantInvalid,
482-
wantMarshalErr: false,
483-
wantErr: true,
484-
},
485-
}
486-
for _, tt := range tests {
487-
tt := tt
488-
t.Run(tt.name, func(t *testing.T) {
489-
t.Parallel()
490-
491-
got, err := marshal(&tt.field)
492-
if (err != nil) != tt.wantMarshalErr {
493-
t.Fatal(err)
494-
}
495-
496-
if diff := cmp.Diff(string(got), tt.want); (diff != "") != tt.wantErr {
497-
t.Errorf("%s: wantErr: %t\n(-got, +want)\n%s", tt.name, tt.wantErr, diff)
498-
}
499-
})
500-
}
501-
})
502-
503-
t.Run("Unmarshal", func(t *testing.T) {
504-
tests := []struct {
505-
name string
506-
field string
507-
want TextDocumentWillSaveEvent
508-
wantUnmarshalErr bool
509-
wantErr bool
510-
}{
511-
{
512-
name: "Valid",
513-
field: want,
514-
want: wantType,
515-
wantUnmarshalErr: false,
516-
wantErr: false,
517-
},
518-
{
519-
name: "Invalid",
520-
field: wantInvalid,
521-
want: wantType,
522-
wantUnmarshalErr: false,
523-
wantErr: true,
524-
},
525-
}
526-
for _, tt := range tests {
527-
tt := tt
528-
t.Run(tt.name, func(t *testing.T) {
529-
t.Parallel()
530-
531-
var got TextDocumentWillSaveEvent
532-
if err := unmarshal([]byte(tt.field), &got); (err != nil) != tt.wantUnmarshalErr {
533-
t.Fatal(err)
534-
}
535-
536-
if diff := cmp.Diff(got, tt.want); (diff != "") != tt.wantErr {
537-
t.Errorf("%s: wantErr: %t\n(-got, +want)\n%s", tt.name, tt.wantErr, diff)
538-
}
539-
})
540-
}
541-
})
542-
}
543-
544448
func testTextDocumentContentChangeEvent(t *testing.T, marshal marshalFunc, unmarshal unmarshalFunc) {
545449
const (
546450
want = `{"range":{"start":{"line":25,"character":1},"end":{"line":25,"character":3}},"rangeLength":2,"text":"testText"}`

0 commit comments

Comments
 (0)