Skip to content

Commit d753510

Browse files
committed
fix: eliminate casting
1 parent f4f60cd commit d753510

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

lib/adapters/definition-adapter.ts

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,10 @@ export default class DefinitionAdapter {
7474
if (locationResult == null) {
7575
return null
7676
}
77-
return (Array.isArray(locationResult) ? (locationResult as any[]) : [locationResult]).filter(
78-
(d: Location | LocationLink) => ("range" in d ? d.range : d.targetRange).start != null
79-
)
77+
if (this.isLocationLinkArray(locationResult)) {
78+
return locationResult.filter((d) => d.targetRange.start != null)
79+
}
80+
return (Array.isArray(locationResult) ? locationResult : [locationResult]).filter((d) => d.range.start != null)
8081
}
8182

8283
/**
@@ -90,11 +91,22 @@ export default class DefinitionAdapter {
9091
locations: Location[] | LocationLink[],
9192
languageName: string
9293
): atomIde.Definition[] {
93-
return (locations as any[]).map((d: Location | LocationLink) => ({
94-
path: Convert.uriToPath("uri" in d ? d.uri : d.targetUri),
95-
position: Convert.positionToPoint(("range" in d ? d.range : d.targetRange).start),
96-
range: Range.fromObject(Convert.lsRangeToAtomRange("range" in d ? d.range : d.targetRange)),
94+
if (this.isLocationLinkArray(locations)) {
95+
return locations.map((d) => ({
96+
path: Convert.uriToPath(d.targetUri),
97+
position: Convert.positionToPoint(d.targetRange.start),
98+
range: Range.fromObject(Convert.lsRangeToAtomRange(d.targetRange)),
99+
language: languageName,
100+
}))
101+
}
102+
return locations.map((d) => ({
103+
path: Convert.uriToPath(d.uri),
104+
position: Convert.positionToPoint(d.range.start),
105+
range: Range.fromObject(Convert.lsRangeToAtomRange(d.range)),
97106
language: languageName,
98107
}))
99108
}
109+
private static isLocationLinkArray(value: any): value is LocationLink[] {
110+
return Array.isArray(value) && LocationLink.is(value[0])
111+
}
100112
}

0 commit comments

Comments
 (0)