@@ -245,6 +245,12 @@ var (
245245 ItemDefaults : & []string {"commitCharacters" , "editRange" },
246246 },
247247 }
248+ defaultDefinitionCapabilities = & lsproto.DefinitionClientCapabilities {
249+ LinkSupport : ptrTrue ,
250+ }
251+ defaultTypeDefinitionCapabilities = & lsproto.TypeDefinitionClientCapabilities {
252+ LinkSupport : ptrTrue ,
253+ }
248254)
249255
250256func getCapabilitiesWithDefaults (capabilities * lsproto.ClientCapabilities ) * lsproto.ClientCapabilities {
@@ -278,6 +284,12 @@ func getCapabilitiesWithDefaults(capabilities *lsproto.ClientCapabilities) *lspr
278284 if capabilitiesWithDefaults .Workspace .Configuration == nil {
279285 capabilitiesWithDefaults .Workspace .Configuration = ptrTrue
280286 }
287+ if capabilitiesWithDefaults .TextDocument .Definition == nil {
288+ capabilitiesWithDefaults .TextDocument .Definition = defaultDefinitionCapabilities
289+ }
290+ if capabilitiesWithDefaults .TextDocument .TypeDefinition == nil {
291+ capabilitiesWithDefaults .TextDocument .TypeDefinition = defaultTypeDefinitionCapabilities
292+ }
281293 return & capabilitiesWithDefaults
282294}
283295
@@ -1032,6 +1044,7 @@ func (f *FourslashTest) VerifyBaselineFindAllReferences(
10321044
10331045func (f * FourslashTest ) VerifyBaselineGoToDefinition (
10341046 t * testing.T ,
1047+ includeOriginalSelectionRange bool ,
10351048 markers ... string ,
10361049) {
10371050 referenceLocations := f .lookupMarkersOrGetRanges (t , markers )
@@ -1064,17 +1077,35 @@ func (f *FourslashTest) VerifyBaselineGoToDefinition(
10641077 }
10651078
10661079 var resultAsLocations []lsproto.Location
1080+ var additionalLocation * lsproto.Location
10671081 if result .Locations != nil {
10681082 resultAsLocations = * result .Locations
10691083 } else if result .Location != nil {
10701084 resultAsLocations = []lsproto.Location {* result .Location }
10711085 } else if result .DefinitionLinks != nil {
1072- t .Fatalf ("Unexpected definition response type at marker '%s': %T" , * f .lastKnownMarkerName , result .DefinitionLinks )
1086+ var originRange * lsproto.Range
1087+ resultAsLocations = core .Map (* result .DefinitionLinks , func (link * lsproto.LocationLink ) lsproto.Location {
1088+ if originRange != nil && originRange != link .OriginSelectionRange {
1089+ panic ("multiple different origin ranges in definition links" )
1090+ }
1091+ originRange = link .OriginSelectionRange
1092+ return lsproto.Location {
1093+ Uri : link .TargetUri ,
1094+ Range : link .TargetSelectionRange ,
1095+ }
1096+ })
1097+ if originRange != nil && includeOriginalSelectionRange {
1098+ additionalLocation = & lsproto.Location {
1099+ Uri : lsconv .FileNameToDocumentURI (f .activeFilename ),
1100+ Range : * originRange ,
1101+ }
1102+ }
10731103 }
10741104
10751105 f .addResultToBaseline (t , "goToDefinition" , f .getBaselineForLocationsWithFileContents (resultAsLocations , baselineFourslashLocationsOptions {
1076- marker : markerOrRange ,
1077- markerName : "/*GOTO DEF*/" ,
1106+ marker : markerOrRange ,
1107+ markerName : "/*GOTO DEF*/" ,
1108+ additionalLocation : additionalLocation ,
10781109 }))
10791110 }
10801111}
@@ -1118,7 +1149,12 @@ func (f *FourslashTest) VerifyBaselineGoToTypeDefinition(
11181149 } else if result .Location != nil {
11191150 resultAsLocations = []lsproto.Location {* result .Location }
11201151 } else if result .DefinitionLinks != nil {
1121- t .Fatalf ("Unexpected type definition response type at marker '%s': %T" , * f .lastKnownMarkerName , result .DefinitionLinks )
1152+ resultAsLocations = core .Map (* result .DefinitionLinks , func (link * lsproto.LocationLink ) lsproto.Location {
1153+ return lsproto.Location {
1154+ Uri : link .TargetUri ,
1155+ Range : link .TargetSelectionRange ,
1156+ }
1157+ })
11221158 }
11231159
11241160 f .addResultToBaseline (t , "goToType" , f .getBaselineForLocationsWithFileContents (resultAsLocations , baselineFourslashLocationsOptions {
0 commit comments