Skip to content

Commit 0abc02d

Browse files
Address PR feedback: Enable default LinkSupport and use core.Map
Co-authored-by: DanielRosenwasser <[email protected]>
1 parent 694ad3b commit 0abc02d

14 files changed

+56
-35
lines changed

internal/fourslash/fourslash.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -893,13 +893,12 @@ func (f *FourslashTest) VerifyBaselineGoToDefinition(
893893
resultAsLocations = []lsproto.Location{*result.Location}
894894
} else if result.DefinitionLinks != nil {
895895
// For DefinitionLinks, extract the target locations and optionally set additionalSpan
896-
resultAsLocations = make([]lsproto.Location, len(*result.DefinitionLinks))
897-
for i, link := range *result.DefinitionLinks {
898-
resultAsLocations[i] = lsproto.Location{
896+
resultAsLocations = core.Map(*result.DefinitionLinks, func(link *lsproto.LocationLink) lsproto.Location {
897+
return lsproto.Location{
899898
Uri: link.TargetUri,
900899
Range: link.TargetSelectionRange,
901900
}
902-
}
901+
})
903902
// If there's a single result and it has an origin selection range, use it as additionalSpan
904903
if len(*result.DefinitionLinks) == 1 && (*result.DefinitionLinks)[0].OriginSelectionRange != nil {
905904
additionalSpan = &lsproto.Location{

internal/lsp/server.go

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -881,7 +881,29 @@ func getCompletionClientCapabilities(params *lsproto.InitializeParams) *lsproto.
881881

882882
func getDefinitionClientCapabilities(params *lsproto.InitializeParams) *lsproto.DefinitionClientCapabilities {
883883
if params == nil || params.Capabilities == nil || params.Capabilities.TextDocument == nil {
884-
return nil
884+
// Return default capabilities with LinkSupport enabled
885+
linkSupport := true
886+
return &lsproto.DefinitionClientCapabilities{
887+
LinkSupport: &linkSupport,
888+
}
889+
}
890+
891+
capabilities := params.Capabilities.TextDocument.Definition
892+
if capabilities == nil {
893+
// Return default capabilities with LinkSupport enabled
894+
linkSupport := true
895+
return &lsproto.DefinitionClientCapabilities{
896+
LinkSupport: &linkSupport,
897+
}
898+
}
899+
900+
// If capabilities exist but LinkSupport is not specified, default to true
901+
if capabilities.LinkSupport == nil {
902+
linkSupport := true
903+
return &lsproto.DefinitionClientCapabilities{
904+
LinkSupport: &linkSupport,
905+
}
885906
}
886-
return params.Capabilities.TextDocument.Definition
907+
908+
return capabilities
887909
}

testdata/baselines/reference/fourslash/goToDef/GoToDefinitionDynamicImport3.baseline.jsonc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
// === /foo.ts ===
33

44
// export function bar() { return "bar"; }
5-
// import('./foo').then(({ ba/*GO TO DEFINITION*/[|bar|] }) => undefined);
5+
// import('./foo').then(({ ba/*GO TO DEFINITION*/[|{ textSpan: true |}bar|] }) => undefined);

testdata/baselines/reference/fourslash/goToDef/GoToDefinitionDynamicImport4.baseline.jsonc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
// === /foo.ts ===
33

44
// export function bar() { return "bar"; }
5-
// import('./foo').then(({ ba/*GO TO DEFINITION*/[|bar|] }) => undefined);
5+
// import('./foo').then(({ ba/*GO TO DEFINITION*/[|{ textSpan: true |}bar|] }) => undefined);
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// === goToDefinition ===
22
// === /a.ts ===
33

4-
// declare module "external/*GO TO DEFINITION*/[|"external"|] {
4+
// declare module "external/*GO TO DEFINITION*/[|{ textSpan: true |}"external"|] {
55
// class Foo { }
66
// }

testdata/baselines/reference/fourslash/goToDef/GoToDefinitionMember.baseline.jsonc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
// === /a.ts ===
33

44
// class A {
5-
// private z/*GO TO DEFINITION*/[|z|]: string;
5+
// private z/*GO TO DEFINITION*/[|{ textSpan: true |}z|]: string;
66
// }

testdata/baselines/reference/fourslash/goToDef/GoToDefinitionModifiers.baseline.jsonc

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// === goToDefinition ===
22
// === /a.ts ===
33

4-
// /*GO TO DEFINITION*/export class [|A|] {
4+
// /*GO TO DEFINITION*/export class [|{ textSpan: true |}A|] {
55
//
66
// private z: string;
77
//
@@ -13,7 +13,7 @@
1313
// === goToDefinition ===
1414
// === /a.ts ===
1515

16-
// export class A/*GO TO DEFINITION*/[|A|] {
16+
// export class A/*GO TO DEFINITION*/[|{ textSpan: true |}A|] {
1717
//
1818
// private z: string;
1919
//
@@ -27,7 +27,7 @@
2727

2828
// export class A {
2929
//
30-
// /*GO TO DEFINITION*/private [|z|]: string;
30+
// /*GO TO DEFINITION*/private [|{ textSpan: true |}z|]: string;
3131
//
3232
// readonly x: string;
3333
//
@@ -41,7 +41,7 @@
4141

4242
// export class A {
4343
//
44-
// private z/*GO TO DEFINITION*/[|z|]: string;
44+
// private z/*GO TO DEFINITION*/[|{ textSpan: true |}z|]: string;
4545
//
4646
// readonly x: string;
4747
//
@@ -57,7 +57,7 @@
5757
//
5858
// private z: string;
5959
//
60-
// /*GO TO DEFINITION*/readonly [|x|]: string;
60+
// /*GO TO DEFINITION*/readonly [|{ textSpan: true |}x|]: string;
6161
//
6262
// async a() { }
6363
//
@@ -73,7 +73,7 @@
7373
//
7474
// private z: string;
7575
//
76-
// readonly x/*GO TO DEFINITION*/[|x|]: string;
76+
// readonly x/*GO TO DEFINITION*/[|{ textSpan: true |}x|]: string;
7777
//
7878
// async a() { }
7979
//
@@ -89,7 +89,7 @@
8989
//
9090
// readonly x: string;
9191
//
92-
// /*GO TO DEFINITION*/async [|a|]() { }
92+
// /*GO TO DEFINITION*/async [|{ textSpan: true |}a|]() { }
9393
//
9494
// override b() {}
9595
//
@@ -105,7 +105,7 @@
105105
//
106106
// readonly x: string;
107107
//
108-
// async a/*GO TO DEFINITION*/[|a|]() { }
108+
// async a/*GO TO DEFINITION*/[|{ textSpan: true |}a|]() { }
109109
//
110110
// override b() {}
111111
//
@@ -121,7 +121,7 @@
121121
//
122122
// async a() { }
123123
//
124-
// /*GO TO DEFINITION*/override [|b|]() {}
124+
// /*GO TO DEFINITION*/override [|{ textSpan: true |}b|]() {}
125125
//
126126
// public async c() { }
127127
// }
@@ -138,7 +138,7 @@
138138
//
139139
// async a() { }
140140
//
141-
// override b/*GO TO DEFINITION*/[|b|]() {}
141+
// override b/*GO TO DEFINITION*/[|{ textSpan: true |}b|]() {}
142142
//
143143
// public async c() { }
144144
// }
@@ -155,7 +155,7 @@
155155
//
156156
// override b() {}
157157
//
158-
// /*GO TO DEFINITION*/public async [|c|]() { }
158+
// /*GO TO DEFINITION*/public async [|{ textSpan: true |}c|]() { }
159159
// }
160160
//
161161
// export function foo() { }
@@ -170,7 +170,7 @@
170170
//
171171
// override b() {}
172172
//
173-
// public/*GO TO DEFINITION*/ async [|c|]() { }
173+
// public/*GO TO DEFINITION*/ async [|{ textSpan: true |}c|]() { }
174174
// }
175175
//
176176
// export function foo() { }
@@ -185,7 +185,7 @@
185185
//
186186
// override b() {}
187187
//
188-
// public as/*GO TO DEFINITION*/ync [|c|]() { }
188+
// public as/*GO TO DEFINITION*/ync [|{ textSpan: true |}c|]() { }
189189
// }
190190
//
191191
// export function foo() { }
@@ -200,7 +200,7 @@
200200
//
201201
// override b() {}
202202
//
203-
// public async c/*GO TO DEFINITION*/[|c|]() { }
203+
// public async c/*GO TO DEFINITION*/[|{ textSpan: true |}c|]() { }
204204
// }
205205
//
206206
// export function foo() { }
@@ -215,7 +215,7 @@
215215
// public async c() { }
216216
// }
217217
//
218-
// exp/*GO TO DEFINITION*/ort function [|foo|]() { }
218+
// exp/*GO TO DEFINITION*/ort function [|{ textSpan: true |}foo|]() { }
219219

220220

221221

@@ -227,4 +227,4 @@
227227
// public async c() { }
228228
// }
229229
//
230-
// export function foo/*GO TO DEFINITION*/[|foo|]() { }
230+
// export function foo/*GO TO DEFINITION*/[|{ textSpan: true |}foo|]() { }

testdata/baselines/reference/fourslash/goToDef/GoToDefinitionOverriddenMember6.baseline.jsonc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@
55
// m() {}
66
// }
77
// class Bar extends Foo {
8-
// /*GO TO DEFINITION*/override [|m1|]() {}
8+
// /*GO TO DEFINITION*/override [|{ textSpan: true |}m1|]() {}
99
// }

testdata/baselines/reference/fourslash/goToDef/GoToDefinitionOverriddenMember7.baseline.jsonc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
// === /goToDefinitionOverriddenMember7.ts ===
33

44
// class Foo {
5-
// /*GO TO DEFINITION*/override [|m|]() {}
5+
// /*GO TO DEFINITION*/override [|{ textSpan: true |}m|]() {}
66
// }

testdata/baselines/reference/fourslash/goToDef/GoToDefinitionSatisfiesExpression1.baseline.jsonc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// === /goToDefinitionSatisfiesExpression1.ts ===
33

44
// const STRINGS = {
5-
// /*GO TO DEFINITION*/[|title|]: 'A Title',
5+
// /*GO TO DEFINITION*/[|{ textSpan: true |}title|]: 'A Title',
66
// } satisfies Record<string,string>;
77
//
88
// //somewhere in app

0 commit comments

Comments
 (0)