1
1
import type * as atomIde from "atom-ide-base"
2
2
import Convert from "../convert"
3
3
import * as Utils from "../utils"
4
- import { LanguageClientConnection , Location , ServerCapabilities } from "../languageclient"
4
+ import { LanguageClientConnection , Location , LocationLink , ServerCapabilities } from "../languageclient"
5
5
import { Point , TextEditor , Range } from "atom"
6
6
7
7
/**
@@ -68,10 +68,17 @@ export default class DefinitionAdapter {
68
68
* @param locationResult Either a single {Location} object or an {Array} of {Locations}.
69
69
* @returns An {Array} of {Location}s or {null} if the locationResult was null.
70
70
*/
71
- public static normalizeLocations ( locationResult : Location | Location [ ] ) : Location [ ] | null {
71
+ public static normalizeLocations (
72
+ locationResult : Location | Location [ ] | LocationLink [ ] | null
73
+ ) : Location [ ] | LocationLink [ ] | null {
72
74
if ( locationResult == null ) {
75
+ // TODO use ===
73
76
return null
74
77
}
78
+ // TODO `d.targetRange.start` never becomes `null` according to the types
79
+ if ( isLocationLinkArray ( locationResult ) ) {
80
+ return locationResult . filter ( ( d ) => d . targetRange . start != null )
81
+ }
75
82
return ( Array . isArray ( locationResult ) ? locationResult : [ locationResult ] ) . filter ( ( d ) => d . range . start != null )
76
83
}
77
84
@@ -82,7 +89,18 @@ export default class DefinitionAdapter {
82
89
* @param languageName The name of the language these objects are written in.
83
90
* @returns An {Array} of {Definition}s that represented the converted {Location}s.
84
91
*/
85
- public static convertLocationsToDefinitions ( locations : Location [ ] , languageName : string ) : atomIde . Definition [ ] {
92
+ public static convertLocationsToDefinitions (
93
+ locations : Location [ ] | LocationLink [ ] ,
94
+ languageName : string
95
+ ) : atomIde . Definition [ ] {
96
+ if ( isLocationLinkArray ( locations ) ) {
97
+ return locations . map ( ( d ) => ( {
98
+ path : Convert . uriToPath ( d . targetUri ) ,
99
+ position : Convert . positionToPoint ( d . targetRange . start ) ,
100
+ range : Range . fromObject ( Convert . lsRangeToAtomRange ( d . targetRange ) ) ,
101
+ language : languageName ,
102
+ } ) )
103
+ }
86
104
return locations . map ( ( d ) => ( {
87
105
path : Convert . uriToPath ( d . uri ) ,
88
106
position : Convert . positionToPoint ( d . range . start ) ,
@@ -91,3 +109,7 @@ export default class DefinitionAdapter {
91
109
} ) )
92
110
}
93
111
}
112
+
113
+ function isLocationLinkArray ( value : any ) : value is LocationLink [ ] {
114
+ return Array . isArray ( value ) && LocationLink . is ( value [ 0 ] )
115
+ }
0 commit comments