@@ -230,8 +230,8 @@ func (f *FourslashTest) initialize(t *testing.T, capabilities *lsproto.ClientCap
230
230
params := & lsproto.InitializeParams {}
231
231
params .Capabilities = getCapabilitiesWithDefaults (capabilities )
232
232
// !!! check for errors?
233
- f . sendRequest (t , lsproto .MethodInitialize , params )
234
- f . sendNotification (t , lsproto .MethodInitialized , & lsproto.InitializedParams {})
233
+ sendRequest (t , f , lsproto .InitializeInfo , params )
234
+ sendNotification (t , f , lsproto .InitializedInfo , & lsproto.InitializedParams {})
235
235
}
236
236
237
237
var (
@@ -267,20 +267,25 @@ func getCapabilitiesWithDefaults(capabilities *lsproto.ClientCapabilities) *lspr
267
267
return & capabilitiesWithDefaults
268
268
}
269
269
270
- func ( f * FourslashTest ) sendRequest (t * testing.T , method lsproto.Method , params any ) * lsproto.Message {
270
+ func sendRequest [ Params , Resp any ] (t * testing.T , f * FourslashTest , mapping lsproto.RequestInfo [ Params , Resp ], params Params ) ( * lsproto.Message , Resp , bool ) {
271
271
id := f .nextID ()
272
272
req := lsproto .NewRequestMessage (
273
- method ,
273
+ mapping . Method ,
274
274
lsproto .NewID (lsproto.IntegerOrString {Integer : & id }),
275
275
params ,
276
276
)
277
277
f .writeMsg (t , req .Message ())
278
- return f .readMsg (t )
278
+ resp := f .readMsg (t )
279
+ if resp == nil {
280
+ return nil , * new (Resp ), false
281
+ }
282
+ result , ok := resp .AsResponse ().Result .(Resp )
283
+ return resp , result , ok
279
284
}
280
285
281
- func ( f * FourslashTest ) sendNotification (t * testing.T , method lsproto.Method , params any ) {
286
+ func sendNotification [ Params any ] (t * testing.T , f * FourslashTest , info lsproto.NotificationInfo [ Params ] , params Params ) {
282
287
notification := lsproto .NewNotificationMessage (
283
- method ,
288
+ info . Method ,
284
289
params ,
285
290
)
286
291
f .writeMsg (t , notification .Message ())
@@ -439,7 +444,7 @@ func (f *FourslashTest) openFile(t *testing.T, filename string) {
439
444
t .Fatalf ("File %s not found in test data" , filename )
440
445
}
441
446
f .activeFilename = filename
442
- f . sendNotification (t , lsproto .MethodTextDocumentDidOpen , & lsproto.DidOpenTextDocumentParams {
447
+ sendNotification (t , f , lsproto .TextDocumentDidOpenInfo , & lsproto.DidOpenTextDocumentParams {
443
448
TextDocument : & lsproto.TextDocumentItem {
444
449
Uri : ls .FileNameToDocumentURI (filename ),
445
450
LanguageId : getLanguageKind (filename ),
@@ -553,17 +558,14 @@ func (f *FourslashTest) verifyCompletionsWorker(t *testing.T, expected *Completi
553
558
TextDocumentPositionParams : f .currentTextDocumentPositionParams (),
554
559
Context : & lsproto.CompletionContext {},
555
560
}
556
- resMsg := f . sendRequest (t , lsproto .MethodTextDocumentCompletion , params )
561
+ resMsg , result , resultOk := sendRequest (t , f , lsproto .TextDocumentCompletionInfo , params )
557
562
if resMsg == nil {
558
563
t .Fatalf (prefix + "Nil response received for completion request" , f .lastKnownMarkerName )
559
564
}
560
- result := resMsg .AsResponse ().Result
561
- switch result := result .(type ) {
562
- case * lsproto.CompletionList :
563
- f .verifyCompletionsResult (t , f .currentCaretPosition , result , expected , prefix )
564
- default :
565
- t .Fatalf (prefix + "Unexpected response type for completion request: %v" , result )
565
+ if ! resultOk {
566
+ t .Fatalf (prefix + "Unexpected response type for completion request: %T" , resMsg .AsResponse ().Result )
566
567
}
568
+ f .verifyCompletionsResult (t , f .currentCaretPosition , result .CompletionList , expected , prefix )
567
569
}
568
570
569
571
func (f * FourslashTest ) verifyCompletionsResult (
@@ -741,15 +743,14 @@ var completionIgnoreOpts = cmp.FilterPath(
741
743
742
744
func (f * FourslashTest ) verifyCompletionItem (t * testing.T , prefix string , actual * lsproto.CompletionItem , expected * lsproto.CompletionItem ) {
743
745
if expected .Detail != nil || expected .Documentation != nil {
744
- response := f . sendRequest (t , lsproto .MethodCompletionItemResolve , actual )
745
- if response == nil {
746
+ resMsg , result , resultOk := sendRequest (t , f , lsproto .CompletionItemResolveInfo , actual )
747
+ if resMsg == nil {
746
748
t .Fatal (prefix + "Expected non-nil response for completion item resolve, got nil" )
747
749
}
748
- resolvedItem , ok := response .AsResponse ().Result .(* lsproto.CompletionItem )
749
- if ! ok {
750
- t .Fatalf (prefix + "Expected response to be *lsproto.CompletionItem, got %T" , response .AsResponse ().Result )
750
+ if ! resultOk {
751
+ t .Fatalf (prefix + "Unexpected response type for completion item resolve: %T" , resMsg .AsResponse ().Result )
751
752
}
752
- actual = resolvedItem
753
+ actual = result
753
754
}
754
755
assertDeepEqual (t , actual , expected , prefix , completionIgnoreOpts )
755
756
if expected .Kind != nil {
@@ -808,28 +809,27 @@ func (f *FourslashTest) VerifyBaselineFindAllReferences(
808
809
TextDocumentPositionParams : f .currentTextDocumentPositionParams (),
809
810
Context : & lsproto.ReferenceContext {},
810
811
}
811
- resMsg := f . sendRequest (t , lsproto .MethodTextDocumentReferences , params )
812
+ resMsg , result , resultOk := sendRequest (t , f , lsproto .TextDocumentReferencesInfo , params )
812
813
if resMsg == nil {
813
814
if f .lastKnownMarkerName == nil {
814
815
t .Fatalf ("Nil response received for references request at pos %v" , f .currentCaretPosition )
815
816
} else {
816
817
t .Fatalf ("Nil response received for references request at marker '%s'" , * f .lastKnownMarkerName )
817
818
}
818
819
}
819
-
820
- result := resMsg .AsResponse ().Result
821
- if resultAsLocation , ok := result .([]* lsproto.Location ); ok {
822
- f .baseline .addResult ("findAllReferences" , f .getBaselineForLocationsWithFileContents (resultAsLocation , baselineFourslashLocationsOptions {
823
- marker : markerOrRange .GetMarker (),
824
- markerName : "/*FIND ALL REFS*/" ,
825
- }))
826
- } else {
820
+ if ! resultOk {
827
821
if f .lastKnownMarkerName == nil {
828
- t .Fatalf ("Unexpected references response type at pos %v: %T" , f .currentCaretPosition , result )
822
+ t .Fatalf ("Unexpected references response type at pos %v: %T" , f .currentCaretPosition , resMsg . AsResponse (). Result )
829
823
} else {
830
- t .Fatalf ("Unexpected references response type at marker '%s': %T" , * f .lastKnownMarkerName , result )
824
+ t .Fatalf ("Unexpected references response type at marker '%s': %T" , * f .lastKnownMarkerName , resMsg . AsResponse (). Result )
831
825
}
832
826
}
827
+
828
+ f .baseline .addResult ("findAllReferences" , f .getBaselineForLocationsWithFileContents (* result , baselineFourslashLocationsOptions {
829
+ marker : markerOrRange .GetMarker (),
830
+ markerName : "/*FIND ALL REFS*/" ,
831
+ }))
832
+
833
833
}
834
834
835
835
baseline .Run (t , f .baseline .getBaselineFileName (), f .baseline .content .String (), baseline.Options {})
@@ -863,39 +863,38 @@ func (f *FourslashTest) VerifyBaselineGoToDefinition(
863
863
params := & lsproto.DefinitionParams {
864
864
TextDocumentPositionParams : f .currentTextDocumentPositionParams (),
865
865
}
866
- resMsg := f .sendRequest (t , lsproto .MethodTextDocumentDefinition , params )
866
+
867
+ resMsg , result , resultOk := sendRequest (t , f , lsproto .TextDocumentDefinitionInfo , params )
867
868
if resMsg == nil {
868
869
if f .lastKnownMarkerName == nil {
869
870
t .Fatalf ("Nil response received for definition request at pos %v" , f .currentCaretPosition )
870
871
} else {
871
872
t .Fatalf ("Nil response received for definition request at marker '%s'" , * f .lastKnownMarkerName )
872
873
}
873
874
}
874
-
875
- result := resMsg .AsResponse ().Result
876
- if resultAsLocOrLocations , ok := result .(* lsproto.LocationOrLocations ); ok {
877
- var resultAsLocations []* lsproto.Location
878
- if resultAsLocOrLocations != nil {
879
- if resultAsLocOrLocations .Locations != nil {
880
- resultAsLocations = core .Map (* resultAsLocOrLocations .Locations , func (loc lsproto.Location ) * lsproto.Location {
881
- return & loc
882
- })
883
- } else {
884
- resultAsLocations = []* lsproto.Location {resultAsLocOrLocations .Location }
885
- }
875
+ if ! resultOk {
876
+ if f .lastKnownMarkerName == nil {
877
+ t .Fatalf ("Unexpected definition response type at pos %v: %T" , f .currentCaretPosition , resMsg .AsResponse ().Result )
878
+ } else {
879
+ t .Fatalf ("Unexpected definition response type at marker '%s': %T" , * f .lastKnownMarkerName , resMsg .AsResponse ().Result )
886
880
}
881
+ }
887
882
888
- f .baseline .addResult ("goToDefinition" , f .getBaselineForLocationsWithFileContents (resultAsLocations , baselineFourslashLocationsOptions {
889
- marker : markerOrRange .GetMarker (),
890
- markerName : "/*GO TO DEFINITION*/" ,
891
- }))
892
- } else {
893
- if f .lastKnownMarkerName == nil {
894
- t .Fatalf ("Unexpected definition response type at pos %v: %T" , f .currentCaretPosition , result )
883
+ var resultAsLocations []lsproto.Location
884
+ if result != nil {
885
+ if result .Locations != nil {
886
+ resultAsLocations = * result .Locations
887
+ } else if result .Location != nil {
888
+ resultAsLocations = []lsproto.Location {* result .Location }
895
889
} else {
896
- t .Fatalf ("Unexpected definition response type at marker '%s': %T" , * f .lastKnownMarkerName , result )
890
+ t .Fatalf ("Unexpected definition response type at marker '%s': %T" , * f .lastKnownMarkerName , result . DefinitionLinks )
897
891
}
898
892
}
893
+
894
+ f .baseline .addResult ("goToDefinition" , f .getBaselineForLocationsWithFileContents (resultAsLocations , baselineFourslashLocationsOptions {
895
+ marker : markerOrRange .GetMarker (),
896
+ markerName : "/*GO TO DEFINITION*/" ,
897
+ }))
899
898
}
900
899
901
900
baseline .Run (t , f .baseline .getBaselineFileName (), f .baseline .content .String (), baseline.Options {})
@@ -1069,14 +1068,14 @@ func (f *FourslashTest) editScript(t *testing.T, fileName string, start int, end
1069
1068
if err != nil {
1070
1069
panic (fmt .Sprintf ("Failed to write file %s: %v" , fileName , err ))
1071
1070
}
1072
- f . sendNotification (t , lsproto .MethodTextDocumentDidChange , & lsproto.DidChangeTextDocumentParams {
1071
+ sendNotification (t , f , lsproto .TextDocumentDidChangeInfo , & lsproto.DidChangeTextDocumentParams {
1073
1072
TextDocument : lsproto.VersionedTextDocumentIdentifier {
1074
1073
TextDocumentIdentifier : lsproto.TextDocumentIdentifier {
1075
1074
Uri : ls .FileNameToDocumentURI (fileName ),
1076
1075
},
1077
1076
Version : script .version ,
1078
1077
},
1079
- ContentChanges : []lsproto.TextDocumentContentChangeEvent {
1078
+ ContentChanges : []lsproto.TextDocumentContentChangePartialOrTextDocumentContentChangeWholeDocument {
1080
1079
{
1081
1080
TextDocumentContentChangePartial : & lsproto.TextDocumentContentChangePartial {
1082
1081
Range : changeRange ,
0 commit comments